aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--RELEASE-NOTES5
-rw-r--r--includes/parser/CoreParserFunctions.php38
-rw-r--r--maintenance/parserTests.txt18
3 files changed, 50 insertions, 11 deletions
diff --git a/RELEASE-NOTES b/RELEASE-NOTES
index dceef205037e..ba50caf87535 100644
--- a/RELEASE-NOTES
+++ b/RELEASE-NOTES
@@ -34,7 +34,9 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN
* Added "__\" magic word to eat up all whitespace and newlines to the next
non-whitespace character, to facilitate writing readable template code where
whitespace is significant.
-* (bug 17002) Add &minor= and &summary= as parameters in the url when editing, to automatically add a summary or a minor edit.
+* (bug 17002) Add &minor= and &summary= as parameters in the url when editing,
+ to automatically add a summary or a minor edit.
+* (bug 16852) padleft and padright now accept multiletter pad characters
=== Bug fixes in 1.15 ===
* Fixing the caching issue by using -{T|xxx}- syntax (only applies on wiki with LanguageConverter class)
@@ -42,6 +44,7 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN
* (bug 16968) Special:Upload no longer throws useless warnings.
* (bug 15470) Special:Upload no longer force-capitalizes titles
* (bug 17000) Special:RevisionDelete now checks if the database is locked before trying to delete the edit.
+* (bug 16852) padleft and padright now handle multibyte characters correctly
== API changes in 1.15 ==
* (bug 16798) JSON encoding errors for some characters outside the BMP
diff --git a/includes/parser/CoreParserFunctions.php b/includes/parser/CoreParserFunctions.php
index 2dfd34bfeaa1..35d7de88a136 100644
--- a/includes/parser/CoreParserFunctions.php
+++ b/includes/parser/CoreParserFunctions.php
@@ -310,20 +310,38 @@ class CoreParserFunctions {
return $lang != '' ? $lang : $arg;
}
- 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 )
- : $string;
+ /**
+ * Unicode-safe str_pad with the restriction that $length is forced to be <= 500
+ */
+ static function pad( $string, $length, $padding = '0', $direction = STR_PAD_RIGHT ) {
+ $lengthOfPadding = mb_strlen( $padding );
+ if ( $lengthOfPadding == 0 ) return $string;
+
+ # The remaining length to add counts down to 0 as padding is added
+ $length = min( $length, 500 ) - mb_strlen( $string );
+ # $finalPadding is just $padding repeated enough times so that
+ # mb_strlen( $string ) + mb_strlen( $finalPadding ) == $length
+ $finalPadding = '';
+ while ( $length > 0 ) {
+ # If $length < $lengthofPadding, truncate $padding so we get the
+ # exact length desired.
+ $finalPadding .= mb_substr( $padding, 0, $length );
+ $length -= $lengthOfPadding;
+ }
+
+ if ( $direction == STR_PAD_LEFT ) {
+ return $finalPadding . $string;
+ } else {
+ return $string . $finalPadding;
+ }
}
- static function padleft( $parser, $string = '', $length = 0, $char = 0 ) {
- return self::pad( $string, $length, $char, STR_PAD_LEFT );
+ static function padleft( $parser, $string = '', $length = 0, $padding = '0' ) {
+ return self::pad( $string, $length, $padding, STR_PAD_LEFT );
}
- static function padright( $parser, $string = '', $length = 0, $char = 0 ) {
- return self::pad( $string, $length, $char );
+ static function padright( $parser, $string = '', $length = 0, $padding = '0' ) {
+ return self::pad( $string, $length, $padding );
}
static function anchorencode( $parser, $text ) {
diff --git a/maintenance/parserTests.txt b/maintenance/parserTests.txt
index c84e0e35cffb..49b71434d680 100644
--- a/maintenance/parserTests.txt
+++ b/maintenance/parserTests.txt
@@ -7233,6 +7233,24 @@ language=fa
</p>
!! end
+!! test
+Multibyte character in padleft
+!! input
+{{padleft:-Hello|7|Æ}}
+!! result
+<p>Æ-Hello
+</p>
+!! end
+
+!! test
+Multibyte character in padright
+!! input
+{{padright:Hello-|7|Æ}}
+!! result
+<p>Hello-Æ
+</p>
+!! end
+
#
#
#