From 269bf3c2397b7e253802ed5098bf51aa53df063f Mon Sep 17 00:00:00 2001 From: Bryan Tong Minh Date: Sat, 22 Jan 2011 20:23:51 +0000 Subject: [PATCH] Add automatic formatting of numeric parameters to Message --- includes/Message.php | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/includes/Message.php b/includes/Message.php index 2a558f931e..9ee6eea51f 100644 --- a/includes/Message.php +++ b/includes/Message.php @@ -169,6 +169,20 @@ class Message { return $this; } + /** + * Add parameters that are numeric and will be passed through + * Language::formatNum before substitution + * @param Varargs: numeric parameters + * @return Message: $this + */ + public function numParams( /*...*/ ) { + $params = func_get_args(); + foreach( $params as $param ) { + $this->parameters[] = self::numParam( $param ); + } + return $this; + } + /** * Request the message in any language that is supported. * As a side effect interface message status is unconditionally @@ -328,6 +342,10 @@ class Message { public static function rawParam( $value ) { return array( 'raw' => $value ); } + + public static function numParam( $value ) { + return array( 'num' => $value ); + } /** * Substitutes any paramaters into the message text. @@ -342,6 +360,9 @@ class Message { $replacementKeys['$' . ($n + 1)] = $param; } elseif ( $type === 'after' && isset( $param['raw'] ) ) { $replacementKeys['$' . ($n + 1)] = $param['raw']; + } elseif ( isset( $param['num'] ) ) { + $replacementKeys['$' . ($n + 1)] = + $this->language->formatNum( $param['num'] ); } } $message = strtr( $message, $replacementKeys ); -- 2.20.1