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

Change subject: Merge mediawiki.legacy.upload into mediawiki.special.upload
......................................................................


Merge mediawiki.legacy.upload into mediawiki.special.upload

Bug: 31946
Change-Id: Iba7d5a655847f00dde8f11c46dfc13f43b610433
---
M includes/specials/SpecialUpload.php
M resources/Resources.php
D resources/src/mediawiki.legacy/upload.js
M resources/src/mediawiki.special/mediawiki.special.upload.js
4 files changed, 248 insertions(+), 260 deletions(-)

Approvals:
  Bartosz Dziewoński: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/includes/specials/SpecialUpload.php 
b/includes/specials/SpecialUpload.php
index 5c5026c..7acd0f9 100644
--- a/includes/specials/SpecialUpload.php
+++ b/includes/specials/SpecialUpload.php
@@ -1135,8 +1135,7 @@
 
                $out->addModules( array(
                        'mediawiki.action.edit', // For <charinsert> support
-                       'mediawiki.legacy.upload', // Old form stuff...
-                       'mediawiki.special.upload', // Newer extras for 
thumbnail preview.
+                       'mediawiki.special.upload', // Extras for thumbnail and 
license preview.
                ) );
        }
 
diff --git a/resources/Resources.php b/resources/Resources.php
index 946f3c9..36959ef 100644
--- a/resources/Resources.php
+++ b/resources/Resources.php
@@ -1309,7 +1309,6 @@
                'scripts' => 
'resources/src/mediawiki.special/mediawiki.special.undelete.js',
        ),
        'mediawiki.special.upload' => array(
-               // @todo merge in remainder of mediawiki.legacy.upload
                'scripts' => 
'resources/src/mediawiki.special/mediawiki.special.upload.js',
                'messages' => array(
                        'widthheight',
@@ -1320,7 +1319,10 @@
                        'largefileserver',
                ),
                'dependencies' => array(
+                       'jquery.spinner',
+                       'mediawiki.api',
                        'mediawiki.libs.jpegmeta',
+                       'mediawiki.Title',
                        'mediawiki.util',
                ),
        ),
