From: Bartosz DziewoƄski Date: Mon, 4 Apr 2016 14:37:58 +0000 (+0200) Subject: mediawiki.special.upload: Don't fail when invalid title is given X-Git-Tag: 1.31.0-rc.0~7284^2 X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=commitdiff_plain;h=f42e1d7f216f44ec98dbb4e16d6b20eb3f281fb6 mediawiki.special.upload: Don't fail when invalid title is given If an invalid title was given (for example, anything including '['), the destination title check would throw an exception and a spinner would spin forever. Change-Id: If6f02051383675817a0e2ad406dd71cab33fb5bf --- diff --git a/resources/src/mediawiki.special/mediawiki.special.upload.js b/resources/src/mediawiki.special/mediawiki.special.upload.js index 8c89ed97d8..6bbe32d38c 100644 --- a/resources/src/mediawiki.special/mediawiki.special.upload.js +++ b/resources/src/mediawiki.special/mediawiki.special.upload.js @@ -57,22 +57,28 @@ }, timeout: function () { - var $spinnerDestCheck; + var $spinnerDestCheck, title; if ( !ajaxUploadDestCheck || this.nameToCheck === '' ) { return; } $spinnerDestCheck = $.createSpinner().insertAfter( '#wpDestFile' ); + title = mw.Title.newFromText( this.nameToCheck, mw.config.get( 'wgNamespaceIds' ).file ); ( new mw.Api() ).get( { action: 'query', - titles: ( new mw.Title( this.nameToCheck, mw.config.get( 'wgNamespaceIds' ).file ) ).getPrefixedText(), + // 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 } ).done( function ( result ) { - var resultOut = ''; - if ( result.query ) { - resultOut = result.query.pages[ result.query.pageids[ 0 ] ].imageinfo[ 0 ]; + 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 ); } $spinnerDestCheck.remove(); uploadWarning.processResult( resultOut, uploadWarning.nameToCheck ); @@ -80,8 +86,8 @@ }, processResult: function ( result, fileName ) { - this.setWarning( result.html ); - this.responseCache[ fileName ] = result.html; + this.setWarning( result ); + this.responseCache[ fileName ] = result; }, setWarning: function ( warning ) {