improve wfStripIllegalFilenameChars()'s readability
authorWaldir Pimenta <waldir@email.com>
Tue, 7 Aug 2012 19:09:26 +0000 (20:09 +0100)
committerWaldir Pimenta <waldir@email.com>
Tue, 7 Aug 2012 19:09:26 +0000 (20:09 +0100)
make the preg_replace regex more readable,
and expand documentation a little.

Change-Id: Id26d9d42be7d3f2780e82da27dd2477d62d8e106

includes/GlobalFunctions.php

index e25ce26..f83a31b 100644 (file)
@@ -3738,17 +3738,18 @@ function wfGenerateToken( $salt = '' ) {
 
 /**
  * Replace all invalid characters with -
+ * Additional characters can be defined in $wgIllegalFileChars (see bug 20489)
+ * By default, $wgIllegalFileChars = ':'
  *
  * @param $name Mixed: filename to process
  * @return String
  */
 function wfStripIllegalFilenameChars( $name ) {
        global $wgIllegalFileChars;
+       $illegalFileChars = $wgIllegalFileChars ? "|[" . $wgIllegalFileChars . "]" : '';
        $name = wfBaseName( $name );
        $name = preg_replace(
-               "/[^" . Title::legalChars() . "]" .
-                       ( $wgIllegalFileChars ? "|[" . $wgIllegalFileChars . "]" : '' ) .
-                       "/",
+               "/[^" . Title::legalChars() . "]" . $illegalFileChars . "/",
                '-',
                $name
        );