From aed7632a1dce080df51d7f4fc338f5a0add0745c Mon Sep 17 00:00:00 2001 From: Bryan Tong Minh Date: Mon, 21 Dec 2009 20:50:37 +0000 Subject: [PATCH] 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. --- includes/specials/SpecialUpload.php | 28 +++++++++++++++++++++++++--- skins/common/upload.js | 16 ++++++++++++++-- 2 files changed, 39 insertions(+), 5 deletions(-) diff --git a/includes/specials/SpecialUpload.php b/includes/specials/SpecialUpload.php index 19591c8d0b..532c6b9166 100644 --- a/includes/specials/SpecialUpload.php +++ b/includes/specials/SpecialUpload.php @@ -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; } diff --git a/skins/common/upload.js b/skins/common/upload.js index bc051581ea..cc506e7b5e 100644 --- a/skins/common/upload.js +++ b/skins/common/upload.js @@ -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 == ' ' ) { + ackElt[0].value = ''; + } else { + ackElt[0].value = '1'; + } + }, 'setInnerHTML' : function (element, text) { // Check for no change to avoid flicker in IE 7 -- 2.20.1