Fixed spacing in api folder
[lhc/web/wiklou.git] / includes / api / ApiBase.php
index 9351a8d..ee5aa97 100644 (file)
@@ -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)";
                                                                }
@@ -822,7 +821,7 @@ abstract class ApiBase extends ContextSource {
         *      If not set will magically default to either watchdefault or watchcreations
         * @return bool
         */
-       protected function getWatchlistValue ( $watchlist, $titleObj, $userOption = null ) {
+       protected function getWatchlistValue( $watchlist, $titleObj, $userOption = null ) {
 
                $userWatching = $this->getUser()->isWatched( $titleObj );
 
@@ -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( <code>, <params> ), array( <another_code>, <params> ) )
-               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' => ... )