r40594 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r40593‎ | r40594 | r40595 >
Date:19:04, 7 September 2008
Author:catrope
Status:old
Tags:
Comment:
(bug 15359) Add APIGetAllowedParams and APIGetParamDescription hooks
Modified paths:
  • /trunk/phase3/docs/hooks.txt (modified) (history)
  • /trunk/phase3/includes/api/ApiBase.php (modified) (history)
  • /trunk/phase3/includes/api/ApiParamInfo.php (modified) (history)

Diff [purge]

Index: trunk/phase3/docs/hooks.txt
@@ -273,6 +273,15 @@
274274 $text : the new text of the article (has yet to be saved)
275275 $resultArr : data in this array will be added to the API result
276276
 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+
277286 'APIQueryInfoTokens': use this hook to add custom tokens to prop=info.
278287 Every token has an action, which will be used in the intoken parameter
279288 and in the output (actiontoken="..."), and a callback function which
Index: trunk/phase3/includes/api/ApiBase.php
@@ -242,10 +242,10 @@
243243 * module's help.
244244 */
245245 public function makeHelpMsgParameters() {
246 - $params = $this->getAllowedParams();
 246+ $params = $this->getFinalParams();
247247 if ($params !== false) {
248248
249 - $paramsDescription = $this->getParamDescription();
 249+ $paramsDescription = $this->getFinalParamDescription();
250250 $msg = '';
251251 $paramPrefix = "\n" . str_repeat(' ', 19);
252252 foreach ($params as $paramName => $paramSettings) {
@@ -323,18 +323,39 @@
324324 }
325325
326326 /**
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.
328330 */
329331 protected function getAllowedParams() {
330332 return false;
331333 }
332334
333335 /**
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.
335339 */
336340 protected function getParamDescription() {
337341 return false;
338342 }
 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+ }
339360
340361 /**
341362 * This method mangles parameter name based on the prefix supplied to the constructor.
@@ -352,7 +373,7 @@
353374 * when the max limit is not definite, e.g. when getting revisions.
354375 */
355376 public function extractRequestParams($parseMaxLimit = true) {
356 - $params = $this->getAllowedParams();
 377+ $params = $this->getFinalParams();
357378 $results = array ();
358379
359380 foreach ($params as $paramName => $paramSettings)
@@ -365,7 +386,7 @@
366387 * Get a value for the given parameter
367388 */
368389 protected function getParameter($paramName, $parseMaxLimit = true) {
369 - $params = $this->getAllowedParams();
 390+ $params = $this->getFinalParams();
370391 $paramSettings = $params[$paramName];
371392 return $this->getParameterFromSettings($paramName, $paramSettings, $parseMaxLimit);
372393 }
Index: trunk/phase3/includes/api/ApiParamInfo.php
@@ -86,12 +86,12 @@
8787 $retval['classname'] = get_class($obj);
8888 $retval['description'] = (is_array($obj->getDescription()) ? implode("\n", $obj->getDescription()) : $obj->getDescription());
8989 $retval['prefix'] = $obj->getModulePrefix();
90 - $allowedParams = $obj->getAllowedParams();
 90+ $allowedParams = $obj->getFinalParams();
9191 if(!is_array($allowedParams))
9292 return $retval;
9393 $retval['parameters'] = array();
94 - $paramDesc = $obj->getParamDescription();
95 - foreach($obj->getAllowedParams() as $n => $p)
 94+ $paramDesc = $obj->getFinalParamDescription();
 95+ foreach($allowedParams as $n => $p)
9696 {
9797 $a = array('name' => $n);
9898 if(!is_array($p))