Worden.lee has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/67173


Change subject: Refactor Special:Upload for extensibility
......................................................................

Refactor Special:Upload for extensibility

This commit splits some functions in SpecialUpload.php and
its associated JavaScript code, separating details of UI output
from internal processing so that extensions (such as
Extension:MultiUpload) can use its features while altering the UI.

A rewritten MultiUpload (to be committed separately) uses this
refactored class as a superclass.

Change-Id: Iedf726770625dd6a6ba101da506088ab959e1767
---
M includes/specials/SpecialUpload.php
M resources/mediawiki.special/mediawiki.special.upload.js
M skins/common/upload.js
3 files changed, 258 insertions(+), 120 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/73/67173/1

diff --git a/includes/specials/SpecialUpload.php 
b/includes/specials/SpecialUpload.php
index 98d0c9a..056ae76 100644
--- a/includes/specials/SpecialUpload.php
+++ b/includes/specials/SpecialUpload.php
@@ -60,7 +60,7 @@
 
        /** User input variables from the root section **/
        public $mIgnoreWarning;
-       public $mWatchThis;
+       public $mWatchthis;
        public $mCopyrightStatus;
        public $mCopyrightSource;
 
@@ -74,8 +74,6 @@
        /** Text injection points for hooks not using HTMLForm **/
        public $uploadFormTextTop;
        public $uploadFormTextAfterSummary;
-
-       public $mWatchthis;
 
        /**
         * Initialize instance variables from request and create an Upload 
handler
@@ -107,12 +105,22 @@
                $this->mCancelUpload = $request->getCheck( 'wpCancelUpload' )
                        || $request->getCheck( 'wpReUpload' ); // b/w compat
 
-               // If it was posted check for the token (no remote POST'ing 
with user credentials)
-               $token = $request->getVal( 'wpEditToken' );
-               $this->mTokenOk = $this->getUser()->matchEditToken( $token );
+               $this->checkToken( $request );
 
                $this->uploadFormTextTop = '';
                $this->uploadFormTextAfterSummary = '';
+       }
+
+       /**
+        * Check for valid edit token, to protect against remote posting
+        * with user credentials.
+        *
+        * @param $request WebRequest object
+        * @since 1.22
+        */
+       protected function checkToken( $request ) {
+               $token = $request->getVal( 'wpEditToken' );
+               $this->mTokenOk = $this->getUser()->matchEditToken( $token );
        }
 
        /**
@@ -154,6 +162,14 @@
                # Check whether we actually want to allow changing stuff
                $this->checkReadOnly();
 
+               $this->handleRequestData();
+       }
+
+       /**
+        * Respond to submitted form data and/or display upload form
+        * @since 1.22
+        */
+       protected function handleRequestData() { 
                $this->loadRequest();
 
                # Unsave the temporary file in case this was a cancelled upload
@@ -165,10 +181,7 @@
                }
 
                # Process upload or show a form
-               if (
-                       $this->mTokenOk && !$this->mCancelUpload &&
-                       ( $this->mUpload && $this->mUploadClicked )
-               ) {
+               if ( $this->shouldProcessUpload() ) {
                        $this->processUpload();
                } else {
                        # Backwards compatibility hook
@@ -183,6 +196,16 @@
                if ( $this->mUpload ) {
                        $this->mUpload->cleanupTempFile();
                }
+       }
+
+       /**
+        * Decide whether an upload has been requested
+        * @return Bool
+        * @since 1.22
+        */
+       protected function shouldProcessUpload() {
+               return ( $this->mTokenOk && !$this->mCancelUpload &&
+                       ( $this->mUpload && $this->mUploadClicked ) );
        }
 
        /**
@@ -269,9 +292,11 @@
        }
 
        /**
-        * Shows the "view X deleted revivions link""
+        * Assemble the text of the "view X deleted revisions" link
+        * @return string
+        * @since 1.22
         */
-       protected function showViewDeletedLinks() {
+       protected function getViewDeletedLinks() {
                $title = Title::makeTitleSafe( NS_FILE, $this->mDesiredDestName 
);
                $user = $this->getUser();
                // Show a subtitle link to deleted revisions (to sysops et al 
only)
@@ -284,13 +309,38 @@
                                );
                                $link = $this->msg( $user->isAllowed( 'delete' 
) ? 'thisisdeleted' : 'viewdeleted' )
                                        ->rawParams( $restorelink 
)->parseAsBlock();
-                               $this->getOutput()->addHTML( "<div 
id=\"contentSub2\">{$link}</div>" );
+                               return "<div id=\"contentSub2\">{$link}</div>";
                        }
