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
|
|
|
$configuration = ( new self() )->getConfiguration(); |
40
|
|
|
|
41
|
|
|
foreach ( $configuration as $varname => $value ) { |
42
|
|
|
$GLOBALS[ $varname ] = array_replace_recursive( $GLOBALS[ $varname ], $value ); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @return array |
49
|
|
|
*/ |
50
|
|
|
public function getConfiguration() { |
51
|
|
|
|
52
|
|
|
$configuration = []; |
53
|
|
|
|
54
|
|
|
$configuration[ 'wgExtensionMessagesFiles' ][ 'SimpleBatchUploadAlias' ] = __DIR__ . '/SimpleBatchUpload.alias.php'; |
55
|
|
|
$configuration[ 'wgExtensionMessagesFiles' ][ 'SimpleBatchUploadMagic' ] = __DIR__ . '/SimpleBatchUpload.magic.php'; |
56
|
|
|
|
57
|
|
|
$configuration[ 'wgSpecialPages' ][ 'BatchUpload' ] = '\SimpleBatchUpload\SpecialBatchUpload'; |
58
|
|
|
|
59
|
|
|
$configuration[ 'wgHooks' ][ 'ParserFirstCallInit' ][ 'ext.simplebatchupload' ] = [ $this, 'registerParserFunction' ]; |
60
|
|
|
$configuration[ 'wgHooks' ][ 'MakeGlobalVariablesScript' ][ 'ext.simplebatchupload' ] = [ $this, 'onMakeGlobalVariablesScript' ]; |
61
|
|
|
|
62
|
|
|
$configuration[ 'wgResourceModules' ] = $this->getUploadSupportModuleDefinition() + $this->getUploadModuleDefinition(); |
63
|
|
|
|
64
|
|
|
return $configuration; |
65
|
|
|
|
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @param \Parser $parser |
|
|
|
|
70
|
|
|
* |
71
|
|
|
* @return bool |
72
|
|
|
* @throws \MWException |
73
|
|
|
*/ |
74
|
|
|
public function registerParserFunction( &$parser ) { |
75
|
|
|
$parser->setFunctionHook( 'batchupload', [ new UploadButtonRenderer(), 'renderParserFunction' ], SFH_OBJECT_ARGS ); |
|
|
|
|
76
|
|
|
return true; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @return array |
82
|
|
|
*/ |
83
|
|
|
protected function getUploadSupportModuleDefinition() { |
84
|
|
|
|
85
|
|
|
return [ 'ext.SimpleBatchUpload.jquery-file-upload' => |
86
|
|
|
|
87
|
|
|
$this->getBasePathsForComposerModules() + |
88
|
|
|
|
89
|
|
|
[ |
90
|
|
|
'scripts' => [ '/vendor/blueimp/jquery-file-upload/js/jquery.fileupload.js' ], |
91
|
|
|
'styles' => [ '/vendor/blueimp/jquery-file-upload/css/jquery.fileupload.css' ], |
92
|
|
|
'position' => 'top', |
93
|
|
|
'dependencies' => [ 'jquery.ui.widget' ], |
94
|
|
|
], |
95
|
|
|
]; |
96
|
|
|
|
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* @return array |
101
|
|
|
*/ |
102
|
|
|
protected function getUploadModuleDefinition() { |
103
|
|
|
|
104
|
|
|
return [ 'ext.SimpleBatchUpload' => |
105
|
|
|
|
106
|
|
|
$this->getBasePathsForNonComposerModules() + |
107
|
|
|
|
108
|
|
|
[ |
109
|
|
|
'scripts' => [ 'res/ext.SimpleBatchUpload.js' ], |
110
|
|
|
'styles' => [ 'res/ext.SimpleBatchUpload.css' ], |
111
|
|
|
'position' => 'top', |
112
|
|
|
'dependencies' => [ 'ext.SimpleBatchUpload.jquery-file-upload', 'mediawiki.Title', 'mediawiki.api.edit', 'mediawiki.jqueryMsg' ], |
113
|
|
|
'messages' => [ 'simplebatchupload-comment', 'simplebatchupload-max-files-alert' ], |
114
|
|
|
], |
115
|
|
|
]; |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* @return string[] |
120
|
|
|
*/ |
121
|
|
|
protected function getBasePathsForNonComposerModules() { |
122
|
|
|
return [ |
123
|
|
|
'localBasePath' => dirname( __DIR__ ), |
124
|
|
|
'remoteBasePath' => $GLOBALS[ 'wgExtensionAssetsPath' ] . '/SimpleBatchUpload', |
125
|
|
|
]; |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* @return string[] |
130
|
|
|
*/ |
131
|
|
|
protected function getBasePathsForComposerModules() { |
132
|
|
|
|
133
|
|
|
if ( file_exists( dirname( __DIR__ ) . '/vendor' ) ) { |
134
|
|
|
return $this->getBasePathsForNonComposerModules(); |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
return [ |
138
|
|
|
'localBasePath' => $GLOBALS[ 'IP' ], |
139
|
|
|
'remoteBasePath' => $GLOBALS[ 'wgScriptPath' ], |
140
|
|
|
]; |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
/** |
144
|
|
|
* @param array $vars |
145
|
|
|
* @param \OutputPage $out |
|
|
|
|
146
|
|
|
*/ |
147
|
|
|
public function onMakeGlobalVariablesScript( &$vars, $out ) { |
|
|
|
|
148
|
|
|
$vars['simpleBatchUploadMaxFilesPerBatch'] = $this->getMaxFilesPerBatch(); |
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