API: Add new hook 'APIGetPossibleErrors'
authorumherirrender <umherirrender_de.wp@web.de>
Fri, 5 Apr 2013 16:34:47 +0000 (18:34 +0200)
committerumherirrender <umherirrender_de.wp@web.de>
Fri, 19 Apr 2013 13:25:58 +0000 (15:25 +0200)
This allows extensions to modify the array.

This completes the serie of hooks for similar get methods in ApiBase.

Change-Id: Ib398f5815ab57f25d56356b0997c55a03fd96874

RELEASE-NOTES-1.22
docs/hooks.txt
includes/api/ApiBase.php
includes/api/ApiImageRotate.php
includes/api/ApiParamInfo.php
includes/api/ApiPurge.php
includes/api/ApiQuery.php
includes/api/ApiSetNotificationTimestamp.php

index 86cdf21..13a3c3c 100644 (file)
@@ -29,6 +29,8 @@ production.
 * Added 'SpecialSearchResultsPrepend' and 'SpecialSearchResultsAppend' hooks.
 * (bug 23343) Implemented ability to apply IP blocks to the contents of X-Forwarded-For headers
   by adding a new configuration variable $wgApplyIpBlocksToXff (disabled by default).
+* The new hook 'APIGetPossibleErrors' to modify the list of possible errors was
+  added.
 
 === Bug fixes in 1.22 ===
 * Disable Special:PasswordReset when $wgEnableEmail. Previously one could still
index e896a72..2cde591 100644 (file)
@@ -371,6 +371,11 @@ result.
 &$module: ApiBase Module object
 &$properties: Array of properties
 
+'APIGetPossibleErrors': Use this hook to modify the module's list of possible
+errors.
+$module: ApiBase Module object
+&$possibleErrors: Array of possible errors
+
 'APIQueryAfterExecute': After calling the execute() method of an
 action=query submodule. Use this to extend core API modules.
 &$module: Module object
index f386a8a..08fde7a 100644 (file)
@@ -1560,6 +1560,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 +1606,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' => ... )
index e4642dd..3ecb0d5 100644 (file)
@@ -218,7 +218,7 @@ class ApiImageRotate extends ApiBase {
                $pageSet = $this->getPageSet();
                return array_merge(
                        parent::getPossibleErrors(),
-                       $pageSet->getPossibleErrors()
+                       $pageSet->getFinalPossibleErrors()
                );
        }
 
index 27f8cef..042396e 100644 (file)
@@ -300,7 +300,7 @@ class ApiParamInfo extends ApiBase {
                }
 
                // Errors
-               $retval['errors'] = $this->parseErrors( $obj->getPossibleErrors() );
+               $retval['errors'] = $this->parseErrors( $obj->getFinalPossibleErrors() );
                $result->setIndexedTagName( $retval['errors'], 'error' );
 
                return $retval;
index 49cc738..f13a50e 100644 (file)
@@ -204,7 +204,7 @@ class ApiPurge extends ApiBase {
        public function getPossibleErrors() {
                return array_merge(
                        parent::getPossibleErrors(),
-                       $this->getPageSet()->getPossibleErrors()
+                       $this->getPageSet()->getFinalPossibleErrors()
                );
        }
 
index 4d9a772..3bee4d3 100644 (file)
@@ -722,7 +722,7 @@ class ApiQuery extends ApiBase {
        public function getPossibleErrors() {
                return array_merge(
                        parent::getPossibleErrors(),
-                       $this->getPageSet()->getPossibleErrors()
+                       $this->getPageSet()->getFinalPossibleErrors()
                );
        }
 
index cae9673..53affbd 100644 (file)
@@ -270,7 +270,7 @@ class ApiSetNotificationTimestamp extends ApiBase {
                $ps = $this->getPageSet();
                return array_merge(
                        parent::getPossibleErrors(),
-                       $ps->getPossibleErrors(),
+                       $ps->getFinalPossibleErrors(),
                        $this->getRequireMaxOneParameterErrorMessages(
                                array( 'timestamp', 'torevid', 'newerthanrevid' ) ),
                        $this->getRequireOnlyOneParameterErrorMessages(