+               }
+               return '';
+       }
+
+       /*
+        * Show the "view X deleted revisions" link
+        */
+       protected function showViewDeletedLinks() {
+               $html = $this->getViewDeletedLinks();
+               if ( $html !== '' ) {
+                       $this->getOutput()->addHTML( $html );
                }
        }
 
        /**
-        * Stashes the upload and shows the main upload form.
+        * Construct a recoverable error message.
+        *
+        * See showRecoverableUploaderror, below.
+        *
+        * @param string $message HTML message to be passed to mainUploadForm
+        * @return string formatted HTML
+        * @since 1.22
+        */
+       protected function getRecoverableUploadError( $message ) {
+               return '<h2>' . $this->msg( 'uploaderror' )->escaped() . 
"</h2>\n" .
+                       '<div class="error">' . $message . "</div>\n";
+       }
+
+       /**
+        * Stash the upload and show the main upload form.
         *
         * Note: only errors that can be handled by changing the name or
         * description should be redirected here. It should be assumed that the
@@ -302,22 +352,23 @@
         */
        protected function showRecoverableUploadError( $message ) {
                $sessionKey = $this->mUpload->stashSession();
-               $message = '<h2>' . $this->msg( 'uploaderror' )->escaped() . 
"</h2>\n" .
-                       '<div class="error">' . $message . "</div>\n";
-
-               $form = $this->getUploadForm( $message, $sessionKey );
+               $form = $this->getUploadForm( 
+                       $this->getRecoverableUploadError( $message ), 
$sessionKey );
                $form->setSubmitText( $this->msg( 'upload-tryagain' 
)->escaped() );
                $this->showUploadForm( $form );
        }
+
        /**
-        * Stashes the upload, shows the main form, but adds a "continue anyway 
button".
-        * Also checks whether there are actually warnings to display.
+        * Construct a formatted list of upload warnings.
         *
         * @param $warnings Array
-        * @return boolean true if warnings were displayed, false if there are 
no
+        * @return mixed: a string if there are warnings to display, false if 
there are no
         *         warnings and it should continue processing
+        * @param Array $warnings
+        * @return string formatted HTML
+        * @since 1.22
         */
