Bartosz Dziewoński has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/300797

Change subject: Stop using and remove mw.UploadWizard.sanitizeFilename
......................................................................

Stop using and remove mw.UploadWizard.sanitizeFilename

It was disallowing some perfectly valid characters (like '%') and
letting through many invalid ones (like '[').

mw.Title.newFromFileName() is the right function to use to turn
anything into a file name, and we were already using it in some
places.

Change-Id: I57a94cf12d58c7e1cddaaba42484039e87ac0bbb
---
M UploadWizardHooks.php
M resources/handlers/mw.ApiUploadFormDataHandler.js
M resources/mw.UploadWizard.js
M resources/mw.UploadWizardUpload.js
M resources/mw.UploadWizardUploadInterface.js
M resources/transports/mw.FormDataTransport.js
D tests/qunit/mw.UploadWizard.test.js
7 files changed, 7 insertions(+), 65 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/UploadWizard 
refs/changes/97/300797/1

diff --git a/UploadWizardHooks.php b/UploadWizardHooks.php
index d4f6382..8a47270 100644
--- a/UploadWizardHooks.php
+++ b/UploadWizardHooks.php
@@ -169,7 +169,6 @@
                                
'tests/qunit/transports/mw.FormDataTransport.test.js',
                                'tests/qunit/uw.EventFlowLogger.test.js',
                                'tests/qunit/uw.ConcurrentQueue.test.js',
-                               'tests/qunit/mw.UploadWizard.test.js',
                                'tests/qunit/mw.UploadWizardUpload.test.js',
                                
'tests/qunit/mw.UploadWizardLicenseInput.test.js',
                                'tests/qunit/mw.FlickrChecker.test.js',
diff --git a/resources/handlers/mw.ApiUploadFormDataHandler.js 
b/resources/handlers/mw.ApiUploadFormDataHandler.js
index aab1c2a..57a30df 100644
--- a/resources/handlers/mw.ApiUploadFormDataHandler.js
+++ b/resources/handlers/mw.ApiUploadFormDataHandler.js
@@ -56,7 +56,7 @@
                                handler.beginTime = ( new Date() ).getTime();
                                handler.upload.ui.setStatus( 
'mwe-upwiz-transport-started' );
                                handler.upload.ui.showTransportProgress();
