r63716 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r63715‎ | r63716 | r63717 >
Date:00:36, 14 March 2010
Author:jeroendedauw
Status:deferred
Tags:
Comment:
Stylized with Stylize.php to conform with MW's specing conventions
Modified paths:
  • /trunk/extensions/Validator/Validator.class.php (modified) (history)
  • /trunk/extensions/Validator/Validator.i18n.php (modified) (history)
  • /trunk/extensions/Validator/Validator_Formats.php (modified) (history)
  • /trunk/extensions/Validator/Validator_Functions.php (modified) (history)
  • /trunk/extensions/Validator/Validator_Manager.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Validator/Validator.class.php
@@ -37,14 +37,14 @@
3838 /**
3939 * @var boolean Indicates whether parameters that are provided more then once
4040 * should be accepted, and use the first provided value, or not, and generate an error.
41 - */
 41+ */
4242 public static $acceptOverriding = false;
4343
4444 /**
4545 * @var boolean Indicates if errors in list items should cause the item to be omitted,
4646 * versus having the whole list be set to it's default.
47 - */
48 - public static $perItemValidation = true;
 47+ */
 48+ public static $perItemValidation = true;
4949
5050 /**
5151 * @var array Holder for the validation functions.
@@ -53,7 +53,7 @@
5454 'in_array' => array( 'ValidatorFunctions', 'in_array' ),
5555 'in_range' => array( 'ValidatorFunctions', 'in_range' ),
5656 'is_numeric' => 'is_numeric',
57 - 'is_integer' => array( 'ValidatorFunctions', 'is_integer' ),
 57+ 'is_integer' => array( 'ValidatorFunctions', 'is_integer' ),
5858 'not_empty' => array( 'ValidatorFunctions', 'not_empty' ),
5959 'has_length' => array( 'ValidatorFunctions', 'has_length' ),
6060 'regex' => array( 'ValidatorFunctions', 'regex' ),
@@ -83,7 +83,7 @@
8484 private $parameterInfo;
8585 private $rawParameters = array();
8686
87 - private $parameters= array();
 87+ private $parameters = array();
8888 private $valid = array();
8989 private $invalid = array();
9090 private $unknown = array();
@@ -123,7 +123,7 @@
124124 if ( $mainName ) {
125125 // Check for parameter overriding. In most cases, this has already largely been taken care off,
126126 // in the form of later parameters overriding earlier ones. This is not true for different aliases though.
127 - if (! array_key_exists($mainName, $this->parameters) || self::$acceptOverriding ) {
 127+ if ( ! array_key_exists( $mainName, $this->parameters ) || self::$acceptOverriding ) {
128128 $this->parameters[$mainName] = $paramValue;
129129 }
130130 else {
@@ -132,7 +132,7 @@
133133 }
134134 else { // If the parameter is not found in the list of allowed ones, add an item to the $this->errors array.
135135 if ( self::$storeUnknownParameters ) $this->unknown[$paramName] = $paramValue;
136 - $this->errors[] = array( 'type' => 'unknown', 'name' => $paramName);
 136+ $this->errors[] = array( 'type' => 'unknown', 'name' => $paramName );
137137 }
138138 }
139139
@@ -147,7 +147,7 @@
148148 if ( $this->validateParameter( $paramName, $paramValue ) ) {
149149 // If the validation succeeded, add the parameter to the list of valid ones.
150150 $this->valid[$paramName] = $paramValue;
151 - $this->setOutputTypes($this->valid[$paramName], $paramInfo);
 151+ $this->setOutputTypes( $this->valid[$paramName], $paramInfo );
152152 }
153153 else {
154154 // If the validation failed, add the parameter to the list of invalid ones.
@@ -161,8 +161,8 @@
162162 }
163163 else {
164164 // Set the default value (or default 'default value' if none is provided), and ensure the type is correct.
165 - $this->valid[$paramName] = array_key_exists( 'default', $paramInfo ) ? $paramInfo['default'] : '';
166 - $this->setOutputTypes($this->valid[$paramName], $paramInfo);
 165+ $this->valid[$paramName] = array_key_exists( 'default', $paramInfo ) ? $paramInfo['default'] : '';
 166+ $this->setOutputTypes( $this->valid[$paramName], $paramInfo );
167167 }
168168 }
169169 }
@@ -205,57 +205,57 @@
206206 * @param string $name
207207 * @param $value
208208 */
209 - private function cleanParameter( $name, &$value ) {
 209+ private function cleanParameter( $name, &$value ) {
210210 // Ensure there is a criteria array.
211 - if (! array_key_exists('criteria', $this->parameterInfo[$name] )) {
 211+ if ( ! array_key_exists( 'criteria', $this->parameterInfo[$name] ) ) {
212212 $this->parameterInfo[$name]['criteria'] = array();
213 - }
 213+ }
214214
215215 // Ensure the type is set in array form.
216 - if (! array_key_exists('type', $this->parameterInfo[$name] )) {
217 - $this->parameterInfo[$name]['type'] = array('string');
 216+ if ( ! array_key_exists( 'type', $this->parameterInfo[$name] ) ) {
 217+ $this->parameterInfo[$name]['type'] = array( 'string' );
218218 }
219 - elseif(! is_array($this->parameterInfo[$name]['type'])) {
220 - $this->parameterInfo[$name]['type'] = array($this->parameterInfo[$name]['type']);
 219+ elseif ( ! is_array( $this->parameterInfo[$name]['type'] ) ) {
 220+ $this->parameterInfo[$name]['type'] = array( $this->parameterInfo[$name]['type'] );
221221 }
222222
223223 if ( array_key_exists( 'type', $this->parameterInfo[$name] ) ) {
224224 // Add type specific criteria.
225 - switch(strtolower($this->parameterInfo[$name]['type'][0])) {
 225+ switch( strtolower( $this->parameterInfo[$name]['type'][0] ) ) {
226226 case 'integer':
227 - $this->addTypeCriteria($name, 'is_integer');
 227+ $this->addTypeCriteria( $name, 'is_integer' );
228228 break;
229229 case 'number':
230 - $this->addTypeCriteria($name, 'is_numeric');
 230+ $this->addTypeCriteria( $name, 'is_numeric' );
231231 break;
232232 case 'boolean':
233233 // TODO: work with list of true and false values.
234 - $this->addTypeCriteria($name, 'in_array', array('yes', 'no', 'on', 'off'));
 234+ $this->addTypeCriteria( $name, 'in_array', array( 'yes', 'no', 'on', 'off' ) );
235235 break;
236236 case 'char':
237 - $this->addTypeCriteria($name, 'has_length', array(1, 1));
238 - break;
 237+ $this->addTypeCriteria( $name, 'has_length', array( 1, 1 ) );
 238+ break;
239239 }
240240 }
241241
242 - if (count($this->parameterInfo[$name]['type']) > 1 && $this->parameterInfo[$name]['type'][1] == 'list') {
 242+ if ( count( $this->parameterInfo[$name]['type'] ) > 1 && $this->parameterInfo[$name]['type'][1] == 'list' ) {
243243 // Trimming and splitting of list values.
244 - $delimiter = count($this->parameterInfo[$name]['type']) > 2 ? $this->parameterInfo[$name]['type'][2] : ',';
245 - $value = preg_replace('/((\s)*' . $delimiter . '(\s)*)/', $delimiter, $value);
246 - $value = explode($delimiter, $value);
 244+ $delimiter = count( $this->parameterInfo[$name]['type'] ) > 2 ? $this->parameterInfo[$name]['type'][2] : ',';
 245+ $value = preg_replace( '/((\s)*' . $delimiter . '(\s)*)/', $delimiter, $value );
 246+ $value = explode( $delimiter, $value );
247247 }
248 - elseif (count($this->parameterInfo[$name]['type']) > 1 && $this->parameterInfo[$name]['type'][1] == 'array' && is_array($value)) {
 248+ elseif ( count( $this->parameterInfo[$name]['type'] ) > 1 && $this->parameterInfo[$name]['type'][1] == 'array' && is_array( $value ) ) {
249249 // Trimming of array values.
250 - for($i = count($value); $i > 0; $i--) $value[$i] = trim ($value[$i]);
 250+ for ( $i = count( $value ); $i > 0; $i-- ) $value[$i] = trim ( $value[$i] );
251251 }
252252 else {
253253 // Trimming of non-list values.
254 - $value = trim ($value);
 254+ $value = trim ( $value );
255255 }
256256 }
257257
258 - private function addTypeCriteria($paramName, $criteriaName, $criteriaArgs = array()) {
259 - $this->parameterInfo[$paramName]['criteria'] = array_merge(array($criteriaName => $criteriaArgs), $this->parameterInfo[$paramName]['criteria']);
 258+ private function addTypeCriteria( $paramName, $criteriaName, $criteriaArgs = array() ) {
 259+ $this->parameterInfo[$paramName]['criteria'] = array_merge( array( $criteriaName => $criteriaArgs ), $this->parameterInfo[$paramName]['criteria'] );
260260 }
261261
262262 /**
@@ -270,12 +270,12 @@
271271 $hasNoErrors = true;
272272 $checkItemCriteria = true;
273273
274 - if (array_key_exists('list-criteria', $this->parameterInfo[$name])) {
 274+ if ( array_key_exists( 'list-criteria', $this->parameterInfo[$name] ) ) {
275275 foreach ( $this->parameterInfo[$name]['list-criteria'] as $criteriaName => $criteriaArgs ) {
276276 // Get the validation function. If there is no matching function, throw an exception.
277 - if (array_key_exists($criteriaName, self::$listValidationFunctions)) {
 277+ if ( array_key_exists( $criteriaName, self::$listValidationFunctions ) ) {
278278 $validationFunction = self::$listValidationFunctions[$criteriaName];
279 - $isValid = $this->doCriteriaValidation($validationFunction, $value, $criteriaArgs);
 279+ $isValid = $this->doCriteriaValidation( $validationFunction, $value, $criteriaArgs );
280280
281281 // Add a new error when the validation failed, and break the loop if errors for one parameter should not be accumulated.
282282 if ( ! $isValid ) {
@@ -287,16 +287,16 @@
288288 $checkItemCriteria = false;
289289 break;
290290 }
291 - }
 291+ }
292292 }
293293 else {
294294 $hasNoErrors = false;
295295 throw new Exception( 'There is no validation function for list criteria type ' . $criteriaName );
296 - }
 296+ }
297297 }
298298 }
299299
300 - if ($checkItemCriteria) $hasNoErrors = $hasNoErrors && $this->doItemValidation($name, $value);
 300+ if ( $checkItemCriteria ) $hasNoErrors = $hasNoErrors && $this->doItemValidation( $name, $value );
301301
302302 return $hasNoErrors;
303303 }
@@ -315,24 +315,24 @@
316316 // Go through all item criteria.
317317 foreach ( $this->parameterInfo[$name]['criteria'] as $criteriaName => $criteriaArgs ) {
318318 // Get the validation function. If there is no matching function, throw an exception.
319 - if (array_key_exists($criteriaName, self::$validationFunctions)) {
 319+ if ( array_key_exists( $criteriaName, self::$validationFunctions ) ) {
320320 $validationFunction = self::$validationFunctions[$criteriaName];
321321
322 - if (is_array($value)) {
 322+ if ( is_array( $value ) ) {
323323 // Handling of list parameters
324324 $invalidItems = array();
325325 $validItems = array();
326326
327327 // Loop through all the items in the parameter value, and validate them.
328 - foreach($value as $item) {
329 - $isValid = $this->doCriteriaValidation($validationFunction, $item, $criteriaArgs);
330 - if ($isValid) {
 328+ foreach ( $value as $item ) {
 329+ $isValid = $this->doCriteriaValidation( $validationFunction, $item, $criteriaArgs );
 330+ if ( $isValid ) {
331331 // If per item validation is on, store the valid items, so only these can be returned by Validator.
332 - if (self::$perItemValidation) $validItems[] = $item;
 332+ if ( self::$perItemValidation ) $validItems[] = $item;
333333 }
334334 else {
335335 // If per item validation is on, store the invalid items, so a fitting error message can be created.
336 - if (self::$perItemValidation) {
 336+ if ( self::$perItemValidation ) {
337337 $invalidItems[] = $item;
338338 }
339339 else {
@@ -343,12 +343,12 @@
344344 }
345345 }
346346
347 - if (self::$perItemValidation) {
 347+ if ( self::$perItemValidation ) {
348348 // If per item validation is on, the parameter value is valid as long as there is at least one valid item.
349 - $isValid = count($validItems) > 0;
 349+ $isValid = count( $validItems ) > 0;
350350
351351 // If the value is valid, but there are invalid items, add an error with a list of these items.
352 - if ($isValid && count($invalidItems) > 0) {
 352+ if ( $isValid && count( $invalidItems ) > 0 ) {
353353 $value = $validItems;
354354 $this->errors[] = array( 'type' => $criteriaName, 'args' => $criteriaArgs, 'name' => $name, 'list' => true, 'invalid-items' => $invalidItems );
355355 }
@@ -356,23 +356,23 @@
357357 }
358358 else {
359359 // Determine if the value is valid for single valued parameters.
360 - $isValid = $this->doCriteriaValidation($validationFunction, $value, $criteriaArgs);
 360+ $isValid = $this->doCriteriaValidation( $validationFunction, $value, $criteriaArgs );
361361 }
362362
363363 // Add a new error when the validation failed, and break the loop if errors for one parameter should not be accumulated.
364364 if ( ! $isValid ) {
365 - $isList = is_array($value);
366 - if ($isList) $value = $this->rawParameters[$name];
 365+ $isList = is_array( $value );
 366+ if ( $isList ) $value = $this->rawParameters[$name];
367367 $this->errors[] = array( 'type' => $criteriaName, 'args' => $criteriaArgs, 'name' => $name, 'list' => $isList, 'value' => $value );
368368 $hasNoErrors = false;
369369 if ( ! self::$accumulateParameterErrors ) break;
370 - }
 370+ }
371371 }
372372 else {
373373 $hasNoErrors = false;
374374 throw new Exception( 'There is no validation function for criteria type ' . $criteriaName );
375375 }
376 - }
 376+ }
377377
378378 return $hasNoErrors;
379379 }
@@ -386,9 +386,9 @@
387387 *
388388 * @return unknown_type
389389 */
390 - private function doCriteriaValidation($validationFunction, $value, $criteriaArgs) {
 390+ private function doCriteriaValidation( $validationFunction, $value, $criteriaArgs ) {
391391 // Call the validation function and store the result.
392 - return call_user_func_array( $validationFunction, array_merge(array($value), $criteriaArgs) );
 392+ return call_user_func_array( $validationFunction, array_merge( array( $value ), $criteriaArgs ) );
393393 }
394394
395395 /**
@@ -398,9 +398,9 @@
399399 foreach ( $this->invalid as $paramName => $paramValue ) {
400400 unset( $this->invalid[$paramName] );
401401 $this->valid[$paramName] = array_key_exists( 'default', $this->parameterInfo[$paramName] ) ? $this->parameterInfo[$paramName]['default'] : '';
402 - $this->setOutputTypes($this->valid[$paramName], $this->parameterInfo[$paramName]);
 402+ $this->setOutputTypes( $this->valid[$paramName], $this->parameterInfo[$paramName] );
403403 }
404 - }
 404+ }
405405
406406 /**
407407 * Ensures the output type values are arrays, and then calls setOutputType.
@@ -409,16 +409,16 @@
410410 * @param $info
411411 * @return unknown_type
412412 */
413 - private function setOutputTypes(&$value, array $info) {
414 - if (array_key_exists('output-types', $info)) {
415 - for($i = 0, $c = count($info['output-types']); $i < $c; $i++) {
416 - if (! is_array($info['output-types'][$i])) $info['output-types'][$i] = array($info['output-types'][$i]);
417 - $this->setOutputType($value, $info['output-types'][$i]);
 413+ private function setOutputTypes( &$value, array $info ) {
 414+ if ( array_key_exists( 'output-types', $info ) ) {
 415+ for ( $i = 0, $c = count( $info['output-types'] ); $i < $c; $i++ ) {
 416+ if ( ! is_array( $info['output-types'][$i] ) ) $info['output-types'][$i] = array( $info['output-types'][$i] );
 417+ $this->setOutputType( $value, $info['output-types'][$i] );
418418 }
419419 }
420 - elseif (array_key_exists('output-type', $info)) {
421 - if (! is_array($info['output-type'])) $info['output-type'] = array($info['output-type']);
422 - $this->setOutputType($value, $info['output-type']);
 420+ elseif ( array_key_exists( 'output-type', $info ) ) {
 421+ if ( ! is_array( $info['output-type'] ) ) $info['output-type'] = array( $info['output-type'] );
 422+ $this->setOutputType( $value, $info['output-type'] );
423423 }
424424
425425 }
@@ -429,14 +429,14 @@
430430 * @param $value
431431 * @param array $typeInfo
432432 */
433 - private function setOutputType(&$value, array $typeInfo) {
 433+ private function setOutputType( &$value, array $typeInfo ) {
434434 // The output type is the first value in the type info array.
435435 // The remaining ones will be any extra arguments.
436 - $outputType = strtolower(array_shift($typeInfo));
 436+ $outputType = strtolower( array_shift( $typeInfo ) );
437437
438 - if (array_key_exists($outputType, self::$outputFormats)) {
 438+ if ( array_key_exists( $outputType, self::$outputFormats ) ) {
439439 // Call the formatting function with as first parameter the value, followed by the extra arguments.
440 - call_user_func_array( self::$outputFormats[$outputType], array_merge(array(&$value), $typeInfo) );
 440+ call_user_func_array( self::$outputFormats[$outputType], array_merge( array( &$value ), $typeInfo ) );
441441 }
442442 else {
443443 throw new Exception( 'There is no formatting function for output format ' . $outputType );
@@ -492,7 +492,7 @@
493493 */
494494 public static function addListValidationFunction( $criteriaName, array $functionName ) {
495495 self::$listValidationFunctions[$criteriaName] = $functionName;
496 - }
 496+ }
497497
498498 /**
499499 * Adds a new output format and the formatting function that should validate values of this type.
@@ -504,5 +504,5 @@
505505 */
506506 public static function addOutputFormat( $formatName, array $functionName ) {
507507 self::$outputFormats[$formatName] = $functionName;
508 - }
 508+ }
509509 }
\ No newline at end of file
Index: trunk/extensions/Validator/Validator_Functions.php
@@ -34,8 +34,8 @@
3535 public static function in_range( $value, $lower = false, $upper = false ) {
3636 if ( ! is_numeric( $value ) ) return false;
3737 $value = (int)$value;
38 - if ($lower !== false && $value < $lower) return false;
39 - if ($upper !== false && $value > $upper) return false;
 38+ if ( $lower !== false && $value < $lower ) return false;
 39+ if ( $upper !== false && $value > $upper ) return false;
4040 return true;
4141 }
4242
@@ -61,8 +61,8 @@
6262 // TODO: It's possible the way the allowed values are passed here is quite inneficient...
6363 $params = func_get_args();
6464 array_shift( $params ); // Ommit the value
65 - return in_array($value, $params);
66 - }
 65+ return in_array( $value, $params );
 66+ }
6767
6868 /**
6969 * Returns whether a variable is an integer or an integer string. Uses the native PHP function.
@@ -73,7 +73,7 @@
7474 */
7575 public static function is_integer( $value ) {
7676 return ctype_digit( (string)$value );
77 - }
 77+ }
7878
7979 /**
8080 * Returns whether the length of the value is within a certain range. Upper bound included.
@@ -85,7 +85,7 @@
8686 * @return boolean
8787 */
8888 public static function has_length( $value, $lower = false, $upper = false ) {
89 - return self::in_range(strlen($value), $lower, $upper);
 89+ return self::in_range( strlen( $value ), $lower, $upper );
9090 }
9191
9292 /**
@@ -98,7 +98,7 @@
9999 * @return boolean
100100 */
101101 public static function has_item_count( array $values, $lower = false, $upper = false ) {
102 - return self::in_range(count($values), $lower, $upper);
 102+ return self::in_range( count( $values ), $lower, $upper );
103103 }
104104
105105 /**
@@ -109,8 +109,8 @@
110110 * @return boolean
111111 */
112112 public static function has_unique_items( array $values ) {
113 - return count($values) == count(array_unique($values));
114 - }
 113+ return count( $values ) == count( array_unique( $values ) );
 114+ }
115115
116116 /**
117117 * Returns the result of preg_match.
@@ -121,6 +121,6 @@
122122 * @return boolean
123123 */
124124 public static function regex( $value, $pattern ) {
125 - return (bool)preg_match($pattern, $value);
 125+ return (bool)preg_match( $pattern, $value );
126126 }
127127 }
Index: trunk/extensions/Validator/Validator_Manager.php
@@ -67,21 +67,21 @@
6868 $errors = array();
6969
7070 foreach ( $this->errors as $error ) {
71 - $error['name'] = '<b>' . Sanitizer::escapeId($error['name']) . '</b>';
 71+ $error['name'] = '<b>' . Sanitizer::escapeId( $error['name'] ) . '</b>';
7272
73 - if ($error['type'] == 'unknown') {
 73+ if ( $error['type'] == 'unknown' ) {
7474 $errors[] = wfMsgExt( 'validator_error_unknown_argument', array( 'parsemag' ), $error['name'] );
7575 }
76 - elseif ($error['type'] == 'missing') {
 76+ elseif ( $error['type'] == 'missing' ) {
7777 $errors[] = wfMsgExt( 'validator_error_required_missing', array( 'parsemag' ), $error['name'] );
7878 }
79 - elseif (array_key_exists('list', $error) && $error['list']) {
 79+ elseif ( array_key_exists( 'list', $error ) && $error['list'] ) {
8080 switch( $error['type'] ) {
8181 case 'not_empty' :
8282 $msg = wfMsgExt( 'validator_list_error_empty_argument', array( 'parsemag' ), $error['name'] );
8383 break;
8484 case 'in_range' :
85 - $msg = wfMsgExt( 'validator_list_error_invalid_range', array( 'parsemag' ), $error['name'], '<b>' . $error['args'][0]. '</b>', '<b>' .$error['args'][1]. '</b>' );
 85+ $msg = wfMsgExt( 'validator_list_error_invalid_range', array( 'parsemag' ), $error['name'], '<b>' . $error['args'][0] . '</b>', '<b>' . $error['args'][1] . '</b>' );
8686 break;
8787 case 'is_numeric' :
8888 $msg = wfMsgExt( 'validator_list_error_must_be_number', array( 'parsemag' ), $error['name'] );
@@ -89,7 +89,7 @@
9090 case 'is_integer' :
9191 $msg = wfMsgExt( 'validator_list_error_must_be_integer', array( 'parsemag' ), $error['name'] );
9292 break;
93 - case 'in_array' :
 93+ case 'in_array' :
9494 $itemsText = $wgLang->listToText( $error['args'] );
9595 $msg = wfMsgExt( 'validator_error_accepts_only', array( 'parsemag' ), $error['name'], $itemsText, count( $error['args'] ) );
9696 break;
@@ -98,11 +98,11 @@
9999 break;
100100 }
101101
102 - if (array_key_exists('invalid-items', $error)) {
 102+ if ( array_key_exists( 'invalid-items', $error ) ) {
103103 $omitted = array();
104 - foreach($error['invalid-items'] as $item) $omitted[] = Sanitizer::escapeId($item);
105 - $msg .= ' ' . wfMsgExt( 'validator_list_omitted', array( 'parsemag' ),
106 - $wgLang->listToText($omitted), count($omitted) );
 104+ foreach ( $error['invalid-items'] as $item ) $omitted[] = Sanitizer::escapeId( $item );
 105+ $msg .= ' ' . wfMsgExt( 'validator_list_omitted', array( 'parsemag' ),
 106+ $wgLang->listToText( $omitted ), count( $omitted ) );
107107 }
108108
109109 $errors[] = $msg;
@@ -113,7 +113,7 @@
114114 $errors[] = wfMsgExt( 'validator_error_empty_argument', array( 'parsemag' ), $error['name'] );
115115 break;
116116 case 'in_range' :
117 - $errors[] = wfMsgExt( 'validator_error_invalid_range', array( 'parsemag' ), $error['name'], '<b>' . $error['args'][0]. '</b>', '<b>' .$error['args'][1]. '</b>' );
 117+ $errors[] = wfMsgExt( 'validator_error_invalid_range', array( 'parsemag' ), $error['name'], '<b>' . $error['args'][0] . '</b>', '<b>' . $error['args'][1] . '</b>' );
118118 break;
119119 case 'is_numeric' :
120120 $errors[] = wfMsgExt( 'validator_error_must_be_number', array( 'parsemag' ), $error['name'] );
@@ -121,14 +121,14 @@
122122 case 'is_integer' :
123123 $errors[] = wfMsgExt( 'validator_error_must_be_integer', array( 'parsemag' ), $error['name'] );
124124 break;
125 - case 'in_array' :
 125+ case 'in_array' :
126126 $itemsText = $wgLang->listToText( $error['args'] );
127127 $errors[] = wfMsgExt( 'validator_error_accepts_only', array( 'parsemag' ), $error['name'], $itemsText, count( $error['args'] ) );
128128 break;
129129 case 'invalid' : default :
130130 $errors[] = wfMsgExt( 'validator_error_invalid_argument', array( 'parsemag' ), '<b>' . Sanitizer::escapeId( $error['value'] ) . '</b>', $error['name'] );
131131 break;
132 - }
 132+ }
133133 }
134134 }
135135
Index: trunk/extensions/Validator/Validator_Formats.php
@@ -27,7 +27,7 @@
2828 * @param $value
2929 */
3030 public static function format_array( &$value ) {
31 - if (! is_array($value)) $value = array($value);
 31+ if ( ! is_array( $value ) ) $value = array( $value );
3232 }
3333
3434 /**
@@ -39,13 +39,13 @@
4040 // TODO: It's possible the way the allowed values are passed here is quite inneficient...
4141 $params = func_get_args();
4242 array_shift( $params ); // Ommit the value
43 -
44 - self::format_array($value);
 43+
 44+ self::format_array( $value );
4545 $filtered = array();
46 - foreach($value as $item) if (in_array($item, $params)) $filtered[] = $item;
 46+ foreach ( $value as $item ) if ( in_array( $item, $params ) ) $filtered[] = $item;
4747
4848 return $filtered;
49 - }
 49+ }
5050
5151 /**
5252 * Changes the value to list notation, by separating items with a delimiter,
@@ -57,8 +57,8 @@
5858 * @param $wrapper
5959 */
6060 public static function format_list( &$value, $delimiter = ',', $wrapper = '' ) {
61 - self::format_array($value);
62 - $value = $wrapper . implode($wrapper . $delimiter . $wrapper, $value) . $wrapper;
 61+ self::format_array( $value );
 62+ $value = $wrapper . implode( $wrapper . $delimiter . $wrapper, $value ) . $wrapper;
6363 }
6464
6565 /**
@@ -69,13 +69,13 @@
7070 * @param $value
7171 */
7272 public static function format_boolean( &$value ) {
73 - if (is_array($value)) {
 73+ if ( is_array( $value ) ) {
7474 $boolArray = array();
75 - foreach ($value as $item) $boolArray[] = in_array($item, array('yes', 'on'));
 75+ foreach ( $value as $item ) $boolArray[] = in_array( $item, array( 'yes', 'on' ) );
7676 $value = $boolArray;
7777 }
7878 else {
79 - $value = in_array($value, array('yes', 'on'));
 79+ $value = in_array( $value, array( 'yes', 'on' ) );
8080 }
8181 }
8282
@@ -85,16 +85,16 @@
8686 * @param $value
8787 */
8888 public static function format_boolean_string( &$value ) {
89 - self::format_boolean($value);
90 - if (is_array($value)) {
 89+ self::format_boolean( $value );
 90+ if ( is_array( $value ) ) {
9191 $boolArray = array();
92 - foreach ($value as $item) $boolArray[] = $item ? 'true' : 'false';
 92+ foreach ( $value as $item ) $boolArray[] = $item ? 'true' : 'false';
9393 $value = $boolArray;
9494 }
9595 else {
9696 $value = $value ? 'true' : 'false';
9797 }
98 - }
 98+ }
9999
100100 /**
101101 * Changes lists into strings, by enumerating the items using $wgLang->listToText.
@@ -102,10 +102,10 @@
103103 * @param $value
104104 */
105105 public static function format_string( &$value ) {
106 - if (is_array($value)) {
 106+ if ( is_array( $value ) ) {
107107 global $wgLang;
108 - $value = $wgLang->listToText($value);
109 - }
 108+ $value = $wgLang->listToText( $value );
 109+ }
110110 }
111111
112112 /**
@@ -114,7 +114,7 @@
115115 * @param $value
116116 */
117117 public static function format_unique_items( &$value ) {
118 - if (is_array($value)) $value = array_unique($value);
 118+ if ( is_array( $value ) ) $value = array_unique( $value );
119119 }
120120
121121 }
\ No newline at end of file
Index: trunk/extensions/Validator/Validator.i18n.php
@@ -37,7 +37,7 @@
3838 'validator_list_error_must_be_number' => 'Parameter $1 can only contain numbers.',
3939 'validator_list_error_must_be_integer' => 'Parameter $1 can only contain integers.',
4040 'validator_list_error_invalid_range' => 'All values of parameter $1 must be between $2 and $3.',
41 - 'validator_list_error_invalid_argument' => 'One or more values for parameter $1 are invalid.',
 41+ 'validator_list_error_invalid_argument' => 'One or more values for parameter $1 are invalid.',
4242
4343 'validator_list_omitted' => 'The {{PLURAL:$2|value|values}} $1 {{PLURAL:$2|has|have}} been omitted.',
4444

Status & tagging log