r60279 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r60278‎ | r60279 | r60280 >
Date:20:50, 21 December 2009
Author:btongminh
Status:ok
Tags:
Comment:
Restored wpDestFileWarningAck, but this time in case this ignored warning is the only warning, continue the upload normally instead of showing an empty warning screen.

Moved the warning message higher up the form just below the filename input box for better visibility.
Modified paths:
  • /trunk/phase3/includes/specials/SpecialUpload.php (modified) (history)
  • /trunk/phase3/skins/common/upload.js (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/specials/SpecialUpload.php
@@ -41,6 +41,7 @@
4242 protected $mCopyrightSource;
4343
4444 /** Hidden variables **/
 45+ protected $mDestWarningAck;
4546 protected $mForReUpload; // The user followed an "overwrite this file" link
4647 protected $mCancelUpload; // The user clicked "Cancel and return to upload form" button
4748 protected $mTokenOk;
@@ -68,6 +69,7 @@
6970 $this->mLicense = $request->getText( 'wpLicense' );
7071
7172
 73+ $this->mDestWarningAck = $request->getText( 'wpDestFileWarningAck' );
7274 $this->mIgnoreWarning = $request->getCheck( 'wpIgnoreWarning' )
7375 || $request->getCheck( 'wpUploadIgnoreWarning' );
7476 $this->mWatchthis = $request->getBool( 'wpWatchthis' ) && $wgUser->isLoggedIn();
@@ -201,6 +203,7 @@
202204 'forreupload' => $this->mForReUpload,
203205 'sessionkey' => $sessionKey,
204206 'hideignorewarning' => $hideIgnoreWarning,
 207+ 'destwarningack' => (bool)$this->mDestWarningAck,
205208 ) );
206209 $form->setTitle( $this->getTitle() );
207210
@@ -276,13 +279,22 @@
277280 $this->showUploadForm( $form );
278281 }
279282 /**
280 - * Stashes the upload, shows the main form, but adds an "continue anyway button"
 283+ * Stashes the upload, shows the main form, but adds an "continue anyway button".
 284+ * Also checks whether there are actually warnings to display.
281285 *
282286 * @param array $warnings
 287+ * @return boolean true if warnings were displayed, false if there are no
 288+ * warnings and the should continue processing like there was no warning
283289 */
284290 protected function showUploadWarning( $warnings ) {
285291 global $wgUser;
286292
 293+ # If there are no warnings, or warnings we can ignore, return early
 294+ if ( !$warnings || ( count( $warnings ) == 1 &&
 295+ isset( $warnings['exists']) && $this->mDestWarningAck ) ) {
 296+ return false;
 297+ }
 298+
287299 $sessionKey = $this->mUpload->stashSession();
288300
289301 $sk = $wgUser->getSkin();
@@ -317,6 +329,9 @@
318330 $form->addButton( 'wpCancelUpload', wfMsg( 'reuploaddesc' ) );
319331
320332 $this->showUploadForm( $form );
 333+
 334+ # Indicate that we showed a form
 335+ return true;
321336 }
322337
323338 /**
@@ -371,8 +386,7 @@
372387 // Check warnings if necessary
373388 if( !$this->mIgnoreWarning ) {
374389 $warnings = $this->mUpload->checkWarnings();
375 - if( count( $warnings ) ) {
376 - $this->showUploadWarning( $warnings );
 390+ if( $this->showUploadWarning( $warnings ) ) {
377391 return;
378392 }
379393 }
@@ -671,6 +685,7 @@
672686 protected $mForReUpload;
673687 protected $mSessionKey;
674688 protected $mHideIgnoreWarning;
 689+ protected $mDestWarningAck;
675690
676691 protected $mSourceIds;
677692
@@ -682,6 +697,7 @@
683698 $this->mSessionKey = isset( $options['sessionkey'] )
684699 ? $options['sessionkey'] : '';
685700 $this->mHideIgnoreWarning = !empty( $options['hideignorewarning'] );
 701+ $this->mDestWarningAck = !empty( $options['destwarningack'] );
686702
687703 $sourceDescriptor = $this->getSourceSection();
688704 $descriptor = $sourceDescriptor
@@ -907,6 +923,12 @@
908924 );
909925 }
910926
 927+ $descriptor['wpDestFileWarningAck'] = array(
 928+ 'type' => 'hidden',
 929+ 'id' => 'wpDestFileWarningAck',
 930+ 'default' => $this->mDestWarningAck ? '1' : '',
 931+ );
 932+
911933 return $descriptor;
912934
913935 }
Index: trunk/phase3/skins/common/upload.js
@@ -46,13 +46,14 @@
4747 document.getElementById( 'wpDestFile' ).onchange = function ( e ) {
4848 wgUploadWarningObj.checkNow(this.value);
4949 };
50 - var optionsTable = document.getElementById( 'mw-htmlform-options' ).tBodies[0];
 50+ var optionsTable = document.getElementById( 'mw-htmlform-description' ).tBodies[0];
5151 var row = document.createElement( 'tr' );
5252 var td = document.createElement( 'td' );
5353 td.id = 'wpDestFile-warning';
5454 td.colSpan = 2;
 55+
5556 row.appendChild( td );
56 - optionsTable.appendChild( row );
 57+ optionsTable.insertBefore( row, optionsTable.children[1] );
5758 }
5859
5960 if ( wgAjaxLicensePreview ) {
@@ -187,7 +188,18 @@
188189
189190 'setWarning' : function (warning) {
190191 var warningElt = document.getElementById( 'wpDestFile-warning' );
 192+ var ackElt = document.getElementsByName( 'wpDestFileWarningAck' );
 193+
191194 this.setInnerHTML(warningElt, warning);
 195+
 196+ // Set a value in the form indicating that the warning is acknowledged and
 197+ // doesn't need to be redisplayed post-upload
 198+ if ( warning == '' || warning == ' ' ) {
 199+ ackElt[0].value = '';
 200+ } else {
 201+ ackElt[0].value = '1';
 202+ }
 203+
192204 },
193205 'setInnerHTML' : function (element, text) {
194206 // Check for no change to avoid flicker in IE 7

Status & tagging log