5 * Created on Sep 6, 2006
7 * Copyright © 2006 Yuri Astrakhan "<Firstname><Lastname>@gmail.com"
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
28 * This is a simple class to handle action=help
32 class ApiHelp
extends ApiBase
{
34 * Module for displaying help
36 public function execute() {
38 $params = $this->extractRequestParams();
40 if ( !isset( $params['modules'] ) && !isset( $params['querymodules'] ) ) {
41 $this->dieUsage( '', 'help' );
44 $this->getMain()->setHelp();
45 $result = $this->getResult();
47 if ( is_array( $params['modules'] ) ) {
48 $modules = $params['modules'];
53 if ( is_array( $params['querymodules'] ) ) {
54 $queryModules = $params['querymodules'];
55 foreach ( $queryModules as $m ) {
56 $modules[] = 'query+' . $m;
59 $queryModules = array();
63 foreach ( $modules as $m ) {
64 // sub-modules could be given in the form of "name[+name[+name...]]"
65 $subNames = explode( '+', $m );
66 if ( count( $subNames ) === 1 ) {
67 // In case the '+' was typed into URL, it resolves as a space
68 $subNames = explode( ' ', $m );
71 $module = $this->getMain();
72 $subNamesCount = count( $subNames );
73 for ( $i = 0; $i < $subNamesCount; $i++
) {
74 $subs = $module->getModuleManager();
75 if ( $subs === null ) {
78 $module = $subs->getModule( $subNames[$i] );
81 if ( $module === null ) {
82 if ( count( $subNames ) === 2
84 && $subNames[0] === 'query'
85 && in_array( $subNames[1], $queryModules )
87 // Legacy: This is one of the renamed 'querymodule=...' parameters,
88 // do not use '+' notation in the output, use submodule's name instead.
91 $name = implode( '+', array_slice( $subNames, 0, $i +
1 ) );
93 $r[] = array( 'name' => $name, 'missing' => '' );
96 $type = $subs->getModuleGroup( $subNames[$i] );
100 if ( $module !== null ) {
101 $r[] = $this->buildModuleHelp( $module, $type );
105 $result->setIndexedTagName( $r, 'module' );
106 $result->addValue( null, $this->getModuleName(), $r );
110 * @param ApiBase $module
111 * @param string $type What type of request is this? e.g. action, query, list, prop, meta, format
114 private function buildModuleHelp( $module, $type ) {
115 $msg = ApiMain
::makeHelpMsgHeader( $module, $type );
117 $msg2 = $module->makeHelpMsg();
118 if ( $msg2 !== false ) {
125 public function shouldCheckMaxlag() {
129 public function isReadMode() {
133 public function getAllowedParams() {
136 ApiBase
::PARAM_ISMULTI
=> true
138 'querymodules' => array(
139 ApiBase
::PARAM_ISMULTI
=> true,
140 ApiBase
::PARAM_DEPRECATED
=> true
145 public function getParamDescription() {
147 'modules' => 'List of module names (value of the action= parameter). ' .
148 'Can specify submodules with a \'+\'',
149 'querymodules' => 'Use modules=query+value instead. List of query ' .
150 'module names (value of prop=, meta= or list= parameter)',
154 public function getDescription() {
155 return 'Display this help screen. Or the help screen for the specified module.';
158 public function getExamples() {
160 'api.php?action=help' => 'Whole help page',
161 'api.php?action=help&modules=protect' => 'Module (action) help page',
162 'api.php?action=help&modules=query+categorymembers'
163 => 'Help for the query/categorymembers module',
164 'api.php?action=help&modules=login|query+info'
165 => 'Help for the login and query/info modules',
169 public function getHelpUrls() {
171 'https://www.mediawiki.org/wiki/API:Main_page',
172 'https://www.mediawiki.org/wiki/API:FAQ',
173 'https://www.mediawiki.org/wiki/API:Quick_start_guide',