00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 if ( !defined( 'MEDIAWIKI' ) ) {
00027
00028 require_once ( "ApiBase.php" );
00029 }
00030
00034 class ApiParamInfo extends ApiBase {
00035
00036 public function __construct( $main, $action ) {
00037 parent :: __construct( $main, $action );
00038 }
00039
00040 public function execute() {
00041
00042 $params = $this->extractRequestParams();
00043 $result = $this->getResult();
00044 $queryObj = new ApiQuery( $this->getMain(), 'query' );
00045 $r = array();
00046 if ( is_array( $params['modules'] ) )
00047 {
00048 $modArr = $this->getMain()->getModules();
00049 $r['modules'] = array();
00050 foreach ( $params['modules'] as $m )
00051 {
00052 if ( !isset( $modArr[$m] ) )
00053 {
00054 $r['modules'][] = array( 'name' => $m, 'missing' => '' );
00055 continue;
00056 }
00057 $obj = new $modArr[$m]( $this->getMain(), $m );
00058 $a = $this->getClassInfo( $obj );
00059 $a['name'] = $m;
00060 $r['modules'][] = $a;
00061 }
00062 $result->setIndexedTagName( $r['modules'], 'module' );
00063 }
00064 if ( is_array( $params['querymodules'] ) )
00065 {
00066 $qmodArr = $queryObj->getModules();
00067 $r['querymodules'] = array();
00068 foreach ( $params['querymodules'] as $qm )
00069 {
00070 if ( !isset( $qmodArr[$qm] ) )
00071 {
00072 $r['querymodules'][] = array( 'name' => $qm, 'missing' => '' );
00073 continue;
00074 }
00075 $obj = new $qmodArr[$qm]( $this, $qm );
00076 $a = $this->getClassInfo( $obj );
00077 $a['name'] = $qm;
00078 $r['querymodules'][] = $a;
00079 }
00080 $result->setIndexedTagName( $r['querymodules'], 'module' );
00081 }
00082 if ( $params['mainmodule'] )
00083 $r['mainmodule'] = $this->getClassInfo( $this->getMain() );
00084 if ( $params['pagesetmodule'] )
00085 {
00086 $pageSet = new ApiPageSet( $queryObj );
00087 $r['pagesetmodule'] = $this->getClassInfo( $pageSet );
00088 }
00089 $result->addValue( null, $this->getModuleName(), $r );
00090 }
00091
00092 function getClassInfo( $obj )
00093 {
00094 $result = $this->getResult();
00095 $retval['classname'] = get_class( $obj );
00096 $retval['description'] = implode( "\n", (array)$obj->getDescription() );
00097 $retval['version'] = implode( "\n", (array)$obj->getVersion() );
00098 $retval['prefix'] = $obj->getModulePrefix();
00099
00100 if ( $obj->isReadMode() )
00101 $retval['readrights'] = '';
00102 if ( $obj->isWriteMode() )
00103 $retval['writerights'] = '';
00104 if ( $obj->mustBePosted() )
00105 $retval['mustbeposted'] = '';
00106 if ( $obj instanceof ApiQueryGeneratorBase )
00107 $retval['generator'] = '';
00108
00109 $allowedParams = $obj->getFinalParams();
00110 if ( !is_array( $allowedParams ) )
00111 return $retval;
00112
00113 $retval['parameters'] = array();
00114 $paramDesc = $obj->getFinalParamDescription();
00115 foreach ( $allowedParams as $n => $p )
00116 {
00117 $a = array( 'name' => $n );
00118 if ( isset( $paramDesc[$n] ) )
00119 $a['description'] = implode( "\n", (array)$paramDesc[$n] );
00120 if ( isset( $p[ApiBase::PARAM_DEPRECATED] ) && $p[ApiBase::PARAM_DEPRECATED] )
00121 $a['deprecated'] = '';
00122 if ( !is_array( $p ) )
00123 {
00124 if ( is_bool( $p ) )
00125 {
00126 $a['type'] = 'bool';
00127 $a['default'] = ( $p ? 'true' : 'false' );
00128 }
00129 else if ( is_string( $p ) || is_null( $p ) )
00130 {
00131 $a['type'] = 'string';
00132 $a['default'] = strval( $p );
00133 }
00134 else if ( is_int( $p ) )
00135 {
00136 $a['type'] = 'integer';
00137 $a['default'] = intval( $p );
00138 }
00139 $retval['parameters'][] = $a;
00140 continue;
00141 }
00142
00143 if ( isset( $p[ApiBase::PARAM_DFLT] ) )
00144 $a['default'] = $p[ApiBase::PARAM_DFLT];
00145 if ( isset( $p[ApiBase::PARAM_ISMULTI] ) )
00146 if ( $p[ApiBase::PARAM_ISMULTI] )
00147 {
00148 $a['multi'] = '';
00149 $a['limit'] = $this->getMain()->canApiHighLimits() ?
00150 ApiBase::LIMIT_SML2 :
00151 ApiBase::LIMIT_SML1;
00152 }
00153
00154 if ( isset( $p[ApiBase::PARAM_ALLOW_DUPLICATES] ) )
00155 if ( $p[ApiBase::PARAM_ALLOW_DUPLICATES] )
00156 $a['allowsduplicates'] = '';
00157
00158 if ( isset( $p[ApiBase::PARAM_TYPE] ) )
00159 {
00160 $a['type'] = $p[ApiBase::PARAM_TYPE];
00161 if ( is_array( $a['type'] ) )
00162 $result->setIndexedTagName( $a['type'], 't' );
00163 }
00164 if ( isset( $p[ApiBase::PARAM_MAX] ) )
00165 $a['max'] = $p[ApiBase::PARAM_MAX];
00166 if ( isset( $p[ApiBase::PARAM_MAX2] ) )
00167 $a['highmax'] = $p[ApiBase::PARAM_MAX2];
00168 if ( isset( $p[ApiBase::PARAM_MIN] ) )
00169 $a['min'] = $p[ApiBase::PARAM_MIN];
00170 $retval['parameters'][] = $a;
00171 }
00172 $result->setIndexedTagName( $retval['parameters'], 'param' );
00173
00174
00175 $retval['errors'] = $this->parseErrors( $obj->getPossibleErrors() );
00176
00177 $result->setIndexedTagName( $retval['errors'], 'error' );
00178
00179 return $retval;
00180 }
00181
00182 public function isReadMode() {
00183 return false;
00184 }
00185
00186 public function getAllowedParams() {
00187 return array (
00188 'modules' => array(
00189 ApiBase :: PARAM_ISMULTI => true
00190 ),
00191 'querymodules' => array(
00192 ApiBase :: PARAM_ISMULTI => true
00193 ),
00194 'mainmodule' => false,
00195 'pagesetmodule' => false,
00196 );
00197 }
00198
00199 public function getParamDescription() {
00200 return array (
00201 'modules' => 'List of module names (value of the action= parameter)',
00202 'querymodules' => 'List of query module names (value of prop=, meta= or list= parameter)',
00203 'mainmodule' => 'Get information about the main (top-level) module as well',
00204 'pagesetmodule' => 'Get information about the pageset module (providing titles= and friends) as well',
00205 );
00206 }
00207
00208 public function getDescription() {
00209 return 'Obtain information about certain API parameters';
00210 }
00211
00212 protected function getExamples() {
00213 return array (
00214 'api.php?action=paraminfo&modules=parse&querymodules=allpages|siteinfo'
00215 );
00216 }
00217
00218 public function getVersion() {
00219 return __CLASS__ . ': $Id: ApiParamInfo.php 62336 2010-02-11 22:22:20Z reedy $';
00220 }
00221 }