r80764 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r80763‎ | r80764 | r80765 >
Date:20:23, 22 January 2011
Author:btongminh
Status:resolved (Comments)
Tags:
Comment:
Add automatic formatting of numeric parameters to Message
Modified paths:
  • /trunk/phase3/includes/Message.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/Message.php
@@ -170,6 +170,20 @@
171171 }
172172
173173 /**
 174+ * Add parameters that are numeric and will be passed through
 175+ * Language::formatNum before substitution
 176+ * @param Varargs: numeric parameters
 177+ * @return Message: $this
 178+ */
 179+ public function numParams( /*...*/ ) {
 180+ $params = func_get_args();
 181+ foreach( $params as $param ) {
 182+ $this->parameters[] = self::numParam( $param );
 183+ }
 184+ return $this;
 185+ }
 186+
 187+ /**
174188 * Request the message in any language that is supported.
175189 * As a side effect interface message status is unconditionally
176190 * turned off.
@@ -328,6 +342,10 @@
329343 public static function rawParam( $value ) {
330344 return array( 'raw' => $value );
331345 }
 346+
 347+ public static function numParam( $value ) {
 348+ return array( 'num' => $value );
 349+ }
332350
333351 /**
334352 * Substitutes any paramaters into the message text.
@@ -342,6 +360,9 @@
343361 $replacementKeys['$' . ($n + 1)] = $param;
344362 } elseif ( $type === 'after' && isset( $param['raw'] ) ) {
345363 $replacementKeys['$' . ($n + 1)] = $param['raw'];
 364+ } elseif ( isset( $param['num'] ) ) {
 365+ $replacementKeys['$' . ($n + 1)] =
 366+ $this->language->formatNum( $param['num'] );
346367 }
347368 }
348369 $message = strtr( $message, $replacementKeys );

Follow-up revisions

RevisionCommit summaryAuthorDate
r81878Fixed two bugs in message parameter handling:...nikerabbit09:10, 10 February 2011

Comments

#Comment by 😂 (talk | contribs)   21:58, 22 January 2011

Does the static numParam need to be public? Or even static?

Also: not a big fan of method names differing by one letter, it generally just leads to confusion.

#Comment by Bryan (talk | contribs)   22:51, 22 January 2011

You can could use numParam() if you want to pass a numeric parameter together with regular parameters in a single function call. In any case it is consistent with rawParam().

Status & tagging log