API:
[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 * @addtogroup 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'][$m] = array('missing' => '');
53 continue;
54 }
55 $obj = new $modArr[$m]($this->getMain(), $m);
56 $r['modules'][$m] = $this->getClassInfo($obj);
57 }
58 }
59 if(is_array($params['querymodules']))
60 {
61 $queryObj = new ApiQuery($this->getMain(), 'query');
62 $qmodArr = $queryObj->getModules();
63 foreach($params['querymodules'] as $qm)
64 {
65 if(!isset($qmodArr[$qm]))
66 {
67 $r['querymodules'][$qm] = array('missing' => '');
68 continue;
69 }
70 $obj = new $qmodArr[$qm]($this, $qm);
71 $r['querymodules'][$qm] = $this->getClassInfo($obj);
72 }
73 }
74 $result->addValue(null, $this->getModuleName(), $r);
75 }
76
77 function getClassInfo($obj)
78 {
79 $result = $this->getResult();
80 $retval['classname'] = get_class($obj);
81 $retval['description'] = (is_array($obj->getDescription()) ? implode("\n", $obj->getDescription()) : $obj->getDescription());
82 $retval['prefix'] = $obj->getModulePrefix();
83 $allowedParams = $obj->getAllowedParams();
84 if(!is_array($allowedParams))
85 return $retval;
86 $retval['parameters'] = array();
87 $paramDesc = $obj->getParamDescription();
88 foreach($obj->getAllowedParams() as $n => $p)
89 {
90 $a = array('name' => $n);
91 if(!is_array($p))
92 {
93 if(is_bool($p))
94 {
95 $a['type'] = 'bool';
96 $a['default'] = ($p ? 'true' : 'false');
97 }
98 if(is_string($p))
99 $a['default'] = $p;
100 $retval['parameters'][] = $a;
101 continue;
102 }
103
104 if(isset($p[ApiBase::PARAM_DFLT]))
105 $a['default'] = $p[ApiBase::PARAM_DFLT];
106 if(isset($p[ApiBase::PARAM_ISMULTI]))
107 if($p[ApiBase::PARAM_ISMULTI])
108 $a['multi'] = '';
109 if(isset($p[ApiBase::PARAM_TYPE]))
110 {
111 $a['type'] = $p[ApiBase::PARAM_TYPE];
112 if(is_array($a['type']))
113 $result->setIndexedTagName($a['type'], 't');
114 }
115 if(isset($p[ApiBase::PARAM_MAX]))
116 $a['max'] = $p[ApiBase::PARAM_MAX];
117 if(isset($p[ApiBase::PARAM_MAX2]))
118 $a['highmax'] = $p[ApiBase::PARAM_MAX2];
119 if(isset($p[ApiBase::PARAM_MIN]))
120 $a['min'] = $p[ApiBase::PARAM_MIN];
121 if(isset($paramDesc[$n]))
122 $a['description'] = (is_array($paramDesc[$n]) ? implode("\n", $paramDesc[$n]) : $paramDesc[$n]);
123 $retval['parameters'][] = $a;
124 }
125 $result->setIndexedTagName($retval['parameters'], 'param');
126 return $retval;
127 }
128
129 protected function getAllowedParams() {
130 return array (
131 'modules' => array(
132 ApiBase :: PARAM_ISMULTI => true
133 ),
134 'querymodules' => array(
135 ApiBase :: PARAM_ISMULTI => true
136 )
137 );
138 }
139
140 protected function getParamDescription() {
141 return array (
142 'modules' => 'List of module names (value of the action= parameter)',
143 'querymodules' => 'List of query module names (value of prop=, meta= or list= parameter)',
144 );
145 }
146
147 protected function getDescription() {
148 return 'Obtain information about certain API parameters';
149 }
150
151 protected function getExamples() {
152 return array (
153 'api.php?action=paraminfo&modules=parse&querymodules=allpages|siteinfo'
154 );
155 }
156
157 public function getVersion() {
158 return __CLASS__ . ': $Id: ApiParse.php 29810 2008-01-15 21:33:08Z catrope $';
159 }
160 }
161