mwdocgen: support multiple --file values
[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 /**
35 * Module for displaying help
36 */
37 public function execute() {
38 // Get parameters
39 $params = $this->extractRequestParams();
40
41 if ( !isset( $params['modules'] ) && !isset( $params['querymodules'] ) ) {
42 $this->dieUsage( '', 'help' );
43 }
44
45 $this->getMain()->setHelp();
46 $result = $this->getResult();
47
48 if ( is_array( $params['modules'] ) ) {
49 $modules = $params['modules'];
50 } else {
51 $modules = array();
52 }
53
54 if ( is_array( $params['querymodules'] ) ) {
55 $queryModules = $params['querymodules'];
56 foreach ( $queryModules as $m ) {
57 $modules[] = 'query+' . $m;
58 }
59 } else {
60 $queryModules = array();
61 }
62
63 $r = 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 );
70 }
71 $module = $this->getMain();
72 for ( $i = 0; $i < count( $subNames ); $i++ ) {
73 $subs = $module->getModuleManager();
74 if ( $subs === null ) {
75 $module = null;
76 } else {
77 $module = $subs->getModule( $subNames[$i] );
78 }
79 if ( $module === null ) {
80 if ( count( $subNames ) === 2
81 && $i === 1
82 && $subNames[0] === 'query'
83 && in_array( $subNames[1], $queryModules )
84 ) {
85 // Legacy: This is one of the renamed 'querymodule=...' parameters,
86 // do not use '+' notation in the output, use submodule's name instead.
87 $name = $subNames[1];
88 } else {
89 $name = implode( '+', array_slice( $subNames, 0, $i + 1 ) );
90 }
91 $r[] = array( 'name' => $name, 'missing' => '' );
92 break;
93 } else {
94 $type = $subs->getModuleGroup( $subNames[$i] );
95 }
96 }
97 if ( $module !== null ) {
98 $r[] = $this->buildModuleHelp( $module, $type );
99 }
100 }
101
102 $result->setIndexedTagName( $r, 'module' );
103 $result->addValue( null, $this->getModuleName(), $r );
104 }
105
106 /**
107 * @param $module ApiBase
108 * @param $type String What type of request is this? e.g. action, query, list, prop, meta, format
109 * @return string
110 */
111 private function buildModuleHelp( $module, $type ) {
112 $msg = ApiMain::makeHelpMsgHeader( $module, $type );
113
114 $msg2 = $module->makeHelpMsg();
115 if ( $msg2 !== false ) {
116 $msg .= $msg2;
117 }
118
119 return $msg;
120 }
121
122 public function shouldCheckMaxlag() {
123 return false;
124 }
125
126 public function isReadMode() {
127 return false;
128 }
129
130 public function getAllowedParams() {
131 return array(
132 'modules' => array(
133 ApiBase::PARAM_ISMULTI => true
134 ),
135 'querymodules' => array(
136 ApiBase::PARAM_ISMULTI => true,
137 ApiBase::PARAM_DEPRECATED => true
138 ),
139 );
140 }
141
142 public function getParamDescription() {
143 return array(
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)',
146 );
147 }
148
149 public function getDescription() {
150 return 'Display this help screen. Or the help screen for the specified module';
151 }
152
153 public function getExamples() {
154 return array(
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',
159 );
160 }
161
162 public function getHelpUrls() {
163 return array(
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',
167 );
168 }
169 }