X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=resources%2Fsrc%2Fmediawiki.special%2Fmediawiki.special.upload.js;h=f818096377720c9b62e37a17dba52e861f100755;hb=2231d4e859628fc4d2fb63a7a752ead5b91ffef2;hp=377b1f7ebd88d8d449943e129b287d69ea642473;hpb=4ce349cdbfe51da968c96ca2c72ae465538510cc;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 377b1f7ebd..f818096377 100644 --- a/resources/src/mediawiki.special/mediawiki.special.upload.js +++ b/resources/src/mediawiki.special/mediawiki.special.upload.js @@ -5,8 +5,11 @@ * @class mw.special.upload * @singleton */ + +/* eslint-disable no-use-before-define */ +/* global Uint8Array */ + ( function ( mw, $ ) { - /*jshint latedef:false */ var uploadWarning, uploadLicense, ajaxUploadDestCheck = mw.config.get( 'wgAjaxUploadDestCheck' ), $license = $( '#wpLicense' ); @@ -65,23 +68,24 @@ title = mw.Title.newFromText( this.nameToCheck, mw.config.get( 'wgNamespaceIds' ).file ); ( new mw.Api() ).get( { + formatversion: 2, action: 'query', // If title is empty, user input is invalid, the API call will produce details about why titles: title ? title.getPrefixedText() : this.nameToCheck, prop: 'imageinfo', - iiprop: 'uploadwarning', - indexpageids: true + iiprop: 'uploadwarning' } ).done( function ( result ) { var resultOut = '', - pageId = result.query.pageids[ 0 ]; - if ( result.query.pages[ pageId ].imageinfo ) { - resultOut = result.query.pages[ pageId ].imageinfo[ 0 ].html; - } else if ( result.query.pages[ pageId ].invalidreason ) { - resultOut = mw.html.escape( result.query.pages[ pageId ].invalidreason ); + page = result.query.pages[ 0 ]; + if ( page.imageinfo ) { + resultOut = page.imageinfo[ 0 ].html; + } else if ( page.invalidreason ) { + resultOut = mw.html.escape( page.invalidreason ); } - $spinnerDestCheck.remove(); uploadWarning.processResult( resultOut, uploadWarning.nameToCheck ); + } ).always( function () { + $spinnerDestCheck.remove(); } ); }, @@ -91,16 +95,19 @@ }, setWarning: function ( warning ) { - var $warning = $( $.parseHTML( warning ) ); + var $warningBox = $( '#wpDestFile-warning' ), + $warning = $( $.parseHTML( warning ) ); mw.hook( 'wikipage.content' ).fire( $warning ); - $( '#wpDestFile-warning' ).empty().append( $warning ); + $warningBox.empty().append( $warning ); // Set a value in the form indicating that the warning is acknowledged and // doesn't need to be redisplayed post-upload if ( !warning ) { $( '#wpDestFileWarningAck' ).val( '' ); + $warningBox.removeAttr( 'class' ); } else { $( '#wpDestFileWarningAck' ).val( '1' ); + $warningBox.attr( 'class', 'mw-destfile-warning' ); } } @@ -123,19 +130,21 @@ $spinnerLicense = $.createSpinner().insertAfter( '#wpLicense' ); ( new mw.Api() ).get( { + formatversion: 2, action: 'parse', text: '{{' + license + '}}', title: $( '#wpDestFile' ).val() || 'File:Sample.jpg', prop: 'text', pst: true } ).done( function ( result ) { - $spinnerLicense.remove(); uploadLicense.processResult( result, license ); + } ).always( function () { + $spinnerLicense.remove(); } ); }, processResult: function ( result, license ) { - this.responseCache[ license ] = result.parse.text[ '*' ]; + this.responseCache[ license ] = result.parse.text; this.showPreview( this.responseCache[ license ] ); }, @@ -260,6 +269,8 @@ $( function () { /** * Is the FileAPI available with sufficient functionality? + * + * @return {boolean} */ function hasFileAPI() { return window.FileReader !== undefined; @@ -415,9 +426,8 @@ }, mw.config.get( 'wgFileCanRotate' ) ? function ( data ) { try { meta = mw.libs.jpegmeta( data, file.fileName ); - // jscs:disable requireCamelCaseOrUpperCaseIdentifiers, disallowDanglingUnderscores + // eslint-disable-next-line no-underscore-dangle, camelcase meta._binary_data = null; - // jscs:enable } catch ( e ) { meta = null; } @@ -493,6 +503,9 @@ /** * Check if the file does not exceed the maximum size + * + * @param {File} file + * @return {boolean} */ function checkMaxUploadSize( file ) { var maxSize, $error; @@ -525,10 +538,11 @@ if ( hasFileAPI() ) { // Update thumbnail when the file selection control is updated. $( '#wpUploadFile' ).change( function () { + var file; clearPreview(); if ( this.files && this.files.length ) { // Note: would need to be updated to handle multiple files. - var file = this.files[ 0 ]; + file = this.files[ 0 ]; if ( !checkMaxUploadSize( file ) ) { return;