1dcd91876f6f31b6ea4d12d85da26934aae06236
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();
44 $queryObj = new ApiQuery( $this->getMain(), 'query' );
46 if ( is_array( $params['modules'] ) )
48 $modArr = $this->getMain()->getModules();
49 $r['modules'] = array();
50 foreach ( $params['modules'] as $m )
52 if ( !isset( $modArr[$m] ) )
54 $r['modules'][] = array( 'name' => $m, 'missing' => '' );
57 $obj = new $modArr[$m]( $this->getMain(), $m );
58 $a = $this->getClassInfo( $obj );
62 $result->setIndexedTagName( $r['modules'], 'module' );
64 if ( is_array( $params['querymodules'] ) )
66 $qmodArr = $queryObj->getModules();
67 $r['querymodules'] = array();
68 foreach ( $params['querymodules'] as $qm )
70 if ( !isset( $qmodArr[$qm] ) )
72 $r['querymodules'][] = array( 'name' => $qm, 'missing' => '' );
75 $obj = new $qmodArr[$qm]( $this, $qm );
76 $a = $this->getClassInfo( $obj );
78 $r['querymodules'][] = $a;
80 $result->setIndexedTagName( $r['querymodules'], 'module' );
82 if ( $params['mainmodule'] )
83 $r['mainmodule'] = $this->getClassInfo( $this->getMain() );
84 if ( $params['pagesetmodule'] )
86 $pageSet = new ApiPageSet( $queryObj );
87 $r['pagesetmodule'] = $this->getClassInfo( $pageSet );
89 $result->addValue( null, $this->getModuleName(), $r );
92 function getClassInfo( $obj )
94 $result = $this->getResult();
95 $retval['classname'] = get_class( $obj );
96 $retval['description'] = implode( "\n", (array)$obj->getDescription() );
97 $retval['version'] = implode( "\n", (array)$obj->getVersion() );
98 $retval['prefix'] = $obj->getModulePrefix();
100 if ( $obj->isReadMode() )
101 $retval['readrights'] = '';
102 if ( $obj->isWriteMode() )
103 $retval['writerights'] = '';
104 if ( $obj->mustBePosted() )
105 $retval['mustbeposted'] = '';
106 if ( $obj instanceof ApiQueryGeneratorBase
)
107 $retval['generator'] = '';
109 $allowedParams = $obj->getFinalParams();
110 if ( !is_array( $allowedParams ) )
113 $retval['parameters'] = array();
114 $paramDesc = $obj->getFinalParamDescription();
115 foreach ( $allowedParams as $n => $p )
117 $a = array( 'name' => $n );
118 if ( isset( $paramDesc[$n] ) )
119 $a['description'] = implode( "\n", (array)$paramDesc[$n] );
120 if ( isset( $p[ApiBase
::PARAM_DEPRECATED
] ) && $p[ApiBase
::PARAM_DEPRECATED
] )
121 $a['deprecated'] = '';
122 if ( !is_array( $p ) )
127 $a['default'] = ( $p ?
'true' : 'false' );
129 else if ( is_string( $p ) ||
is_null( $p ) )
131 $a['type'] = 'string';
132 $a['default'] = strval( $p );
134 else if ( is_int( $p ) )
136 $a['type'] = 'integer';
137 $a['default'] = intval( $p );
139 $retval['parameters'][] = $a;
143 if ( isset( $p[ApiBase
::PARAM_DFLT
] ) )
144 $a['default'] = $p[ApiBase
::PARAM_DFLT
];
145 if ( isset( $p[ApiBase
::PARAM_ISMULTI
] ) )
146 if ( $p[ApiBase
::PARAM_ISMULTI
] )
149 $a['limit'] = $this->getMain()->canApiHighLimits() ?
150 ApiBase
::LIMIT_SML2
:
154 if ( isset( $p[ApiBase
::PARAM_ALLOW_DUPLICATES
] ) )
155 if ( $p[ApiBase
::PARAM_ALLOW_DUPLICATES
] )
156 $a['allowsduplicates'] = '';
158 if ( isset( $p[ApiBase
::PARAM_TYPE
] ) )
160 $a['type'] = $p[ApiBase
::PARAM_TYPE
];
161 if ( is_array( $a['type'] ) )
162 $result->setIndexedTagName( $a['type'], 't' );
164 if ( isset( $p[ApiBase
::PARAM_MAX
] ) )
165 $a['max'] = $p[ApiBase
::PARAM_MAX
];
166 if ( isset( $p[ApiBase
::PARAM_MAX2
] ) )
167 $a['highmax'] = $p[ApiBase
::PARAM_MAX2
];
168 if ( isset( $p[ApiBase
::PARAM_MIN
] ) )
169 $a['min'] = $p[ApiBase
::PARAM_MIN
];
170 $retval['parameters'][] = $a;
172 $result->setIndexedTagName( $retval['parameters'], 'param' );
175 $retval['errors'] = $this->parseErrors( $obj->possibleErrors() );
177 $result->setIndexedTagName( $retval['errors'], 'error' );
182 public function isReadMode() {
186 public function getAllowedParams() {
189 ApiBase
:: PARAM_ISMULTI
=> true
191 'querymodules' => array(
192 ApiBase
:: PARAM_ISMULTI
=> true
194 'mainmodule' => false,
195 'pagesetmodule' => false,
199 public function getParamDescription() {
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';
212 protected function getExamples() {
214 'api.php?action=paraminfo&modules=parse&querymodules=allpages|siteinfo'
218 public function getVersion() {
219 return __CLASS__
. ': $Id$';