X-Git-Url: https://git.cyclocoop.org/?a=blobdiff_plain;f=includes%2Fapi%2FApiBase.php;h=ee5aa972087b83fbe082a48b94868c0bf164d0a7;hb=a35cce4be0bdace9c4203d69942f35cfd6681e3d;hp=d2d50ae2f9ae502f3e5d30ef36bb29bc8fe260e8;hpb=d30fc81dab98755b7eb4332feceba17f62400410;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/api/ApiBase.php b/includes/api/ApiBase.php index d2d50ae2f9..ee5aa97208 100644 --- a/includes/api/ApiBase.php +++ b/includes/api/ApiBase.php @@ -311,8 +311,7 @@ abstract class ApiBase extends ContextSource { ); } $msg .= "Example" . ( count( $examples ) > 1 ? 's' : '' ) . ":\n"; - foreach( $examples as $k => $v ) { - + foreach ( $examples as $k => $v ) { if ( is_numeric( $k ) ) { $msg .= " $v\n"; } else { @@ -445,7 +444,7 @@ abstract class ApiBase extends ContextSource { $hintPipeSeparated = false; break; case 'limit': - $desc .= $paramPrefix . "No more than {$paramSettings[self :: PARAM_MAX]}"; + $desc .= $paramPrefix . "No more than {$paramSettings[self::PARAM_MAX]}"; if ( isset( $paramSettings[self::PARAM_MAX2] ) ) { $desc .= " ({$paramSettings[self::PARAM_MAX2]} for bots)"; } @@ -1081,7 +1080,7 @@ abstract class ApiBase extends ContextSource { if ( !$allowMultiple && count( $valuesList ) != 1 ) { // Bug 33482 - Allow entries with | in them for non-multiple values - if ( in_array( $value, $allowedValues ) ) { + if ( in_array( $value, $allowedValues, true ) ) { return $value; } @@ -1165,7 +1164,7 @@ abstract class ApiBase extends ContextSource { /** * Validate and normalize of parameters of type 'user' * @param string $value Parameter value - * @param string $encParamName Parameter value + * @param string $encParamName Parameter name * @return string Validated and normalized parameter */ private function validateUser( $value, $encParamName ) { @@ -1397,7 +1396,7 @@ abstract class ApiBase extends ContextSource { public function dieUsageMsg( $error ) { # most of the time we send a 1 element, so we might as well send it as # a string and make this an array here. - if( is_string( $error ) ) { + if ( is_string( $error ) ) { $error = array( $error ); } $parsed = $this->parseMsg( $error ); @@ -1412,10 +1411,10 @@ abstract class ApiBase extends ContextSource { */ public function dieUsageMsgOrDebug( $error ) { global $wgDebugAPI; - if( $wgDebugAPI !== true ) { + if ( $wgDebugAPI !== true ) { $this->dieUsageMsg( $error ); } else { - if( is_string( $error ) ) { + if ( is_string( $error ) ) { $error = array( $error ); } $parsed = $this->parseMsg( $error ); @@ -1448,7 +1447,7 @@ abstract class ApiBase extends ContextSource { // Check whether the error array was nested // array( array( , ), array( , ) ) - if( is_array( $key ) ) { + if ( is_array( $key ) ) { $error = $key; $key = array_shift( $error ); } @@ -1535,7 +1534,7 @@ abstract class ApiBase extends ContextSource { public function getWatchlistUser( $params ) { if ( !is_null( $params['owner'] ) && !is_null( $params['token'] ) ) { $user = User::newFromName( $params['owner'], false ); - if ( !($user && $user->getId()) ) { + if ( !( $user && $user->getId() ) ) { $this->dieUsage( 'Specified user does not exist', 'bad_wlowner' ); } $token = $user->getOption( 'watchlisttoken' ); @@ -1560,6 +1559,10 @@ abstract class ApiBase extends ContextSource { /** * Returns a list of all possible errors returned by the module + * + * Don't call this function directly: use getFinalPossibleErrors() to allow + * hooks to modify parameters as needed. + * * @return array in the format of array( key, param1, param2, ... ) or array( 'code' => ..., 'info' => ... ) */ public function getPossibleErrors() { @@ -1602,6 +1605,19 @@ abstract class ApiBase extends ContextSource { return $ret; } + /** + * Get final list of possible errors, after hooks have had a chance to + * tweak it as needed. + * + * @return array + * @since 1.22 + */ + public function getFinalPossibleErrors() { + $possibleErrors = $this->getPossibleErrors(); + wfRunHooks( 'APIGetPossibleErrors', array( $this, &$possibleErrors ) ); + return $possibleErrors; + } + /** * Parses a list of errors into a standardised format * @param array $errors List of errors. Items can be in the for array( key, param1, param2, ... ) or array( 'code' => ..., 'info' => ... )