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
{
35 * Module for displaying help
37 public function execute() {
39 $params = $this->extractRequestParams();
41 if ( !isset( $params['modules'] ) && !isset( $params['querymodules'] ) ) {
42 $this->dieUsage( '', 'help' );
45 $this->getMain()->setHelp();
46 $result = $this->getResult();
48 if ( is_array( $params['modules'] ) ) {
49 $modules = $params['modules'];
54 if ( is_array( $params['querymodules'] ) ) {
55 $queryModules = $params['querymodules'];
56 foreach ( $queryModules as $m ) {
57 $modules[] = 'query+' . $m;
60 $queryModules = array();
64 foreach ( $modules as $m ) {
65 // sub-modules could be given in the form of "name[+name[+name...]]"
66 $subNames = explode( '+', $m );
67 if ( count( $subNames ) === 1 ) {
68 // In case the '+' was typed into URL, it resolves as a space
69 $subNames = explode( ' ', $m );
71 $module = $this->getMain();
72 for ( $i = 0; $i < count( $subNames ); $i++
) {
73 $subs = $module->getModuleManager();
74 if ( $subs === null ) {
77 $module = $subs->getModule( $subNames[$i] );
79 if ( $module === null ) {
80 if ( count( $subNames ) === 2
82 && $subNames[0] === 'query'
83 && in_array( $subNames[1], $queryModules )
85 // Legacy: This is one of the renamed 'querymodule=...' parameters,
86 // do not use '+' notation in the output, use submodule's name instead.
89 $name = implode( '+', array_slice( $subNames, 0, $i +
1 ) );
91 $r[] = array( 'name' => $name, 'missing' => '' );
94 $type = $subs->getModuleGroup( $subNames[$i] );
97 if ( $module !== null ) {
98 $r[] = $this->buildModuleHelp( $module, $type );
102 $result->setIndexedTagName( $r, 'module' );
103 $result->addValue( null, $this->getModuleName(), $r );
107 * @param $module ApiBase
108 * @param $type String What type of request is this? e.g. action, query, list, prop, meta, format
111 private function buildModuleHelp( $module, $type ) {
112 $msg = ApiMain
::makeHelpMsgHeader( $module, $type );
114 $msg2 = $module->makeHelpMsg();
115 if ( $msg2 !== false ) {
122 public function shouldCheckMaxlag() {
126 public function isReadMode() {
130 public function getAllowedParams() {
133 ApiBase
::PARAM_ISMULTI
=> true
135 'querymodules' => array(
136 ApiBase
::PARAM_ISMULTI
=> true,
137 ApiBase
::PARAM_DEPRECATED
=> true
142 public function getParamDescription() {
144 'modules' => 'List of module names (value of the action= parameter). Can specify submodules with a \'+\'',
145 'querymodules' => 'Use modules=query+value instead. List of query module names (value of prop=, meta= or list= parameter)',
149 public function getDescription() {
150 return 'Display this help screen. Or the help screen for the specified module';
153 public function getExamples() {
155 'api.php?action=help' => 'Whole help page',
156 'api.php?action=help&modules=protect' => 'Module (action) help page',
157 'api.php?action=help&modules=query+categorymembers' => 'Help for the query/categorymembers module',
158 'api.php?action=help&modules=login|query+info' => 'Help for the login and query/info modules',
162 public function getHelpUrls() {
164 'https://www.mediawiki.org/wiki/API:Main_page',
165 'https://www.mediawiki.org/wiki/API:FAQ',
166 'https://www.mediawiki.org/wiki/API:Quick_start_guide',