From: Roan Kattouw Date: Sun, 7 Sep 2008 19:04:51 +0000 (+0000) Subject: (bug 15359) Add APIGetAllowedParams and APIGetParamDescription hooks X-Git-Tag: 1.31.0-rc.0~45415 X-Git-Url: https://git.cyclocoop.org/%27.WWW_URL.%27admin/?a=commitdiff_plain;h=76635483de0344f5982a27ed4afa8664d6ee8e95;p=lhc%2Fweb%2Fwiklou.git (bug 15359) Add APIGetAllowedParams and APIGetParamDescription hooks --- diff --git a/docs/hooks.txt b/docs/hooks.txt index d26d514b14..9e9dbf9ee7 100644 --- a/docs/hooks.txt +++ b/docs/hooks.txt @@ -273,6 +273,15 @@ $EditPage : the EditPage object $text : the new text of the article (has yet to be saved) $resultArr : data in this array will be added to the API result +'APIGetAllowedParams': use this hook to modify a module's parameters. +&$module: Module object +&$params: Array of parameters + +'APIGetParamDescription': use this hook to modify a module's parameter +descriptions. +&$module: Module object +&$desc: Array of parameter descriptions + 'APIQueryInfoTokens': use this hook to add custom tokens to prop=info. Every token has an action, which will be used in the intoken parameter and in the output (actiontoken="..."), and a callback function which diff --git a/includes/api/ApiBase.php b/includes/api/ApiBase.php index 144f61f705..779176469f 100644 --- a/includes/api/ApiBase.php +++ b/includes/api/ApiBase.php @@ -242,10 +242,10 @@ abstract class ApiBase { * module's help. */ public function makeHelpMsgParameters() { - $params = $this->getAllowedParams(); + $params = $this->getFinalParams(); if ($params !== false) { - $paramsDescription = $this->getParamDescription(); + $paramsDescription = $this->getFinalParamDescription(); $msg = ''; $paramPrefix = "\n" . str_repeat(' ', 19); foreach ($params as $paramName => $paramSettings) { @@ -323,18 +323,39 @@ abstract class ApiBase { } /** - * Returns an array of allowed parameters (keys) => default value for that parameter + * Returns an array of allowed parameters (keys) => default value for that parameter. + * Don't call this function directly: use getFinalParams() to allow hooks + * to modify parameters as needed. */ protected function getAllowedParams() { return false; } /** - * Returns the description string for the given parameter. + * Returns an array of parameter descriptions. + * Don't call this functon directly: use getFinalParamDescription() to allow + * hooks to modify descriptions as needed. */ protected function getParamDescription() { return false; } + + /** + * Get final list of parameters, after hooks have had + * a chance to tweak it as needed. + */ + public function getFinalParams() { + $params = $this->getAllowedParams(); + wfRunHooks('APIGetAllowedParams', array(&$this, &$params)); + return $params; + } + + + public function getFinalParamDescription() { + $desc = $this->getParamDescription(); + wfRunHooks('APIGetParamDescription', array(&$this, &$desc)); + return $desc; + } /** * This method mangles parameter name based on the prefix supplied to the constructor. @@ -352,7 +373,7 @@ abstract class ApiBase { * when the max limit is not definite, e.g. when getting revisions. */ public function extractRequestParams($parseMaxLimit = true) { - $params = $this->getAllowedParams(); + $params = $this->getFinalParams(); $results = array (); foreach ($params as $paramName => $paramSettings) @@ -365,7 +386,7 @@ abstract class ApiBase { * Get a value for the given parameter */ protected function getParameter($paramName, $parseMaxLimit = true) { - $params = $this->getAllowedParams(); + $params = $this->getFinalParams(); $paramSettings = $params[$paramName]; return $this->getParameterFromSettings($paramName, $paramSettings, $parseMaxLimit); } diff --git a/includes/api/ApiParamInfo.php b/includes/api/ApiParamInfo.php index 91e526e76c..856075315e 100644 --- a/includes/api/ApiParamInfo.php +++ b/includes/api/ApiParamInfo.php @@ -86,12 +86,12 @@ class ApiParamInfo extends ApiBase { $retval['classname'] = get_class($obj); $retval['description'] = (is_array($obj->getDescription()) ? implode("\n", $obj->getDescription()) : $obj->getDescription()); $retval['prefix'] = $obj->getModulePrefix(); - $allowedParams = $obj->getAllowedParams(); + $allowedParams = $obj->getFinalParams(); if(!is_array($allowedParams)) return $retval; $retval['parameters'] = array(); - $paramDesc = $obj->getParamDescription(); - foreach($obj->getAllowedParams() as $n => $p) + $paramDesc = $obj->getFinalParamDescription(); + foreach($allowedParams as $n => $p) { $a = array('name' => $n); if(!is_array($p))