4 * Created on Sep 25, 2006
6 * API for MediaWiki 1.8+
8 * Copyright (C) 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 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 * http://www.gnu.org/copyleft/gpl.html
26 if (!defined('MEDIAWIKI')) {
27 // Eclipse helper - will be ignored in production
28 require_once ('ApiQueryBase.php');
32 * A query action to return meta information about the wiki site.
36 class ApiQuerySiteinfo
extends ApiQueryBase
{
38 public function __construct($query, $moduleName) {
39 parent
:: __construct($query, $moduleName, 'si');
42 public function execute() {
44 $params = $this->extractRequestParams();
46 foreach ($params['prop'] as $p) {
49 ApiBase
:: dieDebug(__METHOD__
, "Unknown prop=$p");
51 $this->appendGeneralInfo($p);
54 $this->appendNamespaces($p);
57 $filteriw = isset($params['filteriw']) ?
$params['filteriw'] : false;
58 $this->appendInterwikiMap($p, $filteriw);
64 protected function appendGeneralInfo($property) {
65 global $wgSitename, $wgVersion, $wgCapitalLinks, $wgRightsCode, $wgRightsText, $wgLanguageCode;
68 $mainPage = Title
:: newFromText(wfMsgForContent('mainpage'));
69 $data['mainpage'] = $mainPage->getText();
70 $data['base'] = $mainPage->getFullUrl();
71 $data['sitename'] = $wgSitename;
72 $data['generator'] = "MediaWiki $wgVersion";
73 $data['case'] = $wgCapitalLinks ?
'first-letter' : 'case-sensitive'; // 'case-insensitive' option is reserved for future
74 if (isset($wgRightsCode))
75 $data['rightscode'] = $wgRightsCode;
76 $data['rights'] = $wgRightsText;
77 $data['lang'] = $wgLanguageCode;
79 $this->getResult()->addValue('query', $property, $data);
82 protected function appendNamespaces($property) {
86 foreach ($wgContLang->getFormattedNamespaces() as $ns => $title) {
90 ApiResult
:: setContent($data[$ns], $title);
93 $this->getResult()->setIndexedTagName($data, 'ns');
94 $this->getResult()->addValue('query', $property, $data);
97 protected function appendInterwikiMap($property, $filter) {
99 $this->addTables('interwiki');
100 $this->addFields(array('iw_prefix', 'iw_local', 'iw_url'));
102 if($filter === 'local')
103 $this->addWhere('iw_local = 1');
104 else if($filter === '!local')
105 $this->addWhere('iw_local = 0');
106 else if($filter !== false)
107 ApiBase
:: dieDebug(__METHOD__
, "Unknown filter=$filter");
109 $this->addOption('ORDER BY', 'iw_prefix');
111 $db = $this->getDB();
112 $res = $this->select(__METHOD__
);
115 while($row = $db->fetchObject($res))
117 $val['prefix'] = $row->iw_prefix
;
118 if ($row->iw_local
== '1')
120 // $val['trans'] = intval($row->iw_trans); // should this be exposed?
121 $val['url'] = $row->iw_url
;
125 $db->freeResult($res);
127 $this->getResult()->setIndexedTagName($data, 'iw');
128 $this->getResult()->addValue('query', $property, $data);
131 protected function getAllowedParams() {
135 ApiBase
:: PARAM_DFLT
=> 'general',
136 ApiBase
:: PARAM_ISMULTI
=> true,
137 ApiBase
:: PARAM_TYPE
=> array (
143 'filteriw' => array (
144 ApiBase
:: PARAM_TYPE
=> array (
151 protected function getParamDescription() {
154 'Which sysinfo properties to get:',
155 ' "general" - Overall system information',
156 ' "namespaces" - List of registered namespaces (localized)',
157 ' "interwikimap" - Return interwiki map (optionally filtered)'
159 'filteriw' => 'Return only local or only nonlocal entries of the interwiki map',
163 protected function getDescription() {
164 return 'Return general information about the site.';
167 protected function getExamples() {
169 'api.php?action=query&meta=siteinfo&siprop=general|namespaces',
170 'api.php?action=query&meta=siteinfo&siprop=interwikimap&sifilteriw=local',
174 public function getVersion() {
175 return __CLASS__
. ': $Id$';