Localisation updates for core and extension messages from translatewiki.net (2010...
[mediawiki.git] / includes / api / ApiParamInfo.php
blob450191ec6a1c5b92a424877a0c498b31f95c25c0
1 <?php
2 /**
3 * API for MediaWiki 1.8+
5 * Created on Dec 01, 2007
7 * Copyright © 2008 Roan Kattouw <Firstname>.<Lastname>@home.nl
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 * http://www.gnu.org/copyleft/gpl.html
24 * @file
27 if ( !defined( 'MEDIAWIKI' ) ) {
28 // Eclipse helper - will be ignored in production
29 require_once( "ApiBase.php" );
32 /**
33 * @ingroup API
35 class ApiParamInfo extends ApiBase {
37 public function __construct( $main, $action ) {
38 parent::__construct( $main, $action );
41 public function execute() {
42 // Get parameters
43 $params = $this->extractRequestParams();
44 $result = $this->getResult();
45 $queryObj = new ApiQuery( $this->getMain(), 'query' );
46 $r = array();
47 if ( is_array( $params['modules'] ) ) {
48 $modArr = $this->getMain()->getModules();
49 $r['modules'] = array();
50 foreach ( $params['modules'] as $m ) {
51 if ( !isset( $modArr[$m] ) ) {
52 $r['modules'][] = array( 'name' => $m, 'missing' => '' );
53 continue;
55 $obj = new $modArr[$m]( $this->getMain(), $m );
56 $a = $this->getClassInfo( $obj );
57 $a['name'] = $m;
58 $r['modules'][] = $a;
60 $result->setIndexedTagName( $r['modules'], 'module' );
62 if ( is_array( $params['querymodules'] ) ) {
63 $qmodArr = $queryObj->getModules();
64 $r['querymodules'] = array();
65 foreach ( $params['querymodules'] as $qm ) {
66 if ( !isset( $qmodArr[$qm] ) ) {
67 $r['querymodules'][] = array( 'name' => $qm, 'missing' => '' );
68 continue;
70 $obj = new $qmodArr[$qm]( $this, $qm );
71 $a = $this->getClassInfo( $obj );
72 $a['name'] = $qm;
73 $r['querymodules'][] = $a;
75 $result->setIndexedTagName( $r['querymodules'], 'module' );
77 if ( $params['mainmodule'] ) {
78 $r['mainmodule'] = $this->getClassInfo( $this->getMain() );
80 if ( $params['pagesetmodule'] ) {
81 $pageSet = new ApiPageSet( $queryObj );
82 $r['pagesetmodule'] = $this->getClassInfo( $pageSet );
84 $result->addValue( null, $this->getModuleName(), $r );
87 function getClassInfo( $obj ) {
88 $result = $this->getResult();
89 $retval['classname'] = get_class( $obj );
90 $retval['description'] = implode( "\n", (array)$obj->getDescription() );
91 $retval['version'] = implode( "\n", (array)$obj->getVersion() );
92 $retval['prefix'] = $obj->getModulePrefix();
94 if ( $obj->isReadMode() ) {
95 $retval['readrights'] = '';
97 if ( $obj->isWriteMode() ) {
98 $retval['writerights'] = '';
100 if ( $obj->mustBePosted() ) {
101 $retval['mustbeposted'] = '';
103 if ( $obj instanceof ApiQueryGeneratorBase ) {
104 $retval['generator'] = '';
107 $allowedParams = $obj->getFinalParams();
108 if ( !is_array( $allowedParams ) ) {
109 return $retval;
112 $retval['parameters'] = array();
113 $paramDesc = $obj->getFinalParamDescription();
114 foreach ( $allowedParams as $n => $p ) {
115 $a = array( 'name' => $n );
116 if ( isset( $paramDesc[$n] ) ) {
117 $a['description'] = implode( "\n", (array)$paramDesc[$n] );
119 if ( isset( $p[ApiBase::PARAM_DEPRECATED] ) && $p[ApiBase::PARAM_DEPRECATED] ) {
120 $a['deprecated'] = '';
122 if ( isset( $p[ApiBase::PARAM_REQUIRED] ) && $p[ApiBase::PARAM_REQUIRED] ) {
123 $a['required'] = '';
126 if ( !is_array( $p ) ) {
127 if ( is_bool( $p ) ) {
128 $a['type'] = 'bool';
129 $a['default'] = ( $p ? 'true' : 'false' );
130 } elseif ( is_string( $p ) || is_null( $p ) ) {
131 $a['type'] = 'string';
132 $a['default'] = strval( $p );
133 } elseif ( is_int( $p ) ) {
134 $a['type'] = 'integer';
135 $a['default'] = intval( $p );
137 $retval['parameters'][] = $a;
138 continue;
141 if ( isset( $p[ApiBase::PARAM_DFLT] ) ) {
142 $a['default'] = $p[ApiBase::PARAM_DFLT];
144 if ( isset( $p[ApiBase::PARAM_ISMULTI] ) && $p[ApiBase::PARAM_ISMULTI] ) {
145 $a['multi'] = '';
146 $a['limit'] = $this->getMain()->canApiHighLimits() ?
147 ApiBase::LIMIT_SML2 :
148 ApiBase::LIMIT_SML1;
151 if ( isset( $p[ApiBase::PARAM_ALLOW_DUPLICATES] ) && $p[ApiBase::PARAM_ALLOW_DUPLICATES] ) {
152 $a['allowsduplicates'] = '';
155 if ( isset( $p[ApiBase::PARAM_TYPE] ) ) {
156 $a['type'] = $p[ApiBase::PARAM_TYPE];
157 if ( is_array( $a['type'] ) ) {
158 $result->setIndexedTagName( $a['type'], 't' );
161 if ( isset( $p[ApiBase::PARAM_MAX] ) ) {
162 $a['max'] = $p[ApiBase::PARAM_MAX];
164 if ( isset( $p[ApiBase::PARAM_MAX2] ) ) {
165 $a['highmax'] = $p[ApiBase::PARAM_MAX2];
167 if ( isset( $p[ApiBase::PARAM_MIN] ) ) {
168 $a['min'] = $p[ApiBase::PARAM_MIN];
170 $retval['parameters'][] = $a;
172 $result->setIndexedTagName( $retval['parameters'], 'param' );
174 // Errors
175 $retval['errors'] = $this->parseErrors( $obj->getPossibleErrors() );
177 $result->setIndexedTagName( $retval['errors'], 'error' );
179 return $retval;
182 public function isReadMode() {
183 return false;
186 public function getAllowedParams() {
187 return array(
188 'modules' => array(
189 ApiBase::PARAM_ISMULTI => true
191 'querymodules' => array(
192 ApiBase::PARAM_ISMULTI => true
194 'mainmodule' => false,
195 'pagesetmodule' => false,
199 public function getParamDescription() {
200 return array(
201 'modules' => 'List of module names (value of the action= parameter)',
202 'querymodules' => 'List of query module names (value of prop=, meta= or list= parameter)',
203 'mainmodule' => 'Get information about the main (top-level) module as well',
204 'pagesetmodule' => 'Get information about the pageset module (providing titles= and friends) as well',
208 public function getDescription() {
209 return 'Obtain information about certain API parameters and errors';
212 protected function getExamples() {
213 return array(
214 'api.php?action=paraminfo&modules=parse&querymodules=allpages|siteinfo'
218 public function getVersion() {
219 return __CLASS__ . ': $Id$';