]> scripts.mit.edu Git - autoinstalls/mediawiki.git/blob - includes/api/ApiHelp.php
MediaWiki 1.17.4
[autoinstalls/mediawiki.git] / includes / api / ApiHelp.php
1 <?php
2 /**
3  * API for MediaWiki 1.8+
4  *
5  * Created on Sep 6, 2006
6  *
7  * Copyright © 2006 Yuri Astrakhan <Firstname><Lastname>@gmail.com
8  *
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.
13  *
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.
18  *
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
23  *
24  * @file
25  */
26
27 if ( !defined( 'MEDIAWIKI' ) ) {
28         // Eclipse helper - will be ignored in production
29         require_once( 'ApiBase.php' );
30 }
31
32 /**
33  * This is a simple class to handle action=help
34  *
35  * @ingroup API
36  */
37 class ApiHelp extends ApiBase {
38
39         public function __construct( $main, $action ) {
40                 parent::__construct( $main, $action );
41         }
42
43         /**
44          * Module for displaying help
45          */
46         public function execute() {
47                 // Get parameters
48                 $params = $this->extractRequestParams();
49
50                 if ( !isset( $params['modules'] ) && !isset( $params['querymodules'] ) ) {
51                         $this->dieUsage( '', 'help' );
52                 }
53
54                 $this->getMain()->setHelp();
55
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();
61
62                         foreach ( $params['modules'] as $m ) {
63                                 if ( !isset( $modArr[$m] ) ) {
64                                         $r[] = array( 'name' => $m, 'missing' => '' );
65                                         continue;
66                                 }
67                                 $module = new $modArr[$m]( $this->getMain(), $m );
68
69                                 $r[] = $this->buildModuleHelp( $module, 'action' );
70                         }
71                 }
72
73                 if ( is_array( $params['querymodules'] ) ) {
74                         $qmodArr = $queryObj->getModules();
75
76                         foreach ( $params['querymodules'] as $qm ) {
77                                 if ( !isset( $qmodArr[$qm] ) ) {
78                                         $r[] = array( 'name' => $qm, 'missing' => '' );
79                                         continue;
80                                 }
81                                 $module = new $qmodArr[$qm]( $this, $qm );
82                                 $type = $queryObj->getModuleType( $qm );
83
84                                 if ( $type === null ) {
85                                         $r[] = array( 'name' => $qm, 'missing' => '' );
86                                         continue;
87                                 }
88
89                                 $r[] = $this->buildModuleHelp( $module, $type );
90                         }
91                 }
92                 $result->setIndexedTagName( $r, 'module' );
93                 $result->addValue( null, $this->getModuleName(), $r );
94         }
95
96         private function buildModuleHelp( $module, $type ) {
97                 $msg = ApiMain::makeHelpMsgHeader( $module, $type );
98
99                 $msg2 = $module->makeHelpMsg();
100                 if ( $msg2 !== false ) {
101                         $msg .= $msg2;
102                 }
103
104                 return $msg;
105         }
106
107         public function shouldCheckMaxlag() {
108                 return false;
109         }
110
111         public function isReadMode() {
112                 return false;
113         }
114
115         public function getAllowedParams() {
116                 return array(
117                         'modules' => array(
118                                 ApiBase::PARAM_ISMULTI => true
119                         ),
120                         'querymodules' => array(
121                                 ApiBase::PARAM_ISMULTI => true
122                         ),
123                 );
124         }
125
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)',
130                 );
131         }
132
133         public function getDescription() {
134                 return 'Display this help screen. Or the help screen for the specified module';
135         }
136
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',
149                 );
150         }
151
152         public function getVersion() {
153                 return __CLASS__ . ': $Id$';
154         }
155 }