Merge "resourceloader: Use state "error" instead of "missing" in case of exceptions"
[lhc/web/wiklou.git] / includes / api / ApiQuerySiteinfo.php
1 <?php
2 /**
3 *
4 *
5 * Created on Sep 25, 2006
6 *
7 * Copyright © 2006 Yuri Astrakhan "<Firstname><Lastname>@gmail.com"
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 * http://www.gnu.org/copyleft/gpl.html
23 *
24 * @file
25 */
26
27 /**
28 * A query action to return meta information about the wiki site.
29 *
30 * @ingroup API
31 */
32 class ApiQuerySiteinfo extends ApiQueryBase {
33
34 public function __construct( $query, $moduleName ) {
35 parent::__construct( $query, $moduleName, 'si' );
36 }
37
38 public function execute() {
39 $params = $this->extractRequestParams();
40 $done = array();
41 $fit = false;
42 foreach ( $params['prop'] as $p ) {
43 switch ( $p ) {
44 case 'general':
45 $fit = $this->appendGeneralInfo( $p );
46 break;
47 case 'namespaces':
48 $fit = $this->appendNamespaces( $p );
49 break;
50 case 'namespacealiases':
51 $fit = $this->appendNamespaceAliases( $p );
52 break;
53 case 'specialpagealiases':
54 $fit = $this->appendSpecialPageAliases( $p );
55 break;
56 case 'magicwords':
57 $fit = $this->appendMagicWords( $p );
58 break;
59 case 'interwikimap':
60 $filteriw = isset( $params['filteriw'] ) ? $params['filteriw'] : false;
61 $fit = $this->appendInterwikiMap( $p, $filteriw );
62 break;
63 case 'dbrepllag':
64 $fit = $this->appendDbReplLagInfo( $p, $params['showalldb'] );
65 break;
66 case 'statistics':
67 $fit = $this->appendStatistics( $p );
68 break;
69 case 'usergroups':
70 $fit = $this->appendUserGroups( $p, $params['numberingroup'] );
71 break;
72 case 'extensions':
73 $fit = $this->appendExtensions( $p );
74 break;
75 case 'fileextensions':
76 $fit = $this->appendFileExtensions( $p );
77 break;
78 case 'rightsinfo':
79 $fit = $this->appendRightsInfo( $p );
80 break;
81 case 'languages':
82 $fit = $this->appendLanguages( $p );
83 break;
84 case 'skins':
85 $fit = $this->appendSkins( $p );
86 break;
87 case 'extensiontags':
88 $fit = $this->appendExtensionTags( $p );
89 break;
90 case 'functionhooks':
91 $fit = $this->appendFunctionHooks( $p );
92 break;
93 case 'showhooks':
94 $fit = $this->appendSubscribedHooks( $p );
95 break;
96 case 'variables':
97 $fit = $this->appendVariables( $p );
98 break;
99 case 'protocols':
100 $fit = $this->appendProtocols( $p );
101 break;
102 default:
103 ApiBase::dieDebug( __METHOD__, "Unknown prop=$p" );
104 }
105 if ( !$fit ) {
106 // Abuse siprop as a query-continue parameter
107 // and set it to all unprocessed props
108 $this->setContinueEnumParameter( 'prop', implode( '|',
109 array_diff( $params['prop'], $done ) ) );
110 break;
111 }
112 $done[] = $p;
113 }
114 }
115
116 protected function appendGeneralInfo( $property ) {
117 global $wgContLang, $wgDisableLangConversion, $wgDisableTitleConversion;
118
119 $data = array();
120 $mainPage = Title::newMainPage();
121 $data['mainpage'] = $mainPage->getPrefixedText();
122 $data['base'] = wfExpandUrl( $mainPage->getFullURL(), PROTO_CURRENT );
123 $data['sitename'] = $GLOBALS['wgSitename'];
124 $data['logo'] = $GLOBALS['wgLogo'];
125 $data['generator'] = "MediaWiki {$GLOBALS['wgVersion']}";
126 $data['phpversion'] = phpversion();
127 $data['phpsapi'] = PHP_SAPI;
128 $data['dbtype'] = $GLOBALS['wgDBtype'];
129 $data['dbversion'] = $this->getDB()->getServerVersion();
130
131 $allowFrom = array( '' );
132 $allowException = true;
133 if ( !$GLOBALS['wgAllowExternalImages'] ) {
134 if ( $GLOBALS['wgEnableImageWhitelist'] ) {
135 $data['imagewhitelistenabled'] = '';
136 }
137 $allowFrom = $GLOBALS['wgAllowExternalImagesFrom'];
138 $allowException = !empty( $allowFrom );
139 }
140 if ( $allowException ) {
141 $data['externalimages'] = (array)$allowFrom;
142 $this->getResult()->setIndexedTagName( $data['externalimages'], 'prefix' );
143 }
144
145 if ( !$wgDisableLangConversion ) {
146 $data['langconversion'] = '';
147 }
148
149 if ( !$wgDisableTitleConversion ) {
150 $data['titleconversion'] = '';
151 }
152
153 if ( $wgContLang->linkPrefixExtension() ) {
154 $linkPrefixCharset = $wgContLang->linkPrefixCharset();
155 $data['linkprefixcharset'] = $linkPrefixCharset;
156 // For backwards compatability
157 $data['linkprefix'] = "/^((?>.*[^$linkPrefixCharset]|))(.+)$/sDu";
158 } else {
159 $data['linkprefixcharset'] = '';
160 $data['linkprefix'] = '';
161 }
162
163 $linktrail = $wgContLang->linkTrail();
164 if ( $linktrail ) {
165 $data['linktrail'] = $linktrail;
166 } else {
167 $data['linktrail'] = '';
168 }
169
170 $git = SpecialVersion::getGitHeadSha1( $GLOBALS['IP'] );
171 if ( $git ) {
172 $data['git-hash'] = $git;
173 } else {
174 $svn = SpecialVersion::getSvnRevision( $GLOBALS['IP'] );
175 if ( $svn ) {
176 $data['rev'] = $svn;
177 }
178 }
179
180 // 'case-insensitive' option is reserved for future
181 $data['case'] = $GLOBALS['wgCapitalLinks'] ? 'first-letter' : 'case-sensitive';
182
183 if ( isset( $GLOBALS['wgRightsCode'] ) ) {
184 $data['rightscode'] = $GLOBALS['wgRightsCode'];
185 }
186 $data['rights'] = $GLOBALS['wgRightsText'];
187 $data['lang'] = $GLOBALS['wgLanguageCode'];
188
189 $fallbacks = array();
190 foreach ( $wgContLang->getFallbackLanguages() as $code ) {
191 $fallbacks[] = array( 'code' => $code );
192 }
193 $data['fallback'] = $fallbacks;
194 $this->getResult()->setIndexedTagName( $data['fallback'], 'lang' );
195
196 if ( $wgContLang->hasVariants() ) {
197 $variants = array();
198 foreach ( $wgContLang->getVariants() as $code ) {
199 $variants[] = array( 'code' => $code );
200 }
201 $data['variants'] = $variants;
202 $this->getResult()->setIndexedTagName( $data['variants'], 'lang' );
203 }
204
205 if ( $wgContLang->isRTL() ) {
206 $data['rtl'] = '';
207 }
208 $data['fallback8bitEncoding'] = $wgContLang->fallback8bitEncoding();
209
210 if ( wfReadOnly() ) {
211 $data['readonly'] = '';
212 $data['readonlyreason'] = wfReadOnlyReason();
213 }
214 if ( $GLOBALS['wgEnableWriteAPI'] ) {
215 $data['writeapi'] = '';
216 }
217
218 $tz = $GLOBALS['wgLocaltimezone'];
219 $offset = $GLOBALS['wgLocalTZoffset'];
220 if ( is_null( $tz ) ) {
221 $tz = 'UTC';
222 $offset = 0;
223 } elseif ( is_null( $offset ) ) {
224 $offset = 0;
225 }
226 $data['timezone'] = $tz;
227 $data['timeoffset'] = intval( $offset );
228 $data['articlepath'] = $GLOBALS['wgArticlePath'];
229 $data['scriptpath'] = $GLOBALS['wgScriptPath'];
230 $data['script'] = $GLOBALS['wgScript'];
231 $data['variantarticlepath'] = $GLOBALS['wgVariantArticlePath'];
232 $data['server'] = $GLOBALS['wgServer'];
233 $data['wikiid'] = wfWikiID();
234 $data['time'] = wfTimestamp( TS_ISO_8601, time() );
235
236 if ( $GLOBALS['wgMiserMode'] ) {
237 $data['misermode'] = '';
238 }
239
240 $data['maxuploadsize'] = UploadBase::getMaxUploadSize();
241
242 wfRunHooks( 'APIQuerySiteInfoGeneralInfo', array( $this, &$data ) );
243
244 return $this->getResult()->addValue( 'query', $property, $data );
245 }
246
247 protected function appendNamespaces( $property ) {
248 global $wgContLang;
249 $data = array();
250 foreach ( $wgContLang->getFormattedNamespaces() as $ns => $title ) {
251 $data[$ns] = array(
252 'id' => intval( $ns ),
253 'case' => MWNamespace::isCapitalized( $ns ) ? 'first-letter' : 'case-sensitive',
254 );
255 ApiResult::setContent( $data[$ns], $title );
256 $canonical = MWNamespace::getCanonicalName( $ns );
257
258 if ( MWNamespace::hasSubpages( $ns ) ) {
259 $data[$ns]['subpages'] = '';
260 }
261
262 if ( $canonical ) {
263 $data[$ns]['canonical'] = strtr( $canonical, '_', ' ' );
264 }
265
266 if ( MWNamespace::isContent( $ns ) ) {
267 $data[$ns]['content'] = '';
268 }
269
270 if ( MWNamespace::isNonincludable( $ns ) ) {
271 $data[$ns]['nonincludable'] = '';
272 }
273
274 $contentmodel = MWNamespace::getNamespaceContentModel( $ns );
275 if ( $contentmodel ) {
276 $data[$ns]['defaultcontentmodel'] = $contentmodel;
277 }
278 }
279
280 $this->getResult()->setIndexedTagName( $data, 'ns' );
281
282 return $this->getResult()->addValue( 'query', $property, $data );
283 }
284
285 protected function appendNamespaceAliases( $property ) {
286 global $wgNamespaceAliases, $wgContLang;
287 $aliases = array_merge( $wgNamespaceAliases, $wgContLang->getNamespaceAliases() );
288 $namespaces = $wgContLang->getNamespaces();
289 $data = array();
290 foreach ( $aliases as $title => $ns ) {
291 if ( $namespaces[$ns] == $title ) {
292 // Don't list duplicates
293 continue;
294 }
295 $item = array(
296 'id' => intval( $ns )
297 );
298 ApiResult::setContent( $item, strtr( $title, '_', ' ' ) );
299 $data[] = $item;
300 }
301
302 sort( $data );
303
304 $this->getResult()->setIndexedTagName( $data, 'ns' );
305
306 return $this->getResult()->addValue( 'query', $property, $data );
307 }
308
309 protected function appendSpecialPageAliases( $property ) {
310 global $wgContLang;
311 $data = array();
312 $aliases = $wgContLang->getSpecialPageAliases();
313 foreach ( SpecialPageFactory::getList() as $specialpage => $stuff ) {
314 if ( isset( $aliases[$specialpage] ) ) {
315 $arr = array( 'realname' => $specialpage, 'aliases' => $aliases[$specialpage] );
316 $this->getResult()->setIndexedTagName( $arr['aliases'], 'alias' );
317 $data[] = $arr;
318 }
319 }
320 $this->getResult()->setIndexedTagName( $data, 'specialpage' );
321
322 return $this->getResult()->addValue( 'query', $property, $data );
323 }
324
325 protected function appendMagicWords( $property ) {
326 global $wgContLang;
327 $data = array();
328 foreach ( $wgContLang->getMagicWords() as $magicword => $aliases ) {
329 $caseSensitive = array_shift( $aliases );
330 $arr = array( 'name' => $magicword, 'aliases' => $aliases );
331 if ( $caseSensitive ) {
332 $arr['case-sensitive'] = '';
333 }
334 $this->getResult()->setIndexedTagName( $arr['aliases'], 'alias' );
335 $data[] = $arr;
336 }
337 $this->getResult()->setIndexedTagName( $data, 'magicword' );
338
339 return $this->getResult()->addValue( 'query', $property, $data );
340 }
341
342 protected function appendInterwikiMap( $property, $filter ) {
343 $local = null;
344 if ( $filter === 'local' ) {
345 $local = 1;
346 } elseif ( $filter === '!local' ) {
347 $local = 0;
348 } elseif ( $filter ) {
349 ApiBase::dieDebug( __METHOD__, "Unknown filter=$filter" );
350 }
351
352 $params = $this->extractRequestParams();
353 $langCode = isset( $params['inlanguagecode'] ) ? $params['inlanguagecode'] : '';
354 $langNames = Language::fetchLanguageNames( $langCode );
355
356 $getPrefixes = Interwiki::getAllPrefixes( $local );
357 $data = array();
358
359 foreach ( $getPrefixes as $row ) {
360 $prefix = $row['iw_prefix'];
361 $val = array();
362 $val['prefix'] = $prefix;
363 if ( $row['iw_local'] == '1' ) {
364 $val['local'] = '';
365 }
366 if ( $row['iw_trans'] == '1' ) {
367 $val['trans'] = '';
368 }
369 if ( isset( $langNames[$prefix] ) ) {
370 $val['language'] = $langNames[$prefix];
371 }
372 $val['url'] = wfExpandUrl( $row['iw_url'], PROTO_CURRENT );
373 if ( isset( $row['iw_wikiid'] ) ) {
374 $val['wikiid'] = $row['iw_wikiid'];
375 }
376 if ( isset( $row['iw_api'] ) ) {
377 $val['api'] = $row['iw_api'];
378 }
379
380 $data[] = $val;
381 }
382
383 $this->getResult()->setIndexedTagName( $data, 'iw' );
384
385 return $this->getResult()->addValue( 'query', $property, $data );
386 }
387
388 protected function appendDbReplLagInfo( $property, $includeAll ) {
389 global $wgShowHostnames;
390 $data = array();
391 $lb = wfGetLB();
392 if ( $includeAll ) {
393 if ( !$wgShowHostnames ) {
394 $this->dieUsage( 'Cannot view all servers info unless $wgShowHostnames is true', 'includeAllDenied' );
395 }
396
397 $lags = $lb->getLagTimes();
398 foreach ( $lags as $i => $lag ) {
399 $data[] = array(
400 'host' => $lb->getServerName( $i ),
401 'lag' => $lag
402 );
403 }
404 } else {
405 list( , $lag, $index ) = $lb->getMaxLag();
406 $data[] = array(
407 'host' => $wgShowHostnames
408 ? $lb->getServerName( $index )
409 : '',
410 'lag' => intval( $lag )
411 );
412 }
413
414 $result = $this->getResult();
415 $result->setIndexedTagName( $data, 'db' );
416
417 return $this->getResult()->addValue( 'query', $property, $data );
418 }
419
420 protected function appendStatistics( $property ) {
421 global $wgDisableCounters;
422 $data = array();
423 $data['pages'] = intval( SiteStats::pages() );
424 $data['articles'] = intval( SiteStats::articles() );
425 if ( !$wgDisableCounters ) {
426 $data['views'] = intval( SiteStats::views() );
427 }
428 $data['edits'] = intval( SiteStats::edits() );
429 $data['images'] = intval( SiteStats::images() );
430 $data['users'] = intval( SiteStats::users() );
431 $data['activeusers'] = intval( SiteStats::activeUsers() );
432 $data['admins'] = intval( SiteStats::numberingroup( 'sysop' ) );
433 $data['jobs'] = intval( SiteStats::jobs() );
434
435 wfRunHooks( 'APIQuerySiteInfoStatisticsInfo', array( &$data ) );
436
437 return $this->getResult()->addValue( 'query', $property, $data );
438 }
439
440 protected function appendUserGroups( $property, $numberInGroup ) {
441 global $wgGroupPermissions, $wgAddGroups, $wgRemoveGroups;
442 global $wgGroupsAddToSelf, $wgGroupsRemoveFromSelf;
443
444 $data = array();
445 $result = $this->getResult();
446 foreach ( $wgGroupPermissions as $group => $permissions ) {
447 $arr = array(
448 'name' => $group,
449 'rights' => array_keys( $permissions, true ),
450 );
451
452 if ( $numberInGroup ) {
453 global $wgAutopromote;
454
455 if ( $group == 'user' ) {
456 $arr['number'] = SiteStats::users();
457 // '*' and autopromote groups have no size
458 } elseif ( $group !== '*' && !isset( $wgAutopromote[$group] ) ) {
459 $arr['number'] = SiteStats::numberInGroup( $group );
460 }
461 }
462
463 $groupArr = array(
464 'add' => $wgAddGroups,
465 'remove' => $wgRemoveGroups,
466 'add-self' => $wgGroupsAddToSelf,
467 'remove-self' => $wgGroupsRemoveFromSelf
468 );
469
470 foreach ( $groupArr as $type => $rights ) {
471 if ( isset( $rights[$group] ) ) {
472 $arr[$type] = $rights[$group];
473 $result->setIndexedTagName( $arr[$type], 'group' );
474 }
475 }
476
477 $result->setIndexedTagName( $arr['rights'], 'permission' );
478 $data[] = $arr;
479 }
480
481 $result->setIndexedTagName( $data, 'group' );
482
483 return $result->addValue( 'query', $property, $data );
484 }
485
486 protected function appendFileExtensions( $property ) {
487 global $wgFileExtensions;
488
489 $data = array();
490 foreach ( array_unique( $wgFileExtensions ) as $ext ) {
491 $data[] = array( 'ext' => $ext );
492 }
493 $this->getResult()->setIndexedTagName( $data, 'fe' );
494
495 return $this->getResult()->addValue( 'query', $property, $data );
496 }
497
498 protected function appendExtensions( $property ) {
499 global $wgExtensionCredits;
500 $data = array();
501 foreach ( $wgExtensionCredits as $type => $extensions ) {
502 foreach ( $extensions as $ext ) {
503 $ret = array();
504 $ret['type'] = $type;
505 if ( isset( $ext['name'] ) ) {
506 $ret['name'] = $ext['name'];
507 }
508 if ( isset( $ext['description'] ) ) {
509 $ret['description'] = $ext['description'];
510 }
511 if ( isset( $ext['descriptionmsg'] ) ) {
512 // Can be a string or array( key, param1, param2, ... )
513 if ( is_array( $ext['descriptionmsg'] ) ) {
514 $ret['descriptionmsg'] = $ext['descriptionmsg'][0];
515 $ret['descriptionmsgparams'] = array_slice( $ext['descriptionmsg'], 1 );
516 $this->getResult()->setIndexedTagName( $ret['descriptionmsgparams'], 'param' );
517 } else {
518 $ret['descriptionmsg'] = $ext['descriptionmsg'];
519 }
520 }
521 if ( isset( $ext['author'] ) ) {
522 $ret['author'] = is_array( $ext['author'] ) ?
523 implode( ', ', $ext['author'] ) : $ext['author'];
524 }
525 if ( isset( $ext['url'] ) ) {
526 $ret['url'] = $ext['url'];
527 }
528 if ( isset( $ext['version'] ) ) {
529 $ret['version'] = $ext['version'];
530 } elseif ( isset( $ext['svn-revision'] ) &&
531 preg_match( '/\$(?:Rev|LastChangedRevision|Revision): *(\d+)/',
532 $ext['svn-revision'], $m )
533 ) {
534 $ret['version'] = 'r' . $m[1];
535 }
536 $data[] = $ret;
537 }
538 }
539
540 $this->getResult()->setIndexedTagName( $data, 'ext' );
541
542 return $this->getResult()->addValue( 'query', $property, $data );
543 }
544
545 protected function appendRightsInfo( $property ) {
546 global $wgRightsPage, $wgRightsUrl, $wgRightsText;
547 $title = Title::newFromText( $wgRightsPage );
548 $url = $title ? wfExpandUrl( $title->getFullURL(), PROTO_CURRENT ) : $wgRightsUrl;
549 $text = $wgRightsText;
550 if ( !$text && $title ) {
551 $text = $title->getPrefixedText();
552 }
553
554 $data = array(
555 'url' => $url ? $url : '',
556 'text' => $text ? $text : ''
557 );
558
559 return $this->getResult()->addValue( 'query', $property, $data );
560 }
561
562 public function appendLanguages( $property ) {
563 $params = $this->extractRequestParams();
564 $langCode = isset( $params['inlanguagecode'] ) ? $params['inlanguagecode'] : '';
565 $langNames = Language::fetchLanguageNames( $langCode );
566
567 $data = array();
568
569 foreach ( $langNames as $code => $name ) {
570 $lang = array( 'code' => $code );
571 ApiResult::setContent( $lang, $name );
572 $data[] = $lang;
573 }
574 $this->getResult()->setIndexedTagName( $data, 'lang' );
575
576 return $this->getResult()->addValue( 'query', $property, $data );
577 }
578
579 public function appendSkins( $property ) {
580 $data = array();
581 $usable = Skin::getUsableSkins();
582 $default = Skin::normalizeKey( 'default' );
583 foreach ( Skin::getSkinNames() as $name => $displayName ) {
584 $skin = array( 'code' => $name );
585 ApiResult::setContent( $skin, $displayName );
586 if ( !isset( $usable[$name] ) ) {
587 $skin['unusable'] = '';
588 }
589 if ( $name === $default ) {
590 $skin['default'] = '';
591 }
592 $data[] = $skin;
593 }
594 $this->getResult()->setIndexedTagName( $data, 'skin' );
595
596 return $this->getResult()->addValue( 'query', $property, $data );
597 }
598
599 public function appendExtensionTags( $property ) {
600 global $wgParser;
601 $wgParser->firstCallInit();
602 $tags = array_map( array( $this, 'formatParserTags' ), $wgParser->getTags() );
603 $this->getResult()->setIndexedTagName( $tags, 't' );
604
605 return $this->getResult()->addValue( 'query', $property, $tags );
606 }
607
608 public function appendFunctionHooks( $property ) {
609 global $wgParser;
610 $wgParser->firstCallInit();
611 $hooks = $wgParser->getFunctionHooks();
612 $this->getResult()->setIndexedTagName( $hooks, 'h' );
613
614 return $this->getResult()->addValue( 'query', $property, $hooks );
615 }
616
617 public function appendVariables( $property ) {
618 $variables = MagicWord::getVariableIDs();
619 $this->getResult()->setIndexedTagName( $variables, 'v' );
620
621 return $this->getResult()->addValue( 'query', $property, $variables );
622 }
623
624 public function appendProtocols( $property ) {
625 global $wgUrlProtocols;
626 // Make a copy of the global so we don't try to set the _element key of it - bug 45130
627 $protocols = array_values( $wgUrlProtocols );
628 $this->getResult()->setIndexedTagName( $protocols, 'p' );
629
630 return $this->getResult()->addValue( 'query', $property, $protocols );
631 }
632
633 private function formatParserTags( $item ) {
634 return "<{$item}>";
635 }
636
637 public function appendSubscribedHooks( $property ) {
638 global $wgHooks;
639 $myWgHooks = $wgHooks;
640 ksort( $myWgHooks );
641
642 $data = array();
643 foreach ( $myWgHooks as $hook => $hooks ) {
644 $arr = array(
645 'name' => $hook,
646 'subscribers' => array_map( array( 'SpecialVersion', 'arrayToString' ), $hooks ),
647 );
648
649 $this->getResult()->setIndexedTagName( $arr['subscribers'], 's' );
650 $data[] = $arr;
651 }
652
653 $this->getResult()->setIndexedTagName( $data, 'hook' );
654
655 return $this->getResult()->addValue( 'query', $property, $data );
656 }
657
658 public function getCacheMode( $params ) {
659 return 'public';
660 }
661
662 public function getAllowedParams() {
663 return array(
664 'prop' => array(
665 ApiBase::PARAM_DFLT => 'general',
666 ApiBase::PARAM_ISMULTI => true,
667 ApiBase::PARAM_TYPE => array(
668 'general',
669 'namespaces',
670 'namespacealiases',
671 'specialpagealiases',
672 'magicwords',
673 'interwikimap',
674 'dbrepllag',
675 'statistics',
676 'usergroups',
677 'extensions',
678 'fileextensions',
679 'rightsinfo',
680 'languages',
681 'skins',
682 'extensiontags',
683 'functionhooks',
684 'showhooks',
685 'variables',
686 'protocols',
687 )
688 ),
689 'filteriw' => array(
690 ApiBase::PARAM_TYPE => array(
691 'local',
692 '!local',
693 )
694 ),
695 'showalldb' => false,
696 'numberingroup' => false,
697 'inlanguagecode' => null,
698 );
699 }
700
701 public function getParamDescription() {
702 $p = $this->getModulePrefix();
703
704 return array(
705 'prop' => array(
706 'Which sysinfo properties to get:',
707 ' general - Overall system information',
708 ' namespaces - List of registered namespaces and their canonical names',
709 ' namespacealiases - List of registered namespace aliases',
710 ' specialpagealiases - List of special page aliases',
711 ' magicwords - List of magic words and their aliases',
712 ' statistics - Returns site statistics',
713 ' interwikimap - Returns interwiki map ' .
714 "(optionally filtered, (optionally localised by using {$p}inlanguagecode))",
715 ' dbrepllag - Returns database server with the highest replication lag',
716 ' usergroups - Returns user groups and the associated permissions',
717 ' extensions - Returns extensions installed on the wiki',
718 ' fileextensions - Returns list of file extensions allowed to be uploaded',
719 ' rightsinfo - Returns wiki rights (license) information if available',
720 ' languages - Returns a list of languages MediaWiki supports' .
721 "(optionally localised by using {$p}inlanguagecode)",
722 ' skins - Returns a list of all enabled skins',
723 ' extensiontags - Returns a list of parser extension tags',
724 ' functionhooks - Returns a list of parser function hooks',
725 ' showhooks - Returns a list of all subscribed hooks (contents of $wgHooks)',
726 ' variables - Returns a list of variable IDs',
727 ' protocols - Returns a list of protocols that are allowed in external links.',
728 ),
729 'filteriw' => 'Return only local or only nonlocal entries of the interwiki map',
730 'showalldb' => 'List all database servers, not just the one lagging the most',
731 'numberingroup' => 'Lists the number of users in user groups',
732 'inlanguagecode' => 'Language code for localised language names (best effort, use CLDR extension)',
733 );
734 }
735
736 public function getDescription() {
737 return 'Return general information about the site';
738 }
739
740 public function getPossibleErrors() {
741 return array_merge( parent::getPossibleErrors(), array( array(
742 'code' => 'includeAllDenied',
743 'info' => 'Cannot view all servers info unless $wgShowHostnames is true'
744 ), ) );
745 }
746
747 public function getExamples() {
748 return array(
749 'api.php?action=query&meta=siteinfo&siprop=general|namespaces|namespacealiases|statistics',
750 'api.php?action=query&meta=siteinfo&siprop=interwikimap&sifilteriw=local',
751 'api.php?action=query&meta=siteinfo&siprop=dbrepllag&sishowalldb=',
752 );
753 }
754
755 public function getHelpUrls() {
756 return 'https://www.mediawiki.org/wiki/API:Meta#siteinfo_.2F_si';
757 }
758 }