Don't use $wgDBservers to get server ip, it isn't set on Wikimedia and return host...
[lhc/web/wiklou.git] / includes / api / ApiQuerySiteinfo.php
index f8a401a..eff3dc6 100644 (file)
@@ -69,12 +69,15 @@ class ApiQuerySiteinfo extends ApiQueryBase {
                                case 'statistics' :
                                        $this->appendStatistics($p);
                                        break;
+                               case 'usergroups' :
+                                       $this->appendUserGroups($p);
+                                       break;
                        }
                }
        }
 
        protected function appendGeneralInfo($property) {
-               global $wgSitename, $wgVersion, $wgCapitalLinks, $wgRightsCode, $wgRightsText, $wgLanguageCode, $IP, $wgEnableWriteAPI;
+               global $wgSitename, $wgVersion, $wgCapitalLinks, $wgRightsCode, $wgRightsText, $wgLanguageCode, $IP, $wgEnableWriteAPI, $wgLang;
                
                $data = array ();
                $mainPage = Title :: newFromText(wfMsgForContent('mainpage'));
@@ -87,10 +90,12 @@ class ApiQuerySiteinfo extends ApiQueryBase {
                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;
                $data['rights'] = $wgRightsText;
                $data['lang'] = $wgLanguageCode;
+               $data['fallback8bitEncoding'] = $wgLang->fallback8bitEncoding();
 
                if ( $wgEnableWriteAPI )
                        $data['writeapi'] = '';
@@ -183,23 +188,23 @@ class ApiQuerySiteinfo extends ApiQueryBase {
        }
        
        protected function appendDbReplLagInfo($property, $includeAll) {
-               global $wgLoadBalancer, $wgShowHostnames;
+               global $wgShowHostnames;
 
                $data = array();
                
                if ($includeAll) {
                        if (!$wgShowHostnames)
                                $this->dieUsage('Cannot view all servers info unless $wgShowHostnames is true', 'includeAllDenied');
-                       
-                       global $wgDBservers;
-                       $lags = $wgLoadBalancer->getLagTimes();
+
+                       $lb = wfGetLB();
+                       $lags = $lb->getLagTimes();
                        foreach( $lags as $i => $lag ) {
                                $data[] = array (
-                                       'host' => $wgDBservers[$i]['host'],
+                                       'host' => $lb->getServerName( $i ),
                                        'lag' => $lag);
                        }
                } else {
-                       list( $host, $lag ) = $wgLoadBalancer->getMaxLag();
+                       list( $host, $lag ) = wfGetLB()->getMaxLag();
                        $data[] = array (
                                'host' => $wgShowHostnames ? $host : '',
                                'lag' => $lag);
@@ -222,7 +227,21 @@ class ApiQuerySiteinfo extends ApiQueryBase {
                $data['jobs'] = intval(SiteStats::jobs());
                $this->getResult()->addValue('query', $property, $data);
        }       
-       
+
+       protected function appendUserGroups($property) {
+               global $wgGroupPermissions;
+
+               $data = array ();
+               foreach ($wgGroupPermissions as $group => $permissions) {
+                       $arr = array ('name' => $group, 'rights' => array_keys($permissions, true));
+                       $this->getResult()->setIndexedTagName($arr['rights'], 'permission');
+                       $data[] = $arr;
+               }
+
+               $this->getResult()->setIndexedTagName($data, 'group');
+               $this->getResult()->addValue('query', $property, $data);
+       }
+
        public function getAllowedParams() {
                return array (
                
@@ -237,6 +256,7 @@ class ApiQuerySiteinfo extends ApiQueryBase {
                                        'interwikimap',
                                        'dbrepllag',
                                        'statistics',
+                                       'usergroups',
                                )),
 
                        'filteriw' => array (
@@ -260,6 +280,7 @@ class ApiQuerySiteinfo extends ApiQueryBase {
                                ' "statistics"   - Returns site statistics',
                                ' "interwikimap" - Returns interwiki map (optionally filtered)',
                                ' "dbrepllag"    - Returns database server with the highest replication lag',
+                               ' "usergroups"   - Returns user groups and the associated permissions',
                        ),
                        'filteriw' =>  'Return only local or only nonlocal entries of the interwiki map',
                        'showalldb' => 'List all database servers, not just the one lagging the most',