Removed more functions marked for removal in 1.19: wfParseCIDR(), wfRFC822Phrase...
[mediawiki.git] / includes / api / ApiHelp.php
blobc5170c4fa6b8ea9bdaebc5c6f0e006faf95e3df7
1 <?php
2 /**
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 /**
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
101 private function buildModuleHelp( $module, $type ) {
102 $msg = ApiMain::makeHelpMsgHeader( $module, $type );
104 $msg2 = $module->makeHelpMsg();
105 if ( $msg2 !== false ) {
106 $msg .= $msg2;
109 return $msg;
112 public function shouldCheckMaxlag() {
113 return false;
116 public function isReadMode() {
117 return false;
120 public function getAllowedParams() {
121 return array(
122 'modules' => array(
123 ApiBase::PARAM_ISMULTI => true
125 'querymodules' => array(
126 ApiBase::PARAM_ISMULTI => true
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)',
138 public function getDescription() {
139 return 'Display this help screen. Or the help screen for the specified module';
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',
157 public function getVersion() {
158 return __CLASS__ . ': $Id$';