From: Pavel Selitskas
Date: Wed, 28 Nov 2012 10:24:45 +0000 (+0300)
Subject: (bug 35753) Allow {{FORMATNUM}} to only do digit transform
X-Git-Tag: 1.31.0-rc.0~20572^2
X-Git-Url: http://git.cyclocoop.org/%22%20.%20generer_url_ecrire%28%22suivi_revisions%22%29%20.%20%22?a=commitdiff_plain;h=eadd393a8188790e35f631234baf907ec13cd472;p=lhc%2Fweb%2Fwiklou.git
(bug 35753) Allow {{FORMATNUM}} to only do digit transform
{{formatnum:1234567.89|NOSEP}} will perform only digit transformations.
Change-Id: Ic882d5ba087665030144e85248680acece8aa901
---
diff --git a/includes/parser/CoreParserFunctions.php b/includes/parser/CoreParserFunctions.php
index 8917b6d06b..36433686ce 100644
--- a/includes/parser/CoreParserFunctions.php
+++ b/includes/parser/CoreParserFunctions.php
@@ -269,12 +269,14 @@ class CoreParserFunctions {
/**
* @param $parser Parser
* @param string $num
- * @param null $raw
- * @return
+ * @param string $arg
+ * @return string
*/
- static function formatnum( $parser, $num = '', $raw = null) {
- if ( self::isRaw( $raw ) ) {
+ static function formatnum( $parser, $num = '', $arg = null ) {
+ if ( self::matchAgainstMagicword( 'rawsuffix', $arg ) ) {
$func = array( $parser->getFunctionLang(), 'parseFormattedNumber' );
+ } elseif ( self::matchAgainstMagicword( 'nocommafysuffix', $arg ) ) {
+ $func = array( $parser->getFunctionLang(), 'formatNumNoSeparators' );
} else {
$func = array( $parser->getFunctionLang(), 'formatNum' );
}
@@ -386,20 +388,23 @@ class CoreParserFunctions {
return '';
}
- static function isRaw( $param ) {
- static $mwRaw;
- if ( !$mwRaw ) {
- $mwRaw =& MagicWord::get( 'rawsuffix' );
- }
- if ( is_null( $param ) ) {
+ /**
+ * Matches the given value against the value of given magic word
+ *
+ * @param string $magicword magic word key
+ * @param mixed $value value to match
+ * @return boolean true on successful match
+ */
+ static private function matchAgainstMagicword( $magicword, $value ) {
+ if ( strval( $value ) === '' ) {
return false;
- } else {
- return $mwRaw->match( $param );
}
+ $mwObject = MagicWord::get( $magicword );
+ return $mwObject->match( $value );
}
static function formatRaw( $num, $raw ) {
- if( self::isRaw( $raw ) ) {
+ if( self::matchAgainstMagicword( 'rawsuffix', $raw ) ) {
return $num;
} else {
global $wgContLang;
@@ -585,7 +590,7 @@ class CoreParserFunctions {
static $cache = array();
// split the given option to its variable
- if( self::isRaw( $arg1 ) ) {
+ if( self::matchAgainstMagicword( 'rawsuffix', $arg1 ) ) {
//{{pagesincategory:|raw[|type]}}
$raw = $arg1;
$type = $magicWords->matchStartToEnd( $arg2 );
diff --git a/languages/Language.php b/languages/Language.php
index 7475d2fb60..cd3acb5be5 100644
--- a/languages/Language.php
+++ b/languages/Language.php
@@ -2910,6 +2910,18 @@ class Language {
return $number;
}
+ /**
+ * Front-end for non-commafied formatNum
+ *
+ * @param mixed $number the string to be formatted, should be an integer
+ * or a floating point number.
+ * @since 1.21
+ * @return string
+ */
+ public function formatNumNoSeparators( $number ) {
+ return $this->formatNum( $number, true );
+ }
+
/**
* @param $number string
* @return string
diff --git a/languages/messages/MessagesEn.php b/languages/messages/MessagesEn.php
index 8cf05dc97e..ec38ab64cb 100644
--- a/languages/messages/MessagesEn.php
+++ b/languages/messages/MessagesEn.php
@@ -322,6 +322,7 @@ $magicWords = array(
'raw' => array( 0, 'RAW:' ),
'displaytitle' => array( 1, 'DISPLAYTITLE' ),
'rawsuffix' => array( 1, 'R' ),
+ 'nocommafysuffix' => array( 0, 'NOSEP' ),
'newsectionlink' => array( 1, '__NEWSECTIONLINK__' ),
'nonewsectionlink' => array( 1, '__NONEWSECTIONLINK__' ),
'currentversion' => array( 1, 'CURRENTVERSION' ),
diff --git a/tests/parser/parserTests.txt b/tests/parser/parserTests.txt
index bc24236223..eef25491eb 100644
--- a/tests/parser/parserTests.txt
+++ b/tests/parser/parserTests.txt
@@ -12003,6 +12003,19 @@ Strip marker in formatNum
!! end
+!! test
+Check noCommafy in formatNum
+!! options
+language=be-tarask
+!! input
+{{formatnum:123456.78}}
+{{formatnum:123456.78|NOSEP}}
+!! result
+123Â 456,78
+123456.78
+
+!! end
+
!! test
Strip marker in grammar
!! options