4 * Created on Sep 6, 2006
6 * API for MediaWiki 1.8+
8 * Copyright © 2006 Yuri Astrakhan <Firstname><Lastname>@gmail.com
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.
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.
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
26 if ( !defined( 'MEDIAWIKI' ) ) {
27 // Eclipse helper - will be ignored in production
28 require_once( 'ApiBase.php' );
32 * This is a simple class to handle action=help
36 class ApiHelp
extends ApiBase
{
38 public function __construct( $main, $action ) {
39 parent
::__construct( $main, $action );
43 * Module for displaying help
45 public function execute() {
47 $params = $this->extractRequestParams();
49 if ( !isset( $params['modules'] ) && !isset( $params['querymodules'] ) ) {
50 $this->dieUsage( '', 'help' );
53 $this->getMain()->setHelp();
55 $result = $this->getResult();
56 $queryObj = new ApiQuery( $this->getMain(), 'query' );
58 if ( is_array( $params['modules'] ) ) {
59 $modArr = $this->getMain()->getModules();
61 foreach ( $params['modules'] as $m ) {
62 if ( !isset( $modArr[$m] ) ) {
63 $r[] = array( 'name' => $m, 'missing' => '' );
66 $module = new $modArr[$m]( $this->getMain(), $m );
68 $r[] = $this->buildModuleHelp( $module, 'action' );
72 if ( is_array( $params['querymodules'] ) ) {
73 $qmodArr = $queryObj->getModules();
75 foreach ( $params['querymodules'] as $qm ) {
76 if ( !isset( $qmodArr[$qm] ) ) {
77 $r[] = array( 'name' => $qm, 'missing' => '' );
80 $module = new $qmodArr[$qm]( $this, $qm );
81 $type = $queryObj->getModuleType( $qm );
83 if ( $type === null ) {
84 $r[] = array( 'name' => $qm, 'missing' => '' );
88 $r[] = $this->buildModuleHelp( $module, $type );
91 $result->setIndexedTagName( $r, 'module' );
92 $result->addValue( null, $this->getModuleName(), $r );
95 private function buildModuleHelp( $module, $type ) {
96 $msg = ApiMain
::makeHelpMsgHeader( $module, $type );
98 $msg2 = $module->makeHelpMsg();
99 if ( $msg2 !== false ) {
106 public function shouldCheckMaxlag() {
110 public function isReadMode() {
114 public function getAllowedParams() {
117 ApiBase
::PARAM_ISMULTI
=> true
119 'querymodules' => array(
120 ApiBase
::PARAM_ISMULTI
=> true
125 public function getParamDescription() {
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)',
132 public function getDescription() {
133 return 'Display this help screen. Or the help screen for the specified module';
136 protected function getExamples() {
139 ' api.php?action=help',
141 ' api.php?action=help&modules=protect',
142 'Query modules help page:',
143 ' api.php?action=help&querymodules=categorymembers',
147 public function getVersion() {
148 return __CLASS__
. ': $Id$';