Robmoen has uploaded a new change for review.

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

Change subject: Delint and general mw.UploadWizardUpload cleanup
......................................................................

Delint and general mw.UploadWizardUpload cleanup

Change-Id: I69b1c68c223fe690db5e1b24d45d2eccb4991614
---
M resources/mw.UploadWizardUpload.js
1 file changed, 146 insertions(+), 152 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/UploadWizard 
refs/changes/39/119639/1

diff --git a/resources/mw.UploadWizardUpload.js 
b/resources/mw.UploadWizardUpload.js
index f983c5d..95a6425 100644
--- a/resources/mw.UploadWizardUpload.js
+++ b/resources/mw.UploadWizardUpload.js
@@ -5,6 +5,10 @@
  *   'new' 'transporting' 'transported' 'metadata' 'stashed' 'details' 
'submitting-details' 'complete' 'error'
  * should fork this into two -- local and remote, e.g. filename
  */
+
+/*jslint nomen: true */
+/*global alert: true */
+
 ( function( mw, $ ) {
 
 var fileNsId = mw.config.get( 'wgNamespaceIds' ).file;
@@ -27,7 +31,7 @@
  * @param {File} providedFile - optional; only used on browsers which support 
FileAPI.
  * @param {int} reservedIndex - optional, what key in the uploads array to 
hold for this upload
  */
-mw.UploadWizardUpload = function( wizard, filesDiv, providedFile, 
reservedIndex ) {
+mw.UploadWizardUpload = function ( wizard, filesDiv, providedFile, 
reservedIndex ) {
 
        this.index = mw.UploadWizardUpload.prototype.count;
        mw.UploadWizardUpload.prototype.count++;
@@ -79,8 +83,7 @@
        count: 0,
 
        acceptDeed: function( deed ) {
-               var _this = this;
-               _this.deed.applyDeed( _this );
+               this.deed.applyDeed( this );
        },
 
        /**
@@ -90,16 +93,16 @@
                var _this = this;
 
                if ( mw.UploadWizard.config.startImmediately === true ) {
-                       _this.wizard.hideFileEndButtons();
-                       _this.wizard.startProgressBar();
-                       _this.wizard.allowCloseWindow = mw.confirmCloseWindow( {
+                       this.wizard.hideFileEndButtons();
+                       this.wizard.startProgressBar();
+                       this.wizard.allowCloseWindow = mw.confirmCloseWindow( {
                                message: function() { return mw.message( 
'mwe-upwiz-prevent-close', _this.wizard.uploads.length ).escaped(); },
                                test: function() { return 
!_this.wizard.isComplete() && _this.wizard.uploads.length > 0; }
                        } );
                }
-               _this.setTransportProgress(0.0);
-               //_this.ui.start();
-               _this.handler.start();
+               this.setTransportProgress(0.0);
+               //this.ui.start();
+               this.handler.start();
        },
 
        /**
@@ -134,10 +137,9 @@
         * @param fraction
         */
        setTransportProgress: function ( fraction ) {
-               var _this = this;
-               _this.state = 'transporting';
-               _this.transportProgress = fraction;
-               $( _this.ui.div ).trigger( 'transportProgressEvent' );
+               this.state = 'transporting';
+               this.transportProgress = fraction;
+               $( this.ui.div ).trigger( 'transportProgressEvent' );
        },
 
        /**
@@ -162,14 +164,14 @@
         * @param result        the API result in parsed JSON form
         */
        setTransported: function( result ) {
-               var _this = this;
-               if ( _this.state == 'aborted' ) {
+               if ( this.state === 'aborted' ) {
                        return;
                }
 
                // default error state
                var code = 'unknown',
-                       info = 'unknown';
+                       info = 'unknown',
+                       comma, warnCode;
 
                if ( result.error ) {
                        // If there was an error, we can't really do anything 
else, so let's get out while we can.
@@ -178,7 +180,7 @@
                        }
                        if ( code === 'filetype-banned' && 
result.error.blacklisted ) {
                                code = 'filetype-banned-type';
-                               var comma = mw.message( 'comma-separator' 
).escaped();
+                               comma = mw.message( 'comma-separator' 
).escaped();
                                info = [
                                        result.error.blacklisted.join( comma ),
                                        result.error.allowed.join( comma ),
@@ -191,8 +193,6 @@
                        this.setError( code, info );
                        return;
                }
-
-               var warnCode;
 
                result.upload = result.upload || {};
                result.upload.warnings = result.upload.warnings || {};
@@ -209,14 +209,14 @@
                                                break;
                                        case 'duplicate':
                                                code = warnCode;
-                                               _this.setError( warnCode, 
_this.duplicateErrorInfo( warnCode, result.upload.warnings[warnCode] ) );
+                                               this.setError( warnCode, 
this.duplicateErrorInfo( warnCode, result.upload.warnings[warnCode] ) );
                                                break;
                                        case 'duplicate-archive':
                                                // This is the case where the 
file did exist, but it was deleted.
                                                // We should definitely tell 
the user, but let them override.
                                                // If they already have, then 
don't execute any of this.
                                                code = warnCode;
-                                               _this.setError( warnCode, 
_this.duplicateErrorInfo( warnCode, result.upload.warnings[warnCode] ) );
+                                               this.setError( warnCode, 
this.duplicateErrorInfo( warnCode, result.upload.warnings[warnCode] ) );
                                                var $override = $( '<a></a>' )
                                                        .attr( 'href', 
'javascript:' )
                                                        .text( mw.message( 
'mwe-upwiz-override' ).text() )
@@ -237,7 +237,7 @@
                                                } else {
                                                        info = 
result.upload.warnings[warnCode];
                                                }
-                                               _this.setError( code, info );
+                                               this.setError( code, info );
                                                break;
                                }
                        }
@@ -246,14 +246,14 @@
                if ( this.state !== 'error' ) {
                        if ( result.upload && result.upload.result === 
'Success' ) {
                                if ( result.upload.imageinfo ) {
-                                       _this.setSuccess( result );
+                                       this.setSuccess( result );
                                } else {
-                                       _this.setError( 'noimageinfo', info );
+                                       this.setError( 'noimageinfo', info );
                                }
                        } else if ( result.upload && result.upload.result === 
'Warning' ) {
                                throw new Error( 'Your browser got back a 
Warning result from the server. Please file a bug.' );
                        } else {
-                               _this.setError( code, info );
+                               this.setError( code, info );
                        }
                }
        },
@@ -264,26 +264,30 @@
         * @param {Object} portion of the API error result listing duplicates
         */
        duplicateErrorInfo: function( code, resultDuplicate ) {
-               var _this = this;
-               var duplicates;
+               var dialogFn,
+                       duplicates,
+                       $ul = $( '<ul></ul>' );
+
+
                if ( typeof resultDuplicate === 'object' ) {
                        duplicates = resultDuplicate;
                } else if ( typeof resultDuplicate === 'string' ) {
                        duplicates = [ resultDuplicate ];
                }
-               var $ul = $( '<ul></ul>' );
                $.each( duplicates, function( i, filename ) {
-                       var $a = $( '<a/>' ).append( filename );
+                       var $a = $( '<a/>' ).append( filename ),
+                               href;
                        try {
-                               var href = new mw.Title( filename, fileNsId 
).getUrl();
+                               href = new mw.Title( filename, fileNsId 
).getUrl();
                                $a.attr( { 'href': href, 'target': '_blank' } );
                        } catch ( e ) {
-                               $a.click( function() { alert('could not parse 
filename=' + filename ); } );
+                               $a.click( function() { alert( 'could not parse 
filename=' + filename ); } );
                                $a.attr( 'href', '#' );
                        }
                        $ul.append( $( '<li></li>' ).append( $a ) );
                } );
-               var dialogFn = function(e) {
+
+               dialogFn = function( e ) {
                        $( '<div></div>' )
                                .html( $ul )
                                .dialog( {
@@ -303,24 +307,23 @@
         * @param {Mixed} result -- result of AJAX call
         */
        setSuccess: function( result ) {
-               var _this = this;
-               _this.state = 'transported';
-               _this.transportProgress = 1;
+               this.state = 'transported';
+               this.transportProgress = 1;
 
-               _this.ui.setStatus( 'mwe-upwiz-getting-metadata' );
+               this.ui.setStatus( 'mwe-upwiz-getting-metadata' );
                if ( result.upload ) {
-                       _this.extractUploadInfo( result.upload );
-                       if ( !_this.fromURL ) {
-                               _this.deedPreview.setup();
+                       this.extractUploadInfo( result.upload );
+                       if ( !this.fromURL ) {
+                               this.deedPreview.setup();
                        }
-                       _this.details.populate();
-                       _this.state = 'stashed';
-                       _this.ui.showStashed();
-                       $.publishReady( 'thumbnails.' + _this.index, 'api' );
+                       this.details.populate();
+                       this.state = 'stashed';
+                       this.ui.showStashed();
+                       $.publishReady( 'thumbnails.' + this.index, 'api' );
                        // check all uploads, if they're complete, show the 
next button
-                       //_this.wizard.showNext( 'file', 'stashed' ); See bug 
39852
+                       //this.wizard.showNext( 'file', 'stashed' ); See bug 
39852
                } else {
-                       _this.setError( 'noimageinfo' );
+                       this.setError( 'noimageinfo' );
                }
 
        },
@@ -343,8 +346,17 @@
         * @param {Function()} callback when resetting FileInput
         */
        checkFile: function( filename, files, fileNameOk, fileNameErr, 
resetFileInput ) {
-               var _this = this;
-               var fileErrors = {};
+               var basename,
+                       tooManyFiles,
+                       actualMaxSize,
+                       totalSize,
+                       binReader,
+                       _this = this,
+                       errorIndex,
+                       fileErrors = {},
+                       hasError = false,
+                       duplicate = false,
+                       extension = this.title.getExtension();
 
                function finishCallback () {
                        if ( _this && _this.ui ) {
@@ -356,18 +368,18 @@
 
                // Check if filename is acceptable
                // TODO sanitize filename
-               var basename = mw.UploadWizardUtil.getBasename( filename );
+               basename = mw.UploadWizardUtil.getBasename( filename );
 
-               var tooManyFiles = files.length + _this.wizard.uploads.length > 
mw.UploadWizard.config.maxUploads;
+               tooManyFiles = files.length + this.wizard.uploads.length > 
mw.UploadWizard.config.maxUploads;
                if ( tooManyFiles ) {
-                       _this.showTooManyFilesWarning( files.length + 
_this.wizard.uploads.length );
+                       this.showTooManyFilesWarning( files.length + 
this.wizard.uploads.length );
                        resetFileInput();
                        return;
                }
 
                if ( files.length > 1 ) {
 
-                       var totalSize = 0;
+                       totalSize = 0;
                        $.each( files, function( i, file ) {
                                totalSize += file.size;
                        });
@@ -375,14 +387,13 @@
                        // Local previews are slow due to the data URI 
insertion into the DOM; for batches we
                        // don't generate them if the size of the batch exceeds 
10 MB
                        if ( totalSize > 10000000 ) {
-                               _this.wizard.makePreviewsFlag = false;
+                               this.wizard.makePreviewsFlag = false;
                        }
 
-                       _this.reservedIndex = _this.wizard.uploads.length;
+                       this.reservedIndex = this.wizard.uploads.length;
                }
 
                // check to see if the file has already been selected for 
upload.
-               var duplicate = false;
                $.each( this.wizard.uploads, function ( i, upload ) {
                        if ( upload !== undefined && _this !== upload && 
filename === upload.filename ) {
                                duplicate = true;
@@ -403,7 +414,6 @@
                }
 
                // Check if extension is acceptable
-               var extension = this.title.getExtension();
                if ( mw.isEmpty( extension ) ) {
                        fileErrors.noext = true;
                        fileNameErr( 'noext', null, fileErrors );
@@ -415,8 +425,7 @@
                        // Split this into a separate case, if the error above 
got ignored,
                        // we want to still trudge forward.
                        if ( !fileErrors.ext ) {
-                               var hasError = false;
-                               for ( var errorIndex in fileErrors ) {
+                               for ( errorIndex in fileErrors ) {
                                        if ( fileErrors[errorIndex] ) {
                                                hasError = true;
                                                break;
@@ -435,7 +444,6 @@
                                        // will accept. Otherwise we're bound 
by PHP's limits.
                                        // NOTE: Because we don't know until 
runtime if the browser supports chunked
                                        // uploading, we can't determine this 
server-side.
-                                       var actualMaxSize;
                                        if ( 
mw.UploadWizard.config.enableChunked && mw.fileApi.isFormDataAvailable() ) {
                                                actualMaxSize = 
mw.UploadWizard.config.maxMwUploadSize;
                                        } else {
@@ -447,10 +455,10 @@
 
                                        // make sure the file isn't too large
                                        // XXX need a way to find the size of 
the Flickr image
-                                       if ( !_this.fromURL ){
+                                       if ( !this.fromURL ){
                                                this.transportWeight = 
this.file.size;
                                                if ( this.transportWeight > 
actualMaxSize ) {
-                                                       
_this.showMaxSizeWarning( this.transportWeight, actualMaxSize );
+                                                       
this.showMaxSizeWarning( this.transportWeight, actualMaxSize );
                                                        return;
                                                }
                                        }
@@ -466,22 +474,20 @@
                                        // For all other file types, we don't 
need or want to run this.
                                        //
                                        // TODO: This should be refactored.
-
                                        if ( this.file.type === 'image/jpeg' ) {
-                                               var binReader = new 
FileReader();
+                                               binReader = new FileReader();
                                                binReader.onload = function() {
-                                                       var binStr;
+                                                       var binStr, arr, meta, 
i = 0;
                                                        if ( typeof 
binReader.result === 'string' ) {
                                                                binStr = 
binReader.result;
                                                        } else {
                                                                // Array 
buffer; convert to binary string for the library.
-                                                               var arr = new 
Uint8Array( binReader.result );
+                                                               arr = new 
Uint8Array( binReader.result );
                                                                binStr = '';
-                                                               for ( var i = 
0; i < arr.byteLength; i++ ) {
+                                                               for ( ; i < 
arr.byteLength; i++ ) {
                                                                        binStr 
+= String.fromCharCode( arr[i] );
                                                                }
                                                        }
-                                                       var meta;
                                                        try {
                                                                meta = 
mw.libs.jpegmeta( binStr, _this.file.fileName );
                                                                
meta._binary_data = null;
@@ -495,9 +501,9 @@
                                                        }
                                                };
                                                if ( 'readAsBinaryString' in 
binReader ) {
-                                                       
binReader.readAsBinaryString( _this.file );
+                                                       
binReader.readAsBinaryString( this.file );
                                                } else if ( 'readAsArrayBuffer' 
in binReader ) {
-                                                       
binReader.readAsArrayBuffer( _this.file );
+                                                       
binReader.readAsArrayBuffer( this.file );
                                                } else {
                                                        // We should never get 
here. :P
                                                        throw new Error( 
'Cannot read thumbnail as binary string or array buffer.' );
@@ -513,9 +519,8 @@
                                        files = files.slice( 1 );
                                        if ( files.length > 0 ) {
                                                $.each( files, function( i, 
file ) {
-
                                                        // NOTE: By running 
newUpload we will end up calling checkfile() again.
-                                                       var upload = 
_this.wizard.newUpload( file, _this.reservedIndex + i + 1 );
+                                                       _this.wizard.newUpload( 
file, _this.reservedIndex + i + 1 );
                                                } );
                                                _this.wizard.updateFileCounts();
                                        }
@@ -540,7 +545,7 @@
                        {
                                text: mw.message( 'mwe-upwiz-file-too-large-ok' 
).escaped(),
                                click: function() {
-                                       $( this ).dialog( "close" );
+                                       $( this ).dialog( 'close' );
                                }
                        }
                ];
@@ -570,7 +575,7 @@
                        {
                                text: mw.message( 'mwe-upwiz-too-many-files-ok' 
).escaped(),
                                click: function() {
-                                       $(this).dialog('destroy').remove();
+                                       $(this).dialog( 'destroy' ).remove();
                                }
                        }
                ];
@@ -596,6 +601,9 @@
         * @param {Object} (as returned by jpegmeta)
         */
        extractMetadataFromJpegMeta: function( meta ) {
+               var degrees,
+                       pixelHeightDim = 'height',
+                       pixelWidthDim = 'width';
                if ( meta !== undefined && meta !== null && typeof meta === 
'object' ) {
                        if ( this.imageinfo === undefined ) {
                                this.imageinfo = {};
@@ -607,12 +615,10 @@
                                this.imageinfo.metadata.orientation = 
meta.tiff.Orientation.value;
                        }
                        if ( meta.general ) {
-                               var pixelHeightDim = 'height';
-                               var pixelWidthDim = 'width';
                                // this must be called after orientation is set 
above. If no orientation set, defaults to 0
-                               var degrees = this.getOrientationDegrees();
+                               degrees = this.getOrientationDegrees();
                                // jpegmeta reports pixelHeight & width
-                               if ( degrees == 90 || degrees == 270 ) {
+                               if ( degrees === 90 || degrees === 270 ) {
                                        pixelHeightDim = 'width';
                                        pixelWidthDim = 'height';
                                }
@@ -652,12 +658,13 @@
         * @param imageinfo JSON object obtained from API result.
         */
        extractImageInfo: function( imageinfo ) {
-               var _this = this;
-               for ( var key in imageinfo ) {
+               var key,
+                       _this = this;
+               for ( key in imageinfo ) {
                        // we get metadata as list of key-val pairs; convert to 
object for easier lookup. Assuming that EXIF fields are unique.
-                       if ( key == 'metadata' ) {
-                               if ( _this.imageinfo.metadata === undefined ) {
-                                       _this.imageinfo.metadata = {};
+                       if ( key === 'metadata' ) {
+                               if ( this.imageinfo.metadata === undefined ) {
+                                       this.imageinfo.metadata = {};
                                }
                                if ( imageinfo.metadata && 
imageinfo.metadata.length ) {
                                        $.each( imageinfo.metadata, function( 
i, pair ) {
@@ -667,21 +674,21 @@
                                        } );
                                }
                        } else {
-                               _this.imageinfo[key] = imageinfo[key];
+                               this.imageinfo[key] = imageinfo[key];
                        }
                }
 
                /*
-               if ( _this.title.getExtension() === null ) {
+               if ( this.title.getExtension() === null ) {
                        // 1;
                        // TODO v1.1 what if we don't have an extension? Should 
be impossible as it is currently impossible to upload without extension, but you
                        // never know... theoretically there is no restriction 
on extensions if we are uploading to the stash, but the check is performed 
anyway.
 
-                       var extension = mw.UploadWizardUtil.getExtension( 
_this.imageinfo.url );
+                       var extension = mw.UploadWizardUtil.getExtension( 
this.imageinfo.url );
                        if ( !extension ) {
-                               if ( _this.imageinfo.mimetype ) {
-                                       if ( 
mw.UploadWizardUtil.mimetypeToExtension[ _this.imageinfo.mimetype ] ) {
-                                               extension = 
mw.UploadWizardUtil.mimetypeToExtension[ _this.imageinfo.mimetype ];
+                               if ( this.imageinfo.mimetype ) {
+                                       if ( 
mw.UploadWizardUtil.mimetypeToExtension[ this.imageinfo.mimetype ] ) {
+                                               extension = 
mw.UploadWizardUtil.mimetypeToExtension[ this.imageinfo.mimetype ];
                                        }
                                }
                        }
@@ -699,15 +706,11 @@
         * @param {Number} optional, height of thumbnail. Will force 'url' to 
be added to props
         */
        getStashImageInfo: function( callback, props, width, height ) {
-               var _this = this;
-
-               if ( props === undefined ) {
-                       props = [];
-               }
-
-               var params = {
+               var params, ok, err;
+               props = props || [];
+               params = {
                        'prop': 'stashimageinfo',
-                       'siifilekey': _this.fileKey,
+                       'siifilekey': this.fileKey,
                        'siiprop': props.join( '|' )
                };
 
@@ -722,21 +725,18 @@
                                params.siiurlheight = height;
                        }
                }
-
-               var ok = function( data ) {
+               ok = function( data ) {
                        if ( !data || !data.query || !data.query.stashimageinfo 
) {
-                               
mw.log.warn("mw.UploadWizardUpload::getStashImageInfo> No data? ");
+                               mw.log.warn( 
'mw.UploadWizardUpload::getStashImageInfo> No data? ' );
                                callback( null );
                                return;
                        }
                        callback( data.query.stashimageinfo );
                };
-
-               var err = function( code, result ) {
+               err = function( code ) {
                        mw.log.warn( 'mw.UploadWizardUpload::getStashImageInfo> 
' + code );
                        callback( null );
                };
-
                this.api.get( params, { ok: ok, err: err } );
        },
 
@@ -750,12 +750,10 @@
         * @param {Number} optional, height of thumbnail. Will force 'url' to 
be added to props
         */
        getImageInfo: function( callback, props, width, height ) {
-               var _this = this;
-               if ( props === undefined ) {
-                       props = [];
-               }
-               var requestedTitle = _this.title.getPrefixedText();
-               var params = {
+               var ok, err, params,
+                       requestedTitle = this.title.getPrefixedText();
+               props = props || [];
+               params = {
                        'prop': 'imageinfo',
                        'titles': requestedTitle,
                        'iiprop': props.join( '|' )
@@ -772,8 +770,7 @@
                                params.iiurlheight = height;
                        }
                }
-
-               var ok = function( data ) {
+               ok = function( data ) {
                        if ( data && data.query && data.query.pages ) {
                                var found = false;
                                $.each( data.query.pages, function( pageId, 
page ) {
@@ -787,15 +784,13 @@
                                        return;
                                }
                        }
-                       mw.log.warn("mw.UploadWizardUpload::getImageInfo> No 
data matching " + requestedTitle + " ? ");
+                       mw.log.warn( 'mw.UploadWizardUpload::getImageInfo> No 
data matching ' + requestedTitle + ' ? ' );
                        callback( null );
                };
-
-               var err = function( code, result ) {
+               err = function( code ) {
                        mw.log.warn( 'mw.UploadWizardUpload::getImageInfo> ' + 
code );
                        callback( null );
                };
-
                this.api.get( params, { ok: ok, err: err } );
        },
 
@@ -803,9 +798,9 @@
         * Get the upload handler per browser capabilities
         * @return upload handler object
         */
-       getUploadHandler: function(){
+       getUploadHandler: function() {
+               var constructor;  // must be the name of a function in 'mw' 
namespace
                if ( !this.uploadHandler ) {
-                       var constructor;  // must be the name of a function in 
'mw' namespace
                        if ( mw.UploadWizard.config.enableFirefogg && 
mw.Firefogg.isInstalled() ) {
                                constructor = 'FirefoggHandler';
                        } else if ( mw.UploadWizard.config.enableFormData && 
mw.fileApi.isAvailable() && mw.fileApi.isFormDataAvailable()) {
@@ -832,14 +827,15 @@
         * @param height - (optional) maximum height of thumbnail
         */
        getAndPublishApiThumbnail: function( key, width, height ) {
-               var _this = this;
+               var thumbnailPublisher,
+                       _this = this;
 
                if ( mw.isEmpty( height ) ) {
                        height = -1;
                }
 
-               if ( _this.thumbnailPublishers[key] === undefined ) {
-                       var thumbnailPublisher = function( thumbnails ) {
+               if ( this.thumbnailPublishers[key] === undefined ) {
+                       thumbnailPublisher = function( thumbnails ) {
                                if ( thumbnails === null ) {
                                        // the api call failed somehow, no 
thumbnail data.
                                        $.publishReady( key, null );
@@ -849,16 +845,17 @@
                                        // on the image. If it loads publish 
the event with the image. If it errors out too many times, give up and publish
                                        // the event with a null.
                                        $.each( thumbnails, function( i, thumb 
) {
+                                               var image,
+                                                       timeoutMs = 100;
                                                if ( thumb.thumberror || ( ! ( 
thumb.thumburl && thumb.thumbwidth && thumb.thumbheight ) ) ) {
-                                                       mw.log.warn( 
"mw.UploadWizardUpload::getThumbnail> Thumbnail error or missing information" );
+                                                       mw.log.warn( 
'mw.UploadWizardUpload::getThumbnail> Thumbnail error or missing information' );
                                                        $.publishReady( key, 
null );
                                                        return;
                                                }
 
                                                // try to load this image with 
exponential backoff
                                                // if the delay goes past 8 
seconds, it gives up and publishes the event with null
-                                               var timeoutMs = 100;
-                                               var image = 
document.createElement( 'img' );
+                                               image = document.createElement( 
'img' );
                                                image.width = thumb.thumbwidth;
                                                image.height = 
thumb.thumbheight;
                                                $( image )
@@ -891,11 +888,11 @@
                                }
                        };
 
-                       _this.thumbnailPublishers[key] = thumbnailPublisher;
-                       if ( _this.state !== 'complete' ) {
-                               _this.getStashImageInfo( thumbnailPublisher, [ 
'url' ], width, height );
+                       this.thumbnailPublishers[key] = thumbnailPublisher;
+                       if ( this.state !== 'complete' ) {
+                               this.getStashImageInfo( thumbnailPublisher, [ 
'url' ], width, height );
                        } else {
-                               _this.getImageInfo( thumbnailPublisher, [ 'url' 
], width, height );
+                               this.getImageInfo( thumbnailPublisher, [ 'url' 
], width, height );
                        }
 
                }
@@ -956,18 +953,26 @@
         * @return {HTMLCanvasElement}
         */
        getTransformedCanvasElement: function( image, constraints ) {
-
-               var rotation = 0;
+               var x, y,
+                       angle,
+                       scaleConstraints,
+                       scaling = this.getScalingFromConstraints( image, 
constraints ),
+                       width = image.width * scaling,
+                       height = image.height * scaling,
+                       // Determine the offset required to center the image
+                       dx = ( constraints.width - width ) / 2,
+                       dy = ( constraints.height - height ) / 2,
+                       $canvas = $( '<canvas></canvas>' ).attr( constraints ),
+                       ctx = $canvas[0].getContext( '2d' ),
+                       rotation = 0;
 
                // if this wiki can rotate images to match their EXIF metadata,
                // we should do the same in our preview
                if ( mw.config.get( 'wgFileCanRotate' ) ) {
-                       var angle = this.getOrientationDegrees();
+                       angle = this.getOrientationDegrees();
                        rotation = angle ? 360 - angle : 0;
                }
-
                // swap scaling constraints if needed by rotation...
-               var scaleConstraints;
                if ( rotation === 90 || rotation === 270 ) {
                        scaleConstraints = {
                                width: constraints.height,
@@ -979,17 +984,6 @@
                                height: constraints.height
                        };
                }
-
-               var scaling = this.getScalingFromConstraints( image, 
constraints );
-
-               var width = image.width * scaling;
-               var height = image.height * scaling;
-
-               // Determine the offset required to center the image
-               var dx = (constraints.width - width) / 2;
-               var dy = (constraints.height - height) / 2;
-               var x, y;
-
                switch ( rotation ) {
                        // If a rotation is applied, the direction of the axis
                        // changes as well. You can derive the values below by
@@ -1013,9 +1007,6 @@
                                y = dy;
                                break;
                }
-
-               var $canvas = $( '<canvas></canvas>' ).attr( constraints );
-               var ctx = $canvas[0].getContext( '2d' );
                ctx.clearRect( 0, 0, width, height );
                ctx.rotate( rotation / 180 * Math.PI );
                ctx.drawImage( image, x, y, width, height );
@@ -1072,26 +1063,28 @@
         * @param boolean add lightbox large preview when ready
         */
        setThumbnail: function( selector, width, height, isLightBox ) {
-               var _this = this;
+               var _this = this,
+                       placed = false,
+                       placeImageCallback;
 
                /**
                 * This callback will add an image to the selector, using 
in-browser scaling if necessary
                 * @param {HTMLImageElement}
                 */
-               var placed = false;
-               var placeImageCallback = function( image ) {
+               placeImageCallback = function( image ) {
+                       var elm;
                        if ( image === null ) {
                                $( selector ).addClass( 
'mwe-upwiz-file-preview-broken' );
                                _this.ui.setStatus( 
'mwe-upwiz-thumbnail-failed' );
                                return;
                        }
-                       var elm = _this.getScaledImageElement( image, width, 
height );
+                       elm = _this.getScaledImageElement( image, width, height 
);
                        // add the image to the DOM, finally
                        $( selector )
                                .css( { background: 'none' } )
                                .html(
                                        $( '<a/></a>' )
-                                               .addClass( 
"mwe-upwiz-thumbnail-link" )
+                                               .addClass( 
'mwe-upwiz-thumbnail-link' )
                                                .append( elm )
                                );
                        placed = true;
@@ -1103,6 +1096,7 @@
                $.subscribeReady(
                        'thumbnails.' + _this.index,
                        function ( x ) {
+                               var key;
                                if ( isLightBox ) {
                                        _this.setLightBox( selector );
                                }
@@ -1110,7 +1104,7 @@
                                        if ( x === 'api' ) {
                                                // get the thumbnail via API. 
This also works with an async pub/sub model; if this thumbnail was already
                                                // fetched for some reason, 
we'll get it immediately
-                                               var key = 'apiThumbnail.' + 
_this.index + ',width=' + width + ',height=' + height;
+                                               key = 'apiThumbnail.' + 
_this.index + ',width=' + width + ',height=' + height;
                                                $.subscribeReady( key, 
placeImageCallback );
                                                
_this.getAndPublishApiThumbnail( key, width, height );
                                        } else if ( x instanceof 
HTMLImageElement ) {
@@ -1131,8 +1125,8 @@
         * @param selector
         */
        setLightBox: function( selector ) {
-               var _this = this;
-               var $imgDiv = $( '<div></div>' ).css( 'text-align', 'center' );
+               var _this = this,
+                       $imgDiv = $( '<div></div>' ).css( 'text-align', 
'center' );
                $( selector )
                        .click( function() {
                                // get large preview image

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I69b1c68c223fe690db5e1b24d45d2eccb4991614
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/UploadWizard
Gerrit-Branch: master
Gerrit-Owner: Robmoen <rm...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to