Index: trunk/phase3/docs/hooks.txt |
— | — | @@ -273,6 +273,15 @@ |
274 | 274 | $text : the new text of the article (has yet to be saved) |
275 | 275 | $resultArr : data in this array will be added to the API result |
276 | 276 | |
| 277 | +'APIGetAllowedParams': use this hook to modify a module's parameters. |
| 278 | +&$module: Module object |
| 279 | +&$params: Array of parameters |
| 280 | + |
| 281 | +'APIGetParamDescription': use this hook to modify a module's parameter |
| 282 | +descriptions. |
| 283 | +&$module: Module object |
| 284 | +&$desc: Array of parameter descriptions |
| 285 | + |
277 | 286 | 'APIQueryInfoTokens': use this hook to add custom tokens to prop=info. |
278 | 287 | Every token has an action, which will be used in the intoken parameter |
279 | 288 | and in the output (actiontoken="..."), and a callback function which |
Index: trunk/phase3/includes/api/ApiBase.php |
— | — | @@ -242,10 +242,10 @@ |
243 | 243 | * module's help. |
244 | 244 | */ |
245 | 245 | public function makeHelpMsgParameters() { |
246 | | - $params = $this->getAllowedParams(); |
| 246 | + $params = $this->getFinalParams(); |
247 | 247 | if ($params !== false) { |
248 | 248 | |
249 | | - $paramsDescription = $this->getParamDescription(); |
| 249 | + $paramsDescription = $this->getFinalParamDescription(); |
250 | 250 | $msg = ''; |
251 | 251 | $paramPrefix = "\n" . str_repeat(' ', 19); |
252 | 252 | foreach ($params as $paramName => $paramSettings) { |
— | — | @@ -323,18 +323,39 @@ |
324 | 324 | } |
325 | 325 | |
326 | 326 | /** |
327 | | - * Returns an array of allowed parameters (keys) => default value for that parameter |
| 327 | + * Returns an array of allowed parameters (keys) => default value for that parameter. |
| 328 | + * Don't call this function directly: use getFinalParams() to allow hooks |
| 329 | + * to modify parameters as needed. |
328 | 330 | */ |
329 | 331 | protected function getAllowedParams() { |
330 | 332 | return false; |
331 | 333 | } |
332 | 334 | |
333 | 335 | /** |
334 | | - * Returns the description string for the given parameter. |
| 336 | + * Returns an array of parameter descriptions. |
| 337 | + * Don't call this functon directly: use getFinalParamDescription() to allow |
| 338 | + * hooks to modify descriptions as needed. |
335 | 339 | */ |
336 | 340 | protected function getParamDescription() { |
337 | 341 | return false; |
338 | 342 | } |
| 343 | + |
| 344 | + /** |
| 345 | + * Get final list of parameters, after hooks have had |
| 346 | + * a chance to tweak it as needed. |
| 347 | + */ |
| 348 | + public function getFinalParams() { |
| 349 | + $params = $this->getAllowedParams(); |
| 350 | + wfRunHooks('APIGetAllowedParams', array(&$this, &$params)); |
| 351 | + return $params; |
| 352 | + } |
| 353 | + |
| 354 | + |
| 355 | + public function getFinalParamDescription() { |
| 356 | + $desc = $this->getParamDescription(); |
| 357 | + wfRunHooks('APIGetParamDescription', array(&$this, &$desc)); |
| 358 | + return $desc; |
| 359 | + } |
339 | 360 | |
340 | 361 | /** |
341 | 362 | * This method mangles parameter name based on the prefix supplied to the constructor. |
— | — | @@ -352,7 +373,7 @@ |
353 | 374 | * when the max limit is not definite, e.g. when getting revisions. |
354 | 375 | */ |
355 | 376 | public function extractRequestParams($parseMaxLimit = true) { |
356 | | - $params = $this->getAllowedParams(); |
| 377 | + $params = $this->getFinalParams(); |
357 | 378 | $results = array (); |
358 | 379 | |
359 | 380 | foreach ($params as $paramName => $paramSettings) |
— | — | @@ -365,7 +386,7 @@ |
366 | 387 | * Get a value for the given parameter |
367 | 388 | */ |
368 | 389 | protected function getParameter($paramName, $parseMaxLimit = true) { |
369 | | - $params = $this->getAllowedParams(); |
| 390 | + $params = $this->getFinalParams(); |
370 | 391 | $paramSettings = $params[$paramName]; |
371 | 392 | return $this->getParameterFromSettings($paramName, $paramSettings, $parseMaxLimit); |
372 | 393 | } |
Index: trunk/phase3/includes/api/ApiParamInfo.php |
— | — | @@ -86,12 +86,12 @@ |
87 | 87 | $retval['classname'] = get_class($obj); |
88 | 88 | $retval['description'] = (is_array($obj->getDescription()) ? implode("\n", $obj->getDescription()) : $obj->getDescription()); |
89 | 89 | $retval['prefix'] = $obj->getModulePrefix(); |
90 | | - $allowedParams = $obj->getAllowedParams(); |
| 90 | + $allowedParams = $obj->getFinalParams(); |
91 | 91 | if(!is_array($allowedParams)) |
92 | 92 | return $retval; |
93 | 93 | $retval['parameters'] = array(); |
94 | | - $paramDesc = $obj->getParamDescription(); |
95 | | - foreach($obj->getAllowedParams() as $n => $p) |
| 94 | + $paramDesc = $obj->getFinalParamDescription(); |
| 95 | + foreach($allowedParams as $n => $p) |
96 | 96 | { |
97 | 97 | $a = array('name' => $n); |
98 | 98 | if(!is_array($p)) |