r64336 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r64335‎ | r64336 | r64337 >
Date:14:08, 29 March 2010
Author:nikerabbit
Status:ok
Tags:
Comment:
Message::key() accepts message parameters as varargs. Renamed ::language() to ::inLanguage()
Modified paths:
  • /trunk/phase3/includes/Message.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/Message.php
@@ -15,8 +15,8 @@
1616 * Messages can have parameters:
1717 * Message::key( 'welcome-to' )->params( $wgSitename )->text();
1818 * {{GRAMMAR}} and friends work correctly
19 - * Message::key( 'are-friends' )->params( $user, $friend );
20 - * Message::key( 'bad-message' )->rawParams( '<script>...</script>' )->escaped()
 19+ * Message::key( 'are-friends', $user, $friend );
 20+ * Message::key( 'bad-message' )->rawParams( '<script>...</script>' )->escaped();
2121 * </pre>
2222 * Sometimes the message text ends up in the database, so content language is needed.
2323 * Message::key( 'file-log' )->params( $user, $filename )->inContentLanguage()->text()
@@ -25,7 +25,7 @@
2626 * Message::key( 'mysterious-message' )->exists()
2727 * </pre>
2828 * If you want to use a different language:
29 - * Message::key( 'email-header' )->language( $user->getOption( 'language' ) )->plain()
 29+ * Message::key( 'email-header' )->inLanguage( $user->getOption( 'language' ) )->plain()
3030 * Note that you cannot parse the text except in the content or interface
3131 * languages
3232 * </pre>
@@ -111,12 +111,12 @@
112112 * Factory function that is just wrapper for the real constructor. It is
113113 * intented to be used instead of the real constructor, because it allows
114114 * chaining method calls, while new objects don't.
115 - * //FIXME: key or get or something else?
116115 * @param $key String: message key
 116+ * @param Varargs: parameters as Strings
117117 * @return Message: $this
118118 */
119 - public static function key( $key ) {
120 - return new self( $key );
 119+ public static function key( $key, /*...*/ ) {
 120+ return new self( $key, array_shift( func_get_args() );
121121 }
122122
123123 /**
@@ -140,7 +140,7 @@
141141 public function rawParams( /*...*/ ) {
142142 $params = func_get_args();
143143 foreach( $params as $param ) {
144 - $this->parameters[] = array( 'raw' => $param );
 144+ $this->parameters[] = self::rawParam( $param );
145145 }
146146 return $this;
147147 }
@@ -152,7 +152,7 @@
153153 * @param $lang Mixed: language code or Language object.
154154 * @return Message: $this
155155 */
156 - public function language( $lang ) {
 156+ public function inLanguage( $lang ) {
157157 if( $lang instanceof Language ){
158158 $this->language = $lang;
159159 } elseif ( is_string( $lang ) ) {
@@ -280,6 +280,10 @@
281281 return $this->fetchMessage() === false;
282282 }
283283
 284+ public static function rawParam( $value ) {
 285+ return array( 'raw' => $value );
 286+ }
 287+
284288 /**
285289 * Substitutes any paramaters into the message text.
286290 * @param $message String, the message text

Status & tagging log