Improve the shell cgroup feature
[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
47 $result = $this->getResult();
48 $queryObj = new ApiQuery( $this->getMain(), 'query' );
49 $r = array();
50 if ( is_array( $params['modules'] ) ) {
51 $modArr = $this->getMain()->getModules();
52
53 foreach ( $params['modules'] as $m ) {
54 if ( !isset( $modArr[$m] ) ) {
55 $r[] = array( 'name' => $m, 'missing' => '' );
56 continue;
57 }
58 $module = new $modArr[$m]( $this->getMain(), $m );
59
60 $r[] = $this->buildModuleHelp( $module, 'action' );
61 }
62 }
63
64 if ( is_array( $params['querymodules'] ) ) {
65 $qmodArr = $queryObj->getModules();
66
67 foreach ( $params['querymodules'] as $qm ) {
68 if ( !isset( $qmodArr[$qm] ) ) {
69 $r[] = array( 'name' => $qm, 'missing' => '' );
70 continue;
71 }
72 $module = new $qmodArr[$qm]( $this, $qm );
73 $type = $queryObj->getModuleType( $qm );
74
75 if ( $type === null ) {
76 $r[] = array( 'name' => $qm, 'missing' => '' );
77 continue;
78 }
79
80 $r[] = $this->buildModuleHelp( $module, $type );
81 }
82 }
83 $result->setIndexedTagName( $r, 'module' );
84 $result->addValue( null, $this->getModuleName(), $r );
85 }
86
87 /**
88 * @param $module ApiBase
89 * @param $type String What type of request is this? e.g. action, query, list, prop, meta, format
90 * @return string
91 */
92 private function buildModuleHelp( $module, $type ) {
93 $msg = ApiMain::makeHelpMsgHeader( $module, $type );
94
95 $msg2 = $module->makeHelpMsg();
96 if ( $msg2 !== false ) {
97 $msg .= $msg2;
98 }
99
100 return $msg;
101 }
102
103 public function shouldCheckMaxlag() {
104 return false;
105 }
106
107 public function isReadMode() {
108 return false;
109 }
110
111 public function getAllowedParams() {
112 return array(
113 'modules' => array(
114 ApiBase::PARAM_ISMULTI => true
115 ),
116 'querymodules' => array(
117 ApiBase::PARAM_ISMULTI => true
118 ),
119 );
120 }
121
122 public function getParamDescription() {
123 return array(
124 'modules' => 'List of module names (value of the action= parameter)',
125 'querymodules' => 'List of query module names (value of prop=, meta= or list= parameter)',
126 );
127 }
128
129 public function getDescription() {
130 return 'Display this help screen. Or the help screen for the specified module';
131 }
132
133 public function getExamples() {
134 return array(
135 'api.php?action=help' => 'Whole help page',
136 'api.php?action=help&modules=protect' => 'Module (action) help page',
137 'api.php?action=help&querymodules=categorymembers' => 'Query (list) modules help page',
138 'api.php?action=help&querymodules=info' => 'Query (prop) modules help page',
139 'api.php?action=help&querymodules=siteinfo' => 'Query (meta) modules help page',
140 );
141 }
142
143 public function getHelpUrls() {
144 return array(
145 'https://www.mediawiki.org/wiki/API:Main_page',
146 'https://www.mediawiki.org/wiki/API:FAQ',
147 'https://www.mediawiki.org/wiki/API:Quick_start_guide',
148 );
149 }
150 }