1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* File containing the SimpleBatchUpload class |
4
|
|
|
* |
5
|
|
|
* @copyright (C) 2016 - 2017, 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
|
|
|
/** |
26
|
|
|
* Class ExtensionManager |
27
|
|
|
* |
28
|
|
|
* @package SimpleBatchUpload |
29
|
|
|
*/ |
30
|
|
|
class SimpleBatchUpload { |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @var integer Max files could be uploaded per batch |
34
|
|
|
*/ |
35
|
|
|
protected $maxFilesPerBatch; |
36
|
|
|
|
37
|
|
|
public static function initCallback() { |
38
|
|
|
|
39
|
|
|
$simpleBatchUpload = new self(); |
40
|
|
|
|
41
|
|
|
$configuration = $simpleBatchUpload->getConfiguration(); |
42
|
|
|
|
43
|
|
|
self::mergeConfiguration( $configuration ); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @param $configuration |
49
|
|
|
*/ |
50
|
|
|
public static function mergeConfiguration( $configuration ) { |
51
|
|
|
foreach ( $configuration as $varname => $value ) { |
52
|
|
|
$GLOBALS[ $varname ] = array_replace_recursive( $GLOBALS[ $varname ], $value ); |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @return array |
58
|
|
|
*/ |
59
|
|
|
public function getConfiguration() { |
60
|
|
|
|
61
|
|
|
$configuration = []; |
62
|
|
|
|
63
|
|
|
$configuration[ 'wgExtensionMessagesFiles' ][ 'SimpleBatchUploadAlias' ] = __DIR__ . '/SimpleBatchUpload.alias.php'; |
64
|
|
|
$configuration[ 'wgExtensionMessagesFiles' ][ 'SimpleBatchUploadMagic' ] = __DIR__ . '/SimpleBatchUpload.magic.php'; |
65
|
|
|
|
66
|
|
|
$configuration[ 'wgSpecialPages' ][ 'BatchUpload' ] = '\SimpleBatchUpload\SpecialBatchUpload'; |
67
|
|
|
|
68
|
|
|
$configuration[ 'wgHooks' ][ 'ParserFirstCallInit' ][ 'ext.simplebatchupload' ] = [ $this, 'registerParserFunction' ]; |
69
|
|
|
$configuration[ 'wgHooks' ][ 'MakeGlobalVariablesScript' ][ 'ext.simplebatchupload' ] = [ $this, 'onMakeGlobalVariablesScript' ]; |
70
|
|
|
$configuration[ 'wgHooks' ][ 'SetupAfterCache' ][ 'ext.simplebatchupload' ] = [ $this, 'onSetupAfterCache']; |
71
|
|
|
|
72
|
|
|
return $configuration; |
73
|
|
|
|
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @param \Parser $parser |
|
|
|
|
78
|
|
|
* |
79
|
|
|
* @return bool |
80
|
|
|
* @throws \MWException |
81
|
|
|
*/ |
82
|
|
|
public function registerParserFunction( &$parser ) { |
83
|
|
|
$parser->setFunctionHook( 'batchupload', [ new UploadButtonRenderer(), 'renderParserFunction' ], SFH_OBJECT_ARGS ); |
|
|
|
|
84
|
|
|
return true; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* @return array |
90
|
|
|
*/ |
91
|
|
|
protected function getUploadSupportModuleDefinition() { |
92
|
|
|
|
93
|
|
|
return [ 'ext.SimpleBatchUpload.jquery-file-upload' => |
94
|
|
|
|
95
|
|
|
$this->getBasePathsForNonComposerModules() + |
96
|
|
|
|
97
|
|
|
[ |
98
|
|
|
'scripts' => [ 'res/jquery.fileupload.js' ], |
99
|
|
|
'styles' => [ 'res/jquery.fileupload.css' ], |
100
|
|
|
'position' => 'top', |
101
|
|
|
'dependencies' => [ 'jquery.ui.widget' ], |
102
|
|
|
], |
103
|
|
|
]; |
104
|
|
|
|
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* @return array |
109
|
|
|
*/ |
110
|
|
|
protected function getUploadModuleDefinition() { |
111
|
|
|
|
112
|
|
|
return [ 'ext.SimpleBatchUpload' => |
113
|
|
|
|
114
|
|
|
$this->getBasePathsForNonComposerModules() + |
115
|
|
|
|
116
|
|
|
[ |
117
|
|
|
'scripts' => [ 'res/ext.SimpleBatchUpload.js' ], |
118
|
|
|
'styles' => [ 'res/ext.SimpleBatchUpload.css' ], |
119
|
|
|
'position' => 'top', |
120
|
|
|
'dependencies' => [ 'ext.SimpleBatchUpload.jquery-file-upload', 'mediawiki.Title', 'mediawiki.api.edit', 'mediawiki.jqueryMsg' ], |
121
|
|
|
'messages' => [ 'simplebatchupload-comment', 'simplebatchupload-max-files-alert' ], |
122
|
|
|
], |
123
|
|
|
]; |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* @return string[] |
128
|
|
|
*/ |
129
|
|
|
protected function getBasePathsForNonComposerModules() { |
130
|
|
|
return [ |
131
|
|
|
'localBasePath' => dirname( __DIR__ ), |
132
|
|
|
'remoteBasePath' => $GLOBALS[ 'wgExtensionAssetsPath' ] . '/SimpleBatchUpload', |
133
|
|
|
]; |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
/** |
137
|
|
|
* @param array $vars |
138
|
|
|
* @param \OutputPage $out |
|
|
|
|
139
|
|
|
*/ |
140
|
|
|
public function onMakeGlobalVariablesScript( &$vars, $out ) { |
|
|
|
|
141
|
|
|
$vars['simpleBatchUploadMaxFilesPerBatch'] = $this->getMaxFilesPerBatch(); |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
public function onSetupAfterCache() { |
145
|
|
|
|
146
|
|
|
$configuration = [ 'wgResourceModules' => $this->getUploadSupportModuleDefinition() + $this->getUploadModuleDefinition() ]; |
147
|
|
|
self::mergeConfiguration( $configuration ); |
148
|
|
|
|
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
/** |
152
|
|
|
* @return integer |
153
|
|
|
*/ |
154
|
|
|
public function getMaxFilesPerBatch() { |
155
|
|
|
global $wgSimpleBatchUploadMaxFilesPerBatch; |
156
|
|
|
return $this->maxFilesPerBatch ? $this->maxFilesPerBatch : $wgSimpleBatchUploadMaxFilesPerBatch; |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
/** |
160
|
|
|
* @param integer $maxFilesPerBatch |
161
|
|
|
*/ |
162
|
|
|
public function setMaxFilesPerBatch( $maxFilesPerBatch ) { |
163
|
|
|
$this->maxFilesPerBatch = $maxFilesPerBatch; |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
} |
167
|
|
|
|
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