Follow-up r69203: remove str_replace( '_', ' ', $query ); was only needed for Special...
[lhc/web/wiklou.git] / includes / api / ApiHelp.php
1 <?php
2
3 /**
4 * Created on Sep 6, 2006
5 *
6 * API for MediaWiki 1.8+
7 *
8 * Copyright © 2006 Yuri Astrakhan <Firstname><Lastname>@gmail.com
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License along
21 * with this program; if not, write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 * http://www.gnu.org/copyleft/gpl.html
24 */
25
26 if ( !defined( 'MEDIAWIKI' ) ) {
27 // Eclipse helper - will be ignored in production
28 require_once( 'ApiBase.php' );
29 }
30
31 /**
32 * This is a simple class to handle action=help
33 *
34 * @ingroup API
35 */
36 class ApiHelp extends ApiBase {
37
38 public function __construct( $main, $action ) {
39 parent::__construct( $main, $action );
40 }
41
42 /**
43 * Module for displaying help
44 */
45 public function execute() {
46 // Get parameters
47 $params = $this->extractRequestParams();
48
49 if ( !isset( $params['modules'] ) && !isset( $params['querymodules'] ) ) {
50 $this->dieUsage( '', 'help' );
51 }
52
53 $this->getMain()->setHelp();
54
55 $result = $this->getResult();
56 $queryObj = new ApiQuery( $this->getMain(), 'query' );
57 $r = array();
58 if ( is_array( $params['modules'] ) ) {
59 $modArr = $this->getMain()->getModules();
60
61 foreach ( $params['modules'] as $m ) {
62 if ( !isset( $modArr[$m] ) ) {
63 $r[] = array( 'name' => $m, 'missing' => '' );
64 continue;
65 }
66 $module = new $modArr[$m]( $this->getMain(), $m );
67
68 $r[] = $this->buildModuleHelp( $module, 'action' );
69 }
70 }
71
72 if ( is_array( $params['querymodules'] ) ) {
73 $qmodArr = $queryObj->getModules();
74
75 foreach ( $params['querymodules'] as $qm ) {
76 if ( !isset( $qmodArr[$qm] ) ) {
77 $r[] = array( 'name' => $qm, 'missing' => '' );
78 continue;
79 }
80 $module = new $qmodArr[$qm]( $this, $qm );
81 $type = $queryObj->getModuleType( $qm );
82
83 if ( $type === null ) {
84 $r[] = array( 'name' => $qm, 'missing' => '' );
85 continue;
86 }
87
88 $r[] = $this->buildModuleHelp( $module, $type );
89 }
90 }
91 $result->setIndexedTagName( $r, 'module' );
92 $result->addValue( null, $this->getModuleName(), $r );
93 }
94
95 private function buildModuleHelp( $module, $type ) {
96 $msg = ApiMain::makeHelpMsgHeader( $module, $type );
97
98 $msg2 = $module->makeHelpMsg();
99 if ( $msg2 !== false ) {
100 $msg .= $msg2;
101 }
102
103 return $msg;
104 }
105
106 public function shouldCheckMaxlag() {
107 return false;
108 }
109
110 public function isReadMode() {
111 return false;
112 }
113
114 public function getAllowedParams() {
115 return array(
116 'modules' => array(
117 ApiBase::PARAM_ISMULTI => true
118 ),
119 'querymodules' => array(
120 ApiBase::PARAM_ISMULTI => true
121 ),
122 );
123 }
124
125 public function getParamDescription() {
126 return array(
127 'modules' => 'List of module names (value of the action= parameter)',
128 'querymodules' => 'List of query module names (value of prop=, meta= or list= parameter)',
129 );
130 }
131
132 public function getDescription() {
133 return 'Display this help screen. Or the help screen for the specified module';
134 }
135
136 protected function getExamples() {
137 return array(
138 'Whole help page:',
139 ' api.php?action=help',
140 'Module help page:',
141 ' api.php?action=help&modules=protect',
142 'Query modules help page:',
143 ' api.php?action=help&querymodules=categorymembers',
144 );
145 }
146
147 public function getVersion() {
148 return __CLASS__ . ': $Id$';
149 }
150 }