jenkins-bot has submitted this change and it was merged. Change subject: Some cleanup and modernization. ......................................................................
Some cleanup and modernization. * Added Finnish (fi) i18n. * Moved the extension description into a translatable message and added a link to the special page to the message. * Replaced dirname( __FILE__ ) with __DIR__. * Removed (incorrect) $wgSpecialPageGroups definition from setup file in favor of defining the getGroup() function in SpecialMultiUpload.php. * Removed a duplicate $wgExtensionMessagesFiles['MultiUploadAlias'] definition and added MultipleUpload (old special page name) as a valid alias to Special:MultiUpload in order to not break link when wikis upgrade to the current version. * Various documentation and coding style tweaks all over the place. * Removed getVersion() from the API module, getVersion() is deprecated and no longer necessary. * Removed seemingly unused and broken numberOfRows() from the SpecialMultiUpload class; the function was returning a global without declaring it as such, hence why it was broken. * Removed some superfluous semicolons. Change-Id: If58206451061985a664473465e66067caa39f3a6 --- M MultiUpload.alias.php M MultiUpload.php M MultiUploadApi.php M SpecialMultiUpload.php M i18n/en.json A i18n/fi.json M resources/ext.multiupload.js M resources/ext.multiupload.shared.js M resources/ext.multiupload.top.js M resources/ext.multiupload.unpack.js 10 files changed, 391 insertions(+), 320 deletions(-) Approvals: Legoktm: Looks good to me, approved Siebrand: Looks good to me, but someone else must approve jenkins-bot: Verified diff --git a/MultiUpload.alias.php b/MultiUpload.alias.php index ee446a5..6296ba5 100644 --- a/MultiUpload.alias.php +++ b/MultiUpload.alias.php @@ -1,7 +1,8 @@ <?php -/* WorkingWiki extension for MediaWiki 1.13 and later - * Copyright (C) 2010 Lee Worden <[email protected]> - * http://lalashan.mcmaster.ca/theobio/projects/index.php/WorkingWiki +/** + * Special page aliases for MultiUpload + * + * Copyright © 2010 Lee Worden <[email protected]> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -17,12 +18,15 @@ * with this program; if not, write to the Free Software Foundation, Inc., * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * http://www.gnu.org/copyleft/gpl.html + * + * @file + * @ingroup Extensions */ +// @codingStandardsIgnoreFile $specialPageAliases = array(); +/** English */ $specialPageAliases['en'] = array( - 'MultiUpload' => array( 'MultiUpload' ), -); - -?> + 'MultiUpload' => array( 'MultiUpload', 'MultipleUpload' ), +); \ No newline at end of file diff --git a/MultiUpload.php b/MultiUpload.php index 55e8f7f..85bc1c3 100644 --- a/MultiUpload.php +++ b/MultiUpload.php @@ -1,6 +1,15 @@ <?php -/* MultiUpload extension for MediaWiki 1.13 and later - * Copyright (C) Lee Worden <[email protected]> +/** + * MultiUpload extension for MediaWiki 1.19 and later + * + * @file + * @ingroup Extensions + * @author Travis Derouin + * @author Lee Worden <[email protected]> + * @version 3.0 + * @date 19 August 2014 + * @copyright Copyright © Lee Worden <[email protected]> + * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -33,7 +42,7 @@ 'version' => '3.0', 'author' => array( 'Travis Derouin', 'Lee Worden' ), 'url' => 'https://www.mediawiki.org/wiki/Extension:MultiUpload', - 'description' => 'Special page to upload multiple files at once', + 'descriptionmsg' => 'multiupload-desc', ); # ===== Configuration variables ===== @@ -42,7 +51,7 @@ $wgMultiUploadInitialNumberOfImportRows = 1; # Can't have a huge number of files to upload on the single form - -# for instance, because of php restrictions on number +# for instance, because of PHP restrictions on number # and length of POST values # $wgMultiUploadMaxImportFilesPerPage = 20; @@ -50,17 +59,13 @@ $wgMultiUploadTempDir = '/tmp'; # ===== Register the special page ===== - $wgSpecialPages['MultiUpload'] = 'SpecialMultiUpload'; $wgSpecialPageGroups['MultipleUpload'] = 'media'; +$wgAutoloadClasses['SpecialMultiUpload'] = __DIR__ . '/SpecialMultiUpload.php'; -$wgAutoloadClasses['SpecialMultiUpload'] - = dirname( __FILE__ ) . '/SpecialMultiUpload.php'; - -# ===== resource loader ===== - +# ===== ResourceLoader ===== $resourceModuleTemplate = array( - 'localBasePath' => dirname( __FILE__ ) . '/resources', + 'localBasePath' => __DIR__ . '/resources', ); $wgResourceModules['special.upload.patched'] = $resourceModuleTemplate + array( @@ -145,19 +150,12 @@ ); # api.php actions - $wgAPIModules['multiupload-unpack'] = 'MultiUploadApiUnpack'; -$wgAutoloadClasses['MultiUploadApiUnpack'] - = dirname( __FILE__ ) . '/MultiUploadApi.php'; +$wgAutoloadClasses['MultiUploadApiUnpack'] = __DIR__ . '/MultiUploadApi.php'; # (potentially) multilingual messages - -$wgExtensionMessagesFiles['MultiUpload'] - = dirname( __FILE__ ) . '/MultiUpload.i18n.php'; -$wgExtensionMessagesFiles['MultiUploadAlias'] - = dirname( __FILE__ ) . '/MultiUpload.alias.php'; +$wgExtensionMessagesFiles['MultiUpload'] = __DIR__ . '/MultiUpload.i18n.php'; $wgMessagesDirs['MultiUpload'] = __DIR__ . '/i18n'; # special page aliases -$wgExtensionMessagesFiles['MultiUploadAlias'] - = dirname( __FILE__ ) . '/MultiUpload.alias.php'; \ No newline at end of file +$wgExtensionMessagesFiles['MultiUploadAlias'] = __DIR__ . '/MultiUpload.alias.php'; \ No newline at end of file diff --git a/MultiUploadApi.php b/MultiUploadApi.php index 8327bb8..35676e2 100644 --- a/MultiUploadApi.php +++ b/MultiUploadApi.php @@ -1,7 +1,9 @@ <?php - -class MultiUploadApiUnpack extends ApiBase -{ +/** + * @file + * @ingroup API + */ +class MultiUploadApiUnpack extends ApiBase { static public $pkgExtensions = array( 'tar', 'tgz', 'tar.gz', 'zip' ); static public $unpackDirBase = 'MultiUpload_unpack_'; @@ -10,119 +12,130 @@ return substr( $string, -$len ) == $extension; } - # given a package (e.g. tar.gz or .zip file), unpack it into a temporary - # location. - # $pkgFile is the file to be unpacked, $srcName is the name the file's - # supposed to have ($pkgFile might be '/tmp/php192ujhK' and $srcName be - # 'package.tar.gz'). - # In case of success, return value is array(true,location_code), where - # location_code is the unique part of the path such that - # tempDir().'/'.$unpackDirBase.location_code is the name of the directory - # where the unpacked files are. - # In case of error, returns array(false, error_message). + /** + * Given a package (e.g. tar.gz or .zip file), unpack it into a temporary + * location. + * + * @param string $pkgFile Path to the file to be unpacked, such as '/tmp/php192ujhK' + * @param string $srcName The name the file's supposed to have (i.e 'package.tar.gz') + * @return array In case of success, return value is array(true, location_code), + * where location_code is the unique part of the path such that + * tempDir().'/'.$unpackDirBase.location_code is the name of the directory + * where the unpacked files are. + * In case of error, returns array(false, error_message). + */ public function unpack( $pkgFile, $srcName ) { global $wgMultiUploadTempDir; + $unpackLocation = realpath( tempnam( $wgMultiUploadTempDir, MultiUploadApiUnpack::$unpackDirBase ) ); $prefix = realpath( $wgMultiUploadTempDir ) . '/' . MultiUploadApiUnpack::$unpackDirBase; - wfDebug( "unpackLocation is $unpackLocation, prefix is $prefix\n" ); + wfDebugLog( 'MultiUploadApi', "unpackLocation is $unpackLocation, prefix is $prefix\n" ); + if ( strncmp( $unpackLocation, $prefix, strlen( $prefix ) ) != 0 ) { - wfDebug( "Temp directory $unpackLocation doesn't start with $prefix!\n" ); - return array( false, "Temp directory " . htmlentities( $unpackLocation ) . - " doesn't start with " . htmlentities( $prefix ) . "!" ); + wfDebugLog( 'MultiUploadApi', "Temp directory $unpackLocation doesn't start with $prefix!\n" ); + return array( false, 'Temp directory ' . htmlentities( $unpackLocation ) . + " doesn't start with " . htmlentities( $prefix ) . '!' ); } + $locationCode = substr( $unpackLocation, strlen( $prefix ) ); - wfDebug( "location code is " . $locationCode . "\n" ); - if ( file_exists( $unpackLocation ) and ! unlink( $unpackLocation ) ) { + wfDebugLog( 'MultiUploadApi', 'location code is ' . $locationCode . "\n" ); + if ( file_exists( $unpackLocation ) && !unlink( $unpackLocation ) ) { return array( false, "Couldn't unlink $unpackLocation" ); } - if ( ! mkdir( $unpackLocation ) ) { + + if ( !mkdir( $unpackLocation ) ) { return array( false, "Couldn't make temp dir $unpackLocation" ); } - if ( ! chmod( $unpackLocation, 0700 ) ) { + + if ( !chmod( $unpackLocation, 0700 ) ) { return array( false, "Couldn't set restricted permissions on temp dir $unpackLocation" ); } + # tar seems trustworthy not to extract files into other locations # TODO (found on Talk:WorkingWiki page): When unpacking uploaded .tar.gz files: # [http://en.wikipedia.org/wiki/Tar_(file_format) Wikipedia says]: GNU tar by default # refuses to create or extract absolute paths, but is still vulnerable to parent-directory - # references. So I would need to check tar contents for ../ before extracting. In practice + # references. So I would need to check tar contents for ../ before extracting. In practice # it seems to be catching this case — but I should trap it explicitly anyway? - if ( $this->suffixMatches( $srcName, '.tgz' ) or $this->suffixMatches( $srcName, '.tar.gz' ) ) { - $unpack_command = 'tar -xz -C ' . escapeshellarg( $unpackLocation ) + if ( $this->suffixMatches( $srcName, '.tgz' ) || $this->suffixMatches( $srcName, '.tar.gz' ) ) { + $unpackCommand = 'tar -xz -C ' . escapeshellarg( $unpackLocation ) . ' -f ' . escapeshellarg( $pkgFile ); - } else if ( $this->suffixMatches( $srcName, '.tar' ) ) { - $unpack_command = 'tar -x -C ' . escapeshellarg( $unpackLocation ) + } elseif ( $this->suffixMatches( $srcName, '.tar' ) ) { + $unpackCommand = 'tar -x -C ' . escapeshellarg( $unpackLocation ) . ' -f ' . escapeshellarg( $pkgFile ); - } - # unzip also rejects files outside of the extraction directory - else if ( $this->suffixMatches( $srcName, '.zip' ) ) { - $unpack_command = 'unzip -q ' . escapeshellarg( $pkgFile ) + } elseif ( $this->suffixMatches( $srcName, '.zip' ) ) { + # unzip also rejects files outside of the extraction directory + $unpackCommand = 'unzip -q ' . escapeshellarg( $pkgFile ) . ' -d ' . escapeshellarg( $unpackLocation ); } else { return array( false, "Unknown filetype $srcName" ); } - system( $unpack_command, $unpack_success ); - if ( $unpack_success != 0 ) { + + system( $unpackCommand, $unpackSuccess ); + + if ( $unpackSuccess != 0 ) { return array( false, - "command “{$unpack_command}” failed with return code $unpack_success" + "command “{$unpackCommand}” failed with return code $unpackSuccess" ); } + return array( true, $locationCode ); } /** - * Search a directory (recursively) for files - * - * @param $dir Path to directory to search - * @return mixed Array of relative filenames on success, or false on failure - */ + * Search a directory (recursively) for files + * + * @param string $dir Path to directory to search + * @return array|bool Array of relative filenames on success, or false on failure + */ public function recursiveFindFiles( $dir ) { if ( is_dir( $dir ) ) { - if ( $dhl = opendir( $dir ) ) { + $dhl = opendir( $dir ); + if ( $dhl ) { $files = array(); while ( ( $file = readdir( $dhl ) ) !== false ) { if ( $file == '.' || $file == '..' ) { continue; } $path = $dir . '/' . $file; - if ( is_dir ( $path ) ) { - $files_within = $this->recursiveFindFiles( $path ); - if ( is_array( $files_within ) and count( $files_within ) > 0 ) { - foreach ( $files_within as $file_within ) { - $files[] = $file . '/' . $file_within; + if ( is_dir( $path ) ) { + $filesWithin = $this->recursiveFindFiles( $path ); + if ( is_array( $filesWithin ) && count( $filesWithin ) > 0 ) { + foreach ( $filesWithin as $fileWithin ) { + $files[] = $file . '/' . $fileWithin; } } - } else if ( is_file( $path ) ) { + } elseif ( is_file( $path ) ) { $files[] = $file; } } return $files; } // else return false; - } else if ( is_file( $dir ) ) { + } elseif ( is_file( $dir ) ) { return array( $dir ); } // else + return false; } - public function recursiveUnlink( $filename, $del_self ) { - if ( ! is_link( $filename ) and is_dir( $filename ) and - ( $handle = opendir( $filename ) ) ) { + public function recursiveUnlink( $filename, $delSelf ) { + if ( !is_link( $filename ) && is_dir( $filename ) && ( $handle = opendir( $filename ) ) ) { while ( ( $entry = readdir( $handle ) ) !== false ) { - if ( $entry !== '.' and $entry !== '..' ) { + if ( $entry !== '.' && $entry !== '..' ) { $this->recursiveUnlink( $filename . '/' . $entry, true ); } } } - if ( $del_self ) { - if ( is_dir( $filename ) and ! is_link( $filename ) ) { + if ( $delSelf ) { + if ( is_dir( $filename ) && !is_link( $filename ) ) { rmdir( $filename ); - } else if ( file_exists( $filename ) ) { + } elseif ( file_exists( $filename ) ) { unlink( $filename ); } } @@ -130,10 +143,10 @@ public function execute() { $params = $this->extractRequestParams(); - error_log( "MultiUploadApiUnpack, params is " . json_encode( $params ) . "\n" ); + wfDebugLog( 'MultiUploadApi', 'MultiUploadApiUnpack, params is ' . json_encode( $params ) . "\n" ); - // we are called with a session key representing a file that's been - // uploaded and stashed. first is to find the physical file. + // We are called with a session key representing a file that's been + // uploaded and stashed. First is to find the physical file. // NOTE: could possibly do this easier using UploadFromBase - when I // wrote this I thought that wasn't working but it actually is. // See https://sourceforge.net/p/workingwiki/bugs/472. @@ -144,34 +157,36 @@ $file = $repo->getLocalReference( $metadata['us_path'] ); $path = $file->getPath(); - // second is to unpack it. Code for that is in ImportQueue. - $packagefilename = $params['filename']; - list( $success, $unpack_code ) = $this->unpack( $path, $packagefilename ); - if ( ! $success ) { + // Second is to unpack it. Code for that is in ImportQueue. + $packageFileName = $params['filename']; + list( $success, $unpackCode ) = $this->unpack( $path, $packageFileName ); + if ( !$success ) { $this->dieUsage( - 'Could not unpack uploaded package: ' . $unpack_code, + 'Could not unpack uploaded package: ' . $unpackCode, 'unknownerror' ); } + global $wgMultiUploadTempDir; - $unpackdir = realpath( $wgMultiUploadTempDir ) . '/' - . MultiUploadApiUnpack::$unpackDirBase - . $unpack_code; + $unpackDir = realpath( $wgMultiUploadTempDir ) . '/' + . MultiUploadApiUnpack::$unpackDirBase + . $unpackCode; + // done with the package - delete it $stash->removeFile( $sessionkey ); - // hmm, that didn't work when I tested it. Make sure it gets deleted. + // hmm, that didn't work when I tested it. Make sure it gets deleted. unlink( $path ); // now to traverse that directory, stash all the files and remember their // names - $filenames = $this->recursiveFindFiles( $unpackdir ); + $filenames = $this->recursiveFindFiles( $unpackDir ); natsort( $filenames ); $filedata = array(); foreach ( $filenames as $filename ) { - $stashed_file = $stash->stashFile( $unpackdir . '/' . $filename, 'file' ); - $filedata[] = array( $stashed_file->getFileKey(), $filename ); + $stashedFile = $stash->stashFile( $unpackDir . '/' . $filename, 'file' ); + $filedata[] = array( $stashedFile->getFileKey(), $filename ); } - $this->recursiveUnlink( $unpackdir, true ); + $this->recursiveUnlink( $unpackDir, true ); $res = array( 'contents' => $filedata, @@ -205,9 +220,5 @@ public function getDescription() { return 'Unpack a zip or tar file before importing its contents.'; - } - - public function getVersion() { - return __CLASS__ . ': (version unknown. By Lee Worden.)'; } } \ No newline at end of file diff --git a/SpecialMultiUpload.php b/SpecialMultiUpload.php index b3334f7..49e5cbd 100644 --- a/SpecialMultiUpload.php +++ b/SpecialMultiUpload.php @@ -1,5 +1,5 @@ <?php -/* +/** * Implements Special:MultiUpload * * This program is free software; you can redistribute it and/or modify @@ -21,24 +21,26 @@ * @ingroup SpecialPage * @ingroup Upload */ +if ( !defined( 'MEDIAWIKI' ) ) { + die(); +} /* use the local, patched version of SpecialUpload.php for now */ global $wgVersion; if ( version_compare( $wgVersion, '1.22', '<' ) ) { $wgAutoloadLocalClasses['SpecialUpload'] - = $wgAutoloadLocalClasses['UploadForm'] - = $wgAutoloadLocalClasses['UploadSourceField'] - = dirname( __FILE__ ) . '/SpecialUpload.1.21.3.php'; + = $wgAutoloadLocalClasses['UploadForm'] + = $wgAutoloadLocalClasses['UploadSourceField'] + = __DIR__ . '/SpecialUpload.1.21.3.php'; } else { $wgAutoloadLocalClasses['SpecialUpload'] - = $wgAutoloadLocalClasses['UploadForm'] - = $wgAutoloadLocalClasses['UploadSourceField'] - = dirname( __FILE__ ) . '/SpecialUpload.php'; + = $wgAutoloadLocalClasses['UploadForm'] + = $wgAutoloadLocalClasses['UploadSourceField'] + = __DIR__ . '/SpecialUpload.php'; } /** * Special page for uploading multiple files in one submission. - * */ class SpecialMultiUpload extends SpecialUpload { @@ -50,6 +52,15 @@ public $mTo; public $mRows; + + /** + * Under which header this special page is listed in Special:SpecialPages + * + * @return string + */ + protected function getGroupName() { + return 'media'; + } protected function handleRequestData() { $request = $this->getRequest(); @@ -71,10 +82,6 @@ $this->showUploadForm( $this->getUploadForm() ); } - protected function numberOfRows() { - return $wgMultiUploadInitialNumberOfImportRows; - } - protected function createRow( $i ) { $row = new UploadRow( $this, $i ); $row->setContext( $this->getContext() ); @@ -93,7 +100,6 @@ # Initialize form $form = new MultiUploadForm( $this, $this->mRows, $this->mTo, $this->getContext() ); $form->setTitle( $this->getTitle() ); - # todo add header, footer, etc. # Check the edit token. # Unlike Special:Upload, no fine distinctions about @@ -103,17 +109,18 @@ } # Add the page-top text. $form->addPreText( $this->msg( 'multiupload-text' )->parse() ); + // @todo FIXME: add footer return $form; } - public function getGlobalFormDescriptors() { + public function getGlobalFormDescriptors() { return array(); } -} ; +} /** - * Subclass of HTMLForm that provides the form section of SpecialMultiUpload + * Subclass of HTMLForm that provides the form section of Special:MultiUpload */ class MultiUploadForm extends UploadForm { protected $mPage; @@ -169,7 +176,7 @@ protected function addJsConfigVars( $out ) { parent::addJsConfigVars( $out ); - $jsconfig = array( + $jsConfig = array( 'wpFirstRowIndex' => $this->mPage->mFrom, 'wpLastRowIndex' => $this->mPage->mTo, 'wgMultiUploadMaxPhpUploadSize' => min( @@ -179,9 +186,9 @@ ); foreach ( $this->mRows as $row ) { - $jsconfig = $jsconfig + $row->jsConfigVars(); + $jsConfig = $jsConfig + $row->jsConfigVars(); } - $out->addJsConfigVars( $jsconfig ); + $out->addJsConfigVars( $jsConfig ); } protected function addRLModules( $out ) { @@ -193,9 +200,9 @@ } /** - * Hoping this gets merged into core, won't have to do it here + * Hoping this gets merged into core, won't have to do it here */ -if ( ! class_exists( 'FauxWebRequestUpload' ) ) { +if ( !class_exists( 'FauxWebRequestUpload' ) ) { /** * A WebRequestUpload that can be faked. */ @@ -205,7 +212,7 @@ * * @param $request WebRequest The associated request * @param array $data Data in the same format that would be found - * in the $_FILES array. If provided, will be used + * in the $_FILES array. If provided, will be used * instead of $_FILES[$key]. */ public function __construct( $request, $data ) { @@ -213,14 +220,14 @@ $this->fileInfo = $data; $this->doesExist = true; } - } ; + } /** * allow DerivativeRequest to include fake uploaded files */ class DerivativeRequestWithFiles extends DerivativeRequest { /** - * @param $key string - * @return WebRequestUpload + * @param string $key + * @return FauxWebRequestUpload|WebRequestUpload */ public function getUpload( $key ) { if ( array_key_exists( $key, $this->data ) ) { @@ -229,12 +236,12 @@ return new WebRequestUpload( $this, $key ); } } - } ; + } } else { /** * If the feature is in MW core, just use it */ - class DerivativeRequestWithFiles extends DerivativeRequest { } ; + class DerivativeRequestWithFiles extends DerivativeRequest { } } class UploadRow extends SpecialUpload { @@ -247,7 +254,7 @@ public $mExtraButtons; /** - * different constructor, let it know which row it is and + * Different constructor, let it know which row it is and * the upload object it belongs to */ public function __construct( $page, $number ) { @@ -263,33 +270,38 @@ /** * UploadBase and various parent class methods expect certain - * form field names that don't have a row number appended. Here - * we create a fake request object that responds to those field - * names. + * form field names that don't have a row number appended. + * Here we create a fake request object that responds to those field names. + * + * @return DerivativeRequestWithFiles */ public function getRequest() { - if ( ! $this->mRequest ) { - $webrequest = $this->mPage->getRequest(); + if ( !$this->mRequest ) { + $webRequest = $this->mPage->getRequest(); $i = $this->mRowNumber; - $values_kept = $values_altered = array(); - foreach ( $webrequest->getValues() + $_FILES as $key => $value ) { + $valuesKept = $valuesAltered = array(); + + foreach ( $webRequest->getValues() + $_FILES as $key => $value ) { $matches = null; - $prefix_match = preg_match( '/^(.*?)(\d+)$/', $key, $matches ); - if ( $prefix_match === false ) { - /// ERROR - } else if ( $prefix_match == 0 ) { + $prefixMatch = preg_match( '/^(.*?)(\d+)$/', $key, $matches ); + if ( $prefixMatch === false ) { + // ERROR + } elseif ( $prefixMatch == 0 ) { // key has no row number - $values_kept[$key] = $value; - } else if ( $matches[2] == $this->mRowNumber ) { + $valuesKept[$key] = $value; + } elseif ( $matches[2] == $this->mRowNumber ) { // key has my row number - $values_altered[$matches[1]] = $value; + $valuesAltered[$matches[1]] = $value; } // else it has some other row number } - # error_log( "request $i : " . json_encode( $values_kept + $values_altered ) ); - $this->mRequest = new DerivativeRequestWithFiles( $webrequest, - $values_kept + $values_altered, - $webrequest->wasPosted() ); + + $this->mRequest = new DerivativeRequestWithFiles( + $webRequest, + $valuesKept + $valuesAltered, + $webRequest->wasPosted() + ); } + return $this->mRequest; } @@ -342,7 +354,7 @@ $this->mHideIgnoreWarning = true; # Special:Upload changes the 'Upload' button to # 'Submit modified file description', and adds two - # additional submit buttons. We add the additional + # additional submit buttons. We add the additional # two as check boxes, and just leave the # 'Upload' button below all rows. $this->mExtraButtons = array( @@ -356,8 +368,8 @@ /** * This is apparently a pretty bad one. * Special:Upload replaces the whole page with an error page - * when this happens. I'll just do it as an error message added - * to the form. But if it happens, you should probably start + * when this happens. I'll just do it as an error message added + * to the form. But if it happens, you should probably start * over clean. */ protected function showFileDeleteError() { @@ -372,18 +384,25 @@ * happens normally when you don't fill all the rows of the form. */ protected function processVerificationError( $details ) { - if ( $details['status'] === UploadBase::EMPTY_FILE - and $this->mDesiredDestName === '' ) { + if ( + $details['status'] === UploadBase::EMPTY_FILE && + $this->mDesiredDestName === '' + ) + { return; } parent::processVerificationError( $details ); } protected function createFormRow() { - return new UploadFormRow( $this, - $this->getFormOptions( $this->mSessionKey, - $this->mHideIgnoreWarning ), - $this->getContext() ); + return new UploadFormRow( + $this, + $this->getFormOptions( + $this->mSessionKey, + $this->mHideIgnoreWarning + ), + $this->getContext() + ); } public function getFormDescriptors() { @@ -402,12 +421,17 @@ $delNotice = ''; // empty by default if ( $desiredTitleObj instanceof Title && !$desiredTitleObj->exists() ) { - LogEventsList::showLogExtract( $delNotice, array( 'delete', 'move' ), + LogEventsList::showLogExtract( + $delNotice, + array( 'delete', 'move' ), $desiredTitleObj, - '', array( 'lim' => 10, - 'conds' => array( "log_action != 'revision'" ), - 'showIfEmpty' => false, - 'msgKey' => array( 'upload-recreate-warning' ) ) + '', + array( + 'lim' => 10, + 'conds' => array( "log_action != 'revision'" ), + 'showIfEmpty' => false, + 'msgKey' => array( 'upload-recreate-warning' ) + ) ); } $preText .= $delNotice; @@ -415,20 +439,23 @@ $preText .= $this->mFormMessage; return $form->descriptor( $preText, $this->mExtraButtons, - $this->mUploadSuccessful ); + $this->mUploadSuccessful ); } protected function shouldProcessUpload() { return ( !$this->mUploadSuccessful && - $this->mPage->mTokenOk && !$this->mCancelUpload && - ( $this->getRequest()->getVal( 'wpDestFile' ) && - $this->mUploadClicked ) ); + $this->mPage->mTokenOk && !$this->mCancelUpload && + ( $this->getRequest()->getVal( 'wpDestFile' ) && + $this->mUploadClicked ) ); } protected function uploadSucceeded() { - $this->mDesiredDestName = $this->mLocalFile->getTitle()->getDBKey(); + $this->mDesiredDestName = $this->mLocalFile->getTitle()->getDBkey(); } + /** + * @return array + */ public function jsConfigVars() { return array( 'wgMultiUploadAutoFill' . $this->mRowNumber => @@ -436,7 +463,7 @@ // if mDestFile was provided in the request, // don't overwrite it by autofilling $this->mDesiredDestName === '' ), - ); + ); } } @@ -450,7 +477,7 @@ # $this->mSourceIds = array(); } - protected function twocolumndescriptor( $text, $section ) { + protected function twoColumnDescriptor( $text, $section ) { return array( 'type' => 'info', 'raw' => true, @@ -471,35 +498,40 @@ . '</div>'; } - protected function uploadSucceededDescriptor( $i, $sectionlabel ) { - return array( - 'UploadedMessage' . $i => - $this->twocolumndescriptor( - $this->uploadedMessage(), - $sectionlabel ), - 'DestFile' . $i => array( - 'type' => 'hidden', - 'default' => $this->mDestFile, - 'section' => $sectionlabel ), - 'UploadSuccessful' . $i => array( - 'type' => 'hidden', - 'default' => true, - 'section' => $sectionlabel ), - ); + protected function uploadSucceededDescriptor( $i, $sectionLabel ) { + return array( + 'UploadedMessage' . $i => $this->twoColumnDescriptor( + $this->uploadedMessage(), + $sectionLabel + ), + 'DestFile' . $i => array( + 'type' => 'hidden', + 'default' => $this->mDestFile, + 'section' => $sectionLabel + ), + 'UploadSuccessful' . $i => array( + 'type' => 'hidden', + 'default' => true, + 'section' => $sectionLabel + ), + ); } public function descriptor( $preText = '', $extraButtons = array(), $uploadSuccessful = false ) { $descriptor = array(); $i = $this->mRow->mRowNumber; - $sectionlabel = 'row-' . $i; + $sectionLabel = 'row-' . $i; + if ( $uploadSuccessful ) { - return $this->uploadSucceededDescriptor( $i, $sectionlabel ); + return $this->uploadSucceededDescriptor( $i, $sectionLabel ); } + $sectionDescriptors = $this->getSourceSection() - + $this->getDescriptionSection() - + $this->getOptionsSection(); + + $this->getDescriptionSection() + + $this->getOptionsSection(); $header = ''; + foreach ( array( $preText, $this->mHeader ) + $this->mSectionHeaders as $head ) { if ( $head != '' ) { if ( $header != '' ) { @@ -508,28 +540,30 @@ $header .= $head; } } + $preTextSection = array(); if ( $header != '' ) { - $preTextSection['Message'] = $this->twocolumndescriptor( - $header, $sectionlabel ); + $preTextSection['Message'] = $this->twoColumnDescriptor( + $header, $sectionLabel ); } - # a couple markers for the javascript animations + + # a couple markers for the JavaScript animations if ( isset( $sectionDescriptors['DestFile'] ) ) { $sectionDescriptors['DestFile']['cssclass'] = 'multiupload-first-to-collapse multiupload-width-exemplar'; } + foreach ( $preTextSection + $sectionDescriptors as $name => $field ) { if ( isset( $field['id'] ) ) { - # put the ids that Special:Upload uses into + # put the IDs that Special:Upload uses into # the class attributes, without numbers appended, - # so that javascript routines can find them that + # so that JavaScript routines can find them that # way if ( isset( $field['cssclass'] ) ) { - $field['cssclass'] .= - ' ' . $field['id']; + $field['cssclass'] .= ' ' . $field['id']; } else { - $field['cssclass'] = $field['id']; + $field['cssclass'] = $field['id']; } - # add the row number to the actual id, for use + # add the row number to the actual ID, for use # as distinct form fields. $field['id'] = $field['id'] . $i; } @@ -545,17 +579,19 @@ $field['cssclass'] .= 'mw-htmlform-section-' . str_replace( '/', '-', $field['section'] ); } - $field['section'] = $sectionlabel; + $field['section'] = $sectionLabel; $descriptor["$name$i"] = $field; } + foreach ( $extraButtons as $key => $msg ) { $descriptor[$key] = array( 'type' => 'check', 'id' => $key, 'label-message' => $msg, - 'section' => $sectionlabel, + 'section' => $sectionLabel, ); } + return $descriptor; } } diff --git a/i18n/en.json b/i18n/en.json index f235e72..9e3d5fd 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -4,18 +4,19 @@ "Lee Worden" ] }, - "multiupload": "MultiUpload", - "multiupload-text": "Use the form below to upload multiple files.\nTo view or search previously uploaded files go to the [[Special:FileList|list of uploaded files]], (re)uploads are also logged in the [[Special:Log/upload|upload log]], deletions in the [[Special:Log/delete|deletion log]].\n\nTo include a file in a page, use a link in one of the following forms:\n* <strong><code><nowiki>[[</nowiki>{{ns:file}}<nowiki>:File.jpg]]</nowiki></code></strong> to use the full version of the file\n* <strong><code><nowiki>[[</nowiki>{{ns:file}}<nowiki>:File.png|200px|thumb|left|alt text]]</nowiki></code></strong> to use a 200 pixel wide rendition in a box in the left margin with \"alt text\" as description\n* <strong><code><nowiki>[[</nowiki>{{ns:media}}<nowiki>:File.ogg]]</nowiki></code></strong> for directly linking to the file without displaying the file.\n\nOnce you select a file, this page will expand, allowing you to select more files before uploading.\n\nTo unpack a <code>.zip</code>, <code>.tar</code>, <code>.tar.gz</code>, or <code>.tgz</code> file and upload the files contained within it, select the package file and then use the \"Unpack\" button that appears.", - "multipleupload": "Upload files", - "multipleupload-toolbox": "Upload multiple files", - "multiupload-submit": "Upload files", - "multiupload-uploadedto": "Uploaded file $1.", - "multiupload-row": "File $1", - "multiupload-unpack-button": "Unpack", - "multiupload-notify-ok": "OK", - "multiupload-upload-package-error": "Error uploading package file", - "multiupload-unpack-error": "Error unpacking package file", - "multiupload-unreadable-package": "Can't read file $1", - "multiupload-http-error": "Couldn't connect to server.", - "multiupload-file-unpacked-from": "File <b>$1</b> from package <b>$2</b>" + "multiupload": "MultiUpload", + "multiupload-desc": "[[Special:MultiUpload|Special page to upload multiple files at once]]", + "multiupload-text": "Use the form below to upload multiple files.\nTo view or search previously uploaded files go to the [[Special:FileList|list of uploaded files]], (re)uploads are also logged in the [[Special:Log/upload|upload log]], deletions in the [[Special:Log/delete|deletion log]].\n\nTo include a file in a page, use a link in one of the following forms:\n* <strong><code><nowiki>[[</nowiki>{{ns:file}}<nowiki>:File.jpg]]</nowiki></code></strong> to use the full version of the file\n* <strong><code><nowiki>[[</nowiki>{{ns:file}}<nowiki>:File.png|200px|thumb|left|alt text]]</nowiki></code></strong> to use a 200 pixel wide rendition in a box in the left margin with \"alt text\" as description\n* <strong><code><nowiki>[[</nowiki>{{ns:media}}<nowiki>:File.ogg]]</nowiki></code></strong> for directly linking to the file without displaying the file.\n\nOnce you select a file, this page will expand, allowing you to select more files before uploading.\n\nTo unpack a <code>.zip</code>, <code>.tar</code>, <code>.tar.gz</code>, or <code>.tgz</code> file and upload the files contained within it, select the package file and then use the \"{{int:multiupload-unpack-button}}\" button that appears.", + "multipleupload": "Upload files", + "multipleupload-toolbox": "Upload multiple files", + "multiupload-submit": "Upload files", + "multiupload-uploadedto": "Uploaded file $1.", + "multiupload-row": "File $1", + "multiupload-unpack-button": "Unpack", + "multiupload-notify-ok": "OK", + "multiupload-upload-package-error": "Error uploading package file", + "multiupload-unpack-error": "Error unpacking package file", + "multiupload-unreadable-package": "Can't read file $1", + "multiupload-http-error": "Couldn't connect to server.", + "multiupload-file-unpacked-from": "File <b>$1</b> from package <b>$2</b>" } diff --git a/i18n/fi.json b/i18n/fi.json new file mode 100644 index 0000000..b1d17c8 --- /dev/null +++ b/i18n/fi.json @@ -0,0 +1,22 @@ +{ + "@metadata": { + "authors": [ + "Jack Phoenix <[email protected]>" + ] + }, + "multiupload": "MultiUpload", + "multiupload-desc": "[[Special:MultiUpload|Toimintosivu useampien tiedostojen tallentamiseen kerralla]]", + "multiupload-text": "Käytä allaolevaa lomaketta useamman tiedoston tallentamiseen kerralla.\nVoit katsella luetteloa aiemmin tallennetuista tiedostoista sivulla [[Special:FileList|tiedostoluettelo]]. Kaikki tallennukset kirjataan myös [[Special:Log/upload|tallennuslokiin]] ja tiedostojen poistot [[Special:Log/delete|poistolokiin]].\n\nJotta saat tiedoston näkymään sivulla, käytä jotakin seuraavista muotoiluista linkkinä siihen:\n* <strong><code><nowiki>[[</nowiki>{{ns:file}}<nowiki>:Tiedosto.jpg]]</nowiki></code></strong> käyttääksesi tiedoston kokonaista versiota\n* <strong><code><nowiki>[[</nowiki>{{ns:file}}<nowiki>:Tiedosto.png|200px|thumb|left|teksti tähän]]</nowiki></code></strong> käyttääksesi tiedostoa sovitettuna 200 kuvapistettä leveään laatikkoon kuvatekstillä \"teksti tähän\"\n* <strong><code><nowiki>[[</nowiki>{{ns:media}}<nowiki>:Tiedosto.ogg]]</nowiki></code></strong> halutessasi suoran linkin tiedostoon ilman että tiedostoa näytetään.\n\nValittuasi tiedoston tämä sivu laajenee ja sallii sinun valita useampia tiedostoja ladattavaksi.\n\nPurkaaksesi tiedoston, jonka tiedostotyyppi on <code>.zip</code>, <code>.tar</code>, <code>.tar.gz</code>, tai <code>.tgz</code> ja ladataksesi sen sisältämät tiedostot, valitse pakettitiedosto ja käytä ilmaantuvaa \"{{int:multiupload-unpack-button}}\" -painiketta.", + "multipleupload": "Tallenna tiedostoja", + "multipleupload-toolbox": "Tallenna useampia tiedostoja", + "multiupload-submit": "Tallenna tiedostot", + "multiupload-uploadedto": "Tallennettiin tiedosto $1.", + "multiupload-row": "Tiedosto $1", + "multiupload-unpack-button": "Pura paketti", + "multiupload-notify-ok": "OK", + "multiupload-upload-package-error": "Virhe pakettitiedostoa tallennettaessa", + "multiupload-unpack-error": "Virhe pakettitiedostoa purettaessa", + "multiupload-unreadable-package": "Tiedostoa $1 ei voi lukea", + "multiupload-http-error": "Palvelimeen ei voitu yhdistää.", + "multiupload-file-unpacked-from": "Tiedosto <b>$1</b> paketista <b>$2</b>" +} diff --git a/resources/ext.multiupload.js b/resources/ext.multiupload.js index 6f1200f..d5b09a2 100644 --- a/resources/ext.multiupload.js +++ b/resources/ext.multiupload.js @@ -5,10 +5,10 @@ var wpLastRowIndex = mw.config.get( 'wpLastRowIndex' ); mw.libs.ext.multiupload.captureTemplate(); - for (var i = wpFirstRowIndex; i <= wpLastRowIndex; ++i ) { + for ( var i = wpFirstRowIndex; i <= wpLastRowIndex; ++i ) { mw.libs.ext.multiupload.setupRow( i ); } - mw.libs.ext.multiupload.maybeAddBlankRow( $('#mw-upload-form') ); + mw.libs.ext.multiupload.maybeAddBlankRow( $( '#mw-upload-form' ) ); mw.libs.ext.multiupload.revealForm(); } ); diff --git a/resources/ext.multiupload.shared.js b/resources/ext.multiupload.shared.js index 74ef589..7a877cb 100644 --- a/resources/ext.multiupload.shared.js +++ b/resources/ext.multiupload.shared.js @@ -15,7 +15,7 @@ toggle = function( $fieldset ) { var collapsed = $fieldset.data( 'collapsed' ); - if ( collapsed ) { + if ( collapsed ) { expand( $fieldset ); } else { collapse( $fieldset ); @@ -41,8 +41,8 @@ mw.libs.ext.multiupload.checkForPackageFile( event.target ); } // else unpack from URL? // this test is because I trigger 'change' in document.ready() - if ( ! mw.libs.ext.multiupload.isBlank( $fieldset ) ) { - expand( $fieldset ); + if ( !mw.libs.ext.multiupload.isBlank( $fieldset ) ) { + expand( $fieldset ); } mw.libs.ext.multiupload.maybeAddBlankRow( $fieldset.parent() ); } ); @@ -80,20 +80,20 @@ } }; -if ( ! mw.libs ) { +if ( !mw.libs ) { mw.libs = {}; } -if ( ! mw.libs.ext ) { +if ( !mw.libs.ext ) { mw.libs.ext = {}; } -if ( ! mw.libs.ext.multiupload ) { +if ( !mw.libs.ext.multiupload ) { mw.libs.ext.multiupload = {}; } $.extend( mw.libs.ext.multiupload, { - checkForPackageFile : function ( input ) { + checkForPackageFile: function ( input ) { // only if HTML5 File API is available - if ( ! ( 'files' in input ) || input.files.length === 0 ) { + if ( !( 'files' in input ) || input.files.length === 0 ) { $( input ).parent().find( '.unpackButton' ).remove(); return; } @@ -129,12 +129,12 @@ }, // row indexes start at 1, sadly - findRow : function ( i ) { + findRow: function ( i ) { return $( $( 'form > fieldset' ).not( '.ww-messages' ).get( i - 1 ) ); }, - setupRow : function( i, $fieldset ) { - if ( ! $fieldset ) { + setupRow: function( i, $fieldset ) { + if ( !$fieldset ) { $fieldset = mw.libs.ext.multiupload.findRow( i ); } $fieldset.addClass( 'row' ); @@ -145,44 +145,44 @@ .appendTo( $fieldset ); } - $fieldset.find( 'input.wpUploadFile,input.wpUploadFileURL' ) .off( 'change' ); window.uploadSetupByIds( - 'wpSourceType'+i+'url', - 'wpUploadFileURL'+i, - 'wpLicense'+i, - 'wpDestFile-warning'+i, - 'wpDestFileWarningAck'+i, - 'wpDestFile'+i, - 'mw-htmlform-row-'+i, - 'mw-license-preview'+i + 'wpSourceType' + i + 'url', + 'wpUploadFileURL' + i, + 'wpLicense' + i, + 'wpDestFile-warning' + i, + 'wpDestFileWarningAck' + i, + 'wpDestFile' + i, + 'mw-htmlform-row-' + i, + 'mw-license-preview' + i ); - var upUrl = document.getElementById( 'wpUploadFileURL'+i ); - var destFile = document.getElementById( 'wpDestFile'+i ); - var upperm = document.getElementById( 'mw-upload-permitted'+i ); - var uppro = document.getElementById( 'mw-upload-prohibited'+i ); - var warningId = 'wpDestFile-warning'+i; - var ackElt = document.getElementsByName( 'wpDestFileWarningAck'+i ); - var configvar = 'wgMultiUploadAutoFill'+i; - if (destFile) { + var upUrl = document.getElementById( 'wpUploadFileURL' + i ); + var destFile = document.getElementById( 'wpDestFile' + i ); + var upperm = document.getElementById( 'mw-upload-permitted' + i ); + var uppro = document.getElementById( 'mw-upload-prohibited' + i ); + var warningId = 'wpDestFile-warning' + i; + var ackElt = document.getElementsByName( 'wpDestFileWarningAck' + i ); + var configvar = 'wgMultiUploadAutoFill' + i; + if ( destFile ) { $fieldset.find( 'input.wpUploadFile,input.wpUploadFileURL' ) .change( function( e ) { - fillDestFilename( this, upUrl, destFile, + fillDestFilename( this, upUrl, destFile, upperm, uppro, warningId, ackElt, configvar ); } ); } - window.setupThumbnail( - 'wpUploadFile'+i, - 'mw-upload-thumbnail'+i, - 'wpSourceTypeFile-error'+i, - 'mw-htmlform-row-'+i + window.setupThumbnail( + 'wpUploadFile' + i, + 'mw-upload-thumbnail' + i, + 'wpSourceTypeFile-error' + i, + 'mw-htmlform-row-' + i ); window.setupSourceFields( - $( '#mw-htmlform-row-'+i+' .mw-htmlform-field-UploadSourceField' ), - 'wpSourceTypeFile-error'+i, - 'wpSourceType'+i ); + $( '#mw-htmlform-row-' + i + ' .mw-htmlform-field-UploadSourceField' ), + 'wpSourceTypeFile-error' + i, + 'wpSourceType' + i + ); setupAnimation( $fieldset ); @@ -201,19 +201,19 @@ } }, -// a fieldset is 'blank' if it has at least one source field, and no source -// field is filled. - isBlank : function( $fieldset ) { + // a fieldset is 'blank' if it has at least one source field, and no source + // field is filled. + isBlank: function( $fieldset ) { var inputs = $fieldset.find( 'input.wpUploadFileUrl,input.wpUploadFile' ); var nfilled = inputs - .filter( function(i) { return this.value ? true: false; } ) + .filter( function( i ) { return this.value ? true: false; } ) .length; var destFile = $fieldset.find( 'input.wpDestFile' ); return ( inputs.length > 0 && nfilled === 0 && ! destFile.val() ); }, -// function to add a blank row at bottom of form when appropriate - maybeAddBlankRow : function ( form ) { + // function to add a blank row at bottom of form when appropriate + maybeAddBlankRow: function ( form ) { lastfs = mw.libs.ext.multiupload.findLastRow( form ); if ( lastfs.length == 1 && mw.libs.ext.multiupload.isBlank( lastfs ) ) { return; @@ -221,7 +221,7 @@ mw.libs.ext.multiupload.addRow( {}, lastfs ); }, - renumberRow : function( $fieldset, i ) { + renumberRow: function( $fieldset, i ) { $fieldset.data( 'row-index', i ); $fieldset.find( '*' ).map( function() { var $this = $( this ); @@ -249,7 +249,7 @@ return $fieldset; }, - findLastRow : function ( form ) { + findLastRow: function ( form ) { var fieldsets; if ( form ) { fieldsets = form.find( '> fieldset' ).not( '.ww-messages' ); @@ -259,9 +259,9 @@ return fieldsets.filter( ':last' ); }, - templateUploadRow : null, + templateUploadRow: null, - addRow : function ( opts, $lastfs ) { + addRow: function ( opts, $lastfs ) { // what is first unused row number? var i = +mw.config.get( 'wpLastRowIndex' ) + 1; // create row and change 'template' to number in attributes @@ -271,7 +271,7 @@ // append the row after the existing rows. $fieldset.hide(); // TODO: make the animation happen sometime after this returns - if ( ! $lastfs || $.isEmpty( $lastfs ) ) { + if ( !$lastfs || $.isEmpty( $lastfs ) ) { $lastfs = mw.libs.ext.multiupload.findLastRow(); } if ( $.isEmpty( $lastfs ) ) { @@ -282,7 +282,7 @@ fixRowNumbers(); mw.libs.ext.multiupload.setupRow( $fieldset.data( 'row-index' ), $fieldset ); mw.libs.ext.multiupload.stuffRow( $fieldset, opts ); - mw.config.set( 'wgMultiUploadAutoFill'+i, true ); + mw.config.set( 'wgMultiUploadAutoFill' + i, true ); // do collapse the fast way if ( mw.libs.ext.multiupload.isBlank( $fieldset ) ) { $fieldset.find( '.multiupload-collapsible' ).hide(); @@ -299,7 +299,7 @@ return $fieldset; }, - stuffRow : function ( $fieldset, opts ) { + stuffRow: function ( $fieldset, opts ) { for ( var name in opts ) { $input = $fieldset.find( ':input.' + name ); var id = name + $fieldset.data( 'row-index' ); @@ -322,9 +322,9 @@ } }, - removeRow : function ( $fieldset ) { + removeRow: function ( $fieldset ) { $fieldset.animate( - { height:'toggle', opacity:'toggle' }, + { height: 'toggle', opacity: 'toggle' }, 500, function () { $fieldset.remove(); @@ -333,9 +333,9 @@ ); }, - // grab the template row and be able to copy it to bottom of the + // grab the template row and be able to copy it to bottom of the // form on demand - captureTemplate : function() { + captureTemplate: function() { $template = $( 'form > fieldset:first-child' ).not( '.ww-messages' ); $template.detach(); mw.libs.ext.multiupload.templateUploadRow = $template; @@ -356,7 +356,7 @@ fixRowNumbers(); }, - revealForm : function() { + revealForm: function() { // make the form visible. $( '#mw-upload-form > *' ).show( 'clip' ); // shut off the spinner. diff --git a/resources/ext.multiupload.top.js b/resources/ext.multiupload.top.js index bbcff5f..6aa8129 100644 --- a/resources/ext.multiupload.top.js +++ b/resources/ext.multiupload.top.js @@ -1,34 +1,33 @@ ( function ( $, mw ) { -if ( ! mw.libs ) { - mw.libs = {}; +if ( !mw.libs ) { + mw.libs = {}; } -if ( ! mw.libs.ext ) { - mw.libs.ext = {}; +if ( !mw.libs.ext ) { + mw.libs.ext = {}; } var spinnerCounter = 0; -// a small portion of js code to be available during page load +// a small portion of JS code to be available during page load mw.libs.ext.multiupload = { - // I want spinners to appear quick, so no waiting for this code to load - createTinySpinner : function( id ) { - return $( '<div>' ).attr( { - id : 'multiupload-tiny-spinner-'+id, - 'class' : 'multiupload-tiny-spinner', - title : '...' - } ); - }, + createTinySpinner: function( id ) { + return $( '<div>' ).attr( { + id: 'multiupload-tiny-spinner-' + id, + 'class': 'multiupload-tiny-spinner', + title: '...' + } ); + }, - injectTinySpinner : function( elt, id ) { - this.removeTinySpinner( id ); - return elt.after( this.createTinySpinner( id ) ); - }, + injectTinySpinner: function( elt, id ) { + this.removeTinySpinner( id ); + return elt.after( this.createTinySpinner( id ) ); + }, - removeTinySpinner : function( id ) { - return $( '#multiupload-tiny-spinner-' + id ).remove(); - }, + removeTinySpinner: function( id ) { + return $( '#multiupload-tiny-spinner-' + id ).remove(); + } }; } )( $, mw ); diff --git a/resources/ext.multiupload.unpack.js b/resources/ext.multiupload.unpack.js index d583908..276a71b 100644 --- a/resources/ext.multiupload.unpack.js +++ b/resources/ext.multiupload.unpack.js @@ -11,10 +11,10 @@ // otherwise, use dialog(). mw.loader.using( 'jquery.ui.dialog', function() { var d_opts = { - buttons : [ { - text : mw.message( 'multiupload-notify-ok' ).plain(), - click : function () { - $(this).dialog( 'close' ); + buttons: [ { + text: mw.message( 'multiupload-notify-ok' ).plain(), + click: function () { + $( this ).dialog( 'close' ); } } ] }; @@ -45,12 +45,12 @@ function unpackOnServer( input, sessionkey, spinnerName ) { mw.loader.using( 'mediawiki.api', function () { - (new mw.Api()).get( { - action : 'multiupload-unpack', - key : sessionkey, - filename : input.files[0].name + ( new mw.Api() ).get( { + action: 'multiupload-unpack', + key: sessionkey, + filename: input.files[0].name }, { - ok : function ( data ) { + ok: function ( data ) { mw.libs.ext.multiupload.removeTinySpinner( spinnerName ); if ( 'multiupload-unpack' in data && 'contents' in data['multiupload-unpack'] ) { reloadForm( input, data['multiupload-unpack']['contents'] ); @@ -59,7 +59,7 @@ notify( 'Error unpacking ' + input.files[0].name ); } }, - err : function ( code, result ) { + err: function ( code, result ) { mw.libs.ext.multiupload.removeTinySpinner( spinnerName ); apiErr( code, result, mw.message( 'multiupload-unpack-error' ).parse() ); } @@ -71,19 +71,19 @@ var packagename = input.files[0].name; var $row = $( input ).parents( 'fieldset.row' ); var projName = $row.find( ':input.wpProjectName' ).val(); - if ( ! projName ) { + if ( !projName ) { projName = ''; } var opts = { - 'wpSourceType' : 'Stash', - 'wpSessionKey' : '', - 'wpUploadFile' : null, - 'wpUploadUrl' : null, - 'wpDestFile' : '', - 'wpProjFilename' : '', - 'wpProjectName' : projName, - 'wpDestTypeTouched' : 0, - 'wpDestPageTouched' : 0 + 'wpSourceType': 'Stash', + 'wpSessionKey': '', + 'wpUploadFile': null, + 'wpUploadUrl': null, + 'wpDestFile': '', + 'wpProjFilename': '', + 'wpProjectName': projName, + 'wpDestTypeTouched': 0, + 'wpDestPageTouched': 0 }; mw.libs.ext.multiupload.removeRow( $row ); for ( var i in filedata ) { @@ -107,28 +107,28 @@ // FormDataTransport looks for these -if ( ! mw.UploadWizard ) { +if ( !mw.UploadWizard ) { mw.UploadWizard = {}; } -if ( ! mw.UploadWizard.config ) { +if ( !mw.UploadWizard.config ) { mw.UploadWizard.config = {}; } var enableChunked = ( mw.config.get( 'wgVersion' ).match( /^1\.2[0-9]\./ ) ? true : false ); $.extend( mw.UploadWizard.config, { - chunkSize : 5 * 1024 * 1024, - enableChunked : enableChunked, - maxPhpUploadSize : mw.config.get( 'wgMultiUploadMaxPhpUploadSize' ) + chunkSize: 5 * 1024 * 1024, + enableChunked: enableChunked, + maxPhpUploadSize: mw.config.get( 'wgMultiUploadMaxPhpUploadSize' ) } ); $.extend( mw.libs.ext.multiupload, { - unpackPackageFile : function ( input, spinnerName ) { + unpackPackageFile: function ( input, spinnerName ) { var upload = { - file : input.files[0], - ui : { setStatus : function ( s ) { } }, - state : undefined + file: input.files[0], + ui: { setStatus : function ( s ) { } }, + state: undefined }; var progressCb = function ( progress ) {}; var doneCb = function ( response ) { @@ -139,12 +139,12 @@ mw.libs.ext.multiupload.removeTinySpinner( spinnerName ); } }; - var transport = new mw.FormDataTransport( + var transport = new mw.FormDataTransport( mw.util.wikiScript( 'api' ), { action: 'upload', stash: 1, - token: $(':input#wpEditToken').val(), + token: $( ':input#wpEditToken' ).val(), format: 'json' }, upload, -- To view, visit https://gerrit.wikimedia.org/r/155010 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: If58206451061985a664473465e66067caa39f3a6 Gerrit-PatchSet: 4 Gerrit-Project: mediawiki/extensions/MultiUpload Gerrit-Branch: master Gerrit-Owner: Jack Phoenix <[email protected]> Gerrit-Reviewer: Jack Phoenix <[email protected]> Gerrit-Reviewer: Legoktm <[email protected]> Gerrit-Reviewer: Lewis Cawte <[email protected]> Gerrit-Reviewer: Siebrand <[email protected]> Gerrit-Reviewer: Worden.lee <[email protected]> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list [email protected] https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
