Revert r37567 for nwo ("(bug 8604) padright: and similar functions fail with non...
authorBrion Vibber <brion@users.mediawiki.org>
Sat, 12 Jul 2008 14:05:04 +0000 (14:05 +0000)
committerBrion Vibber <brion@users.mediawiki.org>
Sat, 12 Jul 2008 14:05:04 +0000 (14:05 +0000)
This implements an mb_str_pad fallback function, but there is no mb_str_pad in PHP documentation, and the doc comments are really weird -- it says it returns an integer!
If this function is created from whole cloth and doesn't exist in PHP, it should be given a MediaWiki style name and not be done with a function_exists check as though it were a compat function.

RELEASE-NOTES
includes/GlobalFunctions.php
includes/parser/CoreParserFunctions.php

index be5952e..8ad7e70 100644 (file)
@@ -431,7 +431,6 @@ 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 b4e0185..56a313f 100644 (file)
@@ -70,29 +70,6 @@ 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 58f5eb6..d9072e9 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 = mb_substr( $char, 0, 1 );
-               return ( $string !== '' && (int)$length > 0 && mb_strlen( trim($char) ) > 0 )
-                               ? mb_str_pad( $string, $length, $char, $direction )
+               $char = substr( $char, 0, 1 );
+               return ( $string !== '' && (int)$length > 0 && strlen( trim( (string)$char ) ) > 0 )
+                               ? str_pad( $string, $length, (string)$char, $direction )
                                : $string;
        }