1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* File containing the SimpleBatchUpload class |
4
|
|
|
* |
5
|
|
|
* @copyright (C) 2016, 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
|
|
|
private static $singleton; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @return SimpleBatchUpload |
36
|
|
|
*/ |
37
|
|
|
public static function singleton() { |
38
|
|
|
if ( !isset( self::$singleton ) ) { |
39
|
|
|
self::$singleton = new self(); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
return self::$singleton; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public static function initCallback() { |
|
|
|
|
46
|
|
|
$GLOBALS[ 'wgHooks' ][ 'SetupAfterCache' ][ ] = function() { |
47
|
|
|
self::singleton()->init(); |
48
|
|
|
}; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public function init() { |
|
|
|
|
52
|
|
|
|
53
|
|
|
$GLOBALS[ 'wgExtensionMessagesFiles' ][ 'SimpleBatchUploadAlias' ] = __DIR__ . '/SimpleBatchUpload.alias.php'; |
54
|
|
|
$GLOBALS[ 'wgSpecialPages' ][ 'BatchUpload' ] = '\SimpleBatchUpload\SpecialBatchUpload'; |
55
|
|
|
|
56
|
|
|
$this->registerUploadProvidingModule(); |
57
|
|
|
$this->registerUploadUtilizingModule(); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
View Code Duplication |
protected function registerUploadProvidingModule() { |
|
|
|
|
61
|
|
|
|
62
|
|
|
$moduleDescription = [ |
63
|
|
|
'scripts' => [ '/vendor/blueimp/jquery-file-upload/js/jquery.fileupload.js' ], |
64
|
|
|
'styles' => [ '/vendor/blueimp/jquery-file-upload/css/jquery.fileupload.css' ], |
65
|
|
|
'position' => 'top', |
66
|
|
|
'dependencies' => [ 'jquery.ui.widget' ], |
67
|
|
|
]; |
68
|
|
|
|
69
|
|
|
$this->registerResourceModule( 'ext.SimpleBatchUpload.jquery-file-upload', $moduleDescription, true ); |
70
|
|
|
|
71
|
|
|
} |
72
|
|
|
|
73
|
|
View Code Duplication |
protected function registerUploadUtilizingModule() { |
|
|
|
|
74
|
|
|
|
75
|
|
|
$moduleDescription = [ |
76
|
|
|
'scripts' => [ 'res/ext.SimpleBatchUpload.js' ], |
77
|
|
|
'styles' => [ 'res/ext.SimpleBatchUpload.css' ], |
78
|
|
|
'position' => 'top', |
79
|
|
|
'dependencies' => [ 'ext.SimpleBatchUpload.jquery-file-upload', 'mediawiki.Title' ], |
80
|
|
|
]; |
81
|
|
|
|
82
|
|
|
$this->registerResourceModule( 'ext.SimpleBatchUpload', $moduleDescription, false ); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* @return array |
87
|
|
|
*/ |
88
|
|
|
protected function registerResourceModule( $moduleName, $moduleDefinition, $isDependency = false ) { |
|
|
|
|
89
|
|
|
|
90
|
|
|
if ( file_exists( dirname( __DIR__ ) . '/vendor' ) || !$isDependency ) { |
91
|
|
|
$localBasePath = dirname( __DIR__ ); |
92
|
|
|
$remoteBasePath = $GLOBALS[ 'wgExtensionAssetsPath' ] . '/SimpleBatchUpload'; |
93
|
|
|
} else { |
94
|
|
|
$localBasePath = $GLOBALS[ 'IP' ]; |
95
|
|
|
$remoteBasePath = $GLOBALS[ 'wgScriptPath' ]; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
$GLOBALS[ 'wgResourceModules' ][ $moduleName ] = |
99
|
|
|
array_merge( [ 'localBasePath' => $localBasePath, 'remoteBasePath' => $remoteBasePath ], $moduleDefinition ); |
100
|
|
|
|
101
|
|
|
} |
102
|
|
|
} |
103
|
|
|
|
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: