API: (bug 16740) Adding list=protectedtitles to list create-protected titles
[lhc/web/wiklou.git] / includes / api / ApiParamInfo.php
1 <?php
2
3 /*
4 * Created on Dec 01, 2007
5 *
6 * API for MediaWiki 1.8+
7 *
8 * Copyright (C) 2008 Roan Kattouw <Firstname>.<Lastname>@home.nl
9 *
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.
14 *
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.
19 *
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
24 */
25
26 if (!defined('MEDIAWIKI')) {
27 // Eclipse helper - will be ignored in production
28 require_once ("ApiBase.php");
29 }
30
31 /**
32 * @ingroup API
33 */
34 class ApiParamInfo extends ApiBase {
35
36 public function __construct($main, $action) {
37 parent :: __construct($main, $action);
38 }
39
40 public function execute() {
41 // Get parameters
42 $params = $this->extractRequestParams();
43 $result = $this->getResult();
44 $r = array();
45 if(is_array($params['modules']))
46 {
47 $modArr = $this->getMain()->getModules();
48 foreach($params['modules'] as $m)
49 {
50 if(!isset($modArr[$m]))
51 {
52 $r['modules'][] = array('name' => $m, 'missing' => '');
53 continue;
54 }
55 $obj = new $modArr[$m]($this->getMain(), $m);
56 $a = $this->getClassInfo($obj);
57 $a['name'] = $m;
58 $r['modules'][] = $a;
59 }
60 $result->setIndexedTagName($r['modules'], 'module');
61 }
62 if(is_array($params['querymodules']))
63 {
64 $queryObj = new ApiQuery($this->getMain(), 'query');
65 $qmodArr = $queryObj->getModules();
66 foreach($params['querymodules'] as $qm)
67 {
68 if(!isset($qmodArr[$qm]))
69 {
70 $r['querymodules'][] = array('name' => $qm, 'missing' => '');
71 continue;
72 }
73 $obj = new $qmodArr[$qm]($this, $qm);
74 $a = $this->getClassInfo($obj);
75 $a['name'] = $qm;
76 $r['querymodules'][] = $a;
77 }
78 $result->setIndexedTagName($r['querymodules'], 'module');
79 }
80 $result->addValue(null, $this->getModuleName(), $r);
81 }
82
83 function getClassInfo($obj)
84 {
85 $result = $this->getResult();
86 $retval['classname'] = get_class($obj);
87 $retval['description'] = (is_array($obj->getDescription()) ? implode("\n", $obj->getDescription()) : $obj->getDescription());
88 $retval['prefix'] = $obj->getModulePrefix();
89 $allowedParams = $obj->getFinalParams();
90 if(!is_array($allowedParams))
91 return $retval;
92 $retval['parameters'] = array();
93 $paramDesc = $obj->getFinalParamDescription();
94 foreach($allowedParams as $n => $p)
95 {
96 $a = array('name' => $n);
97 if(!is_array($p))
98 {
99 if(is_bool($p))
100 {
101 $a['type'] = 'bool';
102 $a['default'] = ($p ? 'true' : 'false');
103 }
104 if(is_string($p))
105 $a['default'] = $p;
106 $retval['parameters'][] = $a;
107 continue;
108 }
109
110 if(isset($p[ApiBase::PARAM_DFLT]))
111 $a['default'] = $p[ApiBase::PARAM_DFLT];
112 if(isset($p[ApiBase::PARAM_ISMULTI]))
113 if($p[ApiBase::PARAM_ISMULTI])
114 {
115 $a['multi'] = '';
116 $a['limit'] = $this->getMain()->canApiHighLimits() ?
117 ApiBase::LIMIT_SML2 :
118 ApiBase::LIMIT_SML1;
119 }
120 if(isset($p[ApiBase::PARAM_ALLOW_DUPLICATES]))
121 if($p[ApiBase::PARAM_ALLOW_DUPLICATES])
122 $a['allowsduplicates'] = '';
123 if(isset($p[ApiBase::PARAM_TYPE]))
124 {
125 $a['type'] = $p[ApiBase::PARAM_TYPE];
126 if(is_array($a['type']))
127 $result->setIndexedTagName($a['type'], 't');
128 }
129 if(isset($p[ApiBase::PARAM_MAX]))
130 $a['max'] = $p[ApiBase::PARAM_MAX];
131 if(isset($p[ApiBase::PARAM_MAX2]))
132 $a['highmax'] = $p[ApiBase::PARAM_MAX2];
133 if(isset($p[ApiBase::PARAM_MIN]))
134 $a['min'] = $p[ApiBase::PARAM_MIN];
135 if(isset($paramDesc[$n]))
136 $a['description'] = (is_array($paramDesc[$n]) ? implode("\n", $paramDesc[$n]) : $paramDesc[$n]);
137 $retval['parameters'][] = $a;
138 }
139 $result->setIndexedTagName($retval['parameters'], 'param');
140 return $retval;
141 }
142
143 public function getAllowedParams() {
144 return array (
145 'modules' => array(
146 ApiBase :: PARAM_ISMULTI => true
147 ),
148 'querymodules' => array(
149 ApiBase :: PARAM_ISMULTI => true
150 )
151 );
152 }
153
154 public function getParamDescription() {
155 return array (
156 'modules' => 'List of module names (value of the action= parameter)',
157 'querymodules' => 'List of query module names (value of prop=, meta= or list= parameter)',
158 );
159 }
160
161 public function getDescription() {
162 return 'Obtain information about certain API parameters';
163 }
164
165 protected function getExamples() {
166 return array (
167 'api.php?action=paraminfo&modules=parse&querymodules=allpages|siteinfo'
168 );
169 }
170
171 public function getVersion() {
172 return __CLASS__ . ': $Id$';
173 }
174 }