Page MenuHomePhabricator

15359.patch

Authored By
bzimport
Nov 21 2014, 10:19 PM
Size
4 KB
Referenced Files
None
Subscribers
None

15359.patch

Index: docs/hooks.txt
===================================================================
--- docs/hooks.txt (revision 40526)
+++ docs/hooks.txt (working copy)
@@ -273,6 +273,15 @@
$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
Index: includes/api/ApiBase.php
===================================================================
--- includes/api/ApiBase.php (revision 40526)
+++ includes/api/ApiBase.php (working copy)
@@ -242,10 +242,10 @@
* 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 @@
}
/**
- * 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 @@
* 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 @@
* 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);
}
Index: includes/api/ApiParamInfo.php
===================================================================
--- includes/api/ApiParamInfo.php (revision 40526)
+++ includes/api/ApiParamInfo.php (working copy)
@@ -86,12 +86,12 @@
$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))

File Metadata

Mime Type
text/x-diff
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
4681
Default Alt Text
15359.patch (4 KB)

Event Timeline