2c9ef2ee93edff76cfe9e97893747f2b0768005a
4 * Created on Dec 01, 2007
6 * API for MediaWiki 1.8+
8 * Copyright (C) 2008 Roan Kattouw <Firstname>.<Lastname>@home.nl
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License along
21 * with this program; if not, write to the Free Software Foundation, Inc.,
22 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 * http://www.gnu.org/copyleft/gpl.html
26 if (!defined('MEDIAWIKI')) {
27 // Eclipse helper - will be ignored in production
28 require_once ("ApiBase.php");
34 class ApiParamInfo
extends ApiBase
{
36 public function __construct($main, $action) {
37 parent
:: __construct($main, $action);
40 public function execute() {
42 $params = $this->extractRequestParams();
43 $result = $this->getResult();
45 if(is_array($params['modules']))
46 foreach($params['modules'] as $m)
49 if(!class_exists($className))
51 $mods[$m] = array('missing' => '');
54 $obj = new $className($this->getMain(), $m);
55 $r['modules'][$m] = $this->getClassInfo($obj);
57 if(is_array($params['querymodules']))
58 foreach($params['querymodules'] as $qm)
60 $className = "ApiQuery$qm";
61 if(!class_exists($className))
63 $qmods[$qm] = array('missing' => '');
66 $obj = new $className($this, $qm);
67 $r['querymodules'][$qm] = $this->getClassInfo($obj);
69 $result->addValue( null, $this->getModuleName(), $r );
72 function getClassInfo($obj)
74 $result = $this->getResult();
75 $retval['classname'] = get_class($obj);
76 $retval['description'] = (is_array($obj->getDescription()) ?
implode("\n", $obj->getDescription()) : $obj->getDescription());
77 $retval['prefix'] = $obj->getModulePrefix();
78 $allowedParams = $obj->getAllowedParams();
79 if(!is_array($allowedParams))
81 $retval['parameters'] = array();
82 $paramDesc = $obj->getParamDescription();
83 foreach($obj->getAllowedParams() as $n => $p)
85 $a = array('name' => $n);
91 $a['default'] = ($p ?
'true' : 'false');
95 $retval['parameters'][] = $a;
99 if(isset($p[ApiBase
::PARAM_DFLT
]))
100 $a['default'] = $p[ApiBase
::PARAM_DFLT
];
101 if(isset($p[ApiBase
::PARAM_ISMULTI
]))
102 if($p[ApiBase
::PARAM_ISMULTI
])
104 if(isset($p[ApiBase
::PARAM_TYPE
]))
106 $a['type'] = $p[ApiBase
::PARAM_TYPE
];
107 if(is_array($a['type']))
108 $result->setIndexedTagName($a['type'], 't');
110 if(isset($p[ApiBase
::PARAM_MAX
]))
111 $a['max'] = $p[ApiBase
::PARAM_MAX
];
112 if(isset($p[ApiBase
::PARAM_MAX2
]))
113 $a['highmax'] = $p[ApiBase
::PARAM_MAX2
];
114 if(isset($p[ApiBase
::PARAM_MIN
]))
115 $a['min'] = $p[ApiBase
::PARAM_MIN
];
116 if(isset($paramDesc[$n]))
117 $a['description'] = (is_array($paramDesc[$n]) ?
implode("\n", $paramDesc[$n]) : $paramDesc[$n]);
118 $retval['parameters'][] = $a;
120 $result->setIndexedTagName($retval['parameters'], 'param');
124 protected function getAllowedParams() {
127 ApiBase
:: PARAM_ISMULTI
=> true
129 'querymodules' => array(
130 ApiBase
:: PARAM_ISMULTI
=> true
135 protected function getParamDescription() {
137 'modules' => 'List of module names (value of the action= parameter)',
138 'querymodules' => 'List of query module names (value of prop=, meta= or list= parameter)',
142 protected function getDescription() {
143 return 'Obtain information about certain API parameters';
146 protected function getExamples() {
148 'api.php?action=paraminfo&modules=parse&querymodules=allpages|siteinfo'
152 public function getVersion() {
153 return __CLASS__
. ': $Id: ApiParse.php 29810 2008-01-15 21:33:08Z catrope $';