Skip to content

Commit

Permalink
Refactor SimpleBatchUpload class
Browse files Browse the repository at this point in the history
  • Loading branch information
s7eph4n committed Jun 6, 2016
1 parent 5078094 commit 5ac601d
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 35 deletions.
2 changes: 1 addition & 1 deletion composer.json
Expand Up @@ -35,7 +35,7 @@
},
"extra": {
"branch-alias": {
"dev-master": "0.x-dev"
"dev-master": "1.x-dev"

}
}
Expand Down
3 changes: 2 additions & 1 deletion res/ext.SimpleBatchUpload.js
Expand Up @@ -19,7 +19,8 @@
* @ingroup SimpleBatchUpload
*/

/** global: jQuery, mediaWiki */
/** global: mediaWiki */
/** global: jQuery */

;( function ( $, mw, undefined ) {

Expand Down
61 changes: 33 additions & 28 deletions src/SimpleBatchUpload.php
Expand Up @@ -42,56 +42,61 @@ public static function singleton() {
return self::$singleton;
}

/**
*
*/
public static function initCallback() {
self::singleton()->init();
$GLOBALS[ 'wgHooks' ][ 'SetupAfterCache' ][ ] = function() {
self::singleton()->init();
};
}

/**
*
*/
public function init() {

$GLOBALS[ 'wgExtensionMessagesFiles' ][ 'SimpleBatchUploadAlias' ] = __DIR__ . '/SimpleBatchUpload.alias.php';
$GLOBALS[ 'wgSpecialPages' ][ 'BatchUpload' ] = '\SimpleBatchUpload\SpecialBatchUpload';

$this->registerUploadModule();
$this->registerUploadProvidingModule();
$this->registerUploadUtilizingModule();
}

protected function registerUploadProvidingModule() {

$moduleDescription = [
'scripts' => [ '/vendor/blueimp/jquery-file-upload/js/jquery.fileupload.js' ],
'styles' => [ '/vendor/blueimp/jquery-file-upload/css/jquery.fileupload.css' ],
'position' => 'top',
'dependencies' => [ 'jquery.ui.widget' ],
];

$this->registerResourceModule( 'ext.SimpleBatchUpload.jquery-file-upload', $moduleDescription, true );

$GLOBALS[ 'wgResourceModules' ][ 'ext.SimpleBatchUpload' ] = [
'localBasePath' => dirname( __DIR__ ),
'remoteExtPath' => $GLOBALS[ 'wgExtensionAssetsPath' ] . '/SimpleBatchUpload',
}

protected function registerUploadUtilizingModule() {

$moduleDescription = [
'scripts' => [ 'res/ext.SimpleBatchUpload.js' ],
'styles' => [ 'res/ext.SimpleBatchUpload.css' ],
'position' => 'top',
'dependencies' => [ 'ext.SimpleBatchUpload.jquery-file-upload', 'mediawiki.Title' ],
];

$this->registerResourceModule( 'ext.SimpleBatchUpload', $moduleDescription, false );
}

protected function registerUploadModule() {
if ( file_exists( '../vendor' ) ) {
/**
* @return array
*/
protected function registerResourceModule( $moduleName, $moduleDefinition, $isDependency = false ) {

if ( file_exists( dirname( __DIR__ ) . '/vendor' ) || !$isDependency ) {
$localBasePath = dirname( __DIR__ );
$remoteBasePath = $GLOBALS[ 'wgExtensionAssetsPath' ] . '/SimpleBatchUpload';
} else {
$localBasePath = $GLOBALS[ 'IP' ];
$remoteBasePath = $GLOBALS[ 'wgScriptPath' ];
}

$GLOBALS[ 'wgResourceModules' ][ 'ext.SimpleBatchUpload.jquery-file-upload' ] = [
'localBasePath' => $localBasePath . '/vendor/blueimp/jquery-file-upload/',
'remoteBasePath' => $remoteBasePath . '/vendor/blueimp/jquery-file-upload/',
$GLOBALS[ 'wgResourceModules' ][ $moduleName ] =
array_merge( [ 'localBasePath' => $localBasePath, 'remoteBasePath' => $remoteBasePath ], $moduleDefinition );

'scripts' => [
'js/jquery.fileupload.js',
],

'styles' => [
'css/jquery.fileupload.css',
],
'position' => 'bottom',
'dependencies' => [ 'jquery.ui.widget' ],
];
}


}
5 changes: 0 additions & 5 deletions src/SpecialBatchUpload.php
Expand Up @@ -55,11 +55,6 @@ protected function getGroupName() {
}

/**
* Execute method
* Checks user permissions
*
* This must be overridden by subclasses; it will be made abstract in a future version
*
* @param null|string $par
* @throws \MWException
*/
Expand Down

0 comments on commit 5ac601d

Please sign in to comment.