jenkins-bot has submitted this change and it was merged.

Change subject: mediawiki.special.upload: Don't fail when invalid title is given
......................................................................


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
---
M resources/src/mediawiki.special/mediawiki.special.upload.js
1 file changed, 13 insertions(+), 7 deletions(-)

Approvals:
  Fomafix: Looks good to me, but someone else must approve
  MarkTraceur: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/resources/src/mediawiki.special/mediawiki.special.upload.js 
b/resources/src/mediawiki.special/mediawiki.special.upload.js
index 8c89ed9..6bbe32d 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 ) {

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

Gerrit-MessageType: merged
Gerrit-Change-Id: If6f02051383675817a0e2ad406dd71cab33fb5bf
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Bartosz Dziewoński <[email protected]>
Gerrit-Reviewer: Bartosz Dziewoński <[email protected]>
Gerrit-Reviewer: Edokter <[email protected]>
Gerrit-Reviewer: Fomafix
Gerrit-Reviewer: Jack Phoenix <[email protected]>
Gerrit-Reviewer: MarkTraceur <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to