-                               return handler.transport.upload( 
handler.upload.file )
+                               return handler.transport.upload( 
handler.upload.file, handler.upload.title.getMainText() )
                                        .progress( function ( fraction ) {
                                                if ( handler.upload.state === 
'aborted' ) {
                                                        
handler.transport.xhr.abort();
diff --git a/resources/mw.UploadWizard.js b/resources/mw.UploadWizard.js
index fe559e6..ae49db2 100644
--- a/resources/mw.UploadWizard.js
+++ b/resources/mw.UploadWizard.js
@@ -462,18 +462,6 @@
        };
 
        /**
-        * Sanitizes a filename for use as a File: page title
-        *
-        * @static
-        * @param {string} filename Pre-sanitization filename.
-        * @return {string} Filename sanitized for use as a title.
-        */
-       mw.UploadWizard.sanitizeFilename = function ( filename ) {
-               var illegalCharRegex = new RegExp( '[' + mw.config.get( 
'wgIllegalFileChars', '' ) + '#:%]', 'g' );
-               return filename.replace( illegalCharRegex, '-' );
-       };
-
-       /**
         * Get the own work and third party licensing deeds if they are needed.
         *
         * @static
diff --git a/resources/mw.UploadWizardUpload.js 
b/resources/mw.UploadWizardUpload.js
index 282bb90..4168b6a 100644
--- a/resources/mw.UploadWizardUpload.js
+++ b/resources/mw.UploadWizardUpload.js
@@ -480,7 +480,7 @@
         * @param {string} title Unsanitized title.
         */
        mw.UploadWizardUpload.prototype.setTitle = function ( title ) {
-               this.title = mw.Title.newFromFileName( 
mw.UploadWizard.sanitizeFilename( title ) );
+               this.title = mw.Title.newFromFileName( title );
        };
 
        /**
diff --git a/resources/mw.UploadWizardUploadInterface.js 
b/resources/mw.UploadWizardUploadInterface.js
index 77313f8..4643ef9 100644
--- a/resources/mw.UploadWizardUploadInterface.js
+++ b/resources/mw.UploadWizardUploadInterface.js
@@ -353,7 +353,7 @@
 
                // visible filename
                this.$form.find( '.mwe-upwiz-visible-file-filename-text' )
-                       .text( mw.UploadWizard.sanitizeFilename( path ) );
+                       .text( path );
 
                if ( !this.isFilled ) {
                        $div = $( this.div );
diff --git a/resources/transports/mw.FormDataTransport.js 
b/resources/transports/mw.FormDataTransport.js
index e637d17..2f6cbf9 100644
--- a/resources/transports/mw.FormDataTransport.js
+++ b/resources/transports/mw.FormDataTransport.js
@@ -104,14 +104,16 @@
        /**
         * Start the upload with the provided file.
         *
+        * @param {File} file
+        * @param {string} tempFileName
         * @return {jQuery.Promise}
         */
-       mw.FormDataTransport.prototype.upload = function ( file ) {
+       mw.FormDataTransport.prototype.upload = function ( file, tempFileName ) 
{
                var formData, deferred, ext,
                        transport = this;
 
                // use timestamp + filename to avoid conflicts on server
-               this.tempname = ( new Date() ).getTime().toString() + 
mw.UploadWizard.sanitizeFilename( file.name );
+               this.tempname = ( new Date() ).getTime().toString() + 
tempFileName;
                // remove unicode characters, tempname is only used during 
upload
                this.tempname = this.tempname.split( '' ).map( function ( c ) {
                        return c.charCodeAt( 0 ) > 128 ? '_' : c;
diff --git a/tests/qunit/mw.UploadWizard.test.js 
b/tests/qunit/mw.UploadWizard.test.js
deleted file mode 100644
index cfbd32c..0000000
--- a/tests/qunit/mw.UploadWizard.test.js
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * This file is part of the MediaWiki extension UploadWizard.
- *
- * UploadWizard is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 2 of the License, or
- * (at your option) any later version.
- *
- * UploadWizard is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with UploadWizard.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-( function ( mw ) {
-       QUnit.module( 'mw.UploadWizard', QUnit.newMwEnvironment() );
-
-       QUnit.test( 'constructor sanity test', 1, function ( assert ) {
-               var wizard = new mw.UploadWizard( {} );
-               assert.ok( wizard );
-       } );
-
-       QUnit.test( 'sanitizeFilename', 3, function ( assert ) {
-               var oldchars = mw.config.get( 'wgIllegalFileChars', '' );
-
-               assert.strictEqual(
-                       mw.UploadWizard.sanitizeFilename( '#winning at 
100%.jpg' ),
-                       '-winning at 100-.jpg'
-               );
-
-               assert.strictEqual(
-                       mw.UploadWizard.sanitizeFilename( 'perfectly acceptable 
filename.jpg' ),
-                       'perfectly acceptable filename.jpg'
-               );
-
-               mw.config.set( 'wgIllegalFileChars', 'f' );
-               assert.strictEqual(
-                       mw.UploadWizard.sanitizeFilename( 'free the forest from 
fires.jpg' ),
-                       '-ree the -orest -rom -ires.jpg'
-               );
-
-               mw.config.set( 'wgIllegalFileChars', oldchars );
-       } );
-}( mediaWiki, jQuery ) );

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I57a94cf12d58c7e1cddaaba42484039e87ac0bbb
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/UploadWizard
Gerrit-Branch: master
Gerrit-Owner: Bartosz Dziewoński <matma....@gmail.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to