Merge "Check validity and availability of usernames during signup via AJAX"
[lhc/web/wiklou.git] / includes / api / ApiHelp.php
1 <?php
2 /**
3 *
4 *
5 * Created on Sep 6, 2006
6 *
7 * Copyright © 2006 Yuri Astrakhan "<Firstname><Lastname>@gmail.com"
8 *
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.
13 *
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.
18 *
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
23 *
24 * @file
25 */
26
27 /**
28 * This is a simple class to handle action=help
29 *
30 * @ingroup API
31 */
32 class ApiHelp extends ApiBase {
33 /**
34 * Module for displaying help
35 */
36 public function execute() {
37 // Get parameters
38 $params = $this->extractRequestParams();
39
40 if ( !isset( $params['modules'] ) && !isset( $params['querymodules'] ) ) {
41 $this->dieUsage( '', 'help' );
42 }
43
44 $this->getMain()->setHelp();
45 $result = $this->getResult();
46
47 if ( is_array( $params['modules'] ) ) {
48 $modules = $params['modules'];
49 } else {
50 $modules = array();
51 }
52
53 if ( is_array( $params['querymodules'] ) ) {
54 $queryModules = $params['querymodules'];
55 foreach ( $queryModules as $m ) {
56 $modules[] = 'query+' . $m;
57 }
58 } else {
59 $queryModules = array();
60 }
61
62 $r = 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 );
69 }
70
71 $module = $this->getMain();
72 $subNamesCount = count( $subNames );
73 for ( $i = 0; $i < $subNamesCount; $i++ ) {
74 $subs = $module->getModuleManager();
75 if ( $subs === null ) {
76 $module = null;
77 } else {
78 $module = $subs->getModule( $subNames[$i] );
79 }
80
81 if ( $module === null ) {
82 if ( count( $subNames ) === 2
83 && $i === 1
84 && $subNames[0] === 'query'
85 && in_array( $subNames[1], $queryModules )
86 ) {
87 // Legacy: This is one of the renamed 'querymodule=...' parameters,
88 // do not use '+' notation in the output, use submodule's name instead.
89 $name = $subNames[1];
90 } else {
91 $name = implode( '+', array_slice( $subNames, 0, $i + 1 ) );
92 }
93 $r[] = array( 'name' => $name, 'missing' => '' );
94 break;
95 } else {
96 $type = $subs->getModuleGroup( $subNames[$i] );
97 }
98 }
99
100 if ( $module !== null ) {
101 $r[] = $this->buildModuleHelp( $module, $type );
102 }
103 }
104
105 $result->setIndexedTagName( $r, 'module' );
106 $result->addValue( null, $this->getModuleName(), $r );
107 }
108
109 /**
110 * @param $module ApiBase
111 * @param $type String What type of request is this? e.g. action, query, list, prop, meta, format
112 * @return string
113 */
114 private function buildModuleHelp( $module, $type ) {
115 $msg = ApiMain::makeHelpMsgHeader( $module, $type );
116
117 $msg2 = $module->makeHelpMsg();
118 if ( $msg2 !== false ) {
119 $msg .= $msg2;
120 }
121
122 return $msg;
123 }
124
125 public function shouldCheckMaxlag() {
126 return false;
127 }
128
129 public function isReadMode() {
130 return false;
131 }
132
133 public function getAllowedParams() {
134 return array(
135 'modules' => array(
136 ApiBase::PARAM_ISMULTI => true
137 ),
138 'querymodules' => array(
139 ApiBase::PARAM_ISMULTI => true,
140 ApiBase::PARAM_DEPRECATED => true
141 ),
142 );
143 }
144
145 public function getParamDescription() {
146 return array(
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)',
151 );
152 }
153
154 public function getDescription() {
155 return 'Display this help screen. Or the help screen for the specified module.';
156 }
157
158 public function getExamples() {
159 return array(
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',
166 );
167 }
168
169 public function getHelpUrls() {
170 return array(
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',
174 );
175 }
176 }