Index: trunk/phase3/includes/api/ApiMain.php |
— | — | @@ -60,6 +60,7 @@ |
61 | 61 | 'opensearch' => 'ApiOpenSearch', |
62 | 62 | 'feedwatchlist' => 'ApiFeedWatchlist', |
63 | 63 | 'help' => 'ApiHelp', |
| 64 | + 'paraminfo' => 'ApiParamInfo', |
64 | 65 | ); |
65 | 66 | |
66 | 67 | private static $WriteModules = array ( |
Index: trunk/phase3/includes/api/ApiParamInfo.php |
— | — | @@ -0,0 +1,152 @@ |
| 2 | +<?php
|
| 3 | +
|
| 4 | +/*
|
| 5 | + * Created on Dec 01, 2007
|
| 6 | + *
|
| 7 | + * API for MediaWiki 1.8+
|
| 8 | + *
|
| 9 | + * Copyright (C) 2008 Roan Kattouw <Firstname>.<Lastname>@home.nl
|
| 10 | + *
|
| 11 | + * This program is free software; you can redistribute it and/or modify
|
| 12 | + * it under the terms of the GNU General Public License as published by
|
| 13 | + * the Free Software Foundation; either version 2 of the License, or
|
| 14 | + * (at your option) any later version.
|
| 15 | + *
|
| 16 | + * This program is distributed in the hope that it will be useful,
|
| 17 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 18 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 19 | + * GNU General Public License for more details.
|
| 20 | + *
|
| 21 | + * You should have received a copy of the GNU General Public License along
|
| 22 | + * with this program; if not, write to the Free Software Foundation, Inc.,
|
| 23 | + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
| 24 | + * http://www.gnu.org/copyleft/gpl.html
|
| 25 | + */
|
| 26 | +
|
| 27 | +if (!defined('MEDIAWIKI')) {
|
| 28 | + // Eclipse helper - will be ignored in production
|
| 29 | + require_once ("ApiBase.php");
|
| 30 | +}
|
| 31 | +
|
| 32 | +/**
|
| 33 | + * @addtogroup API
|
| 34 | + */
|
| 35 | +class ApiParamInfo extends ApiBase {
|
| 36 | +
|
| 37 | + public function __construct($main, $action) {
|
| 38 | + parent :: __construct($main, $action);
|
| 39 | + }
|
| 40 | +
|
| 41 | + public function execute() {
|
| 42 | + // Get parameters
|
| 43 | + $params = $this->extractRequestParams();
|
| 44 | + $result = $this->getResult();
|
| 45 | + $r = array();
|
| 46 | + if(is_array($params['modules']))
|
| 47 | + foreach($params['modules'] as $m)
|
| 48 | + {
|
| 49 | + $className = "Api$m";
|
| 50 | + if(!class_exists($className))
|
| 51 | + {
|
| 52 | + $mods[$m] = array('missing' => '');
|
| 53 | + continue;
|
| 54 | + }
|
| 55 | + $obj = new $className($this->getMain(), $m);
|
| 56 | + $r['modules'][$m] = $this->getClassInfo($obj);
|
| 57 | + }
|
| 58 | + if(is_array($params['querymodules']))
|
| 59 | + foreach($params['querymodules'] as $qm)
|
| 60 | + {
|
| 61 | + $className = "ApiQuery$qm";
|
| 62 | + if(!class_exists($className))
|
| 63 | + {
|
| 64 | + $qmods[$qm] = array('missing' => '');
|
| 65 | + continue;
|
| 66 | + }
|
| 67 | + $obj = new $className($this, 'query');
|
| 68 | + $r['querymodules'][$qm] = $this->getClassInfo($obj);
|
| 69 | + }
|
| 70 | + $result->addValue( null, $this->getModuleName(), $r );
|
| 71 | + }
|
| 72 | +
|
| 73 | + function getClassInfo($obj)
|
| 74 | + {
|
| 75 | + $result = $this->getResult();
|
| 76 | + $retval['classname'] = get_class($obj);
|
| 77 | + $retval['description'] = (is_array($obj->getDescription()) ? implode("\n", $obj->getDescription()) : $obj->getDescription());
|
| 78 | + $allowedParams = $obj->getAllowedParams();
|
| 79 | + if(!is_array($allowedParams))
|
| 80 | + return $retval;
|
| 81 | + $retval['parameters'] = array();
|
| 82 | + foreach($obj->getAllowedParams() as $n => $p)
|
| 83 | + {
|
| 84 | + $a = array('name' => $n);
|
| 85 | + if(!is_array($p))
|
| 86 | + {
|
| 87 | + if(is_bool($p))
|
| 88 | + {
|
| 89 | + $a['type'] = 'bool';
|
| 90 | + $a['default'] = ($p ? 'true' : 'false');
|
| 91 | + }
|
| 92 | + if(is_string($p))
|
| 93 | + $a['default'] = $p;
|
| 94 | + $retval['parameters'][] = $a;
|
| 95 | + continue;
|
| 96 | + }
|
| 97 | +
|
| 98 | + if(isset($p[ApiBase::PARAM_DFLT]))
|
| 99 | + $a['default'] = $p[ApiBase::PARAM_DFLT];
|
| 100 | + if(isset($p[ApiBase::PARAM_ISMULTI]))
|
| 101 | + if($p[ApiBase::PARAM_ISMULTI])
|
| 102 | + $a['multi'] = '';
|
| 103 | + if(isset($p[ApiBase::PARAM_TYPE]))
|
| 104 | + {
|
| 105 | + $a['type'] = $p[ApiBase::PARAM_TYPE];
|
| 106 | + if(is_array($a['type']))
|
| 107 | + $result->setIndexedTagName($a['type'], 't');
|
| 108 | + }
|
| 109 | + if(isset($p[ApiBase::PARAM_MAX]))
|
| 110 | + $a['max'] = $p[ApiBase::PARAM_MAX];
|
| 111 | + if(isset($p[ApiBase::PARAM_MAX2]))
|
| 112 | + $a['highmax'] = $p[ApiBase::PARAM_MAX2];
|
| 113 | + if(isset($p[ApiBase::PARAM_MIN]))
|
| 114 | + $a['min'] = $p[ApiBase::PARAM_MIN];
|
| 115 | + $retval['parameters'][] = $a;
|
| 116 | + }
|
| 117 | + $result->setIndexedTagName($retval['parameters'], 'param');
|
| 118 | + return $retval;
|
| 119 | + }
|
| 120 | +
|
| 121 | + protected function getAllowedParams() {
|
| 122 | + return array (
|
| 123 | + 'modules' => array(
|
| 124 | + ApiBase :: PARAM_ISMULTI => true
|
| 125 | + ),
|
| 126 | + 'querymodules' => array(
|
| 127 | + ApiBase :: PARAM_ISMULTI => true
|
| 128 | + )
|
| 129 | + );
|
| 130 | + }
|
| 131 | +
|
| 132 | + protected function getParamDescription() {
|
| 133 | + return array (
|
| 134 | + 'modules' => 'List of module names (value of the action= parameter)',
|
| 135 | + 'querymodules' => 'List of query module names (value of prop=, meta= or list= parameter)',
|
| 136 | + );
|
| 137 | + }
|
| 138 | +
|
| 139 | + protected function getDescription() {
|
| 140 | + return 'Obtain information about certain API parameters';
|
| 141 | + }
|
| 142 | +
|
| 143 | + protected function getExamples() {
|
| 144 | + return array (
|
| 145 | + 'api.php?action=paraminfo&modules=parse&querymodules=allpages|siteinfo'
|
| 146 | + );
|
| 147 | + }
|
| 148 | +
|
| 149 | + public function getVersion() {
|
| 150 | + return __CLASS__ . ': $Id: ApiParse.php 29810 2008-01-15 21:33:08Z catrope $';
|
| 151 | + }
|
| 152 | +}
|
| 153 | +
|
Index: trunk/phase3/includes/AutoLoader.php |
— | — | @@ -328,6 +328,7 @@ |
329 | 329 | 'ApiMain' => 'includes/api/ApiMain.php', |
330 | 330 | 'ApiOpenSearch' => 'includes/api/ApiOpenSearch.php', |
331 | 331 | 'ApiPageSet' => 'includes/api/ApiPageSet.php', |
| 332 | + 'ApiParamInfo' => 'includes/api/ApiParamInfo.php', |
332 | 333 | 'ApiParse' => 'includes/api/ApiParse.php', |
333 | 334 | 'ApiQuery' => 'includes/api/ApiQuery.php', |
334 | 335 | 'ApiQueryAllpages' => 'includes/api/ApiQueryAllpages.php', |
Index: trunk/phase3/RELEASE-NOTES |
— | — | @@ -459,6 +459,7 @@ |
460 | 460 | * prop=imageinfo interface changed: iihistory replaced by iilimit, iistart and iiend parameters |
461 | 461 | * Added amlang parameter to meta=allmessages |
462 | 462 | * Added apfilterlanglinks parameter to list=allpages, replacing query.php?what=nolanglinks |
| 463 | +* (bug 12718) Added action=paraminfo module that provides information about API modules and their parameters |
463 | 464 | |
464 | 465 | === Languages updated in 1.12 === |
465 | 466 | |