mw.Title: Use $wgIllegalFileChars for file title checking
authorBartosz Dziewoński <matma.rex@gmail.com>
Sun, 24 Jul 2016 20:28:56 +0000 (22:28 +0200)
committerBartosz Dziewoński <matma.rex@gmail.com>
Sat, 30 Jul 2016 17:40:29 +0000 (19:40 +0200)
mw.Title.newFromFileName() will now correctly use $wgIllegalFileChars,
rather than partially and incorrectly duplicating it.

$wgIllegalFileChars is currently defined to contain ':', '/' and '\'.
Previously we incorrectly did not filter out backslashes '\'. The hash
'#' is already disallowed by $wgLegalTitleChars.

Bug: T140222
Change-Id: I17e3ef61e04ae002ef576c9416c8f265ee000e89

includes/resourceloader/ResourceLoaderStartUpModule.php
resources/src/mediawiki/mediawiki.Title.js

index 7b2d532..eb9788c 100644 (file)
@@ -66,6 +66,8 @@ class ResourceLoaderStartUpModule extends ResourceLoaderModule {
                        }
                }
 
+               $illegalFileChars = $conf->get( 'IllegalFileChars' );
+
                // Build list of variables
                $vars = [
                        'wgLoadScript' => wfScript( 'load' ),
@@ -107,6 +109,7 @@ class ResourceLoaderStartUpModule extends ResourceLoaderModule {
                        'wgResourceLoaderMaxQueryLength' => $conf->get( 'ResourceLoaderMaxQueryLength' ),
                        'wgCaseSensitiveNamespaces' => $caseSensitiveNamespaces,
                        'wgLegalTitleChars' => Title::convertByteClassToUnicodeClass( Title::legalChars() ),
+                       'wgIllegalFileChars' => Title::convertByteClassToUnicodeClass( $illegalFileChars ),
                        'wgResourceLoaderStorageVersion' => $conf->get( 'ResourceLoaderStorageVersion' ),
                        'wgResourceLoaderStorageEnabled' => $conf->get( 'ResourceLoaderStorageEnabled' ),
                        'wgResourceLoaderLegacyModules' => self::getLegacyModules(),
index ff4d1c2..4c57faa 100644 (file)
                },
                // slash, colon (not supported by file systems like NTFS/Windows, Mac OS 9 [:], ext4 [/])
                {
-                       pattern: /[:\/#]/g,
+                       pattern: new RegExp( '[' + mw.config.get( 'wgIllegalFileChars', '' ) + ']', 'g' ),
                        replace: '-',
                        fileRule: true
                },