/**
* @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' );
}
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;
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 );
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
'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' ),