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 foreach($params['modules'] as $m)
00050 {
00051 if(!isset($modArr[$m]))
00052 {
00053 $r['modules'][] = array('name' => $m, 'missing' => '');
00054 continue;
00055 }
00056 $obj = new $modArr[$m]($this->getMain(), $m);
00057 $a = $this->getClassInfo($obj);
00058 $a['name'] = $m;
00059 $r['modules'][] = $a;
00060 }
00061 $result->setIndexedTagName($r['modules'], 'module');
00062 }
00063 if(is_array($params['querymodules']))
00064 {
00065 $qmodArr = $queryObj->getModules();
00066 foreach($params['querymodules'] as $qm)
00067 {
00068 if(!isset($qmodArr[$qm]))
00069 {
00070 $r['querymodules'][] = array('name' => $qm, 'missing' => '');
00071 continue;
00072 }
00073 $obj = new $qmodArr[$qm]($this, $qm);
00074 $a = $this->getClassInfo($obj);
00075 $a['name'] = $qm;
00076 $r['querymodules'][] = $a;
00077 }
00078 $result->setIndexedTagName($r['querymodules'], 'module');
00079 }
00080 if($params['mainmodule'])
00081 $r['mainmodule'] = $this->getClassInfo($this->getMain());
00082 if($params['pagesetmodule'])
00083 {
00084 $pageSet = new ApiPageSet($queryObj);
00085 $r['pagesetmodule'] = $this->getClassInfo($pageSet);
00086 }
00087 $result->addValue(null, $this->getModuleName(), $r);
00088 }
00089
00090 function getClassInfo($obj)
00091 {
00092 $result = $this->getResult();
00093 $retval['classname'] = get_class($obj);
00094 $retval['description'] = (is_array($obj->getDescription()) ? implode("\n", $obj->getDescription()) : $obj->getDescription());
00095 $retval['prefix'] = $obj->getModulePrefix();
00096 if($obj->isReadMode())
00097 $retval['readrights'] = '';
00098 if($obj->isWriteMode())
00099 $retval['writerights'] = '';
00100 if($obj->mustBePosted())
00101 $retval['mustbeposted'] = '';
00102 $allowedParams = $obj->getFinalParams();
00103 if(!is_array($allowedParams))
00104 return $retval;
00105 $retval['parameters'] = array();
00106 $paramDesc = $obj->getFinalParamDescription();
00107 foreach($allowedParams as $n => $p)
00108 {
00109 $a = array('name' => $n);
00110 if(!is_array($p))
00111 {
00112 if(is_bool($p))
00113 {
00114 $a['type'] = 'bool';
00115 $a['default'] = ($p ? 'true' : 'false');
00116 }
00117 if(is_string($p))
00118 $a['default'] = $p;
00119 $retval['parameters'][] = $a;
00120 continue;
00121 }
00122
00123 if(isset($p[ApiBase::PARAM_DFLT]))
00124 $a['default'] = $p[ApiBase::PARAM_DFLT];
00125 if(isset($p[ApiBase::PARAM_ISMULTI]))
00126 if($p[ApiBase::PARAM_ISMULTI])
00127 {
00128 $a['multi'] = '';
00129 $a['limit'] = $this->getMain()->canApiHighLimits() ?
00130 ApiBase::LIMIT_SML2 :
00131 ApiBase::LIMIT_SML1;
00132 }
00133 if(isset($p[ApiBase::PARAM_ALLOW_DUPLICATES]))
00134 if($p[ApiBase::PARAM_ALLOW_DUPLICATES])
00135 $a['allowsduplicates'] = '';
00136 if(isset($p[ApiBase::PARAM_TYPE]))
00137 {
00138 $a['type'] = $p[ApiBase::PARAM_TYPE];
00139 if(is_array($a['type']))
00140 $result->setIndexedTagName($a['type'], 't');
00141 }
00142 if(isset($p[ApiBase::PARAM_MAX]))
00143 $a['max'] = $p[ApiBase::PARAM_MAX];
00144 if(isset($p[ApiBase::PARAM_MAX2]))
00145 $a['highmax'] = $p[ApiBase::PARAM_MAX2];
00146 if(isset($p[ApiBase::PARAM_MIN]))
00147 $a['min'] = $p[ApiBase::PARAM_MIN];
00148 if(isset($paramDesc[$n]))
00149 $a['description'] = (is_array($paramDesc[$n]) ? implode("\n", $paramDesc[$n]) : $paramDesc[$n]);
00150 $retval['parameters'][] = $a;
00151 }
00152 $result->setIndexedTagName($retval['parameters'], 'param');
00153 return $retval;
00154 }
00155
00156 public function isReadMode() {
00157 return false;
00158 }
00159
00160 public function getAllowedParams() {
00161 return array (
00162 'modules' => array(
00163 ApiBase :: PARAM_ISMULTI => true
00164 ),
00165 'querymodules' => array(
00166 ApiBase :: PARAM_ISMULTI => true
00167 ),
00168 'mainmodule' => false,
00169 'pagesetmodule' => false,
00170 );
00171 }
00172
00173 public function getParamDescription() {
00174 return array (
00175 'modules' => 'List of module names (value of the action= parameter)',
00176 'querymodules' => 'List of query module names (value of prop=, meta= or list= parameter)',
00177 'mainmodule' => 'Get information about the main (top-level) module as well',
00178 'pagesetmodule' => 'Get information about the pageset module (providing titles= and friends) as well',
00179 );
00180 }
00181
00182 public function getDescription() {
00183 return 'Obtain information about certain API parameters';
00184 }
00185
00186 protected function getExamples() {
00187 return array (
00188 'api.php?action=paraminfo&modules=parse&querymodules=allpages|siteinfo'
00189 );
00190 }
00191
00192 public function getVersion() {
00193 return __CLASS__ . ': $Id: ApiParamInfo.php 48091 2009-03-06 13:49:44Z catrope $';
00194 }
00195 }