@@ -1434,15 +1436,6 @@
        ),
        'mediawiki.legacy.oldshared' => array(
                'styles' => array( 
'resources/src/mediawiki.legacy/oldshared.css' => array( 'media' => 'screen' ) 
),
-       ),
-       'mediawiki.legacy.upload' => array(
-               'scripts' => 'resources/src/mediawiki.legacy/upload.js',
-               'dependencies' => array(
-                       'jquery.spinner',
-                       'mediawiki.api',
-                       'mediawiki.Title',
-                       'mediawiki.util',
-               ),
        ),
        'mediawiki.legacy.wikibits' => array(
                'scripts' => 'resources/src/mediawiki.legacy/wikibits.js',
diff --git a/resources/src/mediawiki.legacy/upload.js 
b/resources/src/mediawiki.legacy/upload.js
deleted file mode 100644
index c81b388..0000000
--- a/resources/src/mediawiki.legacy/upload.js
+++ /dev/null
@@ -1,246 +0,0 @@
-/*jshint camelcase:false */
-( function ( mw, $ ) {
-       var ajaxUploadDestCheck = mw.config.get( 'wgAjaxUploadDestCheck' ),
-               $license = $( '#wpLicense' ), uploadWarning, uploadLicense;
-
-       window.wgUploadWarningObj = uploadWarning = {
-               responseCache: { '': '&nbsp;' },
-               nameToCheck: '',
-               typing: false,
-               delay: 500, // ms
-               timeoutID: false,
-
-               keypress: function () {
-                       if ( !ajaxUploadDestCheck ) {
-                               return;
-                       }
-
-                       // Find file to upload
-                       if ( !$( '#wpDestFile' ).length || !$( 
'#wpDestFile-warning' ).length ) {
-                               return;
-                       }
-
-                       this.nameToCheck = $( '#wpDestFile' ).val();
-
-                       // Clear timer
-                       if ( this.timeoutID ) {
-                               clearTimeout( this.timeoutID );
-                       }
-                       // Check response cache
-                       if ( this.responseCache.hasOwnProperty( 
this.nameToCheck ) ) {
-                               this.setWarning( 
this.responseCache[this.nameToCheck] );
-                               return;
-                       }
-
-                       this.timeoutID = setTimeout( function () {
-                               uploadWarning.timeout();
-                       }, this.delay );
-               },
-
-               checkNow: function ( fname ) {
-                       if ( !ajaxUploadDestCheck ) {
-                               return;
-                       }
-                       if ( this.timeoutID ) {
-                               clearTimeout( this.timeoutID );
-                       }
-                       this.nameToCheck = fname;
-                       this.timeout();
-               },
-
-               timeout: function () {
-                       var $spinnerDestCheck;
-                       if ( !ajaxUploadDestCheck || this.nameToCheck === '' ) {
-                               return;
-                       }
-                       $spinnerDestCheck = $.createSpinner().insertAfter( 
'#wpDestFile' );
-
-                       ( new mw.Api() ).get( {
-                               action: 'query',
-                               titles: ( new mw.Title( this.nameToCheck, 
mw.config.get( 'wgNamespaceIds' ).file ) ).getPrefixedText(),
-                               prop: 'imageinfo',
-                               iiprop: 'uploadwarning',
-                               indexpageids: ''
-                       } ).done( function ( result ) {
-                               var resultOut = '';
-                               if ( result.query ) {
-                                       resultOut = 
result.query.pages[result.query.pageids[0]].imageinfo[0];
-                               }
-                               $spinnerDestCheck.remove();
-                               uploadWarning.processResult( resultOut, 
uploadWarning.nameToCheck );
-                       } );
-               },
-
-               processResult: function ( result, fileName ) {
-                       this.setWarning( result.html );
-                       this.responseCache[fileName] = result.html;
-               },
-
-               setWarning: function ( warning ) {
-                       $( '#wpDestFile-warning' ).html( 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( '' );
-                       } else {
-                               $( '#wpDestFileWarningAck' ).val( '1' );
-                       }
-
-               }
-       };
-
-       uploadLicense = {
-
-               responseCache: { '': '' },
-
-               fetchPreview: function ( license ) {
-                       var $spinnerLicense;
-                       if ( !mw.config.get( 'wgAjaxLicensePreview' ) ) {
-                               return;
-                       }
-                       if ( this.responseCache.hasOwnProperty( license ) ) {
-                               this.showPreview( this.responseCache[license] );
-                               return;
-                       }
-
-                       $spinnerLicense = $.createSpinner().insertAfter( 
'#wpLicense' );
-
-                       ( new mw.Api() ).get( {
-                               action: 'parse',
-                               text: '{{' + license + '}}',
-                               title: $( '#wpDestFile' ).val() || 
'File:Sample.jpg',
-                               prop: 'text',
-                               pst: ''
-                       } ).done( function ( result ) {
-                               $spinnerLicense.remove();
-                               uploadLicense.processResult( result, license );
-                       } );
-               },
-
-               processResult: function ( result, license ) {
-                       this.responseCache[license] = result.parse.text['*'];
-                       this.showPreview( this.responseCache[license] );
-               },
-
-               showPreview: function ( preview ) {
-                       $( '#mw-license-preview' ).html( preview );
-               }
-
-       };
-
-       $( function () {
-               // Disable URL box if the URL copy upload source type is not 
selected
-               if ( !$( '#wpSourceTypeurl' ).prop( 'checked' ) ) {
-                       $( '#wpUploadFileURL' ).prop( 'disabled', true );
-               }
-
-               // AJAX wpDestFile warnings
-               if ( ajaxUploadDestCheck ) {
-                       // Insert an event handler that fetches upload warnings 
when wpDestFile
-                       // has been changed
-                       $( '#wpDestFile' ).change( function () {
-                               uploadWarning.checkNow( $( this ).val() );
-                       } );
-                       // Insert a row where the warnings will be displayed 
just below the
-                       // wpDestFile row
-                       $( '#mw-htmlform-description tbody' ).append(
-                               $( '<tr>' ).append(
-                                       $( '<td>' )
-                                               .attr( 'id', 
'wpDestFile-warning' )
-                                               .attr( 'colspan', 2 )
-                               )
-                       );
-               }
-
-               if ( mw.config.get( 'wgAjaxLicensePreview' ) && $license.length 
) {
-                       // License selector check
-                       $license.change( function () {
-                               // We might show a preview
-                               uploadLicense.fetchPreview( $license.val() );
-                       } );
-
-                       // License selector table row
-                       $license.closest( 'tr' ).after(
-                               $( '<tr>' ).append(
-                                       $( '<td>' ),
-                                       $( '<td>' ).attr( 'id', 
'mw-license-preview' )
-                               )
-                       );
-               }
-
-               // fillDestFile setup
-               $.each( mw.config.get( 'wgUploadSourceIds' ), function ( index, 
sourceId ) {
-                       $( '#' + sourceId ).change( function () {
-                               var path, slash, backslash, fname;
-                               if ( !mw.config.get( 'wgUploadAutoFill' ) ) {
-                                       return;
-                               }
-                               // Remove any previously flagged errors
-                               $( '#mw-upload-permitted' ).attr( 'class', '' );
-                               $( '#mw-upload-prohibited' ).attr( 'class', '' 
);
-
-                               path = $( this ).val();
-                               // Find trailing part
-                               slash = path.lastIndexOf( '/' );
-                               backslash = path.lastIndexOf( '\\' );
-                               if ( slash === -1 && backslash === -1 ) {
-                                       fname = path;
-                               } else if ( slash > backslash ) {
-                                       fname = path.slice( slash + 1 );
-                               } else {
-                                       fname = path.slice( backslash + 1 );
-                               }
-
-                               // Clear the filename if it does not have a 
valid extension.
-                               // URLs are less likely to have a useful 
extension, so don't include them in the
-                               // extension check.
-                               if (
-                                       mw.config.get( 'wgStrictFileExtensions' 
) &&
-                                       mw.config.get( 'wgFileExtensions' ) &&
-                                       $( this ).attr( 'id' ) !== 
'wpUploadFileURL'
-                               ) {
-                                       if (
-                                               fname.lastIndexOf( '.' ) === -1 
||
-                                               $.inArray(
-                                                       fname.slice( 
fname.lastIndexOf( '.' ) + 1 ).toLowerCase(),
-                                                       $.map( mw.config.get( 
'wgFileExtensions' ), function ( element ) {
-                                                               return 
element.toLowerCase();
-                                                       } )
-                                               ) === -1
-                                       ) {
-                                               // Not a valid extension
-                                               // Clear the upload and set 
mw-upload-permitted to error
-                                               $( this ).val( '' );
-                                               $( '#mw-upload-permitted' 
).attr( 'class', 'error' );
-                                               $( '#mw-upload-prohibited' 
).attr( 'class', 'error' );
-                                               // Clear wpDestFile as well
-                                               $( '#wpDestFile' ).val( '' );
-
-                                               return false;
-                                       }
-                               }
-
-                               // Replace spaces by underscores
-                               fname = fname.replace( / /g, '_' );
-                               // Capitalise first letter if needed
-                               if ( mw.config.get( 'wgCapitalizeUploads' ) ) {
-                                       fname = fname.charAt( 0 
).toUpperCase().concat( fname.slice( 1 ) );
-                               }
-
-                               // Output result
-                               if ( $( '#wpDestFile' ).length ) {
-                                       // Call decodeURIComponent function to 
remove possible URL-encoded characters
-                                       // from the file name (bug 30390). 
Especially likely with upload-form-url.
-                                       // decodeURIComponent can throw an 
exception if input is invalid utf-8
-                                       try {
-                                               $( '#wpDestFile' ).val( 
decodeURIComponent( fname ) );
-                                       } catch ( err ) {
-                                               $( '#wpDestFile' ).val( fname );
-                                       }
-                                       uploadWarning.checkNow( fname );
-                               }
-                       } );
-               } );
-       } );
-}( mediaWiki, jQuery ) );
diff --git a/resources/src/mediawiki.special/mediawiki.special.upload.js 
b/resources/src/mediawiki.special/mediawiki.special.upload.js
index 3c7ad52..286befc 100644
--- a/resources/src/mediawiki.special/mediawiki.special.upload.js
+++ b/resources/src/mediawiki.special/mediawiki.special.upload.js
@@ -1,13 +1,255 @@
 /**
  * JavaScript for Special:Upload
  *
- * Note that additional code still lives in skins/common/upload.js
- *
  * @private
  * @class mw.special.upload
  * @singleton
  */
 ( function ( mw, $ ) {
+       var ajaxUploadDestCheck = mw.config.get( 'wgAjaxUploadDestCheck' ),
+               $license = $( '#wpLicense' ), uploadWarning, uploadLicense;
+
+       window.wgUploadWarningObj = uploadWarning = {
+               responseCache: { '': '&nbsp;' },
+               nameToCheck: '',
+               typing: false,
+               delay: 500, // ms
+               timeoutID: false,
+
+               keypress: function () {
+                       if ( !ajaxUploadDestCheck ) {
+                               return;
+                       }
+
+                       // Find file to upload
+                       if ( !$( '#wpDestFile' ).length || !$( 
'#wpDestFile-warning' ).length ) {
+                               return;
+                       }
+
+                       this.nameToCheck = $( '#wpDestFile' ).val();
+
+                       // Clear timer
+                       if ( this.timeoutID ) {
+                               clearTimeout( this.timeoutID );
+                       }
+                       // Check response cache
+                       if ( this.responseCache.hasOwnProperty( 
this.nameToCheck ) ) {
+                               this.setWarning( 
this.responseCache[this.nameToCheck] );
+                               return;
+                       }
+
+                       this.timeoutID = setTimeout( function () {
+                               uploadWarning.timeout();
+                       }, this.delay );
+               },
+
+               checkNow: function ( fname ) {
+                       if ( !ajaxUploadDestCheck ) {
+                               return;
+                       }
+                       if ( this.timeoutID ) {
+                               clearTimeout( this.timeoutID );
+                       }
+                       this.nameToCheck = fname;
+                       this.timeout();
+               },
+
+               timeout: function () {
+                       var $spinnerDestCheck;
+                       if ( !ajaxUploadDestCheck || this.nameToCheck === '' ) {
+                               return;
+                       }
+                       $spinnerDestCheck = $.createSpinner().insertAfter( 
'#wpDestFile' );
+
+                       ( new mw.Api() ).get( {
+                               action: 'query',
+                               titles: ( new mw.Title( this.nameToCheck, 
mw.config.get( 'wgNamespaceIds' ).file ) ).getPrefixedText(),
+                               prop: 'imageinfo',
+                               iiprop: 'uploadwarning',
+                               indexpageids: ''
+                       } ).done( function ( result ) {
+                               var resultOut = '';
+                               if ( result.query ) {
+                                       resultOut = 
result.query.pages[result.query.pageids[0]].imageinfo[0];
+                               }
+                               $spinnerDestCheck.remove();
+                               uploadWarning.processResult( resultOut, 
uploadWarning.nameToCheck );
+                       } );
+               },
+
+               processResult: function ( result, fileName ) {
+                       this.setWarning( result.html );
+                       this.responseCache[fileName] = result.html;
+               },
+
+               setWarning: function ( warning ) {
+                       $( '#wpDestFile-warning' ).html( 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( '' );
+                       } else {
+                               $( '#wpDestFileWarningAck' ).val( '1' );
+                       }
+
+               }
+       };
+
+       uploadLicense = {
+
+               responseCache: { '': '' },
+
+               fetchPreview: function ( license ) {
+                       var $spinnerLicense;
+                       if ( !mw.config.get( 'wgAjaxLicensePreview' ) ) {
+                               return;
+                       }
+                       if ( this.responseCache.hasOwnProperty( license ) ) {
+                               this.showPreview( this.responseCache[license] );
+                               return;
+                       }
+
+                       $spinnerLicense = $.createSpinner().insertAfter( 
'#wpLicense' );
+
+                       ( new mw.Api() ).get( {
+                               action: 'parse',
+                               text: '{{' + license + '}}',
+                               title: $( '#wpDestFile' ).val() || 
'File:Sample.jpg',
+                               prop: 'text',
+                               pst: ''
+                       } ).done( function ( result ) {
+                               $spinnerLicense.remove();
+                               uploadLicense.processResult( result, license );
+                       } );
+               },
+
+               processResult: function ( result, license ) {
+                       this.responseCache[license] = result.parse.text['*'];
+                       this.showPreview( this.responseCache[license] );
+               },
+
+               showPreview: function ( preview ) {
+                       $( '#mw-license-preview' ).html( preview );
+               }
+
+       };
+
+       $( function () {
+               // Disable URL box if the URL copy upload source type is not 
selected
+               if ( !$( '#wpSourceTypeurl' ).prop( 'checked' ) ) {
+                       $( '#wpUploadFileURL' ).prop( 'disabled', true );
+               }
+
+               // AJAX wpDestFile warnings
+               if ( ajaxUploadDestCheck ) {
+                       // Insert an event handler that fetches upload warnings 
when wpDestFile
+                       // has been changed
+                       $( '#wpDestFile' ).change( function () {
+                               uploadWarning.checkNow( $( this ).val() );
+                       } );
+                       // Insert a row where the warnings will be displayed 
just below the
+                       // wpDestFile row
+                       $( '#mw-htmlform-description tbody' ).append(
+                               $( '<tr>' ).append(
+                                       $( '<td>' )
+                                               .attr( 'id', 
'wpDestFile-warning' )
+                                               .attr( 'colspan', 2 )
+                               )
+                       );
+               }
+
+               if ( mw.config.get( 'wgAjaxLicensePreview' ) && $license.length 
) {
+                       // License selector check
+                       $license.change( function () {
+                               // We might show a preview
+                               uploadLicense.fetchPreview( $license.val() );
+                       } );
+
+                       // License selector table row
+                       $license.closest( 'tr' ).after(
+                               $( '<tr>' ).append(
+                                       $( '<td>' ),
+                                       $( '<td>' ).attr( 'id', 
'mw-license-preview' )
+                               )
+                       );
+               }
+
+               // fillDestFile setup
+               $.each( mw.config.get( 'wgUploadSourceIds' ), function ( index, 
sourceId ) {
+                       $( '#' + sourceId ).change( function () {
+                               var path, slash, backslash, fname;
+                               if ( !mw.config.get( 'wgUploadAutoFill' ) ) {
+                                       return;
+                               }
+                               // Remove any previously flagged errors
+                               $( '#mw-upload-permitted' ).attr( 'class', '' );
+                               $( '#mw-upload-prohibited' ).attr( 'class', '' 
);
+
+                               path = $( this ).val();
+                               // Find trailing part
+                               slash = path.lastIndexOf( '/' );
+                               backslash = path.lastIndexOf( '\\' );
+                               if ( slash === -1 && backslash === -1 ) {
+                                       fname = path;
+                               } else if ( slash > backslash ) {
+                                       fname = path.slice( slash + 1 );
+                               } else {
+                                       fname = path.slice( backslash + 1 );
+                               }
+
+                               // Clear the filename if it does not have a 
valid extension.
+                               // URLs are less likely to have a useful 
extension, so don't include them in the
+                               // extension check.
+                               if (
+                                       mw.config.get( 'wgStrictFileExtensions' 
) &&
+                                       mw.config.get( 'wgFileExtensions' ) &&
+                                       $( this ).attr( 'id' ) !== 
'wpUploadFileURL'
+                               ) {
+                                       if (
+                                               fname.lastIndexOf( '.' ) === -1 
||
+                                               $.inArray(
+                                                       fname.slice( 
fname.lastIndexOf( '.' ) + 1 ).toLowerCase(),
+                                                       $.map( mw.config.get( 
'wgFileExtensions' ), function ( element ) {
+                                                               return 
element.toLowerCase();
+                                                       } )
+                                               ) === -1
+                                       ) {
+                                               // Not a valid extension
+                                               // Clear the upload and set 
mw-upload-permitted to error
+                                               $( this ).val( '' );
+                                               $( '#mw-upload-permitted' 
).attr( 'class', 'error' );
+                                               $( '#mw-upload-prohibited' 
).attr( 'class', 'error' );
+                                               // Clear wpDestFile as well
+                                               $( '#wpDestFile' ).val( '' );
+
+                                               return false;
+                                       }
+                               }
+
+                               // Replace spaces by underscores
+                               fname = fname.replace( / /g, '_' );
+                               // Capitalise first letter if needed
+                               if ( mw.config.get( 'wgCapitalizeUploads' ) ) {
+                                       fname = fname.charAt( 0 
).toUpperCase().concat( fname.slice( 1 ) );
+                               }
+
+                               // Output result
+                               if ( $( '#wpDestFile' ).length ) {
+                                       // Call decodeURIComponent function to 
remove possible URL-encoded characters
+                                       // from the file name (bug 30390). 
Especially likely with upload-form-url.
+                                       // decodeURIComponent can throw an 
exception if input is invalid utf-8
+                                       try {
+                                               $( '#wpDestFile' ).val( 
decodeURIComponent( fname ) );
+                                       } catch ( err ) {
+                                               $( '#wpDestFile' ).val( fname );
+                                       }
+                                       uploadWarning.checkNow( fname );
+                               }
+                       } );
+               } );
+       } );
+
        // Add a preview to the upload form
        $( function () {
                /**

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

Gerrit-MessageType: merged
Gerrit-Change-Id: Iba7d5a655847f00dde8f11c46dfc13f43b610433
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Alex Monk <[email protected]>
Gerrit-Reviewer: Bartosz Dziewoński <[email protected]>
Gerrit-Reviewer: Helder.wiki <[email protected]>
Gerrit-Reviewer: Jack Phoenix <[email protected]>
Gerrit-Reviewer: Krinkle <[email protected]>
Gerrit-Reviewer: PleaseStand <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to