Merge "(bug 35753) Allow {{FORMATNUM}} to only do digit transform"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Tue, 26 Feb 2013 08:40:00 +0000 (08:40 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Tue, 26 Feb 2013 08:40:00 +0000 (08:40 +0000)
includes/parser/CoreParserFunctions.php
languages/Language.php
languages/messages/MessagesEn.php
tests/parser/parserTests.txt

index b2a72a4..a1b7ca0 100644 (file)
@@ -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 );
index ffb3268..9ae3d29 100644 (file)
@@ -3007,6 +3007,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
index a9fdf35..73f09ce 100644 (file)
@@ -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' ),
index ede4ae9..9e0b6a4 100644 (file)
@@ -12597,6 +12597,19 @@ Strip marker in formatNum
 </p>
 !! end
 
+!! test
+Check noCommafy in formatNum
+!! options
+language=be-tarask
+!! input
+{{formatnum:123456.78}}
+{{formatnum:123456.78|NOSEP}}
+!! result
+<p>123 456,78
+123456.78
+</p>
+!! end
+
 !! test
 Strip marker in grammar
 !! options