2006-09-26 01:44:13 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Created on Sep 25, 2006
|
|
|
|
|
*
|
|
|
|
|
* API for MediaWiki 1.8+
|
|
|
|
|
*
|
2007-05-20 23:31:44 +00:00
|
|
|
* Copyright (C) 2006 Yuri Astrakhan <Firstname><Lastname>@gmail.com
|
2006-09-26 01:44:13 +00:00
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
if (!defined('MEDIAWIKI')) {
|
|
|
|
|
// Eclipse helper - will be ignored in production
|
2006-10-01 02:02:13 +00:00
|
|
|
require_once ('ApiQueryBase.php');
|
2006-09-26 01:44:13 +00:00
|
|
|
}
|
|
|
|
|
|
2007-04-20 08:55:14 +00:00
|
|
|
/**
|
2007-05-20 23:31:44 +00:00
|
|
|
* A query action to return meta information about the wiki site.
|
|
|
|
|
*
|
2007-04-20 08:55:14 +00:00
|
|
|
* @addtogroup API
|
|
|
|
|
*/
|
2006-09-26 01:44:13 +00:00
|
|
|
class ApiQuerySiteinfo extends ApiQueryBase {
|
|
|
|
|
|
2006-09-26 06:37:26 +00:00
|
|
|
public function __construct($query, $moduleName) {
|
2006-10-03 05:41:55 +00:00
|
|
|
parent :: __construct($query, $moduleName, 'si');
|
2006-09-26 01:44:13 +00:00
|
|
|
}
|
|
|
|
|
|
2006-09-27 05:13:48 +00:00
|
|
|
public function execute() {
|
2006-09-26 01:44:13 +00:00
|
|
|
|
2007-06-14 05:18:58 +00:00
|
|
|
$params = $this->extractRequestParams();
|
2006-09-26 01:44:13 +00:00
|
|
|
|
2007-06-14 05:18:58 +00:00
|
|
|
foreach ($params['prop'] as $p) {
|
|
|
|
|
switch ($p) {
|
|
|
|
|
default :
|
|
|
|
|
ApiBase :: dieDebug(__METHOD__, "Unknown prop=$p");
|
2006-09-26 01:44:13 +00:00
|
|
|
case 'general' :
|
2007-06-14 05:18:58 +00:00
|
|
|
$this->appendGeneralInfo($p);
|
2006-09-26 01:44:13 +00:00
|
|
|
break;
|
|
|
|
|
case 'namespaces' :
|
2007-06-14 05:18:58 +00:00
|
|
|
$this->appendNamespaces($p);
|
|
|
|
|
break;
|
|
|
|
|
case 'interwikimap' :
|
|
|
|
|
$filteriw = isset($params['filteriw']) ? $params['filteriw'] : false;
|
|
|
|
|
$this->appendInterwikiMap($p, $filteriw);
|
2006-09-26 01:44:13 +00:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2007-06-14 05:18:58 +00:00
|
|
|
protected function appendGeneralInfo($property) {
|
2007-06-29 19:00:44 +00:00
|
|
|
global $wgSitename, $wgVersion, $wgCapitalLinks, $wgRightsCode, $wgRightsText, $wgLang;
|
2007-06-14 05:18:58 +00:00
|
|
|
|
|
|
|
|
$data = array ();
|
|
|
|
|
$mainPage = Title :: newFromText(wfMsgForContent('mainpage'));
|
|
|
|
|
$data['mainpage'] = $mainPage->getText();
|
|
|
|
|
$data['base'] = $mainPage->getFullUrl();
|
|
|
|
|
$data['sitename'] = $wgSitename;
|
|
|
|
|
$data['generator'] = "MediaWiki $wgVersion";
|
|
|
|
|
$data['case'] = $wgCapitalLinks ? 'first-letter' : 'case-sensitive'; // 'case-insensitive' option is reserved for future
|
|
|
|
|
if (isset($wgRightsCode))
|
|
|
|
|
$data['rightscode'] = $wgRightsCode;
|
|
|
|
|
$data['rights'] = $wgRightsText;
|
2007-06-29 19:00:44 +00:00
|
|
|
$data['lang'] = $wgLang->getCode();
|
2007-06-14 05:18:58 +00:00
|
|
|
|
|
|
|
|
$this->getResult()->addValue('query', $property, $data);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function appendNamespaces($property) {
|
|
|
|
|
global $wgContLang;
|
|
|
|
|
|
|
|
|
|
$data = array ();
|
|
|
|
|
foreach ($wgContLang->getFormattedNamespaces() as $ns => $title) {
|
|
|
|
|
$data[$ns] = array (
|
|
|
|
|
'id' => $ns
|
|
|
|
|
);
|
|
|
|
|
ApiResult :: setContent($data[$ns], $title);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->getResult()->setIndexedTagName($data, 'ns');
|
|
|
|
|
$this->getResult()->addValue('query', $property, $data);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function appendInterwikiMap($property, $filter) {
|
|
|
|
|
|
|
|
|
|
$this->addTables('interwiki');
|
|
|
|
|
$this->addFields(array('iw_prefix', 'iw_local', 'iw_url'));
|
|
|
|
|
|
|
|
|
|
if($filter === 'local')
|
|
|
|
|
$this->addWhere('iw_local = 1');
|
|
|
|
|
else if($filter === '!local')
|
|
|
|
|
$this->addWhere('iw_local = 0');
|
|
|
|
|
else if($filter !== false)
|
|
|
|
|
ApiBase :: dieDebug(__METHOD__, "Unknown filter=$filter");
|
|
|
|
|
|
|
|
|
|
$this->addOption('ORDER BY', 'iw_prefix');
|
|
|
|
|
|
|
|
|
|
$db = $this->getDB();
|
|
|
|
|
$res = $this->select(__METHOD__);
|
|
|
|
|
|
|
|
|
|
$data = array();
|
|
|
|
|
while($row = $db->fetchObject($res))
|
|
|
|
|
{
|
|
|
|
|
$val['prefix'] = $row->iw_prefix;
|
|
|
|
|
if ($row->iw_local == '1')
|
|
|
|
|
$val['local'] = '';
|
|
|
|
|
// $val['trans'] = intval($row->iw_trans); // should this be exposed?
|
|
|
|
|
$val['url'] = $row->iw_url;
|
|
|
|
|
|
|
|
|
|
$data[] = $val;
|
|
|
|
|
}
|
|
|
|
|
$db->freeResult($res);
|
|
|
|
|
|
|
|
|
|
$this->getResult()->setIndexedTagName($data, 'iw');
|
|
|
|
|
$this->getResult()->addValue('query', $property, $data);
|
|
|
|
|
}
|
|
|
|
|
|
2006-09-27 05:13:48 +00:00
|
|
|
protected function getAllowedParams() {
|
2006-09-26 01:44:13 +00:00
|
|
|
return array (
|
2007-06-14 05:18:58 +00:00
|
|
|
|
2006-10-03 05:41:55 +00:00
|
|
|
'prop' => array (
|
2006-10-01 20:17:16 +00:00
|
|
|
ApiBase :: PARAM_DFLT => 'general',
|
|
|
|
|
ApiBase :: PARAM_ISMULTI => true,
|
|
|
|
|
ApiBase :: PARAM_TYPE => array (
|
2006-09-26 01:44:13 +00:00
|
|
|
'general',
|
2007-06-14 05:18:58 +00:00
|
|
|
'namespaces',
|
|
|
|
|
'interwikimap'
|
|
|
|
|
)),
|
|
|
|
|
|
|
|
|
|
'filteriw' => array (
|
|
|
|
|
ApiBase :: PARAM_TYPE => array (
|
|
|
|
|
'local',
|
|
|
|
|
'!local',
|
|
|
|
|
)),
|
2006-09-26 01:44:13 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2006-09-27 05:13:48 +00:00
|
|
|
protected function getParamDescription() {
|
2006-09-26 01:44:13 +00:00
|
|
|
return array (
|
2006-10-03 05:41:55 +00:00
|
|
|
'prop' => array (
|
2006-09-26 01:44:13 +00:00
|
|
|
'Which sysinfo properties to get:',
|
2007-06-14 05:18:58 +00:00
|
|
|
' "general" - Overall system information',
|
|
|
|
|
' "namespaces" - List of registered namespaces (localized)',
|
|
|
|
|
' "interwikimap" - Return interwiki map (optionally filtered)'
|
|
|
|
|
),
|
|
|
|
|
'filteriw' => 'Return only local or only nonlocal entries of the interwiki map',
|
2006-09-26 01:44:13 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2006-09-27 05:13:48 +00:00
|
|
|
protected function getDescription() {
|
2006-09-26 01:44:13 +00:00
|
|
|
return 'Return general information about the site.';
|
|
|
|
|
}
|
|
|
|
|
|
2006-09-27 05:13:48 +00:00
|
|
|
protected function getExamples() {
|
2007-06-14 05:18:58 +00:00
|
|
|
return array(
|
|
|
|
|
'api.php?action=query&meta=siteinfo&siprop=general|namespaces',
|
|
|
|
|
'api.php?action=query&meta=siteinfo&siprop=interwikimap&sifilteriw=local',
|
|
|
|
|
);
|
2006-09-26 01:44:13 +00:00
|
|
|
}
|
2006-10-01 21:20:55 +00:00
|
|
|
|
|
|
|
|
public function getVersion() {
|
|
|
|
|
return __CLASS__ . ': $Id$';
|
|
|
|
|
}
|
2006-09-26 01:44:13 +00:00
|
|
|
}
|
2007-06-29 01:19:14 +00:00
|
|
|
|