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