Merge "mediawiki.special.upload: Use ES5 .forEach() instead of jQuery"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Mon, 22 Jan 2018 20:24:58 +0000 (20:24 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Mon, 22 Jan 2018 20:24:58 +0000 (20:24 +0000)
1  2 
resources/src/mediawiki.special/mediawiki.special.upload.js

@@@ -61,7 -61,7 +61,7 @@@
  
                timeout: function () {
                        var $spinnerDestCheck, title;
 -                      if ( !ajaxUploadDestCheck || this.nameToCheck === '' ) {
 +                      if ( !ajaxUploadDestCheck || this.nameToCheck.trim() === '' ) {
                                return;
                        }
                        $spinnerDestCheck = $.createSpinner().insertAfter( '#wpDestFile' );
                                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,
 +                              titles: [ title ? title.getPrefixedText() : this.nameToCheck ],
                                prop: 'imageinfo',
 -                              iiprop: 'uploadwarning'
 +                              iiprop: 'uploadwarning',
 +                              errorformat: 'html',
 +                              errorlang: mw.config.get( 'wgUserLanguage' )
                        } ).done( function ( result ) {
                                var
                                        resultOut = '',
@@@ -83,7 -81,7 +83,7 @@@
                                if ( page.imageinfo ) {
                                        resultOut = page.imageinfo[ 0 ].html;
                                } else if ( page.invalidreason ) {
 -                                      resultOut = mw.html.escape( page.invalidreason );
 +                                      resultOut = page.invalidreason.html;
                                }
                                uploadWarning.processResult( resultOut, uploadWarning.nameToCheck );
                        } ).always( function () {
  
                        $spinner = $.createSpinner().insertAfter( $element );
  
 -                      ( new mw.Api() ).get( {
 -                              formatversion: 2,
 -                              action: 'parse',
 -                              text: '{{' + template + '}}',
 +                      ( new mw.Api() ).parse( '{{' + template + '}}', {
                                title: $( '#wpDestFile' ).val() || 'File:Sample.jpg',
                                prop: 'text',
                                pst: true,
                },
  
                processResult: function ( result, template, $previewContainer ) {
 -                      this.responseCache[ template ] = result.parse.text;
 +                      this.responseCache[ template ] = result;
                        this.showPreview( this.responseCache[ template ], $previewContainer );
                },
  
                }
  
                // fillDestFile setup
-               $.each( mw.config.get( 'wgUploadSourceIds' ), function ( index, sourceId ) {
+               mw.config.get( 'wgUploadSourceIds' ).forEach( function ( sourceId ) {
                        $( '#' + sourceId ).change( function () {
                                var path, slash, backslash, fname;
                                if ( !mw.config.get( 'wgUploadAutoFill' ) ) {