X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=resources%2Fsrc%2Fmediawiki.special%2Fmediawiki.special.upload.js;h=677d26d7986ae15616c18b1efd4acae9017bbb32;hb=59ebff658ce912c1b0e7ef8d8f9bfec5a4e17b39;hp=ea1eb99260684337064e49bb2e827200115a908b;hpb=ba9f387ecd4de035f4bb4f48eaa30e1c15563c1f;p=lhc%2Fweb%2Fwiklou.git diff --git a/resources/src/mediawiki.special/mediawiki.special.upload.js b/resources/src/mediawiki.special/mediawiki.special.upload.js index ea1eb99260..677d26d798 100644 --- a/resources/src/mediawiki.special/mediawiki.special.upload.js +++ b/resources/src/mediawiki.special/mediawiki.special.upload.js @@ -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 ) { @@ -107,7 +108,7 @@ return; } if ( this.responseCache.hasOwnProperty( license ) ) { - this.showPreview( this.responseCache[license] ); + this.showPreview( this.responseCache[ license ] ); return; } @@ -126,8 +127,8 @@ }, 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 ) { @@ -228,7 +229,7 @@ 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 @@ -265,14 +266,31 @@ * TODO: Put SVG back after working around Firefox 7 bug * * @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. @@ -291,13 +309,17 @@ ctx, meta, previewSize = 180, + $spinner = $.createSpinner( { size: 'small', type: 'block' } ) + .css( { width: previewSize, height: previewSize } ), thumb = mw.template.get( 'mediawiki.special.upload', 'thumbnail.html' ).render(); - thumb.find( '.filename' ).text( file.name ).end() - .find( '.fileinfo' ).text( prettySize( file.size ) ).end(); + thumb + .find( '.filename' ).text( file.name ).end() + .find( '.fileinfo' ).text( prettySize( file.size ) ).end() + .find( '.thumbinner' ).prepend( $spinner ).end(); - $canvas = $( '' ); - ctx = $canvas[0].getContext( '2d' ); + $canvas = $( '' ).attr( { width: previewSize, height: previewSize } ); + ctx = $canvas[ 0 ].getContext( '2d' ); $( '#mw-htmlform-source' ).parent().prepend( thumb ); fetchPreview( file, function ( dataURL ) { @@ -369,7 +391,7 @@ ctx.clearRect( 0, 0, 180, 180 ); ctx.rotate( rotation / 180 * Math.PI ); ctx.drawImage( img, x, y, width, height ); - thumb.find( '.mw-small-spinner' ).replaceWith( $canvas ); + $spinner.replaceWith( $canvas ); // Image size info = mw.msg( 'widthheight', logicalWidth, logicalHeight ) + @@ -421,7 +443,7 @@ 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 ); @@ -450,23 +472,6 @@ } } - /** - * 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. */ @@ -483,10 +488,10 @@ 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(); @@ -511,7 +516,7 @@ 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;