r37034 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r37033‎ | r37034 | r37035 >
Date:09:21, 4 July 2008
Author:vasilievvv
Status:old
Tags:
Comment:
* (bug 14723) Added time zone and writing direction to meta=siteinfo. Patch by MaxSem
* Some random cleanup
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/includes/api/ApiQuerySiteinfo.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/api/ApiQuerySiteinfo.php
@@ -23,9 +23,9 @@
2424 * http://www.gnu.org/copyleft/gpl.html
2525 */
2626
27 -if (!defined('MEDIAWIKI')) {
 27+if( !defined('MEDIAWIKI') ) {
2828 // Eclipse helper - will be ignored in production
29 - require_once ('ApiQueryBase.php');
 29+ require_once( 'ApiQueryBase.php' );
3030 }
3131
3232 /**
@@ -35,49 +35,50 @@
3636 */
3737 class ApiQuerySiteinfo extends ApiQueryBase {
3838
39 - public function __construct($query, $moduleName) {
40 - parent :: __construct($query, $moduleName, 'si');
 39+ public function __construct( $query, $moduleName ) {
 40+ parent :: __construct( $query, $moduleName, 'si' );
4141 }
4242
4343 public function execute() {
4444 $params = $this->extractRequestParams();
45 - foreach($params['prop'] as $p)
 45+ foreach( $params['prop'] as $p )
4646 {
47 - switch ($p)
 47+ switch ( $p )
4848 {
49 - case 'general' :
50 - $this->appendGeneralInfo($p);
 49+ case 'general':
 50+ $this->appendGeneralInfo( $p );
5151 break;
52 - case 'namespaces' :
53 - $this->appendNamespaces($p);
 52+ case 'namespaces':
 53+ $this->appendNamespaces( $p );
5454 break;
55 - case 'namespacealiases' :
56 - $this->appendNamespaceAliases($p);
 55+ case 'namespacealiases':
 56+ $this->appendNamespaceAliases( $p );
5757 break;
58 - case 'specialpagealiases' :
59 - $this->appendSpecialPageAliases($p);
 58+ case 'specialpagealiases':
 59+ $this->appendSpecialPageAliases( $p );
6060 break;
61 - case 'interwikimap' :
62 - $filteriw = isset($params['filteriw']) ? $params['filteriw'] : false;
63 - $this->appendInterwikiMap($p, $filteriw);
 61+ case 'interwikimap':
 62+ $filteriw = isset( $params['filteriw'] ) ? $params['filteriw'] : false;
 63+ $this->appendInterwikiMap( $p, $filteriw );
6464 break;
65 - case 'dbrepllag' :
66 - $this->appendDbReplLagInfo($p, $params['showalldb']);
 65+ case 'dbrepllag':
 66+ $this->appendDbReplLagInfo( $p, $params['showalldb'] );
6767 break;
68 - case 'statistics' :
69 - $this->appendStatistics($p);
 68+ case 'statistics':
 69+ $this->appendStatistics( $p );
7070 break;
71 - case 'usergroups' :
72 - $this->appendUserGroups($p);
 71+ case 'usergroups':
 72+ $this->appendUserGroups( $p );
7373 break;
7474 default :
75 - ApiBase :: dieDebug(__METHOD__, "Unknown prop=$p");
 75+ ApiBase :: dieDebug( __METHOD__, "Unknown prop=$p" );
7676 }
7777 }
7878 }
7979
80 - protected function appendGeneralInfo($property) {
81 - global $wgSitename, $wgVersion, $wgCapitalLinks, $wgRightsCode, $wgRightsText, $wgLanguageCode, $IP, $wgEnableWriteAPI, $wgLang;
 80+ protected function appendGeneralInfo( $property ) {
 81+ global $wgSitename, $wgVersion, $wgCapitalLinks, $wgRightsCode, $wgRightsText, $wgContLang;
 82+ global $wgLanguageCode, $IP, $wgEnableWriteAPI, $wgLang, $wgLocaltimezone, $wgLocalTZoffset;
8283
8384 $data = array();
8485 $mainPage = Title :: newFromText(wfMsgForContent('mainpage'));
@@ -86,169 +87,182 @@
8788 $data['sitename'] = $wgSitename;
8889 $data['generator'] = "MediaWiki $wgVersion";
8990
90 - $svn = SpecialVersion::getSvnRevision($IP);
91 - if($svn)
 91+ $svn = SpecialVersion::getSvnRevision( $IP );
 92+ if( $svn )
9293 $data['rev'] = $svn;
9394
9495 $data['case'] = $wgCapitalLinks ? 'first-letter' : 'case-sensitive'; // 'case-insensitive' option is reserved for future
9596
96 - if(isset($wgRightsCode))
 97+ if( isset( $wgRightsCode ) )
9798 $data['rightscode'] = $wgRightsCode;
9899 $data['rights'] = $wgRightsText;
99100 $data['lang'] = $wgLanguageCode;
 101+ if( $wgContLang->isRTL() )
 102+ $data['rtl'] = '';
100103 $data['fallback8bitEncoding'] = $wgLang->fallback8bitEncoding();
101104
102 - if(wfReadOnly())
 105+ if( wfReadOnly() )
103106 $data['readonly'] = '';
104 - if($wgEnableWriteAPI)
 107+ if( $wgEnableWriteAPI )
105108 $data['writeapi'] = '';
106109
107 - $this->getResult()->addValue('query', $property, $data);
 110+ $tz = $wgLocaltimezone;
 111+ $offset = $wgLocalTZoffset;
 112+ if( is_null( $tz ) ) {
 113+ $tz = 'UTC';
 114+ $offset = 0;
 115+ } elseif( is_null( $offset ) ) {
 116+ $offset = 0;
 117+ }
 118+ $data['timezone'] = $tz;
 119+ $data['timeoffset'] = $offset;
 120+
 121+ $this->getResult()->addValue( 'query', $property, $data );
108122 }
109123
110 - protected function appendNamespaces($property) {
 124+ protected function appendNamespaces( $property ) {
111125 global $wgContLang;
112126 $data = array();
113 - foreach($wgContLang->getFormattedNamespaces() as $ns => $title)
 127+ foreach( $wgContLang->getFormattedNamespaces() as $ns => $title )
114128 {
115 - $data[$ns] = array (
 129+ $data[$ns] = array(
116130 'id' => $ns
117131 );
118 - ApiResult :: setContent($data[$ns], $title);
119 - if(MWNamespace::hasSubpages($ns))
 132+ ApiResult :: setContent( $data[$ns], $title );
 133+ if( MWNamespace::hasSubpages($ns) )
120134 $data[$ns]['subpages'] = '';
121135 }
122136
123 - $this->getResult()->setIndexedTagName($data, 'ns');
124 - $this->getResult()->addValue('query', $property, $data);
 137+ $this->getResult()->setIndexedTagName( $data, 'ns' );
 138+ $this->getResult()->addValue( 'query', $property, $data );
125139 }
126140
127 - protected function appendNamespaceAliases($property) {
 141+ protected function appendNamespaceAliases( $property ) {
128142 global $wgNamespaceAliases;
129143 $data = array();
130 - foreach($wgNamespaceAliases as $title => $ns) {
131 - $item = array (
 144+ foreach( $wgNamespaceAliases as $title => $ns ) {
 145+ $item = array(
132146 'id' => $ns
133147 );
134 - ApiResult :: setContent($item, strtr($title, '_', ' '));
 148+ ApiResult :: setContent( $item, strtr( $title, '_', ' ' ) );
135149 $data[] = $item;
136150 }
137151
138 - $this->getResult()->setIndexedTagName($data, 'ns');
139 - $this->getResult()->addValue('query', $property, $data);
 152+ $this->getResult()->setIndexedTagName( $data, 'ns' );
 153+ $this->getResult()->addValue( 'query', $property, $data );
140154 }
141155
142 - protected function appendSpecialPageAliases($property)
143 - {
 156+ protected function appendSpecialPageAliases( $property ) {
144157 global $wgLang;
145158 $data = array();
146 - foreach($wgLang->getSpecialPageAliases() as $specialpage => $aliases)
 159+ foreach( $wgLang->getSpecialPageAliases() as $specialpage => $aliases )
147160 {
148 - $arr = array('realname' => $specialpage, 'aliases' => $aliases);
149 - $this->getResult()->setIndexedTagName($arr['aliases'], 'alias');
 161+ $arr = array( 'realname' => $specialpage, 'aliases' => $aliases );
 162+ $this->getResult()->setIndexedTagName( $arr['aliases'], 'alias' );
150163 $data[] = $arr;
151164 }
152 - $this->getResult()->setIndexedTagName($data, 'specialpage');
153 - $this->getResult()->addValue('query', $property, $data);
 165+ $this->getResult()->setIndexedTagName( $data, 'specialpage' );
 166+ $this->getResult()->addValue( 'query', $property, $data );
154167 }
155168
156 - protected function appendInterwikiMap($property, $filter) {
157 -
 169+ protected function appendInterwikiMap( $property, $filter ) {
158170 $this->resetQueryParams();
159 - $this->addTables('interwiki');
160 - $this->addFields(array('iw_prefix', 'iw_local', 'iw_url'));
 171+ $this->addTables( 'interwiki' );
 172+ $this->addFields( array( 'iw_prefix', 'iw_local', 'iw_url' ) );
161173
162 - if($filter === 'local')
163 - $this->addWhere('iw_local = 1');
164 - elseif($filter === '!local')
165 - $this->addWhere('iw_local = 0');
166 - elseif($filter !== false)
167 - ApiBase :: dieDebug(__METHOD__, "Unknown filter=$filter");
 174+ if( $filter === 'local' )
 175+ $this->addWhere( 'iw_local = 1' );
 176+ elseif( $filter === '!local' )
 177+ $this->addWhere( 'iw_local = 0' );
 178+ elseif( $filter !== false )
 179+ ApiBase :: dieDebug( __METHOD__, "Unknown filter=$filter" );
168180
169 - $this->addOption('ORDER BY', 'iw_prefix');
 181+ $this->addOption( 'ORDER BY', 'iw_prefix' );
170182
171183 $db = $this->getDB();
172 - $res = $this->select(__METHOD__);
 184+ $res = $this->select( __METHOD__ );
173185
174186 $data = array();
175187 $langNames = Language::getLanguageNames();
176 - while($row = $db->fetchObject($res))
 188+ while( $row = $db->fetchObject($res) )
177189 {
178190 $val = array();
179191 $val['prefix'] = $row->iw_prefix;
180 - if($row->iw_local == '1')
 192+ if( $row->iw_local == '1' )
181193 $val['local'] = '';
182194 // $val['trans'] = intval($row->iw_trans); // should this be exposed?
183 - if(isset($langNames[$row->iw_prefix]))
 195+ if( isset( $langNames[$row->iw_prefix] ) )
184196 $val['language'] = $langNames[$row->iw_prefix];
185197 $val['url'] = $row->iw_url;
186198
187199 $data[] = $val;
188200 }
189 - $db->freeResult($res);
 201+ $db->freeResult( $res );
190202
191 - $this->getResult()->setIndexedTagName($data, 'iw');
192 - $this->getResult()->addValue('query', $property, $data);
 203+ $this->getResult()->setIndexedTagName( $data, 'iw' );
 204+ $this->getResult()->addValue( 'query', $property, $data );
193205 }
194206
195 - protected function appendDbReplLagInfo($property, $includeAll) {
 207+ protected function appendDbReplLagInfo( $property, $includeAll ) {
196208 global $wgShowHostnames;
197209 $data = array();
198 - if ($includeAll) {
199 - if (!$wgShowHostnames)
 210+ if( $includeAll ) {
 211+ if ( !$wgShowHostnames )
200212 $this->dieUsage('Cannot view all servers info unless $wgShowHostnames is true', 'includeAllDenied');
201213
202214 $lb = wfGetLB();
203215 $lags = $lb->getLagTimes();
204216 foreach( $lags as $i => $lag ) {
205 - $data[] = array (
 217+ $data[] = array(
206218 'host' => $lb->getServerName( $i ),
207 - 'lag' => $lag);
 219+ 'lag' => $lag
 220+ );
208221 }
209222 } else {
210223 list( $host, $lag ) = wfGetLB()->getMaxLag();
211 - $data[] = array (
 224+ $data[] = array(
212225 'host' => $wgShowHostnames ? $host : '',
213 - 'lag' => $lag);
 226+ 'lag' => $lag
 227+ );
214228 }
215229
216230 $result = $this->getResult();
217 - $result->setIndexedTagName($data, 'db');
218 - $result->addValue('query', $property, $data);
 231+ $result->setIndexedTagName( $data, 'db' );
 232+ $result->addValue( 'query', $property, $data );
219233 }
220234
221 - protected function appendStatistics($property) {
 235+ protected function appendStatistics( $property ) {
222236 $data = array();
223 - $data['pages'] = intval(SiteStats::pages());
224 - $data['articles'] = intval(SiteStats::articles());
225 - $data['views'] = intval(SiteStats::views());
226 - $data['edits'] = intval(SiteStats::edits());
227 - $data['images'] = intval(SiteStats::images());
228 - $data['users'] = intval(SiteStats::users());
229 - $data['admins'] = intval(SiteStats::admins());
230 - $data['jobs'] = intval(SiteStats::jobs());
231 - $this->getResult()->addValue('query', $property, $data);
 237+ $data['pages'] = intval( SiteStats::pages() );
 238+ $data['articles'] = intval( SiteStats::articles() );
 239+ $data['views'] = intval( SiteStats::views() );
 240+ $data['edits'] = intval( SiteStats::edits() );
 241+ $data['images'] = intval( SiteStats::images() );
 242+ $data['users'] = intval( SiteStats::users() );
 243+ $data['admins'] = intval( SiteStats::admins() );
 244+ $data['jobs'] = intval( SiteStats::jobs() );
 245+ $this->getResult()->addValue( 'query', $property, $data );
232246 }
233247
234 - protected function appendUserGroups($property) {
 248+ protected function appendUserGroups( $property ) {
235249 global $wgGroupPermissions;
236 - $data = array ();
237 - foreach ($wgGroupPermissions as $group => $permissions) {
238 - $arr = array ('name' => $group, 'rights' => array_keys($permissions, true));
239 - $this->getResult()->setIndexedTagName($arr['rights'], 'permission');
 250+ $data = array();
 251+ foreach( $wgGroupPermissions as $group => $permissions ) {
 252+ $arr = array( 'name' => $group, 'rights' => array_keys( $permissions, true ) );
 253+ $this->getResult()->setIndexedTagName( $arr['rights'], 'permission' );
240254 $data[] = $arr;
241255 }
242256
243 - $this->getResult()->setIndexedTagName($data, 'group');
244 - $this->getResult()->addValue('query', $property, $data);
 257+ $this->getResult()->setIndexedTagName( $data, 'group' );
 258+ $this->getResult()->addValue( 'query', $property, $data );
245259 }
246260
247261 public function getAllowedParams() {
248 - return array (
249 - 'prop' => array (
 262+ return array(
 263+ 'prop' => array(
250264 ApiBase :: PARAM_DFLT => 'general',
251265 ApiBase :: PARAM_ISMULTI => true,
252 - ApiBase :: PARAM_TYPE => array (
 266+ ApiBase :: PARAM_TYPE => array(
253267 'general',
254268 'namespaces',
255269 'namespacealiases',
@@ -257,21 +271,21 @@
258272 'dbrepllag',
259273 'statistics',
260274 'usergroups',
261 - )),
262 -
263 - 'filteriw' => array (
264 - ApiBase :: PARAM_TYPE => array (
 275+ )
 276+ ),
 277+ 'filteriw' => array(
 278+ ApiBase :: PARAM_TYPE => array(
265279 'local',
266280 '!local',
267 - )),
268 -
 281+ )
 282+ ),
269283 'showalldb' => false,
270284 );
271285 }
272286
273287 public function getParamDescription() {
274 - return array (
275 - 'prop' => array (
 288+ return array(
 289+ 'prop' => array(
276290 'Which sysinfo properties to get:',
277291 ' "general" - Overall system information',
278292 ' "namespaces" - List of registered namespaces (localized)',
Index: trunk/phase3/RELEASE-NOTES
@@ -493,6 +493,7 @@
494494 * (bug 14651) apprefix and similar parameters are now canonicalized
495495 * Added clprop=timestamp to prop=categories
496496 * (bug 14678) API errors now respects $wgShowExceptionDetails and $wgShowSQLErrors
 497+* (bug 14723) Added time zone and writing direction to meta=siteinfo
497498
498499 === Languages updated in 1.13 ===
499500

Status & tagging log