* (bug 8604) padright: and similar functions fail with non-ASCII arguments
authorNiklas Laxström <nikerabbit@users.mediawiki.org>
Fri, 11 Jul 2008 18:08:18 +0000 (18:08 +0000)
committerNiklas Laxström <nikerabbit@users.mediawiki.org>
Fri, 11 Jul 2008 18:08:18 +0000 (18:08 +0000)
RELEASE-NOTES
includes/GlobalFunctions.php
includes/parser/CoreParserFunctions.php

index 8ad7e70..be5952e 100644 (file)
@@ -431,6 +431,7 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN
   had stict standards issues with setFakeSlaveLag() and setFakeMaster().
 * (bug 451) Improve the phrase mappings of the Chinese converter arrays.
 * (bug 12487) Rights log is not fully internationalized
+* (bug 8604) padright: and similar functions fail with non-ASCII arguments
 
 === API changes in 1.13 ===
 
index 56a313f..b4e0185 100644 (file)
@@ -70,6 +70,29 @@ if ( !function_exists( 'mb_strlen' ) ) {
        }
 }
 
+if ( !function_exists( 'mb_str_pad' ) ) {
+       /**
+        * Fallback implementation of mb_str_pad, hardcoded to UTF-8.
+        * @param $input String: input string
+        * @param $pad_length Integer: how much to pad
+        * @param $pad_string Character used for padding, only one!
+        * @param $pad_type Only STR_PAD_LEFT and STR_PAD_RIGHT supported.
+        * @return int
+        */
+       function mb_str_pad( $input, $pad_length, $pad_string, $pad_type ) {
+               $toPad = $pad_length - mb_strlen( $input );
+               if ( $toPad <= 0 ) return $input;
+               for ( $i = 0; $i < $toPad; $i++ ) {
+                       if ( $pad_type === STR_PAD_LEFT ) {
+                               $input = $pad_string . $input;
+                       } elseif( $pad_type === STR_PAD_RIGHT ) {
+                               $input .= $pad_string;
+                       }
+               }
+               return $input;
+       }
+}
+
 if ( !function_exists( 'array_diff_key' ) ) {
        /**
         * Exists in PHP 5.1.0+
index d9072e9..58f5eb6 100644 (file)
@@ -287,9 +287,9 @@ class CoreParserFunctions {
 
        static function pad( $string = '', $length = 0, $char = 0, $direction = STR_PAD_RIGHT ) {
                $length = min( max( $length, 0 ), 500 );
-               $char = substr( $char, 0, 1 );
-               return ( $string !== '' && (int)$length > 0 && strlen( trim( (string)$char ) ) > 0 )
-                               ? str_pad( $string, $length, (string)$char, $direction )
+               $char = mb_substr( $char, 0, 1 );
+               return ( $string !== '' && (int)$length > 0 && mb_strlen( trim($char) ) > 0 )
+                               ? mb_str_pad( $string, $length, $char, $direction )
                                : $string;
        }