From: umherirrender Date: Fri, 5 Apr 2013 16:34:47 +0000 (+0200) Subject: API: Add new hook 'APIGetPossibleErrors' X-Git-Tag: 1.31.0-rc.0~19940 X-Git-Url: http://git.cyclocoop.org/url?a=commitdiff_plain;h=4975761eb2a5387ab53fe340cc60d566fce9dae0;p=lhc%2Fweb%2Fwiklou.git API: Add new hook 'APIGetPossibleErrors' This allows extensions to modify the array. This completes the serie of hooks for similar get methods in ApiBase. Change-Id: Ib398f5815ab57f25d56356b0997c55a03fd96874 --- diff --git a/RELEASE-NOTES-1.22 b/RELEASE-NOTES-1.22 index 86cdf21b64..13a3c3cec2 100644 --- a/RELEASE-NOTES-1.22 +++ b/RELEASE-NOTES-1.22 @@ -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 diff --git a/docs/hooks.txt b/docs/hooks.txt index e896a724a5..2cde591942 100644 --- a/docs/hooks.txt +++ b/docs/hooks.txt @@ -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 diff --git a/includes/api/ApiBase.php b/includes/api/ApiBase.php index f386a8a7b1..08fde7ab93 100644 --- a/includes/api/ApiBase.php +++ b/includes/api/ApiBase.php @@ -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' => ... ) diff --git a/includes/api/ApiImageRotate.php b/includes/api/ApiImageRotate.php index e4642dd763..3ecb0d5800 100644 --- a/includes/api/ApiImageRotate.php +++ b/includes/api/ApiImageRotate.php @@ -218,7 +218,7 @@ class ApiImageRotate extends ApiBase { $pageSet = $this->getPageSet(); return array_merge( parent::getPossibleErrors(), - $pageSet->getPossibleErrors() + $pageSet->getFinalPossibleErrors() ); } diff --git a/includes/api/ApiParamInfo.php b/includes/api/ApiParamInfo.php index 27f8cefd4f..042396ea08 100644 --- a/includes/api/ApiParamInfo.php +++ b/includes/api/ApiParamInfo.php @@ -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; diff --git a/includes/api/ApiPurge.php b/includes/api/ApiPurge.php index 49cc738e58..f13a50e937 100644 --- a/includes/api/ApiPurge.php +++ b/includes/api/ApiPurge.php @@ -204,7 +204,7 @@ class ApiPurge extends ApiBase { public function getPossibleErrors() { return array_merge( parent::getPossibleErrors(), - $this->getPageSet()->getPossibleErrors() + $this->getPageSet()->getFinalPossibleErrors() ); } diff --git a/includes/api/ApiQuery.php b/includes/api/ApiQuery.php index 4d9a772b11..3bee4d331a 100644 --- a/includes/api/ApiQuery.php +++ b/includes/api/ApiQuery.php @@ -722,7 +722,7 @@ class ApiQuery extends ApiBase { public function getPossibleErrors() { return array_merge( parent::getPossibleErrors(), - $this->getPageSet()->getPossibleErrors() + $this->getPageSet()->getFinalPossibleErrors() ); } diff --git a/includes/api/ApiSetNotificationTimestamp.php b/includes/api/ApiSetNotificationTimestamp.php index cae967340d..53affbdff5 100644 --- a/includes/api/ApiSetNotificationTimestamp.php +++ b/includes/api/ApiSetNotificationTimestamp.php @@ -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(