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

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

Change subject: Improve how slashes are stripped from filenames
......................................................................

Improve how slashes are stripped from filenames

* Add slash and backslash ('/' and '\') to $wgIllegalFileChars.
* Replace illegal chars before removing paths in wfStripIllegalFilenameChars().

This way users trying to upload a file with slashes in the name will
get a better filename suggestion (e.g. for 'Foo part 1/3.jpg', you
previously got '3.jpg', now you'll get 'Foo part 1-3.jpg'). Uploading
tools that don't special-case slashes will also behave better.

Change-Id: Ib78f48a5f8c92e8ab2dc773ea6789b96b3662177
---
M includes/DefaultSettings.php
M includes/GlobalFunctions.php
2 files changed, 11 insertions(+), 6 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/91/300791/1

diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php
index 1e60302..5926328 100644
--- a/includes/DefaultSettings.php
+++ b/includes/DefaultSettings.php
@@ -398,9 +398,13 @@
 $wgEnableAsyncUploads = false;
 
 /**
- * These are additional characters that should be replaced with '-' in 
filenames
+ * Additional characters that are not allowed in filenames. They are replaced 
with '-' when
+ * uploading. Like $wgLegalTitleChars, this is a regexp character class.
+ *
+ * Slashes and backslashes are disallowed regardless of this setting, but 
included here for
+ * completeness.
  */
-$wgIllegalFileChars = ":";
+$wgIllegalFileChars = ":\\/\\\\";
 
 /**
  * What directory to place deleted uploads in.
diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php
index 66e2440..e262c81 100644
--- a/includes/GlobalFunctions.php
+++ b/includes/GlobalFunctions.php
@@ -3350,9 +3350,9 @@
 }
 
 /**
- * Replace all invalid characters with -
- * Additional characters can be defined in $wgIllegalFileChars (see bug 20489)
- * By default, $wgIllegalFileChars = ':'
+ * Replace all invalid characters with '-'.
+ * Additional characters can be defined in $wgIllegalFileChars (see T22489).
+ * By default, $wgIllegalFileChars includes ':', '/', '\'.
  *
  * @param string $name Filename to process
  * @return string
@@ -3360,12 +3360,13 @@
 function wfStripIllegalFilenameChars( $name ) {
        global $wgIllegalFileChars;
        $illegalFileChars = $wgIllegalFileChars ? "|[" . $wgIllegalFileChars . 
"]" : '';
-       $name = wfBaseName( $name );
        $name = preg_replace(
                "/[^" . Title::legalChars() . "]" . $illegalFileChars . "/",
                '-',
                $name
        );
+       // $wgIllegalFileChars may not include '/' and '\', so we still need to 
do this
+       $name = wfBaseName( $name );
        return $name;
 }
 

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ib78f48a5f8c92e8ab2dc773ea6789b96b3662177
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
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