-       protected function showUploadWarning( $warnings ) {
+       protected function getUploadWarning( $warnings ) {
                # If there are no warnings, or warnings we can ignore, return 
early.
                # mDestWarningAck is set when some javascript has shown the 
warning
                # to the user. mForReUpload is set when the user clicks the 
"upload a
@@ -328,8 +379,6 @@
                {
                        return false;
                }
-
-               $sessionKey = $this->mUpload->stashSession();
 
                $warningHtml = '<h2>' . $this->msg( 'uploadwarning' 
)->escaped() . "</h2>\n"
                        . '<ul class="warning">';
@@ -358,6 +407,25 @@
                $warningHtml .= "</ul>\n";
                $warningHtml .= $this->msg( 'uploadwarning-text' 
)->parseAsBlock();
 
+               return $warningHtml;
+       } 
+
+       /**
+        * Stash the upload, show the main form, but add a "continue anyway" 
button.
+        * Also checks whether there are actually warnings to display.
+        *
+        * @param $warnings Array
+        * @return boolean true if warnings were displayed, false if there are 
no
+        *         warnings and it should continue processing
+        */
+       protected function showUploadWarning( $warnings ) {
+               $warningHtml = $this->getUploadWarning( $warnings );
+               if ($warningHtml === false ) {
+                       return false;
+               }
+
+               $sessionKey = $this->mUpload->stashSession();
+
                $form = $this->getUploadForm( $warningHtml, $sessionKey, /* 
$hideIgnoreWarning */ true );
                $form->setSubmitText( $this->msg( 'upload-tryagain' )->text() );
                $form->addButton( 'wpUploadIgnoreWarning', $this->msg( 
'ignorewarning' )->text() );
@@ -370,14 +438,25 @@
        }
 
        /**
+        * Format an upload error message for display.
+        *
+        * @param string $message HTML string
+        * @return string HTML message
+        * @since 1.22
+        */
+       protected function getUploadError( $message ) {
+               return '<h2>' . $this->msg( 'uploadwarning' )->escaped() . 
"</h2>\n" .
+                       '<div class="error">' . $message . "</div>\n";
+       }
+
+       /**
         * Show the upload form with error message, but do not stash the file.
         *
         * @param string $message HTML string
         */
        protected function showUploadError( $message ) {
-               $message = '<h2>' . $this->msg( 'uploadwarning' )->escaped() . 
"</h2>\n" .
-                       '<div class="error">' . $message . "</div>\n";
-               $this->showUploadForm( $this->getUploadForm( $message ) );
+               $this->showUploadForm( $this->getUploadForm( 
+                       $this->getUploadError( $message ) ) );
        }
 
        /**
@@ -443,6 +522,14 @@
                // Success, redirect to description page
                $this->mUploadSuccessful = true;
                wfRunHooks( 'SpecialUploadComplete', array( &$this ) );
+               $this->uploadSucceeded();
+       }
+
+       /**
+        * Once upload is successful, redirect to the updated File: page
+        * @since 1.22
+        */
+       protected function uploadSucceeded() {
                $this->getOutput()->redirect( 
$this->mLocalFile->getTitle()->getFullURL() );
        }
 
@@ -609,11 +696,19 @@
                }
                $success = $this->mUpload->unsaveUploadedFile();
                if ( !$success ) {
-                       $this->getOutput()->showFileDeleteError( 
$this->mUpload->getTempPath() );
+                       $this->showFileDeleteError();
                        return false;
                } else {
                        return true;
                }
+       }
+
+       /**
+        * Produce error output if uploaded file can't be unsaved.
+        * @since 1.22
+        */
+       protected function showFileDeleteError() {
+               $this->getOutput()->showFileDeleteError( 
$this->mUpload->getTempPath() );
        }
 
        /*** Functions for formatting warnings ***/
@@ -742,7 +837,29 @@
 
        protected $mMaxUploadSize = array();
 
