r64303 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r64302‎ | r64303 | r64304 >
Date:19:23, 28 March 2010
Author:catrope
Status:ok
Tags:
Comment:
Message.php fixes:
* Don't call params() for every param passed to the constructor
* Use self
* Use array_merge() instead of += , the latter behaves contrary to the documentation
* Fix capitalization of toString() calls
* Various style, typo fixes
Modified paths:
  • /trunk/phase3/includes/Message.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/Message.php
@@ -104,9 +104,7 @@
105105 */
106106 public function __construct( $key, $params = array() ) {
107107 $this->key = $key;
108 - foreach( $params as $param ){
109 - $this->params( $param );
110 - }
 108+ $this->parameters = array_values( $params );
111109 }
112110
113111 /**
@@ -118,16 +116,16 @@
119117 * @return Message: $this
120118 */
121119 public static function key( $key ) {
122 - return new Message( $key );
 120+ return new self( $key );
123121 }
124122
125123 /**
126124 * Adds parameters to the parameter list of this message.
127 - * @param Vargars: parameters as Strings
 125+ * @param Varargs: parameters as Strings
128126 * @return Message: $this
129127 */
130128 public function params( /*...*/ ) {
131 - $this->parameters += array_values( func_get_args() );
 129+ $this->parameters = array_merge( $this->parameters, array_values( func_get_args() ) );
132130 return $this;
133131 }
134132
@@ -141,8 +139,8 @@
142140 */
143141 public function rawParams( /*...*/ ) {
144142 $params = func_get_args();
145 - foreach( $params as $param ){
146 - $this->parameters[] = array( 'raw' => $param );
 143+ foreach( $params as $param ) {
 144+ $this->parameters[] = array( 'raw' => $param );
147145 }
148146 return $this;
149147 }
@@ -151,7 +149,7 @@
152150 * Request the message in any language that is supported.
153151 * As a side effect interface message status is unconditionally
154152 * turned off.
155 - * @param $lang Mixed: langauge code or language object.
 153+ * @param $lang Mixed: language code or Language object.
156154 * @return Message: $this
157155 */
158156 public function language( $lang ) {
@@ -232,9 +230,9 @@
233231 * Fully parse the text from wikitext to HTML
234232 * @return String parsed HTML
235233 */
236 - public function parse(){
 234+ public function parse() {
237235 $this->format = 'parse';
238 - return $this->tostring();
 236+ return $this->toString();
239237 }
240238
241239 /**
@@ -243,7 +241,7 @@
244242 */
245243 public function text() {
246244 $this->format = 'text';
247 - return $this->tostring();
 245+ return $this->toString();
248246 }
249247
250248 /**
@@ -252,7 +250,7 @@
253251 */
254252 public function plain() {
255253 $this->format = 'plain';
256 - return $this->tostring();
 254+ return $this->toString();
257255 }
258256
259257 /**
@@ -261,7 +259,7 @@
262260 */
263261 public function parseAsBlock() {
264262 $this->format = 'block-parse';
265 - return $this->tostring();
 263+ return $this->toString();
266264 }
267265
268266 /**
@@ -271,7 +269,7 @@
272270 */
273271 public function escaped() {
274272 $this->format = 'escaped';
275 - return $this->tostring();
 273+ return $this->toString();
276274 }
277275
278276 /**

Status & tagging log