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
28 * This is a simple class to handle action=help
32 class ApiHelp
extends ApiBase
{
35 * Module for displaying help
37 public function execute() {
39 $params = $this->extractRequestParams();
41 if ( !isset( $params['modules'] ) && !isset( $params['querymodules'] ) ) {
42 $this->dieUsage( '', 'help' );
45 $this->getMain()->setHelp();
47 $result = $this->getResult();
48 $queryObj = new ApiQuery( $this->getMain(), 'query' );
50 if ( is_array( $params['modules'] ) ) {
51 $modArr = $this->getMain()->getModules();
53 foreach ( $params['modules'] as $m ) {
54 if ( !isset( $modArr[$m] ) ) {
55 $r[] = array( 'name' => $m, 'missing' => '' );
58 $module = new $modArr[$m]( $this->getMain(), $m );
60 $r[] = $this->buildModuleHelp( $module, 'action' );
64 if ( is_array( $params['querymodules'] ) ) {
65 $qmodArr = $queryObj->getModules();
67 foreach ( $params['querymodules'] as $qm ) {
68 if ( !isset( $qmodArr[$qm] ) ) {
69 $r[] = array( 'name' => $qm, 'missing' => '' );
72 $module = new $qmodArr[$qm]( $this, $qm );
73 $type = $queryObj->getModuleType( $qm );
75 if ( $type === null ) {
76 $r[] = array( 'name' => $qm, 'missing' => '' );
80 $r[] = $this->buildModuleHelp( $module, $type );
83 $result->setIndexedTagName( $r, 'module' );
84 $result->addValue( null, $this->getModuleName(), $r );
88 * @param $module ApiBase
89 * @param $type String What type of request is this? e.g. action, query, list, prop, meta, format
92 private function buildModuleHelp( $module, $type ) {
93 $msg = ApiMain
::makeHelpMsgHeader( $module, $type );
95 $msg2 = $module->makeHelpMsg();
96 if ( $msg2 !== false ) {
103 public function shouldCheckMaxlag() {
107 public function isReadMode() {
111 public function getAllowedParams() {
114 ApiBase
::PARAM_ISMULTI
=> true
116 'querymodules' => array(
117 ApiBase
::PARAM_ISMULTI
=> true
122 public function getParamDescription() {
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)',
129 public function getDescription() {
130 return 'Display this help screen. Or the help screen for the specified module';
133 public function getExamples() {
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',
143 public function getHelpUrls() {
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',