Restored wpDestFileWarningAck, but this time in case this ignored warning is the...
authorBryan Tong Minh <btongminh@users.mediawiki.org>
Mon, 21 Dec 2009 20:50:37 +0000 (20:50 +0000)
committerBryan Tong Minh <btongminh@users.mediawiki.org>
Mon, 21 Dec 2009 20:50:37 +0000 (20:50 +0000)
Moved the warning message higher up the form just below the filename input box for better visibility.

includes/specials/SpecialUpload.php
skins/common/upload.js

index 19591c8..532c6b9 100644 (file)
@@ -41,6 +41,7 @@ class SpecialUpload extends SpecialPage {
        protected $mCopyrightSource;
 
        /** Hidden variables **/
+       protected $mDestWarningAck;
        protected $mForReUpload;                // The user followed an "overwrite this file" link
        protected $mCancelUpload;               // The user clicked "Cancel and return to upload form" button
        protected $mTokenOk;
@@ -68,6 +69,7 @@ class SpecialUpload extends SpecialPage {
                $this->mLicense           = $request->getText( 'wpLicense' );
 
 
+               $this->mDestWarningAck    = $request->getText( 'wpDestFileWarningAck' );
                $this->mIgnoreWarning     = $request->getCheck( 'wpIgnoreWarning' )
                        || $request->getCheck( 'wpUploadIgnoreWarning' );
                $this->mWatchthis         = $request->getBool( 'wpWatchthis' ) && $wgUser->isLoggedIn();
@@ -201,6 +203,7 @@ class SpecialUpload extends SpecialPage {
                        'forreupload' => $this->mForReUpload, 
                        'sessionkey' => $sessionKey,
                        'hideignorewarning' => $hideIgnoreWarning,
+                       'destwarningack' => (bool)$this->mDestWarningAck,
                ) );
                $form->setTitle( $this->getTitle() );
 
@@ -276,13 +279,22 @@ class SpecialUpload extends SpecialPage {
                $this->showUploadForm( $form );
        }
        /**
-        * Stashes the upload, shows the main form, but adds an "continue anyway button"
+        * Stashes the upload, shows the main form, but adds an "continue anyway button".
+        * Also checks whether there are actually warnings to display.
         *
         * @param array $warnings
+        * @return boolean true if warnings were displayed, false if there are no 
+        *      warnings and the should continue processing like there was no warning
         */
        protected function showUploadWarning( $warnings ) {
                global $wgUser;
 
+               # If there are no warnings, or warnings we can ignore, return early
+               if ( !$warnings || ( count( $warnings ) == 1 && 
+                                isset( $warnings['exists']) && $this->mDestWarningAck ) ) {
+                       return false;                                   
+               }
+
                $sessionKey = $this->mUpload->stashSession();
 
                $sk = $wgUser->getSkin();
@@ -317,6 +329,9 @@ class SpecialUpload extends SpecialPage {
                $form->addButton( 'wpCancelUpload', wfMsg( 'reuploaddesc' ) );
 
                $this->showUploadForm( $form );
+               
+               # Indicate that we showed a form
+               return true;
        }
 
        /**
@@ -371,8 +386,7 @@ class SpecialUpload extends SpecialPage {
                // Check warnings if necessary
                if( !$this->mIgnoreWarning ) {
                        $warnings = $this->mUpload->checkWarnings();
-                       if( count( $warnings ) ) {
-                               $this->showUploadWarning( $warnings );
+                       if( $this->showUploadWarning( $warnings ) ) {
                                return;
                        }
                }
@@ -671,6 +685,7 @@ class UploadForm extends HTMLForm {
        protected $mForReUpload;
        protected $mSessionKey;
        protected $mHideIgnoreWarning;
+       protected $mDestWarningAck;
        
        protected $mSourceIds;
 
@@ -682,6 +697,7 @@ class UploadForm extends HTMLForm {
                $this->mSessionKey = isset( $options['sessionkey'] ) 
                                ? $options['sessionkey'] : '';
                $this->mHideIgnoreWarning = !empty( $options['hideignorewarning'] );
+               $this->mDestWarningAck = !empty( $options['destwarningack'] );
 
                $sourceDescriptor = $this->getSourceSection();
                $descriptor = $sourceDescriptor
@@ -907,6 +923,12 @@ class UploadForm extends HTMLForm {
                        );
                }
 
+               $descriptor['wpDestFileWarningAck'] = array(
+                       'type' => 'hidden',
+                       'id' => 'wpDestFileWarningAck',
+                       'default' => $this->mDestWarningAck ? '1' : '',
+               );
+
                return $descriptor;
 
        }
index bc05158..cc506e7 100644 (file)
@@ -46,13 +46,14 @@ function wgUploadSetup() {
                document.getElementById( 'wpDestFile' ).onchange = function ( e ) { 
                        wgUploadWarningObj.checkNow(this.value);
                };
-               var optionsTable = document.getElementById( 'mw-htmlform-options' ).tBodies[0];
+               var optionsTable = document.getElementById( 'mw-htmlform-description' ).tBodies[0];
                var row = document.createElement( 'tr' );
                var td = document.createElement( 'td' );
                td.id = 'wpDestFile-warning';
                td.colSpan = 2;
+               
                row.appendChild( td );
-               optionsTable.appendChild( row );
+               optionsTable.insertBefore( row, optionsTable.children[1] );
        }
        
        if ( wgAjaxLicensePreview ) {
@@ -187,7 +188,18 @@ var wgUploadWarningObj = {
 
        'setWarning' : function (warning) {
                var warningElt = document.getElementById( 'wpDestFile-warning' );
+               var ackElt = document.getElementsByName( 'wpDestFileWarningAck' );
+
                this.setInnerHTML(warningElt, warning);
+               
+               // Set a value in the form indicating that the warning is acknowledged and
+               // doesn't need to be redisplayed post-upload
+               if ( warning == '' || warning == '&nbsp;' ) {
+                       ackElt[0].value = '';
+               } else {
+                       ackElt[0].value = '1';
+               }
+
        },
        'setInnerHTML' : function (element, text) {
                // Check for no change to avoid flicker in IE 7