API: documentation and cleanup.
[lhc/web/wiklou.git] / includes / api / ApiQuerySiteinfo.php
1 <?php
2
3 /*
4 * Created on Sep 25, 2006
5 *
6 * API for MediaWiki 1.8+
7 *
8 * Copyright (C) 2006 Yuri Astrakhan <Firstname><Lastname>@gmail.com
9 *
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.
14 *
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.
19 *
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 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 * http://www.gnu.org/copyleft/gpl.html
24 */
25
26 if (!defined('MEDIAWIKI')) {
27 // Eclipse helper - will be ignored in production
28 require_once ('ApiQueryBase.php');
29 }
30
31 /**
32 * A query action to return meta information about the wiki site.
33 *
34 * @addtogroup API
35 */
36 class ApiQuerySiteinfo extends ApiQueryBase {
37
38 public function __construct($query, $moduleName) {
39 parent :: __construct($query, $moduleName, 'si');
40 }
41
42 public function execute() {
43 $prop = null;
44 extract($this->extractRequestParams());
45
46 foreach ($prop as $p) {
47 switch ($p) {
48
49 case 'general' :
50
51 global $wgSitename, $wgVersion, $wgCapitalLinks, $wgRightsCode, $wgRightsText;
52 $data = array ();
53 $mainPage = Title :: newFromText(wfMsgForContent('mainpage'));
54 $data['mainpage'] = $mainPage->getText();
55 $data['base'] = $mainPage->getFullUrl();
56 $data['sitename'] = $wgSitename;
57 $data['generator'] = "MediaWiki $wgVersion";
58 $data['case'] = $wgCapitalLinks ? 'first-letter' : 'case-sensitive'; // 'case-insensitive' option is reserved for future
59 if (isset($wgRightsCode))
60 $data['rightscode'] = $wgRightsCode;
61 $data['rights'] = $wgRightsText;
62 $this->getResult()->addValue('query', $p, $data);
63 break;
64
65 case 'namespaces' :
66
67 global $wgContLang;
68 $data = array ();
69 foreach ($wgContLang->getFormattedNamespaces() as $ns => $title) {
70 $data[$ns] = array (
71 'id' => $ns
72 );
73 ApiResult :: setContent($data[$ns], $title);
74 }
75 $this->getResult()->setIndexedTagName($data, 'ns');
76 $this->getResult()->addValue('query', $p, $data);
77 break;
78
79 default :
80 ApiBase :: dieDebug(__METHOD__, "Unknown prop=$p");
81 }
82 }
83 }
84
85 protected function getAllowedParams() {
86 return array (
87 'prop' => array (
88 ApiBase :: PARAM_DFLT => 'general',
89 ApiBase :: PARAM_ISMULTI => true,
90 ApiBase :: PARAM_TYPE => array (
91 'general',
92 'namespaces'
93 )
94 )
95 );
96 }
97
98 protected function getParamDescription() {
99 return array (
100 'prop' => array (
101 'Which sysinfo properties to get:',
102 ' "general" - Overall system information',
103 ' "namespaces" - List of registered namespaces (localized)'
104 )
105 );
106 }
107
108 protected function getDescription() {
109 return 'Return general information about the site.';
110 }
111
112 protected function getExamples() {
113 return 'api.php?action=query&meta=siteinfo&siprop=general|namespaces';
114 }
115
116 public function getVersion() {
117 return __CLASS__ . ': $Id$';
118 }
119 }
120 ?>