r76115 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r76114‎ | r76115 | r76116 >
Date:16:42, 5 November 2010
Author:ashley
Status:deferred
Tags:
Comment:
MultiUpload: follow-up to r76108 and r76109 - coding style tweaks and bump version number from 1.01 to 2.0
Modified paths:
  • /trunk/extensions/MultiUpload/MultiUpload.body.php (modified) (history)
  • /trunk/extensions/MultiUpload/MultiUpload.php (modified) (history)
  • /trunk/extensions/MultiUpload/multiupload.js (modified) (history)

Diff [purge]

Index: trunk/extensions/MultiUpload/MultiUpload.body.php
@@ -1,30 +1,28 @@
22 <?php
33 /**
 4+ * Form for handling multiple uploads and special page.
 5+ *
46 * @file
57 * @ingroup SpecialPage
68 * @ingroup Upload
7 - *
8 - * Form for handling multiple uploads and special page.
9 - *
109 */
1110
1211 class MultipleUpload extends SpecialUpload {
13 - /**
14 - * Constructor : initialise object
15 - * Get data POSTed through the form and assign them to the object
16 - * @param WebRequest $request Data posted.
17 - */
18 -
1912 public $mDesiredDestNames;
2013 public $mUploads;
2114 public $mUploadHasBeenShown;
22 - public $mSessionKeys;
 15+ public $mSessionKeys;
2316
2417 // status messagse for multiple files
2518 public $mWarnings;
2619 public $mSuccesses;
27 - public $mErrors;
 20+ public $mErrors;
2821
 22+ /**
 23+ * Constructor : initialise object
 24+ * Get data POSTed through the form and assign them to the object
 25+ * @param WebRequest $request Data posted.
 26+ */
2927 public function __construct( $request = null ) {
3028 global $wgRequest;
3129
@@ -53,50 +51,52 @@
5452 $this->mUploads = array();
5553
5654 // deal with session keys, if we have some pick the first one, for now
57 - $vals = $request->getValues();
58 - $fromsession = false;
59 - foreach ($vals as $k=>$v) {
60 - if (preg_match("@^wpSessionKey@", $k)) {
61 - $request->setVal('wpSessionKey', $v);
 55+ $vals = $request->getValues();
 56+ $fromsession = false;
 57+ foreach ( $vals as $k => $v ) {
 58+ if ( preg_match( "@^wpSessionKey@", $k ) ) {
 59+ $request->setVal( 'wpSessionKey', $v );
6260 $fromsession = true;
63 - $filenum = preg_replace("@wpSessionKey@", "", $k);
64 - $request->setVal('wpDestFile', $request->getVal('wpDestFile' . $filenum));
 61+ $filenum = preg_replace( "@wpSessionKey@", '', $k );
 62+ $request->setVal( 'wpDestFile', $request->getVal( 'wpDestFile' . $filenum ) );
6563 $up = UploadBase::createFromRequest( $request );
6664 $this->mUploads[] = $up;
67 - $this->mDesiredDestNames[] = $request->getVal('wpDestFile' . $filenum);
 65+ $this->mDesiredDestNames[] = $request->getVal( 'wpDestFile' . $filenum );
6866 }
6967 }
70 -
71 - parent::loadRequest($request);
7268
73 - $this->mUploadClicked = $request->wasPosted()
74 - && ( $request->getCheck( 'wpUpload' )
 69+ parent::loadRequest( $request );
 70+
 71+ $this->mUploadClicked = $request->wasPosted()
 72+ && ( $request->getCheck( 'wpUpload' )
7573 || $request->getCheck( 'wpUploadIgnoreWarning' ) );
7674
77 - if (!$fromsession) {
78 - for ($i = 0; $i < $wgMaxUploadFiles; $i++) {
79 - $this->mDesiredDestNames[$i] = $request->getText( 'wpDestFile'. $i);
80 - if( !$this->mDesiredDestNames[$i] && $request->getFileName( 'wpUploadFile' . $i) !== null )
81 - $this->mDesiredDestNames[$i] = $request->getFileName( 'wpUploadFile' . $i);
82 - $request->setVal('wpUploadFile', $_FILES['wpUploadFile' . $i]);
83 - $request->setVal('wpDestFile', $request->getVal('wpDestFile' . $i));
84 - move_uploaded_file('wpUploadFile' . $i, 'wpUploadFile');
 75+ if ( !$fromsession ) {
 76+ for ( $i = 0; $i < $wgMaxUploadFiles; $i++ ) {
 77+ $this->mDesiredDestNames[$i] = $request->getText( 'wpDestFile'. $i );
 78+ if( !$this->mDesiredDestNames[$i] && $request->getFileName( 'wpUploadFile' . $i ) !== null ) {
 79+ $this->mDesiredDestNames[$i] = $request->getFileName( 'wpUploadFile' . $i );
 80+ }
 81+ $request->setVal( 'wpUploadFile', $_FILES['wpUploadFile' . $i] );
 82+ $request->setVal( 'wpDestFile', $request->getVal( 'wpDestFile' . $i ) );
 83+ move_uploaded_file( 'wpUploadFile' . $i, 'wpUploadFile' );
8584 $_FILES['wpUploadFile'] = $_FILES['wpUploadFile' . $i];
8685 $up = UploadBase::createFromRequest( $request );
87 - $this->mUploads[$i] = $up;
 86+ $this->mUploads[$i] = $up;
8887 }
8988 }
90 - //
9189 $this->mDesiredDestName = $this->mDesiredDestNames[0];
9290 $this->mUpload= $this->mUploads[0];
9391 }
9492
95 - function showUploadForm($form) {
96 - if ($this->mUploadHasBeenShown)
 93+ function showUploadForm( $form ) {
 94+ if ( $this->mUploadHasBeenShown ) {
9795 return;
98 - parent::showUploadForm($form);
 96+ }
 97+ parent::showUploadForm( $form );
9998 $this->mUploadHasBeenShown = true;
10099 }
 100+
101101 /**
102102 * Get an UploadForm instance with title and text properly set.
103103 *
@@ -106,21 +106,23 @@
107107 */
108108 protected function getUploadForm( $message = '', $sessionKeys = array(), $hideIgnoreWarning = false ) {
109109 global $wgOut, $wgMaxUploadFiles;
110 -
 110+
111111 # Initialize form
112112 $options = array(
113 - 'watch' => $this->getWatchCheck(),
114 - 'forreupload' => $this->mForReUpload,
 113+ 'watch' => $this->getWatchCheck(),
 114+ 'forreupload' => $this->mForReUpload,
115115 'hideignorewarning' => $hideIgnoreWarning,
116116 'destwarningack' => (bool)$this->mDestWarningAck,
117117 'texttop' => $this->uploadFormTextTop,
118118 'textaftersummary' => $this->uploadFormTextAfterSummary,
119119 );
120 - foreach ($this->mSessionKeys as $f=>$key)
 120+ foreach ( $this->mSessionKeys as $f => $key ) {
121121 $options['sessionkey'. $f] = $key;
122 - for ($i = 0; $i < $wgMaxUploadFiles; $i++)
 122+ }
 123+ for ( $i = 0; $i < $wgMaxUploadFiles; $i++ ) {
123124 $options['destfile' . $i] = $this->mDesiredDestNames[$i];
124 - $form = new MultiUploadForm($options);
 125+ }
 126+ $form = new MultiUploadForm( $options );
125127 $form->setTitle( $this->getTitle() );
126128
127129 # Check the token, but only if necessary
@@ -130,33 +132,33 @@
131133 }
132134
133135 # Add text to form
134 - $form->addPreText( '<div id="uploadtext">' .
135 - wfMsgExt( 'uploadtext', 'parse', array( $this->mDesiredDestName ) ) .
 136+ $form->addPreText( '<div id="uploadtext">' .
 137+ wfMsgExt( 'uploadtext', 'parse', array( $this->mDesiredDestName ) ) .
136138 '</div>' );
137139 # Add upload error message
138140 $form->addPreText( $message );
139 -
 141+
140142 # Add footer to form
141143 $uploadFooter = wfMsgNoTrans( 'uploadfooter' );
142144 if ( $uploadFooter != '-' && !wfEmptyMsg( 'uploadfooter', $uploadFooter ) ) {
143145 $form->addPostText( '<div id="mw-upload-footer-message">'
144146 . $wgOut->parse( $uploadFooter ) . "</div>\n" );
145147 }
146 -
147 - return $form;
148148
 149+ return $form;
149150 }
150151
151152 /**
152 - * Shows the "view X deleted revivions link""
 153+ * Shows the "view X deleted revivions link"
153154 */
154155 protected function showViewDeletedLinks() {
155156 global $wgMaxUploadFiles;
156 - for ($i = 0; $i < $wgMaxUploadFiles; $i++)
157 - $this->showViewDeletedLinksInner($this->mDesiredDestNames[$i]);
 157+ for ( $i = 0; $i < $wgMaxUploadFiles; $i++ ) {
 158+ $this->showViewDeletedLinksInner( $this->mDesiredDestNames[$i] );
 159+ }
158160 }
159161
160 - protected function showViewDeletedLinksInner($name) {
 162+ protected function showViewDeletedLinksInner( $name ) {
161163 global $wgOut, $wgUser;
162164
163165 $title = Title::makeTitleSafe( NS_FILE, $this->mDesiredDestName );
@@ -186,8 +188,8 @@
187189 * Stashes the upload, shows the main form, but adds an "continue anyway button".
188190 * Also checks whether there are actually warnings to display.
189191 *
190 - * @param array $warnings
191 - * @return boolean true if warnings were displayed, false if there are no
 192+ * @param $warnings Array
 193+ * @return Boolean: true if warnings were displayed, false if there are no
192194 * warnings and the should continue processing like there was no warning
193195 */
194196 protected function showUploadWarning( $warnings ) {
@@ -197,14 +199,13 @@
198200 # mDestWarningAck is set when some javascript has shown the warning
199201 # to the user. mForReUpload is set when the user clicks the "upload a
200202 # new version" link.
201 - if ( !$warnings || ( count( $warnings ) == 1 &&
202 - isset( $warnings['exists'] ) &&
 203+ if ( !$warnings || ( count( $warnings ) == 1 &&
 204+ isset( $warnings['exists'] ) &&
203205 ( $this->mDestWarningAck || $this->mForReUpload ) ) )
204206 {
205207 return false;
206208 }
207209
208 -
209210 $sessionKey = $this->mUpload->stashSession();
210211
211212 $sk = $wgUser->getSkin();
@@ -222,10 +223,11 @@
223224 array( Title::makeTitle( NS_FILE, $args )->getPrefixedText() ) )
224225 . "</li>\n";
225226 } else {
226 - if ( $args === true )
 227+ if ( $args === true ) {
227228 $args = array();
228 - elseif ( !is_array( $args ) )
 229+ } elseif ( !is_array( $args ) ) {
229230 $args = array( $args );
 231+ }
230232 $msg = "\t<li>" . wfMsgExt( $warning, 'parseinline', $args ) . "</li>\n";
231233 }
232234 $warningHtml .= $msg;
@@ -234,59 +236,62 @@
235237 $warningHtml .= wfMsgExt( 'uploadwarning-text', 'parse' );
236238
237239 // store it in an array to show later
238 - $this->mWarnings[] = $warningHtml;
 240+ $this->mWarnings[] = $warningHtml;
239241 $this->mSessionKeys[$this->mUpload->getLocalFile()->getName()] = $sessionKey;
240242
241243 # Indicate that we showed a form
242244 return true;
243245 }
244246
245 - /**
246 - * Show the upload form with error message, but do not stash the file.
247 - *
248 - * @param string $message
249 - */
250 - protected function showUploadError( $message ) {
251 - $this->mErrors[] = '<ul><li>' . $this->mLocalFile->getTitle()->getFullText() . ':' . $message . "</li></ul>\n";
252 - }
 247+ /**
 248+ * Show the upload form with error message, but do not stash the file.
 249+ *
 250+ * @param $message String
 251+ */
 252+ protected function showUploadError( $message ) {
 253+ $this->mErrors[] = '<ul><li>' .
 254+ $this->mLocalFile->getTitle()->getFullText() . ':' .
 255+ $message . "</li></ul>\n";
 256+ }
253257
254 -
255258 /**
256259 * Do the upload.
257260 * Checks are made in SpecialUpload::execute()
258261 */
259262 protected function processUpload() {
260 - global $wgMaxUploadFiles, $wgOut;
 263+ global $wgMaxUploadFiles, $wgOut;
261264
262 - for ($i = 0; $i < $wgMaxUploadFiles; $i++) {
263 - if (isset($this->mUploads[$i])) {
 265+ for ( $i = 0; $i < $wgMaxUploadFiles; $i++ ) {
 266+ if ( isset( $this->mUploads[$i] ) ) {
264267 $this->mUpload = $this->mUploads[$i];
265268 $this->mUploadSuccessful = false; // reset
266269 parent::processUpload();
267 - if ( $this->mUploadSuccessful) {
268 - $this->mSuccesses[] = "<ul><li><a href='" . $this->mLocalFile->getTitle()->getFullURL() . "' target='new'>{$this->mLocalFile->getTitle()->getFullText()}: " . wfMsg('multiupload-fileuploaded') . "</a></li></ul>";
 270+ if ( $this->mUploadSuccessful ) {
 271+ $this->mSuccesses[] = "<ul><li><a href='" . $this->mLocalFile->getTitle()->getFullURL() .
 272+ "' target='new'>{$this->mLocalFile->getTitle()->getFullText()}: " .
 273+ wfMsg( 'multiupload-fileuploaded' ) . '</a></li></ul>';
269274 }
270275 }
271276 }
272277 // clear out the redirects
273 - $wgOut->redirect('');
 278+ $wgOut->redirect( '' );
274279
275280 // tell the good news first
276 - if (sizeof($this->mSuccesses) > 0) {
277 - $wgOut->addHTML('<h2>' . wfMsgHtml( 'successfulupload' ) . "</h2>\n");
278 - $wgOut->addHTML(implode($this->mSuccesses));
 281+ if ( sizeof( $this->mSuccesses ) > 0 ) {
 282+ $wgOut->addHTML( '<h2>' . wfMsgHtml( 'successfulupload' ) . "</h2>\n" );
 283+ $wgOut->addHTML( implode( $this->mSuccesses ) );
279284 }
280285
281286 // the bad news
282 - if (sizeof($this->mErrors) > 0) {
283 - $wgOut->addHTML('<h2>' . wfMsgHtml( 'uploadwarning' ) . "</h2>\n");
284 - $wgOut->addHTML(implode($this->mErrors));
 287+ if ( sizeof( $this->mErrors ) > 0 ) {
 288+ $wgOut->addHTML( '<h2>' . wfMsgHtml( 'uploadwarning' ) . "</h2>\n" );
 289+ $wgOut->addHTML( implode( $this->mErrors ) );
285290 }
286291
287292 // the hopefully recoverable news
288 - if (sizeof($this->mWarnings) > 0 || sizeof($this->mErrors) > 0 ) {
289 - $wgOut->addHTML("<br/><br/><hr/>"); // visually separate the form from the errors/successes
290 - $form = $this->getUploadForm( implode($this->mWarnings), $this->mSessionKeys, /* $hideIgnoreWarning */ true );
 293+ if ( sizeof( $this->mWarnings ) > 0 || sizeof( $this->mErrors ) > 0 ) {
 294+ $wgOut->addHTML( '<br /><br /><hr />' ); // visually separate the form from the errors/successes
 295+ $form = $this->getUploadForm( implode( $this->mWarnings ), $this->mSessionKeys, /* $hideIgnoreWarning */ true );
291296 $form->setSubmitText( wfMsg( 'upload-tryagain' ) );
292297 $form->addButton( 'wpUploadIgnoreWarning', wfMsg( 'ignorewarning' ) );
293298 $form->addButton( 'wpCancelUpload', wfMsg( 'reuploaddesc' ) );
@@ -297,30 +302,30 @@
298303
299304 /**
300305 * Remove a temporarily kept file stashed by saveTempUploadedFile().
301 - * @access private
302 - * @return success
 306+ *
 307+ * @return Boolean: success
303308 */
304309 protected function unsaveUploadedFile() {
305310 global $wgMaxUploadFiles;
306311 $ret = true;
307 - for ($i = 0; $i < $wgMaxUploadFiles; $i++) {
308 - if (isset($this->mUploads[$i])) {
 312+ for ( $i = 0; $i < $wgMaxUploadFiles; $i++ ) {
 313+ if ( isset( $this->mUploads[$i] ) ) {
309314 $this->mUpload = $this->mUploads[$i];
310315 // return false if even one of them failed
311316 $ret = $ret && parent::unsaveUploadedFile();
312317 }
313 - }
 318+ }
314319 return $ret;
315320 }
316321
317 - /**
318 - * Construct a warning and a gallery from an array of duplicate files.
 322+ /**
 323+ * Construct a warning and a gallery from an array of duplicate files.
319324 * Override because the original doesn't say which file is a dupe
320 - */
321 - public static function getDupeWarning( $dupes, $dupetitle = null ) {
322 - $result = parent::getDupeWarning($dupes);
323 - return preg_replace("@<li>@", "<li>{$dupetitle->getText()}", $result);
324 - }
 325+ */
 326+ public static function getDupeWarning( $dupes, $dupetitle = null ) {
 327+ $result = parent::getDupeWarning( $dupes );
 328+ return preg_replace( "@<li>@", "<li>{$dupetitle->getText()}", $result );
 329+ }
325330
326331 }
327332
@@ -329,42 +334,42 @@
330335 */
331336 class MultiUploadForm extends UploadForm {
332337
333 - protected $mDestFiles;
 338+ protected $mDestFiles;
334339 protected $mSessionKeys;
335340
336341 public function __construct( $options = array() ) {
337 -
338 -// basically we want to map filenames to session keys here somehow
 342+ // basically we want to map filenames to session keys here somehow
339343 global $wgMaxUploadFiles;
340344 $this->mDestFiles = array();
341 - for($i = 0; $i < $wgMaxUploadFiles; $i++) {
 345+ for( $i = 0; $i < $wgMaxUploadFiles; $i++ ) {
342346 $this->mDestFiles[$i] = $options['destfile'. $i];
343 - }
 347+ }
344348 $this->mSessionKeys = array();
345 - foreach ($options as $k=>$v) {
346 - if (preg_match("@^sessionkey@", $k))
347 - $this->mSessionKeys[$k] = $v;
 349+ foreach ( $options as $k => $v ) {
 350+ if ( preg_match( "@^sessionkey@", $k ) ) {
 351+ $this->mSessionKeys[$k] = $v;
 352+ }
348353 }
349 - parent::__construct( $options) ;
 354+ parent::__construct( $options );
350355 }
351356
352 -
353357 protected function getDescriptionSection() {
354358 // get the usual one and clear out the DestFile
355 - $descriptor = parent::getDescriptionSection();
356 - unset($descriptor['DestFile']);
 359+ $descriptor = parent::getDescriptionSection();
 360+ unset( $descriptor['DestFile'] );
357361 return $descriptor;
358362 }
 363+
359364 /**
360 - * Get the descriptor of the fieldset that contains the file source
 365+ * Get the descriptor of the fieldset that contains the file source
361366 * selection. The section is 'source'
362 - *
 367+ *
363368 * @return array Descriptor array
364369 */
365370 protected function getSourceSection() {
366371 global $wgLang, $wgUser, $wgRequest, $wgMaxUploadFiles;
367372
368 - if ( sizeof($this->mSessionKeys) > 0) {
 373+ if ( sizeof( $this->mSessionKeys ) > 0) {
369374 $data = array(
370375 'wpSourceType' => array(
371376 'type' => 'hidden',
@@ -372,17 +377,19 @@
373378 ),
374379 );
375380 $index = 0;
376 - foreach ($this->mDestFiles as $k=>$v) {
377 - if ($v == "") continue;
 381+ foreach ( $this->mDestFiles as $k => $v ) {
 382+ if ( $v == '' ) {
 383+ continue;
 384+ }
378385 $data['wpDestFile' . $index] = array(
379386 'type' => 'hidden',
380387 'default' => $v,
381388 );
382389 $data['wpSessionKey' . $index] = array(
383390 'type' => 'hidden',
384 - 'default' => $this->mSessionKeys['sessionkey' . $v],
 391+ 'default' => $this->mSessionKeys['sessionkey' . $v],
385392 );
386 - $index++;
 393+ $index++;
387394 }
388395 return $data;
389396 }
@@ -400,29 +407,29 @@
401408 'raw' => true,
402409 );
403410 }
404 -
405 - for ($i = 0; $i < $wgMaxUploadFiles; $i++) {
 411+
 412+ for ( $i = 0; $i < $wgMaxUploadFiles; $i++ ) {
406413 $descriptor['UploadFile' . $i] = array(
407 - 'class' => 'UploadSourceField',
408 - 'section' => 'source',
409 - 'type' => 'file',
410 - 'id' => 'wpUploadFile' . $i,
411 - 'label-message' => 'sourcefilename',
412 - 'upload-type' => 'File',
413 - 'radio' => &$radio,
414 - 'checked' => $selectedSourceType == 'file',
 414+ 'class' => 'UploadSourceField',
 415+ 'section' => 'source',
 416+ 'type' => 'file',
 417+ 'id' => 'wpUploadFile' . $i,
 418+ 'label-message' => 'sourcefilename',
 419+ 'upload-type' => 'File',
 420+ 'radio' => &$radio,
 421+ 'checked' => $selectedSourceType == 'file',
415422 );
416423 $descriptor['DestFile' . $i] = array(
417 - 'type' => 'text',
418 - 'section' => 'source',
419 - 'id' => 'wpDestFile' . $i,
420 - 'label-message' => 'destfilename',
421 - 'size' => 60,
422 - 'default' => $this->mDestFiles[$i],
423 - # FIXME: hack to work around poor handling of the 'default' option in HTMLForm
424 - 'nodata' => strval( $this->mDestFile ) !== '',
425 - );
426 -
 424+ 'type' => 'text',
 425+ 'section' => 'source',
 426+ 'id' => 'wpDestFile' . $i,
 427+ 'label-message' => 'destfilename',
 428+ 'size' => 60,
 429+ 'default' => $this->mDestFiles[$i],
 430+ # FIXME: hack to work around poor handling of the 'default' option in HTMLForm
 431+ 'nodata' => strval( $this->mDestFile ) !== '',
 432+ );
 433+
427434 if ( $canUploadByUrl ) {
428435 global $wgMaxUploadSize;
429436 $descriptor['UploadFileURL'] = array(
@@ -457,14 +464,10 @@
458465 return $descriptor;
459466 }
460467
461 -
462468 /**
463 - * Add upload JS to $wgOut
464 - *
465 - * @param bool $autofill Whether or not to autofill the destination
466 - * filename text box
 469+ * Add upload JavaScript to $wgOut
467470 */
468 - protected function addUploadJS( ) {
 471+ protected function addUploadJS() {
469472 global $wgScriptPath, $wgMaxUploadFiles, $wgFileExtensions;
470473
471474 global $wgUseAjax, $wgAjaxUploadDestCheck, $wgAjaxLicensePreview, $wgEnableAPI;
@@ -484,13 +487,16 @@
485488 );
486489
487490 $wgOut->addScript( Skin::makeVariablesScript( $scriptVars ) );
488 -
 491+
489492 // For <charinsert> support
490493 $wgOut->addScriptFile( 'edit.js' );
491494
492495 // changed
493496 $wgOut->addScriptFile( "$wgScriptPath/extensions/MultiUpload/multiupload.js" );
494 - $newscriptVars = array('wgMaxUploadFiles' => $wgMaxUploadFiles, 'wgFileExtensions' => $wgFileExtensions);
 497+ $newscriptVars = array(
 498+ 'wgMaxUploadFiles' => $wgMaxUploadFiles,
 499+ 'wgFileExtensions' => $wgFileExtensions
 500+ );
495501 $wgOut->addScript( Skin::makeVariablesScript( $newscriptVars ) );
496502 }
497503
Index: trunk/extensions/MultiUpload/MultiUpload.php
@@ -1,7 +1,4 @@
22 <?php
3 -if ( ! defined( 'MEDIAWIKI' ) )
4 - die();
5 -
63 /**
74 * An extension that allows users to upload multiple files at once.
85 *
@@ -12,6 +9,10 @@
1310 * @link http://www.mediawiki.org/wiki/Extension:MultiUpload Documentation
1411 */
1512
 13+if ( !defined( 'MEDIAWIKI' ) ) {
 14+ die();
 15+}
 16+
1617 // change this parameter to limit the # of files one can upload
1718 $wgMaxUploadFiles = isset( $wgMaxUploadFiles ) ? intval( $wgMaxUploadFiles ) : 5;
1819
@@ -20,13 +21,13 @@
2122 'path' => __FILE__,
2223 'name' => 'MultipleUpload',
2324 'author' => 'Travis Derouin',
24 - 'version' => '1.01',
 25+ 'version' => '2.0',
2526 'descriptionmsg' => 'multipleupload-desc',
2627 'url' => 'http://www.mediawiki.org/wiki/Extension:MultiUpload',
2728 );
2829
2930 // Set up the new special page
30 -$dir = dirname(__FILE__) . '/';
 31+$dir = dirname( __FILE__ ) . '/';
3132 $wgAutoloadClasses['MultipleUpload'] = $dir . 'MultiUpload.body.php';
3233 $wgAutoloadClasses['MultipleUploadForm'] = $dir . 'MultiUpload.body.php';
3334 $wgExtensionMessagesFiles['MultiUpload'] = $dir . 'MultiUpload.i18n.php';
Index: trunk/extensions/MultiUpload/multiupload.js
@@ -1,11 +1,10 @@
 2+var current;
23
3 -var current;
4 -
54 function licenseSelectorCheck() {
6 - var selector = document.getElementById( "wpLicense" );
 5+ var selector = document.getElementById( 'wpLicense' );
76 var selection = selector.options[selector.selectedIndex].value;
87 if( selector.selectedIndex > 0 ) {
9 - if( selection == "" ) {
 8+ if( selection == '' ) {
109 // Option disabled, but browser is broken and doesn't respect this
1110 selector.selectedIndex = 0;
1211 }
@@ -20,81 +19,82 @@
2120 if( e ) {
2221 if( !e.checked ) {
2322 var ein = document.getElementById( 'wpUploadFileURL' );
24 - if(ein)
 23+ if( ein ) {
2524 ein.setAttribute( 'disabled', 'disabled' );
 25+ }
2626 }
2727 }
2828
2929 // For MSIE/Mac: non-breaking spaces cause the <option> not to render.
3030 // But for some reason, setting the text to itself works
31 - var selector = document.getElementById("wpLicense");
32 - if (selector) {
 31+ var selector = document.getElementById( 'wpLicense' );
 32+ if ( selector ) {
3333 var ua = navigator.userAgent;
34 - var isMacIe = (ua.indexOf("MSIE") != -1) && (ua.indexOf("Mac") != -1);
35 - if (isMacIe) {
36 - for (var i = 0; i < selector.options.length; i++) {
 34+ var isMacIe = ( ua.indexOf( 'MSIE' ) != -1 ) && ( ua.indexOf( 'Mac' ) != -1 );
 35+ if ( isMacIe ) {
 36+ for ( var i = 0; i < selector.options.length; i++ ) {
3737 selector.options[i].text = selector.options[i].text;
3838 }
3939 }
4040 }
41 -
 41+
4242 // Toggle source type
4343 var sourceTypeCheckboxes = document.getElementsByName( 'wpSourceType' );
4444 for ( var i = 0; i < sourceTypeCheckboxes.length; i++ ) {
4545 sourceTypeCheckboxes[i].onchange = toggleUploadInputs;
4646 }
47 -
 47+
4848 // AJAX wpDestFile warnings
4949 if ( wgAjaxUploadDestCheck ) {
5050 // Insert an event handler that fetches upload warnings when wpDestFile
5151 // has been changed
52 - for (i = 0; i < wgMaxUploadFiles; i++) {
53 - document.getElementById( 'wpDestFile' + i ).onchange = function ( e ) {
54 - wgUploadWarningObj.checkNow(this.value);
 52+ for ( i = 0; i < wgMaxUploadFiles; i++ ) {
 53+ document.getElementById( 'wpDestFile' + i ).onchange = function( e ) {
 54+ wgUploadWarningObj.checkNow( this.value );
5555 };
5656 }
57 - // Insert a row where the warnings will be displayed just below the
 57+ // Insert a row where the warnings will be displayed just below the
5858 // wpDestFile row
5959 var optionsTable = document.getElementById( 'mw-htmlform-description' ).tBodies[0];
6060 var row = optionsTable.insertRow( 1 );
6161 var td = document.createElement( 'td' );
6262 td.id = 'wpDestFile-warning';
6363 td.colSpan = 2;
64 -
 64+
6565 row.appendChild( td );
6666 }
67 -
 67+
6868 if ( wgAjaxLicensePreview ) {
6969 // License selector check
7070 document.getElementById( 'wpLicense' ).onchange = licenseSelectorCheck;
71 -
 71+
7272 // License selector table row
7373 var wpLicense = document.getElementById( 'wpLicense' );
7474 var wpLicenseRow = wpLicense.parentNode.parentNode;
7575 var wpLicenseTbody = wpLicenseRow.parentNode;
76 -
 76+
7777 var row = document.createElement( 'tr' );
7878 var td = document.createElement( 'td' );
7979 row.appendChild( td );
8080 td = document.createElement( 'td' );
8181 td.id = 'mw-license-preview';
8282 row.appendChild( td );
83 -
 83+
8484 wpLicenseTbody.insertBefore( row, wpLicenseRow.nextSibling );
8585 }
86 -
87 -
 86+
8887 // fillDestFile setup
89 - for ( var i = 0; i < wgUploadSourceIds.length; i++ )
90 - document.getElementById( wgUploadSourceIds[i] ).onchange = function (e) {
 88+ for ( var i = 0; i < wgUploadSourceIds.length; i++ ) {
 89+ document.getElementById( wgUploadSourceIds[i] ).onchange = function( e ) {
9190 fillDestFilename( this.id );
9291 };
 92+ }
9393 }
9494
9595 /**
9696 * Iterate over all upload source fields and disable all except the selected one.
97 - *
98 - * @param enabledId The id of the selected radio button
 97+ *
 98+ * @param enabledId The id of the selected radio button
9999 * @return emptiness
100100 */
101101 function toggleUploadInputs() {
@@ -105,28 +105,31 @@
106106 } else {
107107 // Older browsers don't support getElementsByClassName
108108 rows = new Array();
109 -
 109+
110110 var allRows = document.getElementsByTagName( 'tr' );
111111 for ( var i = 0; i < allRows.length; i++ ) {
112 - if ( allRows[i].className == 'mw-htmlform-field-UploadSourceField' )
 112+ if ( allRows[i].className == 'mw-htmlform-field-UploadSourceField' ) {
113113 rows.push( allRows[i] );
 114+ }
114115 }
115116 }
116 -
 117+
117118 for ( var i = 0; i < rows.length; i++ ) {
118119 var inputs = rows[i].getElementsByTagName( 'input' );
119 -
 120+
120121 // Check if this row is selected
121122 var isChecked = true; // Default true in case wpSourceType is not found
122123 for ( var j = 0; j < inputs.length; j++ ) {
123 - if ( inputs[j].name == 'wpSourceType' )
 124+ if ( inputs[j].name == 'wpSourceType' ) {
124125 isChecked = inputs[j].checked;
 126+ }
125127 }
126 -
 128+
127129 // Disable all unselected rows
128130 for ( var j = 0; j < inputs.length; j++ ) {
129 - if ( inputs[j].type != 'radio')
 131+ if ( inputs[j].type != 'radio' ) {
130132 inputs[j].disabled = !isChecked;
 133+ }
131134 }
132135 }
133136 }
@@ -138,24 +141,28 @@
139142 'delay': 500, // ms
140143 'timeoutID': false,
141144
142 - 'keypress': function () {
143 - if ( !wgAjaxUploadDestCheck || !sajax_init_object() ) return;
 145+ 'keypress': function() {
 146+ if ( !wgAjaxUploadDestCheck || !sajax_init_object() ) {
 147+ return;
 148+ }
144149
145150 // Find file to upload
146 - var destFile = document.getElementById('wpDestFile' + current);
 151+ var destFile = document.getElementById( 'wpDestFile' + current );
147152 var warningElt = document.getElementById( 'wpDestFile-warning' );
148 - if ( !destFile || !warningElt ) return ;
 153+ if ( !destFile || !warningElt ) {
 154+ return;
 155+ }
149156
150 - this.nameToCheck = destFile.value ;
 157+ this.nameToCheck = destFile.value;
151158
152159 // Clear timer
153160 if ( this.timeoutID ) {
154161 window.clearTimeout( this.timeoutID );
155162 }
156163 // Check response cache
157 - for (cached in this.responseCache) {
158 - if (this.nameToCheck == cached) {
159 - this.setWarning(this.responseCache[this.nameToCheck]);
 164+ for ( cached in this.responseCache ) {
 165+ if ( this.nameToCheck == cached ) {
 166+ this.setWarning( this.responseCache[this.nameToCheck] );
160167 return;
161168 }
162169 }
@@ -163,8 +170,10 @@
164171 this.timeoutID = window.setTimeout( 'wgUploadWarningObj.timeout()', this.delay );
165172 },
166173
167 - 'checkNow': function (fname) {
168 - if ( !wgAjaxUploadDestCheck || !sajax_init_object() ) return;
 174+ 'checkNow': function( fname ) {
 175+ if ( !wgAjaxUploadDestCheck || !sajax_init_object() ) {
 176+ return;
 177+ }
169178 if ( this.timeoutID ) {
170179 window.clearTimeout( this.timeoutID );
171180 }
@@ -173,33 +182,35 @@
174183 },
175184
176185 'timeout' : function() {
177 - if ( !wgAjaxUploadDestCheck || !sajax_init_object() ) return;
 186+ if ( !wgAjaxUploadDestCheck || !sajax_init_object() ) {
 187+ return;
 188+ }
178189 injectSpinner( document.getElementById( 'wpDestFile' + current ), 'destcheck' );
179190
180191 // Get variables into local scope so that they will be preserved for the
181192 // anonymous callback. fileName is copied so that multiple overlapping
182 - // ajax requests can be supported.
 193+ // AJAX requests can be supported.
183194 var obj = this;
184195 var fileName = this.nameToCheck;
185196 sajax_do_call( 'SpecialUpload::ajaxGetExistsWarning', [this.nameToCheck],
186 - function (result) {
187 - obj.processResult(result, fileName)
 197+ function( result ) {
 198+ obj.processResult( result, fileName );
188199 }
189200 );
190201 },
191202
192 - 'processResult' : function (result, fileName) {
 203+ 'processResult' : function( result, fileName ) {
193204 removeSpinner( 'destcheck' );
194205 this.setWarning(result.responseText);
195206 this.responseCache[fileName] = result.responseText;
196207 },
197208
198 - 'setWarning' : function (warning) {
 209+ 'setWarning' : function( warning ) {
199210 var warningElt = document.getElementById( 'wpDestFile-warning' );
200211 var ackElt = document.getElementsByName( 'wpDestFileWarningAck' );
201212
202 - this.setInnerHTML(warningElt, warning);
203 -
 213+ this.setInnerHTML( warningElt, warning );
 214+
204215 // Set a value in the form indicating that the warning is acknowledged and
205216 // doesn't need to be redisplayed post-upload
206217 if ( warning == '' || warning == '&nbsp;' ) {
@@ -209,46 +220,49 @@
210221 }
211222
212223 },
213 - 'setInnerHTML' : function (element, text) {
 224+ 'setInnerHTML' : function( element, text ) {
214225 // Check for no change to avoid flicker in IE 7
215 - if (element.innerHTML != text) {
 226+ if ( element.innerHTML != text ) {
216227 element.innerHTML = text;
217228 }
218229 }
219230 }
220231
221 -function fillDestFilename(id) {
222 - if (!wgUploadAutoFill) {
 232+function fillDestFilename( id ) {
 233+ if ( !wgUploadAutoFill ) {
223234 return;
224235 }
225 - if (!document.getElementById) {
 236+ if ( !document.getElementById ) {
226237 return;
227238 }
228239 // Remove any previously flagged errors
229240 var e = document.getElementById( 'mw-upload-permitted' );
230 - if( e ) e.className = '';
 241+ if( e ) {
 242+ e.className = '';
 243+ }
231244
232245 var e = document.getElementById( 'mw-upload-prohibited' );
233 - if( e ) e.className = '';
 246+ if( e ) {
 247+ e.className = '';
 248+ }
234249
235 -
236 - var path = document.getElementById(id).value;
 250+ var path = document.getElementById( id ).value;
237251 // Find trailing part
238 - var slash = path.lastIndexOf('/');
239 - var backslash = path.lastIndexOf('\\');
 252+ var slash = path.lastIndexOf( '/' );
 253+ var backslash = path.lastIndexOf( '\\' );
240254 var fname;
241 - if (slash == -1 && backslash == -1) {
 255+ if ( slash == -1 && backslash == -1 ) {
242256 fname = path;
243 - } else if (slash > backslash) {
244 - fname = path.substring(slash+1, 10000);
 257+ } else if ( slash > backslash ) {
 258+ fname = path.substring( slash + 1, 10000 );
245259 } else {
246 - fname = path.substring(backslash+1, 10000);
 260+ fname = path.substring( backslash + 1, 10000 );
247261 }
248262
249263 // Clear the filename if it does not have a valid extension.
250 - // URLs are less likely to have a useful extension, so don't include them in the
 264+ // URLs are less likely to have a useful extension, so don't include them in the
251265 // extension check.
252 - current= id.replace(/[^0-9]/g, "");
 266+ current = id.replace( /[^0-9]/g, '' );
253267 if( wgFileExtensions && id != 'wpUploadFileURL' ) {
254268 var found = false;
255269 if( fname.lastIndexOf( '.' ) != -1 ) {
@@ -263,16 +277,22 @@
264278 if( !found ) {
265279 // Not a valid extension
266280 // Clear the upload and set mw-upload-permitted to error
267 - document.getElementById(id).value = '';
 281+ document.getElementById( id ).value = '';
268282 var e = document.getElementById( 'mw-upload-permitted' );
269 - if( e ) e.className = 'error';
 283+ if( e ) {
 284+ e.className = 'error';
 285+ }
270286
271287 var e = document.getElementById( 'mw-upload-prohibited' );
272 - if( e ) e.className = 'error';
 288+ if( e ) {
 289+ e.className = 'error';
 290+ }
273291
274292 // Clear wpDestFile as well
275 - var e = document.getElementById( 'wpDestFile' + current)
276 - if( e ) e.value = '';
 293+ var e = document.getElementById( 'wpDestFile' + current );
 294+ if( e ) {
 295+ e.value = '';
 296+ }
277297
278298 return false;
279299 }
@@ -280,21 +300,23 @@
281301
282302 // Capitalise first letter and replace spaces by underscores
283303 // FIXME: $wgCapitalizedNamespaces
284 - fname = fname.charAt(0).toUpperCase().concat(fname.substring(1,10000)).replace(/ /g, '_');
 304+ fname = fname.charAt( 0 ).toUpperCase().concat( fname.substring( 1, 10000 ) ).replace( / /g, '_' );
285305
286306 // Output result
287 - var destFile = document.getElementById('wpDestFile' + current);
288 - if (destFile) {
 307+ var destFile = document.getElementById( 'wpDestFile' + current );
 308+ if ( destFile ) {
289309 destFile.value = fname;
290 - wgUploadWarningObj.checkNow(fname) ;
 310+ wgUploadWarningObj.checkNow( fname );
291311 }
292312 }
293313
294314 function toggleFilenameFiller() {
295 - if(!document.getElementById) return;
296 - var upfield = document.getElementById('wpUploadFile');
297 - var destName = document.getElementById('wpDestFile').value;
298 - if (destName=='' || destName==' ') {
 315+ if( !document.getElementById ) {
 316+ return;
 317+ }
 318+ var upfield = document.getElementById( 'wpUploadFile' );
 319+ var destName = document.getElementById( 'wpDestFile' ).value;
 320+ if ( destName == '' || destName == ' ' ) {
299321 wgUploadAutoFill = true;
300322 } else {
301323 wgUploadAutoFill = false;
@@ -306,27 +328,32 @@
307329 'responseCache' : { '' : '' },
308330
309331 'fetchPreview': function( license ) {
310 - if( !wgAjaxLicensePreview ) return;
311 - for (cached in this.responseCache) {
312 - if (cached == license) {
 332+ if( !wgAjaxLicensePreview ) {
 333+ return;
 334+ }
 335+ for ( cached in this.responseCache ) {
 336+ if ( cached == license ) {
313337 this.showPreview( this.responseCache[license] );
314338 return;
315339 }
316340 }
317341 injectSpinner( document.getElementById( 'wpLicense' ), 'license' );
318 -
319 - var title = document.getElementById('wpDestFile' + current).value;
320 - if ( !title ) title = 'File:Sample.jpg';
321 -
 342+
 343+ var title = document.getElementById( 'wpDestFile' + current ).value;
 344+ if ( !title ) {
 345+ title = 'File:Sample.jpg';
 346+ }
 347+
322348 var url = wgScriptPath + '/api' + wgScriptExtension
323349 + '?action=parse&text={{' + encodeURIComponent( license ) + '}}'
324 - + '&title=' + encodeURIComponent( title )
 350+ + '&title=' + encodeURIComponent( title )
325351 + '&prop=text&pst&format=json';
326 -
 352+
327353 var req = sajax_init_object();
328354 req.onreadystatechange = function() {
329 - if ( req.readyState == 4 && req.status == 200 )
 355+ if ( req.readyState == 4 && req.status == 200 ) {
330356 wgUploadLicenseObj.processResult( eval( '(' + req.responseText + ')' ), license );
 357+ }
331358 };
332359 req.open( 'GET', url, true );
333360 req.send( '' );
@@ -336,15 +363,15 @@
337364 removeSpinner( 'license' );
338365 this.responseCache[license] = result['parse']['text']['*'];
339366 this.showPreview( this.responseCache[license] );
340 -
341367 },
342368
343369 'showPreview' : function( preview ) {
344370 var previewPanel = document.getElementById( 'mw-license-preview' );
345 - if( previewPanel.innerHTML != preview )
 371+ if( previewPanel.innerHTML != preview ) {
346372 previewPanel.innerHTML = preview;
 373+ }
347374 }
348375
349376 }
350377
351 -addOnloadHook( wgUploadSetup );
 378+addOnloadHook( wgUploadSetup );
\ No newline at end of file

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r76108rewrite make it compatible with 1.16travis16:14, 5 November 2010
r76109rewrite make it compatible with 1.16travis16:16, 5 November 2010

Status & tagging log