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