Merge "Don't check namespace in SpecialWantedtemplates"
[lhc/web/wiklou.git] / resources / src / mediawiki.special / mediawiki.special.upload.js
index 8f72d63..677d26d 100644 (file)
@@ -6,6 +6,7 @@
  * @singleton
  */
 ( function ( mw, $ ) {
+       /*jshint latedef:false */
        var uploadWarning, uploadLicense,
                ajaxUploadDestCheck = mw.config.get( 'wgAjaxUploadDestCheck' ),
                $license = $( '#wpLicense' );
@@ -35,7 +36,7 @@
                        }
                        // Check response cache
                        if ( this.responseCache.hasOwnProperty( this.nameToCheck ) ) {
-                               this.setWarning( this.responseCache[this.nameToCheck] );
+                               this.setWarning( this.responseCache[ this.nameToCheck ] );
                                return;
                        }
 
@@ -71,7 +72,7 @@
                        } ).done( function ( result ) {
                                var resultOut = '';
                                if ( result.query ) {
-                                       resultOut = result.query.pages[result.query.pageids[0]].imageinfo[0];
+                                       resultOut = result.query.pages[ result.query.pageids[ 0 ] ].imageinfo[ 0 ];
                                }
                                $spinnerDestCheck.remove();
                                uploadWarning.processResult( resultOut, uploadWarning.nameToCheck );
@@ -80,7 +81,7 @@
 
                processResult: function ( result, fileName ) {
                        this.setWarning( result.html );
-                       this.responseCache[fileName] = result.html;
+                       this.responseCache[ fileName ] = result.html;
                },
 
                setWarning: function ( warning ) {
                                return;
                        }
                        if ( this.responseCache.hasOwnProperty( license ) ) {
-                               this.showPreview( this.responseCache[license] );
+                               this.showPreview( this.responseCache[ license ] );
                                return;
                        }
 
                },
 
                processResult: function ( result, license ) {
-                       this.responseCache[license] = result.parse.text['*'];
-                       this.showPreview( this.responseCache[license] );
+                       this.responseCache[ license ] = result.parse.text[ '*' ];
+                       this.showPreview( this.responseCache[ license ] );
                },
 
                showPreview: function ( preview ) {
                                fname = fname.replace( / /g, '_' );
                                // Capitalise first letter if needed
                                if ( mw.config.get( 'wgCapitalizeUploads' ) ) {
-                                       fname = fname[0].toUpperCase() + fname.slice( 1 );
+                                       fname = fname[ 0 ].toUpperCase() + fname.slice( 1 );
                                }
 
                                // Output result
                 * TODO: Put SVG back after working around Firefox 7 bug <https://bugzilla.wikimedia.org/show_bug.cgi?id=31643>
                 *
                 * @param {File} file
-                * @return boolean
+                * @return {boolean}
                 */
                function fileIsPreviewable( file ) {
-                       var known = ['image/png', 'image/gif', 'image/jpeg', 'image/svg+xml'],
+                       var known = [ 'image/png', 'image/gif', 'image/jpeg', 'image/svg+xml' ],
                                tooHuge = 10 * 1024 * 1024;
                        return ( $.inArray( file.type, known ) !== -1 ) && file.size > 0 && file.size < tooHuge;
                }
 
+               /**
+                * Format a file size attractively.
+                *
+                * TODO: Match numeric formatting
+                *
+                * @param {number} s
+                * @return {string}
+                */
+               function prettySize( s ) {
+                       var sizeMsgs = [ 'size-bytes', 'size-kilobytes', 'size-megabytes', 'size-gigabytes' ];
+                       while ( s >= 1024 && sizeMsgs.length > 1 ) {
+                               s /= 1024;
+                               sizeMsgs = sizeMsgs.slice( 1 );
+                       }
+                       return mw.msg( sizeMsgs[ 0 ], Math.round( s ) );
+               }
+
                /**
                 * Show a thumbnail preview of PNG, JPEG, GIF, and SVG files prior to upload
                 * in browsers supporting HTML5 FileAPI.
                                .find( '.thumbinner' ).prepend( $spinner ).end();
 
                        $canvas = $( '<canvas>' ).attr( { width: previewSize, height: previewSize } );
-                       ctx = $canvas[0].getContext( '2d' );
+                       ctx = $canvas[ 0 ].getContext( '2d' );
                        $( '#mw-htmlform-source' ).parent().prepend( thumb );
 
                        fetchPreview( file, function ( dataURL ) {
                                                buffer = new Uint8Array( reader.result ),
                                                string = '';
                                        for ( i = 0; i < buffer.byteLength; i++ ) {
-                                               string += String.fromCharCode( buffer[i] );
+                                               string += String.fromCharCode( buffer[ i ] );
                                        }
                                        callbackBinary( string );
 
                        }
                }
 
-               /**
-                * Format a file size attractively.
-                *
-                * TODO: Match numeric formatting
-                *
-                * @param {number} s
-                * @return {string}
-                */
-               function prettySize( s ) {
-                       var sizeMsgs = ['size-bytes', 'size-kilobytes', 'size-megabytes', 'size-gigabytes'];
-                       while ( s >= 1024 && sizeMsgs.length > 1 ) {
-                               s /= 1024;
-                               sizeMsgs = sizeMsgs.slice( 1 );
-                       }
-                       return mw.msg( sizeMsgs[0], Math.round( s ) );
-               }
-
                /**
                 * Clear the file upload preview area.
                 */
                        function getMaxUploadSize( type ) {
                                var sizes = mw.config.get( 'wgMaxUploadSize' );
 
-                               if ( sizes[type] !== undefined ) {
-                                       return sizes[type];
+                               if ( sizes[ type ] !== undefined ) {
+                                       return sizes[ type ];
                                }
-                               return sizes['*'];
+                               return sizes[ '*' ];
                        }
 
                        $( '.mw-upload-source-error' ).remove();
                                clearPreview();
                                if ( this.files && this.files.length ) {
                                        // Note: would need to be updated to handle multiple files.
-                                       var file = this.files[0];
+                                       var file = this.files[ 0 ];
 
                                        if ( !checkMaxUploadSize( file ) ) {
                                                return;