1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* File containing the SimpleBatchUpload class |
4
|
|
|
* |
5
|
|
|
* @copyright (C) 2016 - 2019, Stephan Gambke |
6
|
|
|
* @license GNU General Public License, version 2 (or any later version) |
7
|
|
|
* |
8
|
|
|
* This software is free software; you can redistribute it and/or |
9
|
|
|
* modify it under the terms of the GNU General Public License |
10
|
|
|
* as published by the Free Software Foundation; either version 2 |
11
|
|
|
* of the License, or (at your option) any later version. |
12
|
|
|
* This software is distributed in the hope that it will be useful, |
13
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
14
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15
|
|
|
* GNU General Public License for more details. |
16
|
|
|
* You should have received a copy of the GNU General Public License |
17
|
|
|
* along with this program; if not, see <http://www.gnu.org/licenses/>. |
18
|
|
|
* |
19
|
|
|
* @file |
20
|
|
|
* @ingroup SimpleBatchUpload |
21
|
|
|
*/ |
22
|
|
|
|
23
|
|
|
namespace SimpleBatchUpload; |
24
|
|
|
|
25
|
|
|
use MediaWiki\MediaWikiServices; |
|
|
|
|
26
|
|
|
use Parser; |
|
|
|
|
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Class ExtensionManager |
30
|
|
|
* |
31
|
|
|
* @package SimpleBatchUpload |
32
|
|
|
*/ |
33
|
|
|
class SimpleBatchUpload { |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @var array Max files could be uploaded per batch |
37
|
|
|
*/ |
38
|
|
|
protected $maxFilesPerBatchConfig; |
39
|
|
|
|
40
|
|
|
public static function initCallback() { |
41
|
|
|
|
42
|
|
|
$simpleBatchUpload = new self(); |
43
|
|
|
$simpleBatchUpload->registerEarlyConfiguration( $GLOBALS ); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @param $targetConfiguration |
49
|
|
|
*/ |
50
|
|
|
public function registerEarlyConfiguration( &$targetConfiguration ){ |
51
|
|
|
$sourceConfiguration = $this->getEarlyConfiguration(); |
52
|
|
|
$this->mergeConfiguration( $sourceConfiguration, $targetConfiguration ); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @param $targetConfiguration |
57
|
|
|
*/ |
58
|
|
|
public function registerLateConfiguration( &$targetConfiguration ){ |
59
|
|
|
$sourceConfiguration = $this->getLateConfiguration(); |
60
|
|
|
$this->mergeConfiguration( $sourceConfiguration, $targetConfiguration ); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @param array $targetConfiguration |
65
|
|
|
*/ |
66
|
|
|
protected function mergeConfiguration( $sourceConfiguration, &$targetConfiguration ) { |
67
|
|
|
foreach ( $sourceConfiguration as $varname => $value ) { |
68
|
|
|
$targetConfiguration[ $varname ] = array_key_exists( $varname, $targetConfiguration )?array_replace_recursive( $targetConfiguration[ $varname ], $value ):$value; |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @return array |
74
|
|
|
*/ |
75
|
|
|
protected function getEarlyConfiguration(): array { |
76
|
|
|
|
77
|
|
|
$configuration = []; |
78
|
|
|
|
79
|
|
|
$configuration[ 'wgExtensionMessagesFiles' ][ 'SimpleBatchUploadAlias' ] = __DIR__ . '/SimpleBatchUpload.alias.php'; |
80
|
|
|
$configuration[ 'wgExtensionMessagesFiles' ][ 'SimpleBatchUploadMagic' ] = __DIR__ . '/SimpleBatchUpload.magic.php'; |
81
|
|
|
|
82
|
|
|
$configuration[ 'wgSpecialPages' ][ 'BatchUpload' ] = '\SimpleBatchUpload\SpecialBatchUpload'; |
83
|
|
|
|
84
|
|
|
$configuration[ 'wgHooks' ][ 'ParserFirstCallInit' ][ 'ext.simplebatchupload' ] = [ $this, 'registerParserFunction' ]; |
85
|
|
|
$configuration[ 'wgHooks' ][ 'MakeGlobalVariablesScript' ][ 'ext.simplebatchupload' ] = [ $this, 'onMakeGlobalVariablesScript' ]; |
86
|
|
|
$configuration[ 'wgHooks' ][ 'SetupAfterCache' ][ 'ext.simplebatchupload' ] = [ $this, 'onSetupAfterCache']; |
87
|
|
|
|
88
|
|
|
return $configuration; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* @return array |
94
|
|
|
*/ |
95
|
|
|
protected function getLateConfiguration(): array { |
96
|
|
|
|
97
|
|
|
$configuration = []; |
98
|
|
|
$configuration[ 'wgResourceModules' ] = $this->getUploadSupportModuleDefinition() + $this->getUploadModuleDefinition(); |
99
|
|
|
|
100
|
|
|
return $configuration; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* @param \Parser $parser |
105
|
|
|
* |
106
|
|
|
* @return bool |
107
|
|
|
* @throws \MWException |
108
|
|
|
*/ |
109
|
|
|
public function registerParserFunction( &$parser ) { |
110
|
|
|
$parser->setFunctionHook( 'batchupload', [ new UploadButtonRenderer(), 'renderParserFunction' ], Parser::SFH_OBJECT_ARGS ); |
111
|
|
|
return true; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* @return array |
117
|
|
|
*/ |
118
|
|
|
protected function getUploadSupportModuleDefinition() { |
119
|
|
|
|
120
|
|
|
return [ 'ext.SimpleBatchUpload.jquery-file-upload' => |
121
|
|
|
|
122
|
|
|
$this->getBasePathsForNonComposerModules() + |
123
|
|
|
|
124
|
|
|
[ |
125
|
|
|
'scripts' => [ 'res/jquery.fileupload.js' ], |
126
|
|
|
'styles' => [ 'res/jquery.fileupload.css' ], |
127
|
|
|
'position' => 'top', |
128
|
|
|
'dependencies' => [ 'jquery.ui.widget' ], |
129
|
|
|
], |
130
|
|
|
]; |
131
|
|
|
|
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* @return array |
136
|
|
|
*/ |
137
|
|
|
protected function getUploadModuleDefinition() { |
138
|
|
|
|
139
|
|
|
$dependencies = [ 'ext.SimpleBatchUpload.jquery-file-upload', 'mediawiki.Title', 'mediawiki.jqueryMsg' ]; |
140
|
|
|
|
141
|
|
|
if ( version_compare( $GLOBALS[ 'wgVersion' ], '1.32.0', '>' ) ) { |
142
|
|
|
$dependencies[] = 'mediawiki.api'; |
143
|
|
|
} else { |
144
|
|
|
$dependencies[] = 'mediawiki.api.edit'; |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
return [ 'ext.SimpleBatchUpload' => |
148
|
|
|
|
149
|
|
|
$this->getBasePathsForNonComposerModules() + |
150
|
|
|
|
151
|
|
|
[ |
152
|
|
|
'scripts' => [ 'res/ext.SimpleBatchUpload.js' ], |
153
|
|
|
'styles' => [ 'res/ext.SimpleBatchUpload.css' ], |
154
|
|
|
'position' => 'top', |
155
|
|
|
'dependencies' => $dependencies, |
156
|
|
|
'messages' => [ 'simplebatchupload-comment', 'simplebatchupload-max-files-alert' ], |
157
|
|
|
], |
158
|
|
|
]; |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
/** |
162
|
|
|
* @return string[] |
163
|
|
|
*/ |
164
|
|
|
protected function getBasePathsForNonComposerModules() { |
165
|
|
|
return [ |
166
|
|
|
'localBasePath' => dirname( __DIR__ ), |
167
|
|
|
'remoteBasePath' => $GLOBALS[ 'wgExtensionAssetsPath' ] . '/SimpleBatchUpload', |
168
|
|
|
]; |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
/** |
172
|
|
|
* @param array &$vars |
173
|
|
|
* @param \OutputPage $out |
|
|
|
|
174
|
|
|
*/ |
175
|
|
|
public function onMakeGlobalVariablesScript( &$vars, $out ) { |
|
|
|
|
176
|
|
|
$vars['simpleBatchUploadMaxFilesPerBatch'] = $this->getMaxFilesPerBatchConfig(); |
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
public function onSetupAfterCache() { |
180
|
|
|
$this->registerLateConfiguration( $GLOBALS ); |
181
|
|
|
} |
182
|
|
|
|
183
|
|
|
/** |
184
|
|
|
* @return array |
185
|
|
|
*/ |
186
|
|
|
public function getMaxFilesPerBatchConfig() { |
187
|
|
|
|
188
|
|
|
if ( $this->maxFilesPerBatchConfig === null ) { |
189
|
|
|
$this->maxFilesPerBatchConfig = $GLOBALS[ 'wgSimpleBatchUploadMaxFilesPerBatch' ]; |
190
|
|
|
} |
191
|
|
|
|
192
|
|
|
return $this->maxFilesPerBatchConfig; |
193
|
|
|
} |
194
|
|
|
} |
195
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths