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;
|
2008-02-03 19:29:59 +00:00
|
|
|
case 'namespacealiases' :
|
|
|
|
|
$this->appendNamespaceAliases($p);
|
|
|
|
|
break;
|
2007-06-14 05:18:58 +00:00
|
|
|
case 'interwikimap' :
|
|
|
|
|
$filteriw = isset($params['filteriw']) ? $params['filteriw'] : false;
|
|
|
|
|
$this->appendInterwikiMap($p, $filteriw);
|
2006-09-26 01:44:13 +00:00
|
|
|
break;
|
2007-07-07 04:58:52 +00:00
|
|
|
case 'dbrepllag' :
|
|
|
|
|
$this->appendDbReplLagInfo($p, $params['showalldb']);
|
2007-07-07 04:53:07 +00:00
|
|
|
break;
|
2007-08-09 12:39:41 +00:00
|
|
|
case 'statistics' :
|
|
|
|
|
$this->appendStatistics($p);
|
|
|
|
|
break;
|
2006-09-26 01:44:13 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2007-06-14 05:18:58 +00:00
|
|
|
protected function appendGeneralInfo($property) {
|
2008-03-04 17:29:05 +00:00
|
|
|
global $wgSitename, $wgVersion, $wgCapitalLinks, $wgRightsCode, $wgRightsText, $wgLanguageCode, $IP, $wgEnableWriteAPI;
|
2007-06-14 05:18:58 +00:00
|
|
|
|
|
|
|
|
$data = array ();
|
|
|
|
|
$mainPage = Title :: newFromText(wfMsgForContent('mainpage'));
|
2008-02-24 18:36:16 +00:00
|
|
|
$data['mainpage'] = $mainPage->getPrefixedText();
|
2007-06-14 05:18:58 +00:00
|
|
|
$data['base'] = $mainPage->getFullUrl();
|
|
|
|
|
$data['sitename'] = $wgSitename;
|
|
|
|
|
$data['generator'] = "MediaWiki $wgVersion";
|
2007-10-06 02:30:00 +00:00
|
|
|
|
|
|
|
|
$svn = SpecialVersion::getSvnRevision ( $IP );
|
|
|
|
|
if ( $svn ) $data['rev'] = $svn;
|
|
|
|
|
|
2007-06-14 05:18:58 +00:00
|
|
|
$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 21:44:15 +00:00
|
|
|
$data['lang'] = $wgLanguageCode;
|
2008-03-04 17:29:05 +00:00
|
|
|
|
|
|
|
|
if ( $wgEnableWriteAPI )
|
|
|
|
|
$data['writeapi'] = '';
|
2007-06-14 05:18:58 +00:00
|
|
|
|
|
|
|
|
$this->getResult()->addValue('query', $property, $data);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function appendNamespaces($property) {
|
2008-02-25 22:11:56 +00:00
|
|
|
global $wgContLang, $wgNamespacesWithSubpages;
|
2007-06-14 05:18:58 +00:00
|
|
|
|
|
|
|
|
$data = array ();
|
|
|
|
|
foreach ($wgContLang->getFormattedNamespaces() as $ns => $title) {
|
|
|
|
|
$data[$ns] = array (
|
|
|
|
|
'id' => $ns
|
|
|
|
|
);
|
|
|
|
|
ApiResult :: setContent($data[$ns], $title);
|
2008-02-25 22:11:56 +00:00
|
|
|
if(@$wgNamespacesWithSubpages[$ns])
|
|
|
|
|
$data[$ns]['subpages'] = '';
|
2007-06-14 05:18:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->getResult()->setIndexedTagName($data, 'ns');
|
|
|
|
|
$this->getResult()->addValue('query', $property, $data);
|
|
|
|
|
}
|
|
|
|
|
|
2008-02-03 19:29:59 +00:00
|
|
|
protected function appendNamespaceAliases($property) {
|
|
|
|
|
global $wgNamespaceAliases;
|
|
|
|
|
|
|
|
|
|
$data = array ();
|
|
|
|
|
foreach ($wgNamespaceAliases as $title => $ns) {
|
|
|
|
|
$item = array (
|
|
|
|
|
'id' => $ns
|
|
|
|
|
);
|
|
|
|
|
ApiResult :: setContent($item, strtr($title, '_', ' '));
|
|
|
|
|
$data[] = $item;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->getResult()->setIndexedTagName($data, 'ns');
|
|
|
|
|
$this->getResult()->addValue('query', $property, $data);
|
|
|
|
|
}
|
|
|
|
|
|
2007-06-14 05:18:58 +00:00
|
|
|
protected function appendInterwikiMap($property, $filter) {
|
|
|
|
|
|
2007-07-31 17:53:37 +00:00
|
|
|
$this->resetQueryParams();
|
2007-06-14 05:18:58 +00:00
|
|
|
$this->addTables('interwiki');
|
|
|
|
|
$this->addFields(array('iw_prefix', 'iw_local', 'iw_url'));
|
|
|
|
|
|
2007-08-21 03:57:54 +00:00
|
|
|
if($filter === 'local') {
|
2007-06-14 05:18:58 +00:00
|
|
|
$this->addWhere('iw_local = 1');
|
2007-08-21 03:57:54 +00:00
|
|
|
} elseif($filter === '!local') {
|
2007-06-14 05:18:58 +00:00
|
|
|
$this->addWhere('iw_local = 0');
|
2007-08-21 03:57:54 +00:00
|
|
|
} elseif($filter !== false) {
|
2007-06-14 05:18:58 +00:00
|
|
|
ApiBase :: dieDebug(__METHOD__, "Unknown filter=$filter");
|
2007-08-21 03:57:54 +00:00
|
|
|
}
|
2007-06-14 05:18:58 +00:00
|
|
|
|
|
|
|
|
$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);
|
|
|
|
|
}
|
2007-07-07 04:53:07 +00:00
|
|
|
|
2007-07-07 04:58:52 +00:00
|
|
|
protected function appendDbReplLagInfo($property, $includeAll) {
|
2007-07-10 13:46:22 +00:00
|
|
|
global $wgLoadBalancer, $wgShowHostnames;
|
2007-07-07 04:53:07 +00:00
|
|
|
|
|
|
|
|
$data = array();
|
|
|
|
|
|
|
|
|
|
if ($includeAll) {
|
2007-07-10 13:46:22 +00:00
|
|
|
if (!$wgShowHostnames)
|
|
|
|
|
$this->dieUsage('Cannot view all servers info unless $wgShowHostnames is true', 'includeAllDenied');
|
|
|
|
|
|
2007-07-07 04:53:07 +00:00
|
|
|
global $wgDBservers;
|
|
|
|
|
$lags = $wgLoadBalancer->getLagTimes();
|
|
|
|
|
foreach( $lags as $i => $lag ) {
|
|
|
|
|
$data[] = array (
|
|
|
|
|
'host' => $wgDBservers[$i]['host'],
|
|
|
|
|
'lag' => $lag);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
list( $host, $lag ) = $wgLoadBalancer->getMaxLag();
|
|
|
|
|
$data[] = array (
|
2007-07-10 13:46:22 +00:00
|
|
|
'host' => $wgShowHostnames ? $host : '',
|
2007-07-07 04:53:07 +00:00
|
|
|
'lag' => $lag);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$result = $this->getResult();
|
|
|
|
|
$result->setIndexedTagName($data, 'db');
|
|
|
|
|
$result->addValue('query', $property, $data);
|
|
|
|
|
}
|
2007-06-14 05:18:58 +00:00
|
|
|
|
2007-08-09 12:39:41 +00:00
|
|
|
protected function appendStatistics($property) {
|
|
|
|
|
$data = array ();
|
|
|
|
|
$data['pages'] = intval(SiteStats::pages());
|
|
|
|
|
$data['articles'] = intval(SiteStats::articles());
|
|
|
|
|
$data['views'] = intval(SiteStats::views());
|
|
|
|
|
$data['edits'] = intval(SiteStats::edits());
|
|
|
|
|
$data['images'] = intval(SiteStats::images());
|
|
|
|
|
$data['users'] = intval(SiteStats::users());
|
|
|
|
|
$data['admins'] = intval(SiteStats::admins());
|
|
|
|
|
$data['jobs'] = intval(SiteStats::jobs());
|
|
|
|
|
$this->getResult()->addValue('query', $property, $data);
|
|
|
|
|
}
|
|
|
|
|
|
2008-01-28 19:05:26 +00:00
|
|
|
public 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',
|
2008-02-03 19:29:59 +00:00
|
|
|
'namespacealiases',
|
2007-07-07 04:53:07 +00:00
|
|
|
'interwikimap',
|
2007-07-07 04:58:52 +00:00
|
|
|
'dbrepllag',
|
2007-08-09 12:39:41 +00:00
|
|
|
'statistics',
|
2007-06-14 05:18:58 +00:00
|
|
|
)),
|
|
|
|
|
|
|
|
|
|
'filteriw' => array (
|
|
|
|
|
ApiBase :: PARAM_TYPE => array (
|
|
|
|
|
'local',
|
|
|
|
|
'!local',
|
|
|
|
|
)),
|
2007-07-07 04:53:07 +00:00
|
|
|
|
|
|
|
|
'showalldb' => false,
|
2006-09-26 01:44:13 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2008-01-28 19:05:26 +00:00
|
|
|
public 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)',
|
2008-02-03 19:29:59 +00:00
|
|
|
' "namespacealiases" - List of registered namespace aliases',
|
2007-08-28 15:37:31 +00:00
|
|
|
' "statistics" - Returns site statistics',
|
|
|
|
|
' "interwikimap" - Returns interwiki map (optionally filtered)',
|
|
|
|
|
' "dbrepllag" - Returns database server with the highest replication lag',
|
2007-06-14 05:18:58 +00:00
|
|
|
),
|
|
|
|
|
'filteriw' => 'Return only local or only nonlocal entries of the interwiki map',
|
2007-08-28 15:37:31 +00:00
|
|
|
'showalldb' => 'List all database servers, not just the one lagging the most',
|
2006-09-26 01:44:13 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2008-01-28 19:05:26 +00:00
|
|
|
public 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(
|
2008-02-03 19:29:59 +00:00
|
|
|
'api.php?action=query&meta=siteinfo&siprop=general|namespaces|namespacealiases|statistics',
|
2007-06-14 05:18:58 +00:00
|
|
|
'api.php?action=query&meta=siteinfo&siprop=interwikimap&sifilteriw=local',
|
2007-07-07 04:58:52 +00:00
|
|
|
'api.php?action=query&meta=siteinfo&siprop=dbrepllag&sishowalldb',
|
2007-06-14 05:18:58 +00:00
|
|
|
);
|
2006-09-26 01:44:13 +00:00
|
|
|
}
|
2006-10-01 21:20:55 +00:00
|
|
|
|
|
|
|
|
public function getVersion() {
|
2007-12-06 18:33:18 +00:00
|
|
|
return __CLASS__ . ': $Id$';
|
2006-10-01 21:20:55 +00:00
|
|
|
}
|
2007-10-06 02:30:00 +00:00
|
|
|
}
|