Spaces to tab, add a couple of braces
[mediawiki.git] / includes / api / ApiHelp.php
blobcb896e5f2df1f32308589a4d0306cef155427cc7
1 <?php
2 /**
3 * API for MediaWiki 1.8+
5 * Created on Sep 6, 2006
7 * Copyright © 2006 Yuri Astrakhan <Firstname><Lastname>@gmail.com
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.
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.
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
24 * @file
27 if ( !defined( 'MEDIAWIKI' ) ) {
28 // Eclipse helper - will be ignored in production
29 require_once( 'ApiBase.php' );
32 /**
33 * This is a simple class to handle action=help
35 * @ingroup API
37 class ApiHelp extends ApiBase {
39 public function __construct( $main, $action ) {
40 parent::__construct( $main, $action );
43 /**
44 * Module for displaying help
46 public function execute() {
47 // Get parameters
48 $params = $this->extractRequestParams();
50 if ( !isset( $params['modules'] ) && !isset( $params['querymodules'] ) ) {
51 $this->dieUsage( '', 'help' );
54 $this->getMain()->setHelp();
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();
62 foreach ( $params['modules'] as $m ) {
63 if ( !isset( $modArr[$m] ) ) {
64 $r[] = array( 'name' => $m, 'missing' => '' );
65 continue;
67 $module = new $modArr[$m]( $this->getMain(), $m );
69 $r[] = $this->buildModuleHelp( $module, 'action' );
73 if ( is_array( $params['querymodules'] ) ) {
74 $qmodArr = $queryObj->getModules();
76 foreach ( $params['querymodules'] as $qm ) {
77 if ( !isset( $qmodArr[$qm] ) ) {
78 $r[] = array( 'name' => $qm, 'missing' => '' );
79 continue;
81 $module = new $qmodArr[$qm]( $this, $qm );
82 $type = $queryObj->getModuleType( $qm );
84 if ( $type === null ) {
85 $r[] = array( 'name' => $qm, 'missing' => '' );
86 continue;
89 $r[] = $this->buildModuleHelp( $module, $type );
92 $result->setIndexedTagName( $r, 'module' );
93 $result->addValue( null, $this->getModuleName(), $r );
96 private function buildModuleHelp( $module, $type ) {
97 $msg = ApiMain::makeHelpMsgHeader( $module, $type );
99 $msg2 = $module->makeHelpMsg();
100 if ( $msg2 !== false ) {
101 $msg .= $msg2;
104 return $msg;
107 public function shouldCheckMaxlag() {
108 return false;
111 public function isReadMode() {
112 return false;
115 public function getAllowedParams() {
116 return array(
117 'modules' => array(
118 ApiBase::PARAM_ISMULTI => true
120 'querymodules' => array(
121 ApiBase::PARAM_ISMULTI => true
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)',
133 public function getDescription() {
134 return 'Display this help screen. Or the help screen for the specified module';
137 protected function getExamples() {
138 return array(
139 'Whole help page:',
140 ' api.php?action=help',
141 'Module (action) help page:',
142 ' api.php?action=help&modules=protect',
143 'Query (list) modules help page:',
144 ' api.php?action=help&querymodules=categorymembers',
145 'Query (prop) modules help page:',
146 ' api.php?action=help&querymodules=info',
147 'Query (meta) modules help page:',
148 ' api.php?action=help&querymodules=siteinfo',
152 public function getVersion() {
153 return __CLASS__ . ': $Id$';