r62750 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r62749‎ | r62750 | r62751 >
Date:19:39, 20 February 2010
Author:ashley
Status:ok
Tags:
Comment:
ApiBase.php: coding style cleanup, added more braces, trimmed trailing spaces, changed copyright symbol to the proper one
Modified paths:
  • /trunk/phase3/includes/api/ApiBase.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/api/ApiBase.php
@@ -1,11 +1,11 @@
22 <?php
33
4 -/*
 4+/**
55 * Created on Sep 5, 2006
66 *
77 * API for MediaWiki 1.8+
88 *
9 - * Copyright (C) 2006, 2010 Yuri Astrakhan <Firstname><Lastname>@gmail.com
 9+ * Copyright © 2006, 2010 Yuri Astrakhan <Firstname><Lastname>@gmail.com
1010 *
1111 * This program is free software; you can redistribute it and/or modify
1212 * it under the terms of the GNU General Public License as published by
@@ -121,10 +121,11 @@
122122 * @return string
123123 */
124124 public function getModuleProfileName( $db = false ) {
125 - if ( $db )
 125+ if ( $db ) {
126126 return 'API:' . $this->mModuleName . '-DB';
127 - else
 127+ } else {
128128 return 'API:' . $this->mModuleName;
 129+ }
129130 }
130131
131132 /**
@@ -151,8 +152,9 @@
152153 public function getResult() {
153154 // Main module has getResult() method overriden
154155 // Safety - avoid infinite loop:
155 - if ( $this->isMain() )
156 - ApiBase :: dieDebug( __METHOD__, 'base method was called on main module. ' );
 156+ if ( $this->isMain() ) {
 157+ ApiBase::dieDebug( __METHOD__, 'base method was called on main module. ' );
 158+ }
157159 return $this->getMain()->getResult();
158160 }
159161
@@ -173,19 +175,20 @@
174176 */
175177 public function setWarning( $warning ) {
176178 $data = $this->getResult()->getData();
177 - if ( isset( $data['warnings'][$this->getModuleName()] ) )
178 - {
 179+ if ( isset( $data['warnings'][$this->getModuleName()] ) ) {
179180 // Don't add duplicate warnings
180181 $warn_regex = preg_quote( $warning, '/' );
181182 if ( preg_match( "/{$warn_regex}(\\n|$)/", $data['warnings'][$this->getModuleName()]['*'] ) )
 183+ {
182184 return;
 185+ }
183186 $oldwarning = $data['warnings'][$this->getModuleName()]['*'];
184187 // If there is a warning already, append it to the existing one
185188 $warning = "$oldwarning\n$warning";
186189 $this->getResult()->unsetValue( 'warnings', $this->getModuleName() );
187190 }
188191 $msg = array();
189 - ApiResult :: setContent( $msg, $warning );
 192+ ApiResult::setContent( $msg, $warning );
190193 $this->getResult()->disableSizeCheck();
191194 $this->getResult()->addValue( 'warnings', $this->getModuleName(), $msg );
192195 $this->getResult()->enableSizeCheck();
@@ -206,28 +209,33 @@
207210 * @return mixed string or false
208211 */
209212 public function makeHelpMsg() {
210 -
211213 static $lnPrfx = "\n ";
212214
213215 $msg = $this->getDescription();
214216
215217 if ( $msg !== false ) {
216218
217 - if ( !is_array( $msg ) )
218 - $msg = array (
 219+ if ( !is_array( $msg ) ) {
 220+ $msg = array(
219221 $msg
220222 );
 223+ }
221224 $msg = $lnPrfx . implode( $lnPrfx, $msg ) . "\n";
222225
223 - if ( $this->isReadMode() )
 226+ if ( $this->isReadMode() ) {
224227 $msg .= "\nThis module requires read rights.";
225 - if ( $this->isWriteMode() )
 228+ }
 229+ if ( $this->isWriteMode() ) {
226230 $msg .= "\nThis module requires write rights.";
227 - if ( $this->mustBePosted() )
 231+ }
 232+ if ( $this->mustBePosted() ) {
228233 $msg .= "\nThis module only accepts POST requests.";
 234+ }
229235 if ( $this->isReadMode() || $this->isWriteMode() ||
230236 $this->mustBePosted() )
 237+ {
231238 $msg .= "\n";
 239+ }
232240
233241 // Parameters
234242 $paramsMsg = $this->makeHelpMsgParameters();
@@ -238,10 +246,11 @@
239247 // Examples
240248 $examples = $this->getExamples();
241249 if ( $examples !== false ) {
242 - if ( !is_array( $examples ) )
243 - $examples = array (
 250+ if ( !is_array( $examples ) ) {
 251+ $examples = array(
244252 $examples
245253 );
 254+ }
246255 $msg .= 'Example' . ( count( $examples ) > 1 ? 's' : '' ) . ":\n ";
247256 $msg .= implode( $lnPrfx, $examples ) . "\n";
248257 }
@@ -252,12 +261,13 @@
253262 $callback = array( $this, 'makeHelpMsg_callback' );
254263
255264 if ( is_array( $versions ) ) {
256 - foreach ( $versions as &$v )
 265+ foreach ( $versions as &$v ) {
257266 $v = preg_replace_callback( $pattern, $callback, $v );
 267+ }
258268 $versions = implode( "\n ", $versions );
 269+ } else {
 270+ $versions = preg_replace_callback( $pattern, $callback, $versions );
259271 }
260 - else
261 - $versions = preg_replace_callback( $pattern, $callback, $versions );
262272
263273 $msg .= "Version:\n $versions\n";
264274 }
@@ -279,50 +289,55 @@
280290 $msg = '';
281291 $paramPrefix = "\n" . str_repeat( ' ', 19 );
282292 foreach ( $params as $paramName => $paramSettings ) {
283 - $desc = isset ( $paramsDescription[$paramName] ) ? $paramsDescription[$paramName] : '';
284 - if ( is_array( $desc ) )
 293+ $desc = isset( $paramsDescription[$paramName] ) ? $paramsDescription[$paramName] : '';
 294+ if ( is_array( $desc ) ) {
285295 $desc = implode( $paramPrefix, $desc );
 296+ }
286297
287 - $deprecated = isset( $paramSettings[self :: PARAM_DEPRECATED] ) ?
288 - $paramSettings[self :: PARAM_DEPRECATED] : false;
289 - if ( $deprecated )
 298+ $deprecated = isset( $paramSettings[self::PARAM_DEPRECATED] ) ?
 299+ $paramSettings[self::PARAM_DEPRECATED] : false;
 300+ if ( $deprecated ) {
290301 $desc = "DEPRECATED! $desc";
 302+ }
291303
292 - $type = isset( $paramSettings[self :: PARAM_TYPE] ) ? $paramSettings[self :: PARAM_TYPE] : null;
293 - if ( isset ( $type ) ) {
294 - if ( isset ( $paramSettings[self :: PARAM_ISMULTI] ) )
 304+ $type = isset( $paramSettings[self::PARAM_TYPE] ) ? $paramSettings[self::PARAM_TYPE] : null;
 305+ if ( isset( $type ) ) {
 306+ if ( isset( $paramSettings[self::PARAM_ISMULTI] ) ) {
295307 $prompt = 'Values (separate with \'|\'): ';
296 - else
 308+ } else {
297309 $prompt = 'One value: ';
 310+ }
298311
299312 if ( is_array( $type ) ) {
300313 $choices = array();
301314 $nothingPrompt = false;
302315 foreach ( $type as $t )
303 - if ( $t === '' )
 316+ if ( $t === '' ) {
304317 $nothingPrompt = 'Can be empty, or ';
305 - else
 318+ } else {
306319 $choices[] = $t;
 320+ }
307321 $desc .= $paramPrefix . $nothingPrompt . $prompt . implode( ', ', $choices );
308322 } else {
309323 switch ( $type ) {
310324 case 'namespace':
311325 // Special handling because namespaces are type-limited, yet they are not given
312 - $desc .= $paramPrefix . $prompt . implode( ', ', ApiBase :: getValidNamespaces() );
 326+ $desc .= $paramPrefix . $prompt . implode( ', ', ApiBase::getValidNamespaces() );
313327 break;
314328 case 'limit':
315 - $desc .= $paramPrefix . "No more than {$paramSettings[self :: PARAM_MAX]} ({$paramSettings[self :: PARAM_MAX2]} for bots) allowed.";
 329+ $desc .= $paramPrefix . "No more than {$paramSettings[self :: PARAM_MAX]} ({$paramSettings[self::PARAM_MAX2]} for bots) allowed.";
316330 break;
317331 case 'integer':
318 - $hasMin = isset( $paramSettings[self :: PARAM_MIN] );
319 - $hasMax = isset( $paramSettings[self :: PARAM_MAX] );
 332+ $hasMin = isset( $paramSettings[self::PARAM_MIN] );
 333+ $hasMax = isset( $paramSettings[self::PARAM_MAX] );
320334 if ( $hasMin || $hasMax ) {
321 - if ( !$hasMax )
322 - $intRangeStr = "The value must be no less than {$paramSettings[self :: PARAM_MIN]}";
323 - elseif ( !$hasMin )
324 - $intRangeStr = "The value must be no more than {$paramSettings[self :: PARAM_MAX]}";
325 - else
326 - $intRangeStr = "The value must be between {$paramSettings[self :: PARAM_MIN]} and {$paramSettings[self :: PARAM_MAX]}";
 335+ if ( !$hasMax ) {
 336+ $intRangeStr = "The value must be no less than {$paramSettings[self::PARAM_MIN]}";
 337+ } elseif ( !$hasMin ) {
 338+ $intRangeStr = "The value must be no more than {$paramSettings[self::PARAM_MAX]}";
 339+ } else {
 340+ $intRangeStr = "The value must be between {$paramSettings[self::PARAM_MIN]} and {$paramSettings[self::PARAM_MAX]}";
 341+ }
327342
328343 $desc .= $paramPrefix . $intRangeStr;
329344 }
@@ -331,16 +346,18 @@
332347 }
333348 }
334349
335 - $default = is_array( $paramSettings ) ? ( isset ( $paramSettings[self :: PARAM_DFLT] ) ? $paramSettings[self :: PARAM_DFLT] : null ) : $paramSettings;
336 - if ( !is_null( $default ) && $default !== false )
 350+ $default = is_array( $paramSettings ) ? ( isset( $paramSettings[self::PARAM_DFLT] ) ? $paramSettings[self::PARAM_DFLT] : null ) : $paramSettings;
 351+ if ( !is_null( $default ) && $default !== false ) {
337352 $desc .= $paramPrefix . "Default: $default";
 353+ }
338354
339355 $msg .= sprintf( " %-14s - %s\n", $this->encodeParamName( $paramName ), $desc );
340356 }
341357 return $msg;
342358
343 - } else
 359+ } else {
344360 return false;
 361+ }
345362 }
346363
347364 /**
@@ -349,27 +366,30 @@
350367 */
351368 public function makeHelpMsg_callback( $matches ) {
352369 global $wgAutoloadClasses, $wgAutoloadLocalClasses;
353 - if ( isset( $wgAutoloadLocalClasses[get_class( $this )] ) )
 370+ if ( isset( $wgAutoloadLocalClasses[get_class( $this )] ) ) {
354371 $file = $wgAutoloadLocalClasses[get_class( $this )];
355 - else if ( isset( $wgAutoloadClasses[get_class( $this )] ) )
 372+ } elseif ( isset( $wgAutoloadClasses[get_class( $this )] ) ) {
356373 $file = $wgAutoloadClasses[get_class( $this )];
 374+ }
357375
358376 // Do some guesswork here
359377 $path = strstr( $file, 'includes/api/' );
360 - if ( $path === false )
 378+ if ( $path === false ) {
361379 $path = strstr( $file, 'extensions/' );
362 - else
 380+ } else {
363381 $path = 'phase3/' . $path;
 382+ }
364383
365384 // Get the filename from $matches[2] instead of $file
366385 // If they're not the same file, they're assumed to be in the
367386 // same directory
368387 // This is necessary to make stuff like ApiMain::getVersion()
369388 // returning the version string for ApiBase work
370 - if ( $path )
 389+ if ( $path ) {
371390 return "{$matches[0]}\n http://svn.wikimedia.org/" .
372391 "viewvc/mediawiki/trunk/" . dirname( $path ) .
373392 "/{$matches[2]}";
 393+ }
374394 return $matches[0];
375395 }
376396
@@ -443,20 +463,21 @@
444464 }
445465
446466 /**
447 - * Using getAllowedParams(), this function makes an array of the values
448 - * provided by the user, with key being the name of the variable, and
449 - * value - validated value from user or default. limits will not be
450 - * parsed if $parseLimit is set to false; use this when the max
451 - * limit is not definitive yet, e.g. when getting revisions.
452 - * @param $parseLimit bool
453 - * @return array
454 - */
 467+ * Using getAllowedParams(), this function makes an array of the values
 468+ * provided by the user, with key being the name of the variable, and
 469+ * value - validated value from user or default. limits will not be
 470+ * parsed if $parseLimit is set to false; use this when the max
 471+ * limit is not definitive yet, e.g. when getting revisions.
 472+ * @param $parseLimit Boolean: true by default
 473+ * @return array
 474+ */
455475 public function extractRequestParams( $parseLimit = true ) {
456476 $params = $this->getFinalParams();
457 - $results = array ();
 477+ $results = array();
458478
459 - foreach ( $params as $paramName => $paramSettings )
 479+ foreach ( $params as $paramName => $paramSettings ) {
460480 $results[$paramName] = $this->getParameterFromSettings( $paramName, $paramSettings, $parseLimit );
 481+ }
461482
462483 return $results;
463484 }
@@ -498,15 +519,17 @@
499520 */
500521 public static function getValidNamespaces() {
501522 static $mValidNamespaces = null;
 523+
502524 if ( is_null( $mValidNamespaces ) ) {
503 -
504525 global $wgContLang;
505 - $mValidNamespaces = array ();
 526+ $mValidNamespaces = array();
506527 foreach ( array_keys( $wgContLang->getNamespaces() ) as $ns ) {
507 - if ( $ns >= 0 )
 528+ if ( $ns >= 0 ) {
508529 $mValidNamespaces[] = $ns;
 530+ }
509531 }
510532 }
 533+
511534 return $mValidNamespaces;
512535 }
513536
@@ -520,7 +543,6 @@
521544 * @return mixed Parameter value
522545 */
523546 protected function getParameterFromSettings( $paramName, $paramSettings, $parseLimit ) {
524 -
525547 // Some classes may decide to change parameter names
526548 $encParamName = $this->encodeParamName( $paramName );
527549
@@ -531,52 +553,55 @@
532554 $dupes = false;
533555 $deprecated = false;
534556 } else {
535 - $default = isset ( $paramSettings[self :: PARAM_DFLT] ) ? $paramSettings[self :: PARAM_DFLT] : null;
536 - $multi = isset ( $paramSettings[self :: PARAM_ISMULTI] ) ? $paramSettings[self :: PARAM_ISMULTI] : false;
537 - $type = isset ( $paramSettings[self :: PARAM_TYPE] ) ? $paramSettings[self :: PARAM_TYPE] : null;
538 - $dupes = isset ( $paramSettings[self:: PARAM_ALLOW_DUPLICATES] ) ? $paramSettings[self :: PARAM_ALLOW_DUPLICATES] : false;
539 - $deprecated = isset ( $paramSettings[self:: PARAM_DEPRECATED] ) ? $paramSettings[self :: PARAM_DEPRECATED] : false;
 557+ $default = isset( $paramSettings[self::PARAM_DFLT] ) ? $paramSettings[self::PARAM_DFLT] : null;
 558+ $multi = isset( $paramSettings[self::PARAM_ISMULTI] ) ? $paramSettings[self::PARAM_ISMULTI] : false;
 559+ $type = isset( $paramSettings[self::PARAM_TYPE] ) ? $paramSettings[self::PARAM_TYPE] : null;
 560+ $dupes = isset( $paramSettings[self::PARAM_ALLOW_DUPLICATES] ) ? $paramSettings[self::PARAM_ALLOW_DUPLICATES] : false;
 561+ $deprecated = isset( $paramSettings[self::PARAM_DEPRECATED] ) ? $paramSettings[self::PARAM_DEPRECATED] : false;
540562
541563 // When type is not given, and no choices, the type is the same as $default
542 - if ( !isset ( $type ) ) {
543 - if ( isset ( $default ) )
 564+ if ( !isset( $type ) ) {
 565+ if ( isset( $default ) ) {
544566 $type = gettype( $default );
545 - else
 567+ } else {
546568 $type = 'NULL'; // allow everything
 569+ }
547570 }
548571 }
549572
550573 if ( $type == 'boolean' ) {
551 - if ( isset ( $default ) && $default !== false ) {
 574+ if ( isset( $default ) && $default !== false ) {
552575 // Having a default value of anything other than 'false' is pointless
553 - ApiBase :: dieDebug( __METHOD__, "Boolean param $encParamName's default is set to '$default'" );
 576+ ApiBase::dieDebug( __METHOD__, "Boolean param $encParamName's default is set to '$default'" );
554577 }
555578
556579 $value = $this->getMain()->getRequest()->getCheck( $encParamName );
557580 } else {
558581 $value = $this->getMain()->getRequest()->getVal( $encParamName, $default );
559582
560 - if ( isset ( $value ) && $type == 'namespace' )
561 - $type = ApiBase :: getValidNamespaces();
 583+ if ( isset( $value ) && $type == 'namespace' ) {
 584+ $type = ApiBase::getValidNamespaces();
 585+ }
562586 }
563587
564 - if ( isset ( $value ) && ( $multi || is_array( $type ) ) )
 588+ if ( isset( $value ) && ( $multi || is_array( $type ) ) ) {
565589 $value = $this->parseMultiValue( $encParamName, $value, $multi, is_array( $type ) ? $type : null );
 590+ }
566591
567592 // More validation only when choices were not given
568593 // choices were validated in parseMultiValue()
569 - if ( isset ( $value ) ) {
 594+ if ( isset( $value ) ) {
570595 if ( !is_array( $type ) ) {
571596 switch ( $type ) {
572 - case 'NULL' : // nothing to do
 597+ case 'NULL': // nothing to do
573598 break;
574 - case 'string' : // nothing to do
 599+ case 'string': // nothing to do
575600 break;
576 - case 'integer' : // Force everything using intval() and optionally validate limits
 601+ case 'integer': // Force everything using intval() and optionally validate limits
577602
578603 $value = is_array( $value ) ? array_map( 'intval', $value ) : intval( $value );
579 - $min = isset ( $paramSettings[self :: PARAM_MIN] ) ? $paramSettings[self :: PARAM_MIN] : null;
580 - $max = isset ( $paramSettings[self :: PARAM_MAX] ) ? $paramSettings[self :: PARAM_MAX] : null;
 604+ $min = isset ( $paramSettings[self::PARAM_MIN] ) ? $paramSettings[self::PARAM_MIN] : null;
 605+ $max = isset ( $paramSettings[self::PARAM_MAX] ) ? $paramSettings[self::PARAM_MAX] : null;
581606
582607 if ( !is_null( $min ) || !is_null( $max ) ) {
583608 $values = is_array( $value ) ? $value : array( $value );
@@ -585,50 +610,56 @@
586611 }
587612 }
588613 break;
589 - case 'limit' :
590 - if ( !$parseLimit )
 614+ case 'limit':
 615+ if ( !$parseLimit ) {
591616 // Don't do any validation whatsoever
592617 break;
593 - if ( !isset ( $paramSettings[self :: PARAM_MAX] ) || !isset ( $paramSettings[self :: PARAM_MAX2] ) )
594 - ApiBase :: dieDebug( __METHOD__, "MAX1 or MAX2 are not defined for the limit $encParamName" );
595 - if ( $multi )
596 - ApiBase :: dieDebug( __METHOD__, "Multi-values not supported for $encParamName" );
597 - $min = isset ( $paramSettings[self :: PARAM_MIN] ) ? $paramSettings[self :: PARAM_MIN] : 0;
 618+ }
 619+ if ( !isset( $paramSettings[self::PARAM_MAX] ) || !isset( $paramSettings[self::PARAM_MAX2] ) ) {
 620+ ApiBase::dieDebug( __METHOD__, "MAX1 or MAX2 are not defined for the limit $encParamName" );
 621+ }
 622+ if ( $multi ) {
 623+ ApiBase::dieDebug( __METHOD__, "Multi-values not supported for $encParamName" );
 624+ }
 625+ $min = isset( $paramSettings[self::PARAM_MIN] ) ? $paramSettings[self::PARAM_MIN] : 0;
598626 if ( $value == 'max' ) {
599 - $value = $this->getMain()->canApiHighLimits() ? $paramSettings[self :: PARAM_MAX2] : $paramSettings[self :: PARAM_MAX];
600 - $this->getResult()->addValue( 'limits', $this->getModuleName(), $value );
601 - }
602 - else {
 627+ $value = $this->getMain()->canApiHighLimits() ? $paramSettings[self::PARAM_MAX2] : $paramSettings[self::PARAM_MAX];
 628+ $this->getResult()->addValue( 'limits', $this->getModuleName(), $value );
 629+ } else {
603630 $value = intval( $value );
604 - $this->validateLimit( $paramName, $value, $min, $paramSettings[self :: PARAM_MAX], $paramSettings[self :: PARAM_MAX2] );
 631+ $this->validateLimit( $paramName, $value, $min, $paramSettings[self::PARAM_MAX], $paramSettings[self::PARAM_MAX2] );
605632 }
606633 break;
607 - case 'boolean' :
 634+ case 'boolean':
608635 if ( $multi )
609 - ApiBase :: dieDebug( __METHOD__, "Multi-values not supported for $encParamName" );
 636+ ApiBase::dieDebug( __METHOD__, "Multi-values not supported for $encParamName" );
610637 break;
611 - case 'timestamp' :
612 - if ( $multi )
613 - ApiBase :: dieDebug( __METHOD__, "Multi-values not supported for $encParamName" );
 638+ case 'timestamp':
 639+ if ( $multi ) {
 640+ ApiBase::dieDebug( __METHOD__, "Multi-values not supported for $encParamName" );
 641+ }
614642 $value = wfTimestamp( TS_UNIX, $value );
615 - if ( $value === 0 )
 643+ if ( $value === 0 ) {
616644 $this->dieUsage( "Invalid value '$value' for timestamp parameter $encParamName", "badtimestamp_{$encParamName}" );
 645+ }
617646 $value = wfTimestamp( TS_MW, $value );
618647 break;
619 - case 'user' :
 648+ case 'user':
620649 $title = Title::makeTitleSafe( NS_USER, $value );
621 - if ( is_null( $title ) )
 650+ if ( is_null( $title ) ) {
622651 $this->dieUsage( "Invalid value for user parameter $encParamName", "baduser_{$encParamName}" );
 652+ }
623653 $value = $title->getText();
624654 break;
625 - default :
626 - ApiBase :: dieDebug( __METHOD__, "Param $encParamName's type is unknown - $type" );
 655+ default:
 656+ ApiBase::dieDebug( __METHOD__, "Param $encParamName's type is unknown - $type" );
627657 }
628658 }
629659
630660 // Throw out duplicates if requested
631 - if ( is_array( $value ) && !$dupes )
 661+ if ( is_array( $value ) && !$dupes ) {
632662 $value = array_unique( $value );
 663+ }
633664
634665 // Set a warning if a deprecated parameter has been passed
635666 if ( $deprecated && $value !== false ) {
@@ -640,21 +671,22 @@
641672 }
642673
643674 /**
644 - * Return an array of values that were given in a 'a|b|c' notation,
645 - * after it optionally validates them against the list allowed values.
646 - *
647 - * @param $valueName string The name of the parameter (for error
648 - * reporting)
649 - * @param $value mixed The value being parsed
650 - * @param $allowMultiple bool Can $value contain more than one value
651 - * separated by '|'?
652 - * @param $allowedValues mixed An array of values to check against. If
653 - * null, all values are accepted.
654 - * @return mixed (allowMultiple ? an_array_of_values : a_single_value)
655 - */
 675+ * Return an array of values that were given in a 'a|b|c' notation,
 676+ * after it optionally validates them against the list allowed values.
 677+ *
 678+ * @param $valueName string The name of the parameter (for error
 679+ * reporting)
 680+ * @param $value mixed The value being parsed
 681+ * @param $allowMultiple bool Can $value contain more than one value
 682+ * separated by '|'?
 683+ * @param $allowedValues mixed An array of values to check against. If
 684+ * null, all values are accepted.
 685+ * @return mixed (allowMultiple ? an_array_of_values : a_single_value)
 686+ */
656687 protected function parseMultiValue( $valueName, $value, $allowMultiple, $allowedValues ) {
657 - if ( trim( $value ) === "" && $allowMultiple )
 688+ if ( trim( $value ) === '' && $allowMultiple ) {
658689 return array();
 690+ }
659691
660692 // This is a bit awkward, but we want to avoid calling canApiHighLimits() because it unstubs $wgUser
661693 $valuesList = explode( '|', $value, self::LIMIT_SML2 + 1 );
@@ -673,16 +705,14 @@
674706 if ( is_array( $allowedValues ) ) {
675707 // Check for unknown values
676708 $unknown = array_diff( $valuesList, $allowedValues );
677 - if ( count( $unknown ) )
678 - {
679 - if ( $allowMultiple )
680 - {
681 - $s = count( $unknown ) > 1 ? "s" : "";
 709+ if ( count( $unknown ) ) {
 710+ if ( $allowMultiple ) {
 711+ $s = count( $unknown ) > 1 ? 's' : '';
682712 $vals = implode( ", ", $unknown );
683713 $this->setWarning( "Unrecognized value$s for parameter '$valueName': $vals" );
 714+ } else {
 715+ $this->dieUsage( "Unrecognized value for parameter '$valueName': {$valuesList[0]}", "unknown_$valueName" );
684716 }
685 - else
686 - $this->dieUsage( "Unrecognized value for parameter '$valueName': {$valuesList[0]}", "unknown_$valueName" );
687717 }
688718 // Now throw them out
689719 $valuesList = array_intersect( $valuesList, $allowedValues );
@@ -707,8 +737,9 @@
708738 }
709739
710740 // Minimum is always validated, whereas maximum is checked only if not running in internal call mode
711 - if ( $this->getMain()->isInternalMode() )
 741+ if ( $this->getMain()->isInternalMode() ) {
712742 return;
 743+ }
713744
714745 // Optimization: do not check user's bot status unless really needed -- skips db query
715746 // assumes $botMax >= $max
@@ -731,11 +762,9 @@
732763 * @param $limit int Maximum length
733764 * @return bool True if the array was truncated, false otherwise
734765 */
735 - public static function truncateArray( &$arr, $limit )
736 - {
 766+ public static function truncateArray( &$arr, $limit ) {
737767 $modified = false;
738 - while ( count( $arr ) > $limit )
739 - {
 768+ while ( count( $arr ) > $limit ) {
740769 $junk = array_pop( $arr );
741770 $modified = true;
742771 }
@@ -919,12 +948,13 @@
920949 */
921950 public function parseMsg( $error ) {
922951 $key = array_shift( $error );
923 - if ( isset( self::$messageMap[$key] ) )
924 - return array( 'code' =>
 952+ if ( isset( self::$messageMap[$key] ) ) {
 953+ return array( 'code' =>
925954 wfMsgReplaceArgs( self::$messageMap[$key]['code'], $error ),
926955 'info' =>
927956 wfMsgReplaceArgs( self::$messageMap[$key]['info'], $error )
928957 );
 958+ }
929959 // If the key isn't present, throw an "unknown error"
930960 return $this->parseMsg( array( 'unknownerror', $key ) );
931961 }
@@ -968,35 +998,35 @@
969999 public function mustBePosted() {
9701000 return false;
9711001 }
972 -
 1002+
9731003 /**
974 - * Returns the token salt if there is one, '' if the module doesn't require a salt, else false if the module doesn't need a token
975 - * @returns bool
976 - */
 1004+ * Returns the token salt if there is one, '' if the module doesn't require a salt, else false if the module doesn't need a token
 1005+ * @returns bool
 1006+ */
9771007 public function getTokenSalt() {
9781008 return false;
9791009 }
9801010
9811011 /**
982 - * Returns a list of all possible errors returned by the module
983 - * @return array in the format of array( key, param1, param2, ... ) or array( 'code' => ..., 'info' => ... )
984 - */
 1012+ * Returns a list of all possible errors returned by the module
 1013+ * @return array in the format of array( key, param1, param2, ... ) or array( 'code' => ..., 'info' => ... )
 1014+ */
9851015 public function getPossibleErrors() {
9861016 $ret = array();
9871017
9881018 if ( $this->mustBePosted() ) {
989 - $ret[] = array ( 'mustbeposted', $this->getModuleName() );
 1019+ $ret[] = array( 'mustbeposted', $this->getModuleName() );
9901020 }
9911021
9921022 if ( $this->isReadMode() ) {
993 - $ret[] = array ( 'readrequired' );
 1023+ $ret[] = array( 'readrequired' );
9941024 }
9951025
9961026 if ( $this->isWriteMode() ) {
997 - $ret[] = array ( 'writerequired' );
998 - $ret[] = array ( 'writedisabled' );
 1027+ $ret[] = array( 'writerequired' );
 1028+ $ret[] = array( 'writedisabled' );
9991029 }
1000 -
 1030+
10011031 if ( $this->getTokenSalt() !== false ) {
10021032 $ret[] = array( 'missingparam', 'token' );
10031033 $ret[] = array( 'sessionfailure' );
@@ -1006,19 +1036,17 @@
10071037 }
10081038
10091039 /**
1010 - * Parses a list of errors into a standardised format
1011 - * @param $errors array List of errors. Items can be in the for array( key, param1, param2, ... ) or array( 'code' => ..., 'info' => ... )
1012 - * @return array Parsed list of errors with items in the form array( 'code' => ..., 'info' => ... )
1013 - */
 1040+ * Parses a list of errors into a standardised format
 1041+ * @param $errors array List of errors. Items can be in the for array( key, param1, param2, ... ) or array( 'code' => ..., 'info' => ... )
 1042+ * @return array Parsed list of errors with items in the form array( 'code' => ..., 'info' => ... )
 1043+ */
10141044 public function parseErrors( $errors ) {
10151045 $ret = array();
10161046
1017 - foreach ( $errors as $row )
1018 - {
 1047+ foreach ( $errors as $row ) {
10191048 if ( isset( $row['code'] ) && isset( $row['info'] ) ) {
10201049 $ret[] = $row;
1021 - }
1022 - else {
 1050+ } else {
10231051 $ret[] = $this->parseMsg( $row );
10241052 }
10251053 }
@@ -1034,8 +1062,9 @@
10351063 * Start module profiling
10361064 */
10371065 public function profileIn() {
1038 - if ( $this->mTimeIn !== 0 )
1039 - ApiBase :: dieDebug( __METHOD__, 'called twice without calling profileOut()' );
 1066+ if ( $this->mTimeIn !== 0 ) {
 1067+ ApiBase::dieDebug( __METHOD__, 'called twice without calling profileOut()' );
 1068+ }
10401069 $this->mTimeIn = microtime( true );
10411070 wfProfileIn( $this->getModuleProfileName() );
10421071 }
@@ -1044,10 +1073,12 @@
10451074 * End module profiling
10461075 */
10471076 public function profileOut() {
1048 - if ( $this->mTimeIn === 0 )
1049 - ApiBase :: dieDebug( __METHOD__, 'called without calling profileIn() first' );
1050 - if ( $this->mDBTimeIn !== 0 )
1051 - ApiBase :: dieDebug( __METHOD__, 'must be called after database profiling is done with profileDBOut()' );
 1077+ if ( $this->mTimeIn === 0 ) {
 1078+ ApiBase::dieDebug( __METHOD__, 'called without calling profileIn() first' );
 1079+ }
 1080+ if ( $this->mDBTimeIn !== 0 ) {
 1081+ ApiBase::dieDebug( __METHOD__, 'must be called after database profiling is done with profileDBOut()' );
 1082+ }
10521083
10531084 $this->mModuleTime += microtime( true ) - $this->mTimeIn;
10541085 $this->mTimeIn = 0;
@@ -1060,8 +1091,9 @@
10611092 */
10621093 public function safeProfileOut() {
10631094 if ( $this->mTimeIn !== 0 ) {
1064 - if ( $this->mDBTimeIn !== 0 )
 1095+ if ( $this->mDBTimeIn !== 0 ) {
10651096 $this->profileDBOut();
 1097+ }
10661098 $this->profileOut();
10671099 }
10681100 }
@@ -1071,8 +1103,9 @@
10721104 * @return float
10731105 */
10741106 public function getProfileTime() {
1075 - if ( $this->mTimeIn !== 0 )
1076 - ApiBase :: dieDebug( __METHOD__, 'called without calling profileOut() first' );
 1107+ if ( $this->mTimeIn !== 0 ) {
 1108+ ApiBase::dieDebug( __METHOD__, 'called without calling profileOut() first' );
 1109+ }
10771110 return $this->mModuleTime;
10781111 }
10791112
@@ -1085,10 +1118,12 @@
10861119 * Start module profiling
10871120 */
10881121 public function profileDBIn() {
1089 - if ( $this->mTimeIn === 0 )
1090 - ApiBase :: dieDebug( __METHOD__, 'must be called while profiling the entire module with profileIn()' );
1091 - if ( $this->mDBTimeIn !== 0 )
1092 - ApiBase :: dieDebug( __METHOD__, 'called twice without calling profileDBOut()' );
 1122+ if ( $this->mTimeIn === 0 ) {
 1123+ ApiBase::dieDebug( __METHOD__, 'must be called while profiling the entire module with profileIn()' );
 1124+ }
 1125+ if ( $this->mDBTimeIn !== 0 ) {
 1126+ ApiBase::dieDebug( __METHOD__, 'called twice without calling profileDBOut()' );
 1127+ }
10931128 $this->mDBTimeIn = microtime( true );
10941129 wfProfileIn( $this->getModuleProfileName( true ) );
10951130 }
@@ -1097,10 +1132,12 @@
10981133 * End database profiling
10991134 */
11001135 public function profileDBOut() {
1101 - if ( $this->mTimeIn === 0 )
1102 - ApiBase :: dieDebug( __METHOD__, 'must be called while profiling the entire module with profileIn()' );
1103 - if ( $this->mDBTimeIn === 0 )
1104 - ApiBase :: dieDebug( __METHOD__, 'called without calling profileDBIn() first' );
 1136+ if ( $this->mTimeIn === 0 ) {
 1137+ ApiBase::dieDebug( __METHOD__, 'must be called while profiling the entire module with profileIn()' );
 1138+ }
 1139+ if ( $this->mDBTimeIn === 0 ) {
 1140+ ApiBase::dieDebug( __METHOD__, 'called without calling profileDBIn() first' );
 1141+ }
11051142
11061143 $time = microtime( true ) - $this->mDBTimeIn;
11071144 $this->mDBTimeIn = 0;
@@ -1115,8 +1152,9 @@
11161153 * @return float
11171154 */
11181155 public function getProfileDBTime() {
1119 - if ( $this->mDBTimeIn !== 0 )
1120 - ApiBase :: dieDebug( __METHOD__, 'called without calling profileDBOut() first' );
 1156+ if ( $this->mDBTimeIn !== 0 ) {
 1157+ ApiBase::dieDebug( __METHOD__, 'called without calling profileDBOut() first' );
 1158+ }
11211159 return $this->mDBTime;
11221160 }
11231161
@@ -1129,12 +1167,12 @@
11301168 public static function debugPrint( $value, $name = 'unknown', $backtrace = false ) {
11311169 print "\n\n<pre><b>Debugging value '$name':</b>\n\n";
11321170 var_export( $value );
1133 - if ( $backtrace )
 1171+ if ( $backtrace ) {
11341172 print "\n" . wfBacktrace();
 1173+ }
11351174 print "\n</pre>\n";
11361175 }
11371176
1138 -
11391177 /**
11401178 * Returns a string that identifies the version of this class.
11411179 * @return string

Status & tagging log