* $wgDebugTidy feature
[lhc/web/wiklou.git] / includes / api / ApiQuerySiteinfo.php
index a05ea12..1bd34cd 100644 (file)
@@ -57,15 +57,18 @@ class ApiQuerySiteinfo extends ApiQueryBase {
                                        $filteriw = isset($params['filteriw']) ? $params['filteriw'] : false; 
                                        $this->appendInterwikiMap($p, $filteriw);
                                        break;
-                               case 'dbserverlag' :
-                                       $this->appendDbServerLagInfo($p, $params['showalldb']);
+                               case 'dbrepllag' :
+                                       $this->appendDbReplLagInfo($p, $params['showalldb']);
+                                       break;
+                               case 'statistics' :
+                                       $this->appendStatistics($p);
                                        break;
                        }
                }
        }
 
        protected function appendGeneralInfo($property) {
-               global $wgSitename, $wgVersion, $wgCapitalLinks, $wgRightsCode, $wgRightsText, $wgLanguageCode;
+               global $wgSitename, $wgVersion, $wgCapitalLinks, $wgRightsCode, $wgRightsText, $wgLanguageCode, $IP;
                
                $data = array ();
                $mainPage = Title :: newFromText(wfMsgForContent('mainpage'));
@@ -73,6 +76,10 @@ class ApiQuerySiteinfo extends ApiQueryBase {
                $data['base'] = $mainPage->getFullUrl();
                $data['sitename'] = $wgSitename;
                $data['generator'] = "MediaWiki $wgVersion";
+
+               $svn = SpecialVersion::getSvnRevision ( $IP );
+               if ( $svn ) $data['rev'] = $svn;
+
                $data['case'] = $wgCapitalLinks ? 'first-letter' : 'case-sensitive'; // 'case-insensitive' option is reserved for future
                if (isset($wgRightsCode))
                        $data['rightscode'] = $wgRightsCode;
@@ -99,15 +106,17 @@ class ApiQuerySiteinfo extends ApiQueryBase {
        
        protected function appendInterwikiMap($property, $filter) {
 
+               $this->resetQueryParams();
                $this->addTables('interwiki');
                $this->addFields(array('iw_prefix', 'iw_local', 'iw_url'));
 
-               if($filter === 'local')
+               if($filter === 'local') {
                        $this->addWhere('iw_local = 1');
-               else if($filter === '!local')
+               } elseif($filter === '!local') {
                        $this->addWhere('iw_local = 0');
-               else if($filter !== false)
+               } elseif($filter !== false) {
                        ApiBase :: dieDebug(__METHOD__, "Unknown filter=$filter");
+               }
 
                $this->addOption('ORDER BY', 'iw_prefix');
                
@@ -131,12 +140,15 @@ class ApiQuerySiteinfo extends ApiQueryBase {
                $this->getResult()->addValue('query', $property, $data);
        }
        
-       protected function appendDbServerLagInfo($property, $includeAll) {
-               global $wgLoadBalancer;
+       protected function appendDbReplLagInfo($property, $includeAll) {
+               global $wgLoadBalancer, $wgShowHostnames;
 
                $data = array();
                
                if ($includeAll) {
+                       if (!$wgShowHostnames)
+                               $this->dieUsage('Cannot view all servers info unless $wgShowHostnames is true', 'includeAllDenied');
+                       
                        global $wgDBservers;
                        $lags = $wgLoadBalancer->getLagTimes();
                        foreach( $lags as $i => $lag ) {
@@ -147,7 +159,7 @@ class ApiQuerySiteinfo extends ApiQueryBase {
                } else {
                        list( $host, $lag ) = $wgLoadBalancer->getMaxLag();
                        $data[] = array (
-                               'host' => $host,
+                               'host' => $wgShowHostnames ? $host : '',
                                'lag' => $lag);
                }                                       
 
@@ -156,6 +168,19 @@ class ApiQuerySiteinfo extends ApiQueryBase {
                $result->addValue('query', $property, $data);
        }       
 
+       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);
+       }       
+       
        protected function getAllowedParams() {
                return array (
                
@@ -166,7 +191,8 @@ class ApiQuerySiteinfo extends ApiQueryBase {
                                        'general',
                                        'namespaces',
                                        'interwikimap',
-                                       'dbserverlag',
+                                       'dbrepllag',
+                                       'statistics',
                                )),
 
                        'filteriw' => array (
@@ -185,11 +211,12 @@ class ApiQuerySiteinfo extends ApiQueryBase {
                                'Which sysinfo properties to get:',
                                ' "general"      - Overall system information',
                                ' "namespaces"   - List of registered namespaces (localized)',
-                               ' "interwikimap" - Return interwiki map (optionally filtered)',
-                               ' "dbserverlag"  - Get highest database replication server lag',
+                               ' "statistics"   - Returns site statistics',
+                               ' "interwikimap" - Returns interwiki map (optionally filtered)',
+                               ' "dbrepllag"    - Returns database server with the highest replication lag',
                        ),
                        'filteriw' =>  'Return only local or only nonlocal entries of the interwiki map',
-                       'showalldb' => 'List all DB servers, not just the one lagging the most',
+                       'showalldb' => 'List all database servers, not just the one lagging the most',
                );
        }
 
@@ -199,8 +226,9 @@ class ApiQuerySiteinfo extends ApiQueryBase {
 
        protected function getExamples() {
                return array(
-                       'api.php?action=query&meta=siteinfo&siprop=general|namespaces',
+                       'api.php?action=query&meta=siteinfo&siprop=general|namespaces|statistics',
                        'api.php?action=query&meta=siteinfo&siprop=interwikimap&sifilteriw=local',
+                       'api.php?action=query&meta=siteinfo&siprop=dbrepllag&sishowalldb',
                        );
        }
 
@@ -208,4 +236,3 @@ class ApiQuerySiteinfo extends ApiQueryBase {
                return __CLASS__ . ': $Id$';
        }
 }
-