+       /**
+        * constructor: make upload form using options provided by SpecialUpload
+        */
        public function __construct( array $options = array(), IContextSource 
$context = null ) {
+               $this->constructData( $options, $context );
+
+               # Set some form properties
+               $this->setSubmitText( $this->msg( 'uploadbtn' )->text() );
+               $this->setSubmitName( 'wpUpload' );
+               # Used message keys: 'accesskey-upload', 'tooltip-upload'
+               $this->setSubmitTooltip( 'upload' );
+               $this->setId( 'mw-upload-form' );
+       }
+
+       /**
+        * Initialize member data and form descriptors using options provided 
by SpecialUpload
+        * @since 1.22
+        */
+       protected function constructData( array $options = array(), 
IContextSource $context = null ) {
+               # setContext is called in the constructor, but it's needed
+               # before we get there
+               $this->setContext( $context );
+
                $this->mWatch = !empty( $options['watch'] );
                $this->mForReUpload = !empty( $options['forreupload'] );
                $this->mSessionKey = isset( $options['sessionkey'] )
@@ -767,13 +884,6 @@
 
                wfRunHooks( 'UploadFormInitDescriptor', array( &$descriptor ) );
                parent::__construct( $descriptor, $context, 'upload' );
-
-               # Set some form properties
-               $this->setSubmitText( $this->msg( 'uploadbtn' )->text() );
-               $this->setSubmitName( 'wpUpload' );
-               # Used message keys: 'accesskey-upload', 'tooltip-upload'
-               $this->setSubmitTooltip( 'upload' );
-               $this->setId( 'mw-upload-form' );
 
                # Build a list of IDs for javascript insertion
                $this->mSourceIds = array();
diff --git a/resources/mediawiki.special/mediawiki.special.upload.js 
b/resources/mediawiki.special/mediawiki.special.upload.js
index 75532f1..3790662 100644
--- a/resources/mediawiki.special/mediawiki.special.upload.js
+++ b/resources/mediawiki.special/mediawiki.special.upload.js
@@ -41,13 +41,15 @@
                 * @todo check file size limits and warn of likely failures
                 *
                 * @param {File} file
+                * @param {id} tableId ID of table element above which to 
insert the thumbnail
+                * @param {id} thumbnailId ID to be given to thumbnail element
                 */
-               function showPreview( file ) {
+               function showPreview( file, tableId, thumbnailId ) {
                        var $canvas,
                                ctx,
                                meta,
                                previewSize = 180,
-                               thumb = $( '<div id="mw-upload-thumbnail" 
class="thumb tright">' +
+                               thumb = $( '<div id="' + thumbnailId + '" 
class="thumb tright">' +
                                                        '<div 
class="thumbinner">' +
                                                                '<div 
class="mw-small-spinner" style="width: 180px; height: 180px"></div>' +
                                                                '<div 
class="thumbcaption"><div class="filename"></div><div 
class="fileinfo"></div></div>' +
@@ -59,7 +61,7 @@
 
                        $canvas = $('<canvas width="' + previewSize + '" 
height="' + previewSize + '" ></canvas>');
                        ctx = $canvas[0].getContext( '2d' );
-                       $( '#mw-htmlform-source' ).parent().prepend( thumb );
+                       $( '#' + tableId ).parent().prepend( thumb );
 
                        fetchPreview( file, function ( dataURL ) {
                                var img = new Image(),
@@ -136,7 +138,7 @@
                                        info = mw.msg( 'widthheight', 
logicalWidth, logicalHeight ) +
                                                ', ' + prettySize( file.size );
 
-                                       $( '#mw-upload-thumbnail .fileinfo' 
).text( info );
+                                       $( '#' + thumbnailId + ' .fileinfo' 
).text( info );
                                };
                                img.src = dataURL;
                        }, mw.config.get( 'wgFileCanRotate' ) ? function ( data 
) {
@@ -228,15 +230,21 @@
 
                /**
                 * Clear the file upload preview area.
+                *
+                * @param {id} thumbnailId ID of thumbnail element to be removed
                 */
-               function clearPreview() {
-                       $( '#mw-upload-thumbnail' ).remove();
+               function clearPreview( thumbnailId ) {
+                       $( '#' + thumbnailId ).remove();
                }
 
                /**
                 * Check if the file does not exceed the maximum size
+                *
+                * @param {File} file
+                * @param {id} fileId ID of upload form field
+                * @param {id} errorId ID of element to contain error output
                 */
-               function checkMaxUploadSize( file ) {
+               function checkMaxUploadSize( file, fileId, errorId ) {
                        var maxSize, $error;
 
                        function getMaxUploadSize( type ) {
@@ -248,14 +256,14 @@
                                return sizes['*'];
                        }
 
-                       $( '.mw-upload-source-error' ).remove();
+                       $( '.' + errorId ).remove();
 
                        maxSize = getMaxUploadSize( 'file' );
                        if ( file.size > maxSize ) {
-                               $error = $( '<p class="error 
mw-upload-source-error" id="wpSourceTypeFile-error">' +
+                               $error = $( '<p class="error 
mw-upload-source-error" id="' + errorId + '">' +
                                        mw.message( 'largefileserver', 
file.size, maxSize ).escaped() + '</p>' );
 
-                               $( '#wpUploadFile' ).after( $error );
+                               $( '#' + fileId ).after( $error );
 
                                return false;
                        }
@@ -263,28 +271,38 @@
                        return true;
                }
 
-
                /**
                 * Initialization
+                *
+                * @param {id} fileId ID of upload field
+                * @param {id} thumbnailId ID of thumbnail element
+                * @param {id} errorId ID of element where error output will 
appear
+                * @param {id} tableId ID of table element above which 
thumbnail will be added
                 */
-               if ( hasFileAPI() ) {
-                       // Update thumbnail when the file selection control is 
updated.
-                       $( '#wpUploadFile' ).change( function () {
-                               clearPreview();
-                               if ( this.files && this.files.length ) {
-                                       // Note: would need to be updated to 
handle multiple files.
-                                       var file = this.files[0];
+               window.setupThumbnail = function( fileId, thumbnailId, errorId, 
tableId ) {
+                       if ( hasFileAPI() ) {
+                               // Update thumbnail when the file selection 
control is updated.
+                               $( '#'+fileId ).change( function() {
+                                       clearPreview( thumbnailId );
+                                       if ( this.files && this.files.length ) {
+                                               // Note: would need to be 
updated to handle multiple files.
+                                               var file = this.files[0];
 
-                                       if ( !checkMaxUploadSize( file ) ) {
-                                               return;
-                                       }
+                                               if ( !checkMaxUploadSize( file, 
fileId,
+                                                      errorId ) ) {
+                                                       return;
+                                               }
 
-                                       if ( fileIsPreviewable( file ) ) {
-                                               showPreview( file );
+                                               if ( fileIsPreviewable( file ) 
) {
+                                                       showPreview( file, 
tableId,
+                                                               thumbnailId );
+                                               }
                                        }
-                               }
-                       } );
+                               } );
+                       }
                }
+               window.setupThumbnail( 'wpUploadFile', 'mw-upload-thumbnail',
+                               'wpSourceTypeFile-error', 'mw-htmlform-source' 
);
        } );
 
        /**
diff --git a/skins/common/upload.js b/skins/common/upload.js
index df819e1..0a3aa32 100644
--- a/skins/common/upload.js
+++ b/skins/common/upload.js
@@ -15,12 +15,12 @@
        wgUploadLicenseObj.fetchPreview( selection );
 };
 
-function uploadSetup() {
+window.uploadSetupByIds = function( sourceTypeId, uploadUrlId, licenseId, 
warningId, ackId, destFileId, descriptionId, previewId ) {
        // Disable URL box if the URL copy upload source type is not selected
-       var e = document.getElementById( 'wpSourceTypeurl' );
+       var e = document.getElementById( sourceTypeId );
        if( e ) {
                if( !e.checked ) {
-                       var ein = document.getElementById( 'wpUploadFileURL' );
+                       var ein = document.getElementById( uploadUrlId );
                        if(ein)
                                ein.setAttribute( 'disabled', 'disabled' );
                }
@@ -28,7 +28,7 @@
 
        // For MSIE/Mac: non-breaking spaces cause the <option> not to render.
        // But for some reason, setting the text to itself works
-       var selector = document.getElementById("wpLicense");
+       var selector = document.getElementById( licenseId );
        if (selector) {
                var ua = navigator.userAgent;
                var isMacIe = (ua.indexOf("MSIE") != -1) && (ua.indexOf("Mac") 
!= -1);
@@ -43,21 +43,32 @@
        if ( ajaxUploadDestCheck ) {
                // Insert an event handler that fetches upload warnings when 
wpDestFile
                // has been changed
-               document.getElementById( 'wpDestFile' ).onchange = function ( e 
) {
-                       wgUploadWarningObj.checkNow(this.value);
-               };
+               var ackElt = document.getElementsByName( ackId );
+               var destElt = document.getElementById( destFileId );
+               if( destElt ) 
+                       destElt.onchange = function ( e ) {
+                               wgUploadWarningObj.checkNow(this, warningId, 
ackElt);
+                       };
                // Insert a row where the warnings will be displayed just below 
the
                // wpDestFile row
-               var optionsTable = document.getElementById( 
'mw-htmlform-description' ).tBodies[0];
-               var row = optionsTable.insertRow( 1 );
-               var td = document.createElement( 'td' );
-               td.id = 'wpDestFile-warning';
-               td.colSpan = 2;
+               var descElt = document.getElementById( descriptionId )
+               if( descElt && destElt ) {
+                       var destFileRow = destElt.parentNode.parentNode;
+                       var destFileTbody = destFileRow.parentNode;
 
-               row.appendChild( td );
+                       var optionsTable = descElt.tBodies[0];
+                       //var row = optionsTable.insertRow( 1 );
+                       var row = document.createElement( 'tr' );
+                       var td = document.createElement( 'td' );
+                       td.id = warningId;
+                       td.colSpan = 2;
+
+                       row.appendChild( td );
+                       destFileTbody.insertBefore( row, 
destFileRow.nextSibling );
+               }
        }
 
-       var wpLicense = document.getElementById( 'wpLicense' );
+       var wpLicense = document.getElementById( licenseId );
        if ( mw.config.get( 'wgAjaxLicensePreview' ) && wpLicense ) {
                // License selector check
                wpLicense.onchange = licenseSelectorCheck;
@@ -70,23 +81,31 @@
                var td = document.createElement( 'td' );
                row.appendChild( td );
                td = document.createElement( 'td' );
-               td.id = 'mw-license-preview';
+               td.id = previewId;
                row.appendChild( td );
 
                wpLicenseTbody.insertBefore( row, wpLicenseRow.nextSibling );
        }
+};
 
-
+function uploadSetup() {
+       uploadSetupByIds( 'wpSourceTypeurl', 'wpUploadFileURL', 'wpLicense', 
'wpDestFile-warning', 'wpDestFileWarningAck', 'wpDestFile', 
'mw-htmlform-description', 'mw-license-preview' );
+       
        // fillDestFile setup
        var     i,
                uploadSourceIds = mw.config.get( 'wgUploadSourceIds' ),
-               len = uploadSourceIds.length;
+               len = Array.isArray(uploadSourceIds) ? uploadSourceIds.length : 
0;
+       var upUrl = document.getElementById( 'wpUploadFileURL' );
+       var destFile = document.getElementById( 'wpDestFile' );
+       var upperm = document.getElementById( 'mw-upload-permitted' );
+       var uppro = document.getElementById( 'mw-upload-prohibited' );
+       var warningId = 'wpDestFile-warning';
+       var ackElt = document.getElementsByName( 'wpDestFileWarningAck' );
        for ( i = 0; i < len; i += 1 )
                document.getElementById( uploadSourceIds[i] ).onchange = 
function (e) {
-                       fillDestFilename( this.id );
-               };
-};
-
+                       fillDestFilename( this, upUrl, destFile, upperm, uppro, 
warningId, ackElt, 'wgUploadAutoFill' );
+               }
+}
 
 window.wgUploadWarningObj = {
        'responseCache' : { '' : '&nbsp;' },
@@ -100,7 +119,9 @@
 
                // Find file to upload
                var destFile = document.getElementById('wpDestFile');
-               var warningElt = document.getElementById( 'wpDestFile-warning' 
);
+               var warningId = 'wpDestFile-warning';
+               var warningElt = document.getElementById( warningId );
+               var ackElt = document.getElementsByName( 'wpDestFileWarningAck' 
);
                if ( !destFile || !warningElt ) return ;
 
                this.nameToCheck = destFile.value ;
@@ -112,7 +133,7 @@
                // Check response cache
                for (cached in this.responseCache) {
                        if (this.nameToCheck == cached) {
-                               
this.setWarning(this.responseCache[this.nameToCheck]);
+                               
this.setWarning(this.responseCache[this.nameToCheck], warningId, ackElt);
                                return;
                        }
                }
@@ -120,42 +141,41 @@
                this.timeoutID = window.setTimeout( 
'wgUploadWarningObj.timeout()', this.delay );
        },
 
-       'checkNow': function (fname) {
+       'checkNow': function (field, wid, wack) {
                if ( !ajaxUploadDestCheck || !sajax_init_object() ) return;
                if ( this.timeoutID ) {
                        window.clearTimeout( this.timeoutID );
                }
-               this.nameToCheck = fname;
-               this.timeout();
+               this.nameToCheck = field.value;
+               this.timeout(field, wid, wack);
        },
 
-       'timeout' : function() {
+       'timeout' : function(field, wid, wack) {
                if ( !ajaxUploadDestCheck || !sajax_init_object() ) return;
-               injectSpinner( document.getElementById( 'wpDestFile' ), 
'destcheck' );
+               injectSpinner( field, 'destcheck' );
 
                // Get variables into local scope so that they will be 
preserved for the
                // anonymous callback. fileName is copied so that multiple 
overlapping
                // ajax requests can be supported.
                var obj = this;
                var fileName = this.nameToCheck;
+               //var warningElt = document.getElementById( wid );
+               //var warningAck = wack;
                sajax_do_call( 'SpecialUpload::ajaxGetExistsWarning', 
[this.nameToCheck],
                        function (result) {
-                               obj.processResult(result, fileName)
+                               obj.processResult(result, fileName, wid, wack)
                        }
                );
        },
 
-       'processResult' : function (result, fileName) {
+       'processResult' : function (result, fileName, wid, wack) {
                removeSpinner( 'destcheck' );
-               this.setWarning(result.responseText);
+               this.setWarning(result.responseText, wid, wack);
                this.responseCache[fileName] = result.responseText;
        },
 
-       'setWarning' : function (warning) {
-               var warningElt = document.getElementById( 'wpDestFile-warning' 
);
-               var ackElt = document.getElementsByName( 'wpDestFileWarningAck' 
);
-
-               this.setInnerHTML(warningElt, warning);
+       'setWarning' : function (warning, warningId, ackElt) {
+               this.setInnerHTML(warningId, warning);
 
                // Set a value in the form indicating that the warning is 
acknowledged and
                // doesn't need to be redisplayed post-upload
@@ -166,7 +186,8 @@
                }
 
        },
-       'setInnerHTML' : function (element, text) {
+       'setInnerHTML' : function (id, text) {
+               var element = document.getElementById( id );
                // Check for no change to avoid flicker in IE 7
                if (element.innerHTML != text) {
                        element.innerHTML = text;
@@ -174,21 +195,17 @@
        }
 };
 
-window.fillDestFilename = function(id) {
-       if ( !mw.config.get( 'wgUploadAutoFill' ) ) {
-               return;
-       }
-       if (!document.getElementById) {
+window.fillDestFilename = function(upFile, upUrl, destFile, upperm, uppro, 
warningId, ackElt, configvar) {
+       // e.g. mw.config.get( 'wgUploadAutoFill' )
+       if ( !mw.config.get( configvar ) ) {
                return;
        }
        // Remove any previously flagged errors
-       var e = document.getElementById( 'mw-upload-permitted' );
-       if( e ) e.className = '';
+       if( upperm ) upperm.className = '';
 
-       var e = document.getElementById( 'mw-upload-prohibited' );
-       if( e ) e.className = '';
+       if( uppro ) uppro.className = '';
 
-       var path = document.getElementById(id).value;
+       var path = upFile.value;
        // Find trailing part
        var slash = path.lastIndexOf('/');
        var backslash = path.lastIndexOf('\\');
@@ -204,7 +221,7 @@
        // Clear the filename if it does not have a valid extension.
        // URLs are less likely to have a useful extension, so don't include 
them in the
        // extension check.
-       if ( mw.config.get( 'wgStrictFileExtensions' ) && fileExtensions && id 
!== 'wpUploadFileURL' ) {
+       if ( upUrl && mw.config.get( 'wgStrictFileExtensions' ) && 
fileExtensions && upFile.id !== upUrl.id ) {
                var found = false;
                if ( fname.lastIndexOf( '.' ) !== -1 ) {
                        var ext = fname.substr( fname.lastIndexOf( '.' ) + 1 );
@@ -218,17 +235,11 @@
                if( !found ) {
                        // Not a valid extension
                        // Clear the upload and set mw-upload-permitted to error
-                       document.getElementById(id).value = '';
-                       var e = document.getElementById( 'mw-upload-permitted' 
);
-                       if( e ) e.className = 'error';
-
-                       var e = document.getElementById( 'mw-upload-prohibited' 
);
-                       if( e ) e.className = 'error';
-
+                       upFile.value = '';
+                       if( upperm ) upperm.className = 'error';
+                       if( uppro ) uppro.className = 'error';
                        // Clear wpDestFile as well
-                       var e = document.getElementById( 'wpDestFile' );
-                       if( e ) e.value = '';
-
+                       if( destFile ) destFile.value = '';
                        return false;
                }
        }
@@ -241,7 +252,6 @@
        }
 
        // Output result
-       var destFile = document.getElementById( 'wpDestFile' );
        if ( destFile ) {
                // Call decodeURIComponent function to remove possible 
URL-encoded characters
                // from the file name (bug 30390). Especially likely with 
upload-form-url.
@@ -251,7 +261,7 @@
                } catch ( e ) {
                        destFile.value = fname;
                }
-               wgUploadWarningObj.checkNow( fname );
+               wgUploadWarningObj.checkNow(destFile, warningId, ackElt) ;
        }
 };
 

-- 
To view, visit https://gerrit.wikimedia.org/r/67173
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Iedf726770625dd6a6ba101da506088ab959e1767
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Worden.lee <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to