|
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
|
1 |
|
public function registerEarlyConfiguration( &$targetConfiguration ){ |
|
51
|
1 |
|
$sourceConfiguration = $this->getEarlyConfiguration(); |
|
52
|
1 |
|
$this->mergeConfiguration( $sourceConfiguration, $targetConfiguration ); |
|
53
|
1 |
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* @param $targetConfiguration |
|
57
|
|
|
*/ |
|
58
|
1 |
|
public function registerLateConfiguration( &$targetConfiguration ){ |
|
59
|
1 |
|
$sourceConfiguration = $this->getLateConfiguration(); |
|
60
|
1 |
|
$this->mergeConfiguration( $sourceConfiguration, $targetConfiguration ); |
|
61
|
1 |
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* @param array $targetConfiguration |
|
65
|
|
|
*/ |
|
66
|
2 |
|
protected function mergeConfiguration( $sourceConfiguration, &$targetConfiguration ) { |
|
67
|
2 |
|
foreach ( $sourceConfiguration as $varname => $value ) { |
|
68
|
2 |
|
$targetConfiguration[ $varname ] = array_key_exists( $varname, $targetConfiguration )?array_replace_recursive( $targetConfiguration[ $varname ], $value ):$value; |
|
69
|
|
|
} |
|
70
|
2 |
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* @return array |
|
74
|
|
|
*/ |
|
75
|
1 |
|
protected function getEarlyConfiguration(): array { |
|
76
|
|
|
|
|
77
|
1 |
|
$configuration = []; |
|
78
|
|
|
|
|
79
|
1 |
|
$configuration[ 'wgExtensionMessagesFiles' ][ 'SimpleBatchUploadAlias' ] = __DIR__ . '/SimpleBatchUpload.alias.php'; |
|
80
|
1 |
|
$configuration[ 'wgExtensionMessagesFiles' ][ 'SimpleBatchUploadMagic' ] = __DIR__ . '/SimpleBatchUpload.magic.php'; |
|
81
|
|
|
|
|
82
|
1 |
|
$configuration[ 'wgSpecialPages' ][ 'BatchUpload' ] = '\SimpleBatchUpload\SpecialBatchUpload'; |
|
83
|
|
|
|
|
84
|
1 |
|
$configuration[ 'wgHooks' ][ 'ParserFirstCallInit' ][ 'ext.simplebatchupload' ] = [ $this, 'registerParserFunction' ]; |
|
85
|
1 |
|
$configuration[ 'wgHooks' ][ 'MakeGlobalVariablesScript' ][ 'ext.simplebatchupload' ] = [ $this, 'onMakeGlobalVariablesScript' ]; |
|
86
|
1 |
|
$configuration[ 'wgHooks' ][ 'SetupAfterCache' ][ 'ext.simplebatchupload' ] = [ $this, 'onSetupAfterCache']; |
|
87
|
|
|
|
|
88
|
1 |
|
return $configuration; |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* @return array |
|
94
|
|
|
*/ |
|
95
|
1 |
|
protected function getLateConfiguration(): array { |
|
96
|
|
|
|
|
97
|
1 |
|
$configuration = []; |
|
98
|
1 |
|
$configuration[ 'wgResourceModules' ] = $this->getUploadSupportModuleDefinition() + $this->getUploadModuleDefinition(); |
|
99
|
|
|
|
|
100
|
1 |
|
return $configuration; |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
/** |
|
104
|
|
|
* @param \Parser $parser |
|
105
|
|
|
* |
|
106
|
|
|
* @return bool |
|
107
|
|
|
* @throws \MWException |
|
108
|
|
|
*/ |
|
109
|
1 |
|
public function registerParserFunction( &$parser ) { |
|
110
|
1 |
|
$parser->setFunctionHook( 'batchupload', [ new UploadButtonRenderer(), 'renderParserFunction' ], Parser::SFH_OBJECT_ARGS ); |
|
111
|
1 |
|
return true; |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
|
|
115
|
|
|
/** |
|
116
|
|
|
* @return array |
|
117
|
|
|
*/ |
|
118
|
1 |
|
protected function getUploadSupportModuleDefinition() { |
|
119
|
|
|
|
|
120
|
|
|
return [ 'ext.SimpleBatchUpload.jquery-file-upload' => |
|
121
|
|
|
|
|
122
|
1 |
|
$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
|
1 |
|
protected function getUploadModuleDefinition() { |
|
138
|
|
|
|
|
139
|
1 |
|
$dependencies = [ 'ext.SimpleBatchUpload.jquery-file-upload', 'mediawiki.Title', 'mediawiki.jqueryMsg' ]; |
|
140
|
|
|
|
|
141
|
1 |
|
if ( version_compare( $GLOBALS[ 'wgVersion' ], '1.32.0', '>' ) ) { |
|
142
|
1 |
|
$dependencies[] = 'mediawiki.api'; |
|
143
|
|
|
} else { |
|
144
|
|
|
$dependencies[] = 'mediawiki.api.edit'; |
|
145
|
|
|
} |
|
146
|
|
|
|
|
147
|
|
|
return [ 'ext.SimpleBatchUpload' => |
|
148
|
|
|
|
|
149
|
1 |
|
$this->getBasePathsForNonComposerModules() + |
|
150
|
|
|
|
|
151
|
|
|
[ |
|
152
|
|
|
'scripts' => [ 'res/ext.SimpleBatchUpload.js' ], |
|
153
|
|
|
'styles' => [ 'res/ext.SimpleBatchUpload.css' ], |
|
154
|
1 |
|
'position' => 'top', |
|
155
|
1 |
|
'dependencies' => $dependencies, |
|
156
|
|
|
'messages' => [ 'simplebatchupload-comment', 'simplebatchupload-max-files-alert' ], |
|
157
|
|
|
], |
|
158
|
|
|
]; |
|
159
|
|
|
} |
|
160
|
|
|
|
|
161
|
|
|
/** |
|
162
|
|
|
* @return string[] |
|
163
|
|
|
*/ |
|
164
|
1 |
|
protected function getBasePathsForNonComposerModules() { |
|
165
|
|
|
return [ |
|
166
|
1 |
|
'localBasePath' => dirname( __DIR__ ), |
|
167
|
1 |
|
'remoteBasePath' => $GLOBALS[ 'wgExtensionAssetsPath' ] . '/SimpleBatchUpload', |
|
168
|
|
|
]; |
|
169
|
|
|
} |
|
170
|
|
|
|
|
171
|
|
|
/** |
|
172
|
|
|
* @param array &$vars |
|
173
|
|
|
* @param \OutputPage $out |
|
174
|
|
|
*/ |
|
175
|
1 |
|
public function onMakeGlobalVariablesScript( &$vars, $out ) { |
|
|
|
|
|
|
176
|
1 |
|
$vars['simpleBatchUploadMaxFilesPerBatch'] = $this->getMaxFilesPerBatchConfig(); |
|
177
|
1 |
|
} |
|
178
|
|
|
|
|
179
|
|
|
public function onSetupAfterCache() { |
|
180
|
|
|
$this->registerLateConfiguration( $GLOBALS ); |
|
181
|
|
|
} |
|
182
|
|
|
|
|
183
|
|
|
/** |
|
184
|
|
|
* @return array |
|
185
|
|
|
*/ |
|
186
|
1 |
|
public function getMaxFilesPerBatchConfig() { |
|
187
|
|
|
|
|
188
|
1 |
|
if ( $this->maxFilesPerBatchConfig === null ) { |
|
189
|
1 |
|
$this->maxFilesPerBatchConfig = $GLOBALS[ 'wgSimpleBatchUploadMaxFilesPerBatch' ]; |
|
190
|
|
|
} |
|
191
|
|
|
|
|
192
|
1 |
|
return $this->maxFilesPerBatchConfig; |
|
193
|
|
|
} |
|
194
|
|
|
} |
|
195
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.