From abaf9995baab6ffaaa3956c951c1b68f1fa46b76 Mon Sep 17 00:00:00 2001 From: Roan Kattouw Date: Tue, 22 Jan 2008 21:22:04 +0000 Subject: [PATCH] (bug 12718) Added action=paraminfo module that provides information about API modules and their parameters --- RELEASE-NOTES | 1 + includes/AutoLoader.php | 1 + includes/api/ApiMain.php | 1 + includes/api/ApiParamInfo.php | 152 ++++++++++++++++++++++++++++++++++ 4 files changed, 155 insertions(+) create mode 100644 includes/api/ApiParamInfo.php diff --git a/RELEASE-NOTES b/RELEASE-NOTES index be151966dc..b5f152d2e1 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -459,6 +459,7 @@ Full API documentation is available at http://www.mediawiki.org/wiki/API * prop=imageinfo interface changed: iihistory replaced by iilimit, iistart and iiend parameters * Added amlang parameter to meta=allmessages * Added apfilterlanglinks parameter to list=allpages, replacing query.php?what=nolanglinks +* (bug 12718) Added action=paraminfo module that provides information about API modules and their parameters === Languages updated in 1.12 === diff --git a/includes/AutoLoader.php b/includes/AutoLoader.php index 819fbd72fa..8509c618e2 100644 --- a/includes/AutoLoader.php +++ b/includes/AutoLoader.php @@ -328,6 +328,7 @@ function __autoload($className) { 'ApiMain' => 'includes/api/ApiMain.php', 'ApiOpenSearch' => 'includes/api/ApiOpenSearch.php', 'ApiPageSet' => 'includes/api/ApiPageSet.php', + 'ApiParamInfo' => 'includes/api/ApiParamInfo.php', 'ApiParse' => 'includes/api/ApiParse.php', 'ApiQuery' => 'includes/api/ApiQuery.php', 'ApiQueryAllpages' => 'includes/api/ApiQueryAllpages.php', diff --git a/includes/api/ApiMain.php b/includes/api/ApiMain.php index 4c294a464d..dff4ab9aa7 100644 --- a/includes/api/ApiMain.php +++ b/includes/api/ApiMain.php @@ -60,6 +60,7 @@ class ApiMain extends ApiBase { 'opensearch' => 'ApiOpenSearch', 'feedwatchlist' => 'ApiFeedWatchlist', 'help' => 'ApiHelp', + 'paraminfo' => 'ApiParamInfo', ); private static $WriteModules = array ( diff --git a/includes/api/ApiParamInfo.php b/includes/api/ApiParamInfo.php new file mode 100644 index 0000000000..cc527023d1 --- /dev/null +++ b/includes/api/ApiParamInfo.php @@ -0,0 +1,152 @@ +.@home.nl + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * http://www.gnu.org/copyleft/gpl.html + */ + +if (!defined('MEDIAWIKI')) { + // Eclipse helper - will be ignored in production + require_once ("ApiBase.php"); +} + +/** + * @addtogroup API + */ +class ApiParamInfo extends ApiBase { + + public function __construct($main, $action) { + parent :: __construct($main, $action); + } + + public function execute() { + // Get parameters + $params = $this->extractRequestParams(); + $result = $this->getResult(); + $r = array(); + if(is_array($params['modules'])) + foreach($params['modules'] as $m) + { + $className = "Api$m"; + if(!class_exists($className)) + { + $mods[$m] = array('missing' => ''); + continue; + } + $obj = new $className($this->getMain(), $m); + $r['modules'][$m] = $this->getClassInfo($obj); + } + if(is_array($params['querymodules'])) + foreach($params['querymodules'] as $qm) + { + $className = "ApiQuery$qm"; + if(!class_exists($className)) + { + $qmods[$qm] = array('missing' => ''); + continue; + } + $obj = new $className($this, 'query'); + $r['querymodules'][$qm] = $this->getClassInfo($obj); + } + $result->addValue( null, $this->getModuleName(), $r ); + } + + function getClassInfo($obj) + { + $result = $this->getResult(); + $retval['classname'] = get_class($obj); + $retval['description'] = (is_array($obj->getDescription()) ? implode("\n", $obj->getDescription()) : $obj->getDescription()); + $allowedParams = $obj->getAllowedParams(); + if(!is_array($allowedParams)) + return $retval; + $retval['parameters'] = array(); + foreach($obj->getAllowedParams() as $n => $p) + { + $a = array('name' => $n); + if(!is_array($p)) + { + if(is_bool($p)) + { + $a['type'] = 'bool'; + $a['default'] = ($p ? 'true' : 'false'); + } + if(is_string($p)) + $a['default'] = $p; + $retval['parameters'][] = $a; + continue; + } + + if(isset($p[ApiBase::PARAM_DFLT])) + $a['default'] = $p[ApiBase::PARAM_DFLT]; + if(isset($p[ApiBase::PARAM_ISMULTI])) + if($p[ApiBase::PARAM_ISMULTI]) + $a['multi'] = ''; + if(isset($p[ApiBase::PARAM_TYPE])) + { + $a['type'] = $p[ApiBase::PARAM_TYPE]; + if(is_array($a['type'])) + $result->setIndexedTagName($a['type'], 't'); + } + if(isset($p[ApiBase::PARAM_MAX])) + $a['max'] = $p[ApiBase::PARAM_MAX]; + if(isset($p[ApiBase::PARAM_MAX2])) + $a['highmax'] = $p[ApiBase::PARAM_MAX2]; + if(isset($p[ApiBase::PARAM_MIN])) + $a['min'] = $p[ApiBase::PARAM_MIN]; + $retval['parameters'][] = $a; + } + $result->setIndexedTagName($retval['parameters'], 'param'); + return $retval; + } + + protected function getAllowedParams() { + return array ( + 'modules' => array( + ApiBase :: PARAM_ISMULTI => true + ), + 'querymodules' => array( + ApiBase :: PARAM_ISMULTI => true + ) + ); + } + + protected function getParamDescription() { + return array ( + 'modules' => 'List of module names (value of the action= parameter)', + 'querymodules' => 'List of query module names (value of prop=, meta= or list= parameter)', + ); + } + + protected function getDescription() { + return 'Obtain information about certain API parameters'; + } + + protected function getExamples() { + return array ( + 'api.php?action=paraminfo&modules=parse&querymodules=allpages|siteinfo' + ); + } + + public function getVersion() { + return __CLASS__ . ': $Id: ApiParse.php 29810 2008-01-15 21:33:08Z catrope $'; + } +} + -- 2.20.1