Index: trunk/phase3/includes/api/ApiQuerySiteinfo.php |
— | — | @@ -23,9 +23,9 @@ |
24 | 24 | * http://www.gnu.org/copyleft/gpl.html |
25 | 25 | */ |
26 | 26 | |
27 | | -if (!defined('MEDIAWIKI')) { |
| 27 | +if( !defined('MEDIAWIKI') ) { |
28 | 28 | // Eclipse helper - will be ignored in production |
29 | | - require_once ('ApiQueryBase.php'); |
| 29 | + require_once( 'ApiQueryBase.php' ); |
30 | 30 | } |
31 | 31 | |
32 | 32 | /** |
— | — | @@ -35,49 +35,50 @@ |
36 | 36 | */ |
37 | 37 | class ApiQuerySiteinfo extends ApiQueryBase { |
38 | 38 | |
39 | | - public function __construct($query, $moduleName) { |
40 | | - parent :: __construct($query, $moduleName, 'si'); |
| 39 | + public function __construct( $query, $moduleName ) { |
| 40 | + parent :: __construct( $query, $moduleName, 'si' ); |
41 | 41 | } |
42 | 42 | |
43 | 43 | public function execute() { |
44 | 44 | $params = $this->extractRequestParams(); |
45 | | - foreach($params['prop'] as $p) |
| 45 | + foreach( $params['prop'] as $p ) |
46 | 46 | { |
47 | | - switch ($p) |
| 47 | + switch ( $p ) |
48 | 48 | { |
49 | | - case 'general' : |
50 | | - $this->appendGeneralInfo($p); |
| 49 | + case 'general': |
| 50 | + $this->appendGeneralInfo( $p ); |
51 | 51 | break; |
52 | | - case 'namespaces' : |
53 | | - $this->appendNamespaces($p); |
| 52 | + case 'namespaces': |
| 53 | + $this->appendNamespaces( $p ); |
54 | 54 | break; |
55 | | - case 'namespacealiases' : |
56 | | - $this->appendNamespaceAliases($p); |
| 55 | + case 'namespacealiases': |
| 56 | + $this->appendNamespaceAliases( $p ); |
57 | 57 | break; |
58 | | - case 'specialpagealiases' : |
59 | | - $this->appendSpecialPageAliases($p); |
| 58 | + case 'specialpagealiases': |
| 59 | + $this->appendSpecialPageAliases( $p ); |
60 | 60 | 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 ); |
64 | 64 | break; |
65 | | - case 'dbrepllag' : |
66 | | - $this->appendDbReplLagInfo($p, $params['showalldb']); |
| 65 | + case 'dbrepllag': |
| 66 | + $this->appendDbReplLagInfo( $p, $params['showalldb'] ); |
67 | 67 | break; |
68 | | - case 'statistics' : |
69 | | - $this->appendStatistics($p); |
| 68 | + case 'statistics': |
| 69 | + $this->appendStatistics( $p ); |
70 | 70 | break; |
71 | | - case 'usergroups' : |
72 | | - $this->appendUserGroups($p); |
| 71 | + case 'usergroups': |
| 72 | + $this->appendUserGroups( $p ); |
73 | 73 | break; |
74 | 74 | default : |
75 | | - ApiBase :: dieDebug(__METHOD__, "Unknown prop=$p"); |
| 75 | + ApiBase :: dieDebug( __METHOD__, "Unknown prop=$p" ); |
76 | 76 | } |
77 | 77 | } |
78 | 78 | } |
79 | 79 | |
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; |
82 | 83 | |
83 | 84 | $data = array(); |
84 | 85 | $mainPage = Title :: newFromText(wfMsgForContent('mainpage')); |
— | — | @@ -86,169 +87,182 @@ |
87 | 88 | $data['sitename'] = $wgSitename; |
88 | 89 | $data['generator'] = "MediaWiki $wgVersion"; |
89 | 90 | |
90 | | - $svn = SpecialVersion::getSvnRevision($IP); |
91 | | - if($svn) |
| 91 | + $svn = SpecialVersion::getSvnRevision( $IP ); |
| 92 | + if( $svn ) |
92 | 93 | $data['rev'] = $svn; |
93 | 94 | |
94 | 95 | $data['case'] = $wgCapitalLinks ? 'first-letter' : 'case-sensitive'; // 'case-insensitive' option is reserved for future |
95 | 96 | |
96 | | - if(isset($wgRightsCode)) |
| 97 | + if( isset( $wgRightsCode ) ) |
97 | 98 | $data['rightscode'] = $wgRightsCode; |
98 | 99 | $data['rights'] = $wgRightsText; |
99 | 100 | $data['lang'] = $wgLanguageCode; |
| 101 | + if( $wgContLang->isRTL() ) |
| 102 | + $data['rtl'] = ''; |
100 | 103 | $data['fallback8bitEncoding'] = $wgLang->fallback8bitEncoding(); |
101 | 104 | |
102 | | - if(wfReadOnly()) |
| 105 | + if( wfReadOnly() ) |
103 | 106 | $data['readonly'] = ''; |
104 | | - if($wgEnableWriteAPI) |
| 107 | + if( $wgEnableWriteAPI ) |
105 | 108 | $data['writeapi'] = ''; |
106 | 109 | |
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 ); |
108 | 122 | } |
109 | 123 | |
110 | | - protected function appendNamespaces($property) { |
| 124 | + protected function appendNamespaces( $property ) { |
111 | 125 | global $wgContLang; |
112 | 126 | $data = array(); |
113 | | - foreach($wgContLang->getFormattedNamespaces() as $ns => $title) |
| 127 | + foreach( $wgContLang->getFormattedNamespaces() as $ns => $title ) |
114 | 128 | { |
115 | | - $data[$ns] = array ( |
| 129 | + $data[$ns] = array( |
116 | 130 | 'id' => $ns |
117 | 131 | ); |
118 | | - ApiResult :: setContent($data[$ns], $title); |
119 | | - if(MWNamespace::hasSubpages($ns)) |
| 132 | + ApiResult :: setContent( $data[$ns], $title ); |
| 133 | + if( MWNamespace::hasSubpages($ns) ) |
120 | 134 | $data[$ns]['subpages'] = ''; |
121 | 135 | } |
122 | 136 | |
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 ); |
125 | 139 | } |
126 | 140 | |
127 | | - protected function appendNamespaceAliases($property) { |
| 141 | + protected function appendNamespaceAliases( $property ) { |
128 | 142 | global $wgNamespaceAliases; |
129 | 143 | $data = array(); |
130 | | - foreach($wgNamespaceAliases as $title => $ns) { |
131 | | - $item = array ( |
| 144 | + foreach( $wgNamespaceAliases as $title => $ns ) { |
| 145 | + $item = array( |
132 | 146 | 'id' => $ns |
133 | 147 | ); |
134 | | - ApiResult :: setContent($item, strtr($title, '_', ' ')); |
| 148 | + ApiResult :: setContent( $item, strtr( $title, '_', ' ' ) ); |
135 | 149 | $data[] = $item; |
136 | 150 | } |
137 | 151 | |
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 ); |
140 | 154 | } |
141 | 155 | |
142 | | - protected function appendSpecialPageAliases($property) |
143 | | - { |
| 156 | + protected function appendSpecialPageAliases( $property ) { |
144 | 157 | global $wgLang; |
145 | 158 | $data = array(); |
146 | | - foreach($wgLang->getSpecialPageAliases() as $specialpage => $aliases) |
| 159 | + foreach( $wgLang->getSpecialPageAliases() as $specialpage => $aliases ) |
147 | 160 | { |
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' ); |
150 | 163 | $data[] = $arr; |
151 | 164 | } |
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 ); |
154 | 167 | } |
155 | 168 | |
156 | | - protected function appendInterwikiMap($property, $filter) { |
157 | | - |
| 169 | + protected function appendInterwikiMap( $property, $filter ) { |
158 | 170 | $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' ) ); |
161 | 173 | |
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" ); |
168 | 180 | |
169 | | - $this->addOption('ORDER BY', 'iw_prefix'); |
| 181 | + $this->addOption( 'ORDER BY', 'iw_prefix' ); |
170 | 182 | |
171 | 183 | $db = $this->getDB(); |
172 | | - $res = $this->select(__METHOD__); |
| 184 | + $res = $this->select( __METHOD__ ); |
173 | 185 | |
174 | 186 | $data = array(); |
175 | 187 | $langNames = Language::getLanguageNames(); |
176 | | - while($row = $db->fetchObject($res)) |
| 188 | + while( $row = $db->fetchObject($res) ) |
177 | 189 | { |
178 | 190 | $val = array(); |
179 | 191 | $val['prefix'] = $row->iw_prefix; |
180 | | - if($row->iw_local == '1') |
| 192 | + if( $row->iw_local == '1' ) |
181 | 193 | $val['local'] = ''; |
182 | 194 | // $val['trans'] = intval($row->iw_trans); // should this be exposed? |
183 | | - if(isset($langNames[$row->iw_prefix])) |
| 195 | + if( isset( $langNames[$row->iw_prefix] ) ) |
184 | 196 | $val['language'] = $langNames[$row->iw_prefix]; |
185 | 197 | $val['url'] = $row->iw_url; |
186 | 198 | |
187 | 199 | $data[] = $val; |
188 | 200 | } |
189 | | - $db->freeResult($res); |
| 201 | + $db->freeResult( $res ); |
190 | 202 | |
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 ); |
193 | 205 | } |
194 | 206 | |
195 | | - protected function appendDbReplLagInfo($property, $includeAll) { |
| 207 | + protected function appendDbReplLagInfo( $property, $includeAll ) { |
196 | 208 | global $wgShowHostnames; |
197 | 209 | $data = array(); |
198 | | - if ($includeAll) { |
199 | | - if (!$wgShowHostnames) |
| 210 | + if( $includeAll ) { |
| 211 | + if ( !$wgShowHostnames ) |
200 | 212 | $this->dieUsage('Cannot view all servers info unless $wgShowHostnames is true', 'includeAllDenied'); |
201 | 213 | |
202 | 214 | $lb = wfGetLB(); |
203 | 215 | $lags = $lb->getLagTimes(); |
204 | 216 | foreach( $lags as $i => $lag ) { |
205 | | - $data[] = array ( |
| 217 | + $data[] = array( |
206 | 218 | 'host' => $lb->getServerName( $i ), |
207 | | - 'lag' => $lag); |
| 219 | + 'lag' => $lag |
| 220 | + ); |
208 | 221 | } |
209 | 222 | } else { |
210 | 223 | list( $host, $lag ) = wfGetLB()->getMaxLag(); |
211 | | - $data[] = array ( |
| 224 | + $data[] = array( |
212 | 225 | 'host' => $wgShowHostnames ? $host : '', |
213 | | - 'lag' => $lag); |
| 226 | + 'lag' => $lag |
| 227 | + ); |
214 | 228 | } |
215 | 229 | |
216 | 230 | $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 ); |
219 | 233 | } |
220 | 234 | |
221 | | - protected function appendStatistics($property) { |
| 235 | + protected function appendStatistics( $property ) { |
222 | 236 | $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 ); |
232 | 246 | } |
233 | 247 | |
234 | | - protected function appendUserGroups($property) { |
| 248 | + protected function appendUserGroups( $property ) { |
235 | 249 | 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' ); |
240 | 254 | $data[] = $arr; |
241 | 255 | } |
242 | 256 | |
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 ); |
245 | 259 | } |
246 | 260 | |
247 | 261 | public function getAllowedParams() { |
248 | | - return array ( |
249 | | - 'prop' => array ( |
| 262 | + return array( |
| 263 | + 'prop' => array( |
250 | 264 | ApiBase :: PARAM_DFLT => 'general', |
251 | 265 | ApiBase :: PARAM_ISMULTI => true, |
252 | | - ApiBase :: PARAM_TYPE => array ( |
| 266 | + ApiBase :: PARAM_TYPE => array( |
253 | 267 | 'general', |
254 | 268 | 'namespaces', |
255 | 269 | 'namespacealiases', |
— | — | @@ -257,21 +271,21 @@ |
258 | 272 | 'dbrepllag', |
259 | 273 | 'statistics', |
260 | 274 | 'usergroups', |
261 | | - )), |
262 | | - |
263 | | - 'filteriw' => array ( |
264 | | - ApiBase :: PARAM_TYPE => array ( |
| 275 | + ) |
| 276 | + ), |
| 277 | + 'filteriw' => array( |
| 278 | + ApiBase :: PARAM_TYPE => array( |
265 | 279 | 'local', |
266 | 280 | '!local', |
267 | | - )), |
268 | | - |
| 281 | + ) |
| 282 | + ), |
269 | 283 | 'showalldb' => false, |
270 | 284 | ); |
271 | 285 | } |
272 | 286 | |
273 | 287 | public function getParamDescription() { |
274 | | - return array ( |
275 | | - 'prop' => array ( |
| 288 | + return array( |
| 289 | + 'prop' => array( |
276 | 290 | 'Which sysinfo properties to get:', |
277 | 291 | ' "general" - Overall system information', |
278 | 292 | ' "namespaces" - List of registered namespaces (localized)', |
Index: trunk/phase3/RELEASE-NOTES |
— | — | @@ -493,6 +493,7 @@ |
494 | 494 | * (bug 14651) apprefix and similar parameters are now canonicalized |
495 | 495 | * Added clprop=timestamp to prop=categories |
496 | 496 | * (bug 14678) API errors now respects $wgShowExceptionDetails and $wgShowSQLErrors |
| 497 | +* (bug 14723) Added time zone and writing direction to meta=siteinfo |
497 | 498 | |
498 | 499 | === Languages updated in 1.13 === |
499 | 500 | |