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

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

Change subject: uw.TitleDetailsWidget: Check for $wgIllegalFileChars client-side
......................................................................

uw.TitleDetailsWidget: Check for $wgIllegalFileChars client-side

Also remove 'wgIllegalFileChars' from our JS config variables,
as it's provided by MediaWiki now.

Bug: T140222
Depends-On: I17e3ef61e04ae002ef576c9416c8f265ee000e89
Change-Id: I979e1707f6287e6f69841b0f28a6f90c472d42e0
---
M includes/specials/SpecialUploadWizard.php
M resources/details/uw.TitleDetailsWidget.js
M tests/qunit/uw.TitleDetailsWidget.test.js
3 files changed, 16 insertions(+), 7 deletions(-)


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

diff --git a/includes/specials/SpecialUploadWizard.php 
b/includes/specials/SpecialUploadWizard.php
index fc20b9a..dd9dd48 100644
--- a/includes/specials/SpecialUploadWizard.php
+++ b/includes/specials/SpecialUploadWizard.php
@@ -173,8 +173,6 @@
         * @param subpage, e.g. the "foo" in Special:UploadWizard/foo
         */
        public function addJsVars( $subPage ) {
-               global $wgIllegalFileChars;
-
                $config = UploadWizardConfig::getConfig( $this->campaign );
 
                if ( array_key_exists( 'trackingCategory', $config ) ) {
@@ -248,7 +246,6 @@
                        [
                                'UploadWizardConfig' => $config,
                                'wgFileCanRotate' => 
$bitmapHandler->canRotate(),
-                               'wgIllegalFileChars' => $wgIllegalFileChars,
                        ]
                );
        }
diff --git a/resources/details/uw.TitleDetailsWidget.js 
b/resources/details/uw.TitleDetailsWidget.js
index 9de3e37..6a46c2b 100644
--- a/resources/details/uw.TitleDetailsWidget.js
+++ b/resources/details/uw.TitleDetailsWidget.js
@@ -29,20 +29,27 @@
        OO.inheritClass( uw.TitleDetailsWidget, uw.DetailsWidget );
 
        /**
-        * Reliably turn input into a MediaWiki title that is located in the 
File: namespace
+        * Reliably turn input into a MediaWiki title that is located in the 
'File:' namespace.
+        * Also applies file-specific checks ($wgIllegalFileChars).
         *
         *     var title = uw.TitleDetailsWidget.static.makeTitleInFileNS( 
'filename.ext' );
         *
         * @static
-        * @param {string} filename Desired file name; optionally with File: 
namespace prefixed
+        * @param {string} filename Desired file name; optionally with 'File:' 
namespace prefixed
         * @return {mw.Title|null}
         */
        uw.TitleDetailsWidget.static.makeTitleInFileNS = function ( filename ) {
-               var mwTitle = mw.Title.newFromText( filename, NS_FILE );
+               var
+                       mwTitle = mw.Title.newFromText( filename, NS_FILE ),
+                       illegalFileChars = new RegExp( '[' + mw.config.get( 
'wgIllegalFileChars', '' ) + ']' );
                if ( mwTitle && mwTitle.getNamespaceId() !== NS_FILE ) {
                        // Force file namespace
                        mwTitle = mw.Title.makeTitle( NS_FILE, filename );
                }
+               if ( mwTitle && illegalFileChars.test( mwTitle.getMainText() ) 
) {
+                       // Consider the title invalid if it contains characters 
disallowed in file names
+                       mwTitle = null;
+               }
                return mwTitle;
        };
        
diff --git a/tests/qunit/uw.TitleDetailsWidget.test.js 
b/tests/qunit/uw.TitleDetailsWidget.test.js
index 4274b44..25f115a 100644
--- a/tests/qunit/uw.TitleDetailsWidget.test.js
+++ b/tests/qunit/uw.TitleDetailsWidget.test.js
@@ -25,6 +25,10 @@
                filename: 'file:foo_bar.jpg',
                prefixedText: 'File:Foo bar.jpg',
                desc: 'filename starting with file:'
+       }, {
+               filename: 'Foo part 1/2.jpg',
+               prefixedText: null,
+               desc: 'filename with characters disallowed in file names'
        } ];
 
        QUnit.module( 'uw.TitleDetailsWidget', QUnit.newMwEnvironment() );
@@ -33,8 +37,9 @@
                var makeTitleInFileNS = 
mw.UploadWizardDetails.makeTitleInFileNS;
 
                $.each( makeTitleInFileNSCases, function ( i, test ) {
+                       var title = makeTitleInFileNS( test.filename );
                        QUnit.equal(
-                               makeTitleInFileNS( test.filename 
).getPrefixedText(),
+                               title ? title.getPrefixedText() : title,
                                test.prefixedText,
                                test.desc
                        );

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I979e1707f6287e6f69841b0f28a6f90c472d42e0
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