Rillke has uploaded a new change for review.

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

Change subject: Accept files that have whose name are invalid titles
......................................................................

Accept files that have whose name are invalid titles

Invalid titles from the perspective of MediaWiki but valid file names
for most file systems/ operation systems.

Currently UploadWizard rejects all selected files if just one of them
carries an invalid title as its name.

Bug: 64912
Change-Id: Ia57e4b0e804dfbf70e85b1bc2b7e9362277730bd
---
M resources/mw.UploadWizardUpload.js
1 file changed, 28 insertions(+), 1 deletion(-)


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

diff --git a/resources/mw.UploadWizardUpload.js 
b/resources/mw.UploadWizardUpload.js
index 8d36aad..21400c5 100644
--- a/resources/mw.UploadWizardUpload.js
+++ b/resources/mw.UploadWizardUpload.js
@@ -331,6 +331,33 @@
        },
 
        /**
+        * Sanitizes a file name so it is most likely a valid MediaWiki title
+        * after processing.
+        * Slightly modified from Flinfo. Credit goes to Lupo and Flomiator.
+        *
+        * @param {string} uncleanName the unclean file name
+        * @return {string} the clean file name that could be passed to the 
mw.Title constructor
+        */
+       sanitizeFileName: function( uncleanName ) {
+               // "signature" first
+               return uncleanName.replace(/~{3,}/g, '')
+                               // NBSP and other unusual spaces
+                               
.replace(/[\u00A0\u1680\u180E\u2000-\u200B\u2028\u2029\u202F\u205F\u3000]/, ' ')
+                               // control characters
+                               .replace(/[\x00-\x1f\x7f]/g, '')
+                               // URL encoding
+                               .replace(/%([0-9A-Fa-f]{2})/g, '% $1')
+                               // URL-params?
+                               
.replace(/&(([A-Za-z0-9\x80-\xff]+|#[0-9]+|#x[0-9A-Fa-f]+);)/g, '& $1')
+                               // colon, slash, hash
+                               .replace(/[:\/|#]/g, '-')
+                               // brackets, greater than
+                               .replace(/[\]\}>]/g, ')')
+                               // brackets, lower than
+                               .replace(/[\[\{<]/g, '(');
+       },
+
+       /**
         * Called when the file is entered into the file input, bound to its 
change() event.
         * Checks for file validity, then extracts metadata.
         * Error out if filename or its contents are determined to be 
unacceptable
@@ -402,7 +429,7 @@
                }
 
                try {
-                       this.title = new mw.Title( basename.replace( /:/g, '_' 
), fileNsId );
+                       this.title = new mw.Title( this.sanitizeFileName( 
basename ), fileNsId );
                } catch ( e ) {
                        fileErrors.unparseable = true;
                        fileNameErr( 'unparseable', null, fileErrors );

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ia57e4b0e804dfbf70e85b1bc2b7e9362277730bd
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/UploadWizard
Gerrit-Branch: master
Gerrit-Owner: Rillke <[email protected]>

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

Reply via email to