ApiQuerySiteinfo: Add prop=restrictions for protection information
[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 'restrictions':
82 $fit = $this->appendRestrictions( $p );
83 break;
84 case 'languages':
85 $fit = $this->appendLanguages( $p );
86 break;
87 case 'skins':
88 $fit = $this->appendSkins( $p );
89 break;
90 case 'extensiontags':
91 $fit = $this->appendExtensionTags( $p );
92 break;
93 case 'functionhooks':
94 $fit = $this->appendFunctionHooks( $p );
95 break;
96 case 'showhooks':
97 $fit = $this->appendSubscribedHooks( $p );
98 break;
99 case 'variables':
100 $fit = $this->appendVariables( $p );
101 break;
102 case 'protocols':
103 $fit = $this->appendProtocols( $p );
104 break;
105 case 'defaultoptions':
106 $fit = $this->appendDefaultOptions( $p );
107 break;
108 default:
109 ApiBase::dieDebug( __METHOD__, "Unknown prop=$p" );
110 }
111 if ( !$fit ) {
112 // Abuse siprop as a query-continue parameter
113 // and set it to all unprocessed props
114 $this->setContinueEnumParameter( 'prop', implode( '|',
115 array_diff( $params['prop'], $done ) ) );
116 break;
117 }
118 $done[] = $p;
119 }
120 }
121
122 protected function appendGeneralInfo( $property ) {
123 global $wgContLang, $wgDisableLangConversion, $wgDisableTitleConversion;
124
125 $data = array();
126 $mainPage = Title::newMainPage();
127 $data['mainpage'] = $mainPage->getPrefixedText();
128 $data['base'] = wfExpandUrl( $mainPage->getFullURL(), PROTO_CURRENT );
129 $data['sitename'] = $GLOBALS['wgSitename'];
130
131 // wgLogo can either be a relative or an absolute path
132 // make sure we always return an absolute path
133 $data['logo'] = wfExpandUrl( $GLOBALS['wgLogo'], PROTO_RELATIVE );
134
135 $data['generator'] = "MediaWiki {$GLOBALS['wgVersion']}";
136 $data['phpversion'] = phpversion();
137 $data['phpsapi'] = PHP_SAPI;
138 $data['dbtype'] = $GLOBALS['wgDBtype'];
139 $data['dbversion'] = $this->getDB()->getServerVersion();
140
141 $allowFrom = array( '' );
142 $allowException = true;
143 if ( !$GLOBALS['wgAllowExternalImages'] ) {
144 if ( $GLOBALS['wgEnableImageWhitelist'] ) {
145 $data['imagewhitelistenabled'] = '';
146 }
147 $allowFrom = $GLOBALS['wgAllowExternalImagesFrom'];
148 $allowException = !empty( $allowFrom );
149 }
150 if ( $allowException ) {
151 $data['externalimages'] = (array)$allowFrom;
152 $this->getResult()->setIndexedTagName( $data['externalimages'], 'prefix' );
153 }
154
155 if ( !$wgDisableLangConversion ) {
156 $data['langconversion'] = '';
157 }
158
159 if ( !$wgDisableTitleConversion ) {
160 $data['titleconversion'] = '';
161 }
162
163 if ( $wgContLang->linkPrefixExtension() ) {
164 $linkPrefixCharset = $wgContLang->linkPrefixCharset();
165 $data['linkprefixcharset'] = $linkPrefixCharset;
166 // For backwards compatability
167 $data['linkprefix'] = "/^((?>.*[^$linkPrefixCharset]|))(.+)$/sDu";
168 } else {
169 $data['linkprefixcharset'] = '';
170 $data['linkprefix'] = '';
171 }
172
173 $linktrail = $wgContLang->linkTrail();
174 if ( $linktrail ) {
175 $data['linktrail'] = $linktrail;
176 } else {
177 $data['linktrail'] = '';
178 }
179
180 $git = SpecialVersion::getGitHeadSha1( $GLOBALS['IP'] );
181 if ( $git ) {
182 $data['git-hash'] = $git;
183 } else {
184 $svn = SpecialVersion::getSvnRevision( $GLOBALS['IP'] );
185 if ( $svn ) {
186 $data['rev'] = $svn;
187 }
188 }
189
190 // 'case-insensitive' option is reserved for future
191 $data['case'] = $GLOBALS['wgCapitalLinks'] ? 'first-letter' : 'case-sensitive';
192
193 $data['lang'] = $GLOBALS['wgLanguageCode'];
194
195 $fallbacks = array();
196 foreach ( $wgContLang->getFallbackLanguages() as $code ) {
197 $fallbacks[] = array( 'code' => $code );
198 }
199 $data['fallback'] = $fallbacks;
200 $this->getResult()->setIndexedTagName( $data['fallback'], 'lang' );
201
202 if ( $wgContLang->hasVariants() ) {
203 $variants = array();
204 foreach ( $wgContLang->getVariants() as $code ) {
205 $variants[] = array(
206 'code' => $code,
207 'name' => $wgContLang->getVariantname( $code ),
208 );
209 }
210 $data['variants'] = $variants;
211 $this->getResult()->setIndexedTagName( $data['variants'], 'lang' );
212 }
213
214 if ( $wgContLang->isRTL() ) {
215 $data['rtl'] = '';
216 }
217 $data['fallback8bitEncoding'] = $wgContLang->fallback8bitEncoding();
218
219 if ( wfReadOnly() ) {
220 $data['readonly'] = '';
221 $data['readonlyreason'] = wfReadOnlyReason();
222 }
223 if ( $GLOBALS['wgEnableWriteAPI'] ) {
224 $data['writeapi'] = '';
225 }
226
227 $tz = $GLOBALS['wgLocaltimezone'];
228 $offset = $GLOBALS['wgLocalTZoffset'];
229 if ( is_null( $tz ) ) {
230 $tz = 'UTC';
231 $offset = 0;
232 } elseif ( is_null( $offset ) ) {
233 $offset = 0;
234 }
235 $data['timezone'] = $tz;
236 $data['timeoffset'] = intval( $offset );
237 $data['articlepath'] = $GLOBALS['wgArticlePath'];
238 $data['scriptpath'] = $GLOBALS['wgScriptPath'];
239 $data['script'] = $GLOBALS['wgScript'];
240 $data['variantarticlepath'] = $GLOBALS['wgVariantArticlePath'];
241 $data['server'] = $GLOBALS['wgServer'];
242 $data['wikiid'] = wfWikiID();
243 $data['time'] = wfTimestamp( TS_ISO_8601, time() );
244
245 if ( $GLOBALS['wgMiserMode'] ) {
246 $data['misermode'] = '';
247 }
248
249 $data['maxuploadsize'] = UploadBase::getMaxUploadSize();
250
251 $data['thumblimits'] = $GLOBALS['wgThumbLimits'];
252 $this->getResult()->setIndexedTagName( $data['thumblimits'], 'limit' );
253 $data['imagelimits'] = array();
254 $this->getResult()->setIndexedTagName( $data['imagelimits'], 'limit' );
255 foreach ( $GLOBALS['wgImageLimits'] as $k => $limit ) {
256 $data['imagelimits'][$k] = array( 'width' => $limit[0], 'height' => $limit[1] );
257 }
258
259 if ( !empty( $GLOBALS['wgFavicon'] ) ) {
260 // wgFavicon can either be a relative or an absolute path
261 // make sure we always return an absolute path
262 $data['favicon'] = wfExpandUrl( $GLOBALS['wgFavicon'], PROTO_RELATIVE );
263 }
264
265 wfRunHooks( 'APIQuerySiteInfoGeneralInfo', array( $this, &$data ) );
266
267 return $this->getResult()->addValue( 'query', $property, $data );
268 }
269
270 protected function appendNamespaces( $property ) {
271 global $wgContLang;
272 $data = array();
273 foreach ( $wgContLang->getFormattedNamespaces() as $ns => $title ) {
274 $data[$ns] = array(
275 'id' => intval( $ns ),
276 'case' => MWNamespace::isCapitalized( $ns ) ? 'first-letter' : 'case-sensitive',
277 );
278 ApiResult::setContent( $data[$ns], $title );
279 $canonical = MWNamespace::getCanonicalName( $ns );
280
281 if ( MWNamespace::hasSubpages( $ns ) ) {
282 $data[$ns]['subpages'] = '';
283 }
284
285 if ( $canonical ) {
286 $data[$ns]['canonical'] = strtr( $canonical, '_', ' ' );
287 }
288
289 if ( MWNamespace::isContent( $ns ) ) {
290 $data[$ns]['content'] = '';
291 }
292
293 if ( MWNamespace::isNonincludable( $ns ) ) {
294 $data[$ns]['nonincludable'] = '';
295 }
296
297 $contentmodel = MWNamespace::getNamespaceContentModel( $ns );
298 if ( $contentmodel ) {
299 $data[$ns]['defaultcontentmodel'] = $contentmodel;
300 }
301 }
302
303 $this->getResult()->setIndexedTagName( $data, 'ns' );
304
305 return $this->getResult()->addValue( 'query', $property, $data );
306 }
307
308 protected function appendNamespaceAliases( $property ) {
309 global $wgNamespaceAliases, $wgContLang;
310 $aliases = array_merge( $wgNamespaceAliases, $wgContLang->getNamespaceAliases() );
311 $namespaces = $wgContLang->getNamespaces();
312 $data = array();
313 foreach ( $aliases as $title => $ns ) {
314 if ( $namespaces[$ns] == $title ) {
315 // Don't list duplicates
316 continue;
317 }
318 $item = array(
319 'id' => intval( $ns )
320 );
321 ApiResult::setContent( $item, strtr( $title, '_', ' ' ) );
322 $data[] = $item;
323 }
324
325 sort( $data );
326
327 $this->getResult()->setIndexedTagName( $data, 'ns' );
328
329 return $this->getResult()->addValue( 'query', $property, $data );
330 }
331
332 protected function appendSpecialPageAliases( $property ) {
333 global $wgContLang;
334 $data = array();
335 $aliases = $wgContLang->getSpecialPageAliases();
336 foreach ( SpecialPageFactory::getList() as $specialpage => $stuff ) {
337 if ( isset( $aliases[$specialpage] ) ) {
338 $arr = array( 'realname' => $specialpage, 'aliases' => $aliases[$specialpage] );
339 $this->getResult()->setIndexedTagName( $arr['aliases'], 'alias' );
340 $data[] = $arr;
341 }
342 }
343 $this->getResult()->setIndexedTagName( $data, 'specialpage' );
344
345 return $this->getResult()->addValue( 'query', $property, $data );
346 }
347
348 protected function appendMagicWords( $property ) {
349 global $wgContLang;
350 $data = array();
351 foreach ( $wgContLang->getMagicWords() as $magicword => $aliases ) {
352 $caseSensitive = array_shift( $aliases );
353 $arr = array( 'name' => $magicword, 'aliases' => $aliases );
354 if ( $caseSensitive ) {
355 $arr['case-sensitive'] = '';
356 }
357 $this->getResult()->setIndexedTagName( $arr['aliases'], 'alias' );
358 $data[] = $arr;
359 }
360 $this->getResult()->setIndexedTagName( $data, 'magicword' );
361
362 return $this->getResult()->addValue( 'query', $property, $data );
363 }
364
365 protected function appendInterwikiMap( $property, $filter ) {
366 $local = null;
367 if ( $filter === 'local' ) {
368 $local = 1;
369 } elseif ( $filter === '!local' ) {
370 $local = 0;
371 } elseif ( $filter ) {
372 ApiBase::dieDebug( __METHOD__, "Unknown filter=$filter" );
373 }
374
375 $params = $this->extractRequestParams();
376 $langCode = isset( $params['inlanguagecode'] ) ? $params['inlanguagecode'] : '';
377 $langNames = Language::fetchLanguageNames( $langCode );
378
379 $getPrefixes = Interwiki::getAllPrefixes( $local );
380 $data = array();
381
382 foreach ( $getPrefixes as $row ) {
383 $prefix = $row['iw_prefix'];
384 $val = array();
385 $val['prefix'] = $prefix;
386 if ( $row['iw_local'] == '1' ) {
387 $val['local'] = '';
388 }
389 if ( $row['iw_trans'] == '1' ) {
390 $val['trans'] = '';
391 }
392 if ( isset( $langNames[$prefix] ) ) {
393 $val['language'] = $langNames[$prefix];
394 }
395 $val['url'] = wfExpandUrl( $row['iw_url'], PROTO_CURRENT );
396 if ( isset( $row['iw_wikiid'] ) ) {
397 $val['wikiid'] = $row['iw_wikiid'];
398 }
399 if ( isset( $row['iw_api'] ) ) {
400 $val['api'] = $row['iw_api'];
401 }
402
403 $data[] = $val;
404 }
405
406 $this->getResult()->setIndexedTagName( $data, 'iw' );
407
408 return $this->getResult()->addValue( 'query', $property, $data );
409 }
410
411 protected function appendDbReplLagInfo( $property, $includeAll ) {
412 global $wgShowHostnames;
413 $data = array();
414 $lb = wfGetLB();
415 if ( $includeAll ) {
416 if ( !$wgShowHostnames ) {
417 $this->dieUsage(
418 'Cannot view all servers info unless $wgShowHostnames is true',
419 'includeAllDenied'
420 );
421 }
422
423 $lags = $lb->getLagTimes();
424 foreach ( $lags as $i => $lag ) {
425 $data[] = array(
426 'host' => $lb->getServerName( $i ),
427 'lag' => $lag
428 );
429 }
430 } else {
431 list( , $lag, $index ) = $lb->getMaxLag();
432 $data[] = array(
433 'host' => $wgShowHostnames
434 ? $lb->getServerName( $index )
435 : '',
436 'lag' => intval( $lag )
437 );
438 }
439
440 $result = $this->getResult();
441 $result->setIndexedTagName( $data, 'db' );
442
443 return $this->getResult()->addValue( 'query', $property, $data );
444 }
445
446 protected function appendStatistics( $property ) {
447 global $wgDisableCounters;
448 $data = array();
449 $data['pages'] = intval( SiteStats::pages() );
450 $data['articles'] = intval( SiteStats::articles() );
451 if ( !$wgDisableCounters ) {
452 $data['views'] = intval( SiteStats::views() );
453 }
454 $data['edits'] = intval( SiteStats::edits() );
455 $data['images'] = intval( SiteStats::images() );
456 $data['users'] = intval( SiteStats::users() );
457 $data['activeusers'] = intval( SiteStats::activeUsers() );
458 $data['admins'] = intval( SiteStats::numberingroup( 'sysop' ) );
459 $data['jobs'] = intval( SiteStats::jobs() );
460
461 wfRunHooks( 'APIQuerySiteInfoStatisticsInfo', array( &$data ) );
462
463 return $this->getResult()->addValue( 'query', $property, $data );
464 }
465
466 protected function appendUserGroups( $property, $numberInGroup ) {
467 global $wgGroupPermissions, $wgAddGroups, $wgRemoveGroups;
468 global $wgGroupsAddToSelf, $wgGroupsRemoveFromSelf;
469
470 $data = array();
471 $result = $this->getResult();
472 foreach ( $wgGroupPermissions as $group => $permissions ) {
473 $arr = array(
474 'name' => $group,
475 'rights' => array_keys( $permissions, true ),
476 );
477
478 if ( $numberInGroup ) {
479 global $wgAutopromote;
480
481 if ( $group == 'user' ) {
482 $arr['number'] = SiteStats::users();
483 // '*' and autopromote groups have no size
484 } elseif ( $group !== '*' && !isset( $wgAutopromote[$group] ) ) {
485 $arr['number'] = SiteStats::numberInGroup( $group );
486 }
487 }
488
489 $groupArr = array(
490 'add' => $wgAddGroups,
491 'remove' => $wgRemoveGroups,
492 'add-self' => $wgGroupsAddToSelf,
493 'remove-self' => $wgGroupsRemoveFromSelf
494 );
495
496 foreach ( $groupArr as $type => $rights ) {
497 if ( isset( $rights[$group] ) ) {
498 $arr[$type] = $rights[$group];
499 $result->setIndexedTagName( $arr[$type], 'group' );
500 }
501 }
502
503 $result->setIndexedTagName( $arr['rights'], 'permission' );
504 $data[] = $arr;
505 }
506
507 $result->setIndexedTagName( $data, 'group' );
508
509 return $result->addValue( 'query', $property, $data );
510 }
511
512 protected function appendFileExtensions( $property ) {
513 global $wgFileExtensions;
514
515 $data = array();
516 foreach ( array_unique( $wgFileExtensions ) as $ext ) {
517 $data[] = array( 'ext' => $ext );
518 }
519 $this->getResult()->setIndexedTagName( $data, 'fe' );
520
521 return $this->getResult()->addValue( 'query', $property, $data );
522 }
523
524 protected function appendExtensions( $property ) {
525 global $wgExtensionCredits;
526 $data = array();
527 foreach ( $wgExtensionCredits as $type => $extensions ) {
528 foreach ( $extensions as $ext ) {
529 $ret = array();
530 $ret['type'] = $type;
531 if ( isset( $ext['name'] ) ) {
532 $ret['name'] = $ext['name'];
533 }
534 if ( isset( $ext['description'] ) ) {
535 $ret['description'] = $ext['description'];
536 }
537 if ( isset( $ext['descriptionmsg'] ) ) {
538 // Can be a string or array( key, param1, param2, ... )
539 if ( is_array( $ext['descriptionmsg'] ) ) {
540 $ret['descriptionmsg'] = $ext['descriptionmsg'][0];
541 $ret['descriptionmsgparams'] = array_slice( $ext['descriptionmsg'], 1 );
542 $this->getResult()->setIndexedTagName( $ret['descriptionmsgparams'], 'param' );
543 } else {
544 $ret['descriptionmsg'] = $ext['descriptionmsg'];
545 }
546 }
547 if ( isset( $ext['author'] ) ) {
548 $ret['author'] = is_array( $ext['author'] ) ?
549 implode( ', ', $ext['author'] ) : $ext['author'];
550 }
551 if ( isset( $ext['url'] ) ) {
552 $ret['url'] = $ext['url'];
553 }
554 if ( isset( $ext['version'] ) ) {
555 $ret['version'] = $ext['version'];
556 } elseif ( isset( $ext['svn-revision'] ) &&
557 preg_match( '/\$(?:Rev|LastChangedRevision|Revision): *(\d+)/',
558 $ext['svn-revision'], $m )
559 ) {
560 $ret['version'] = 'r' . $m[1];
561 }
562 if ( isset( $ext['path'] ) ) {
563 $extensionPath = dirname( $ext['path'] );
564 $gitInfo = new GitInfo( $extensionPath );
565 $vcsVersion = $gitInfo->getHeadSHA1();
566 if ( $vcsVersion !== false ) {
567 $ret['vcs-system'] = 'git';
568 $ret['vcs-version'] = $vcsVersion;
569 $ret['vcs-url'] = $gitInfo->getHeadViewUrl();
570 $ret['vcs-date'] = wfTimestamp( TS_ISO_8601, $gitInfo->getHeadCommitDate() );
571 } else {
572 $svnInfo = SpecialVersion::getSvnInfo( $extensionPath );
573 if ( $svnInfo !== false ) {
574 $ret['vcs-system'] = 'svn';
575 $ret['vcs-version'] = $svnInfo['checkout-rev'];
576 $ret['vcs-url'] = isset( $svnInfo['viewvc-url'] ) ? $svnInfo['viewvc-url'] : '';
577 }
578 }
579
580 if ( SpecialVersion::getExtLicenseFileName( $extensionPath ) ) {
581 $ret['license-name'] = isset( $ext['license-name'] ) ? $ext['license-name'] : '';
582 $ret['license'] = SpecialPage::getTitleFor(
583 'Version',
584 "License/{$ext['name']}"
585 )->getLinkURL();
586 }
587
588 if ( SpecialVersion::getExtAuthorsFileName( $extensionPath ) ) {
589 $ret['credits'] = SpecialPage::getTitleFor(
590 'Version',
591 "Credits/{$ext['name']}"
592 )->getLinkURL();
593 }
594 }
595 $data[] = $ret;
596 }
597 }
598
599 $this->getResult()->setIndexedTagName( $data, 'ext' );
600
601 return $this->getResult()->addValue( 'query', $property, $data );
602 }
603
604 protected function appendRightsInfo( $property ) {
605 global $wgRightsPage, $wgRightsUrl, $wgRightsText;
606 $title = Title::newFromText( $wgRightsPage );
607 $url = $title ? wfExpandUrl( $title->getFullURL(), PROTO_CURRENT ) : $wgRightsUrl;
608 $text = $wgRightsText;
609 if ( !$text && $title ) {
610 $text = $title->getPrefixedText();
611 }
612
613 $data = array(
614 'url' => $url ? $url : '',
615 'text' => $text ? $text : ''
616 );
617
618 return $this->getResult()->addValue( 'query', $property, $data );
619 }
620
621 protected function appendRestrictions( $property ) {
622 global $wgRestrictionTypes, $wgRestrictionLevels,
623 $wgCascadingRestrictionLevels, $wgSemiprotectedRestrictionLevels;
624
625 $data = array(
626 'types' => $wgRestrictionTypes,
627 'levels' => $wgRestrictionLevels,
628 'cascadinglevels' => $wgCascadingRestrictionLevels,
629 'semiprotectedlevels' => $wgSemiprotectedRestrictionLevels,
630 );
631
632 $this->getResult()->setIndexedTagName( $data['types'], 'type' );
633 $this->getResult()->setIndexedTagName( $data['levels'], 'level' );
634 $this->getResult()->setIndexedTagName( $data['cascadinglevels'], 'level' );
635 $this->getResult()->setIndexedTagName( $data['semiprotectedlevels'], 'level' );
636
637 return $this->getResult()->addValue( 'query', $property, $data );
638 }
639
640 public function appendLanguages( $property ) {
641 $params = $this->extractRequestParams();
642 $langCode = isset( $params['inlanguagecode'] ) ? $params['inlanguagecode'] : '';
643 $langNames = Language::fetchLanguageNames( $langCode );
644
645 $data = array();
646
647 foreach ( $langNames as $code => $name ) {
648 $lang = array( 'code' => $code );
649 ApiResult::setContent( $lang, $name );
650 $data[] = $lang;
651 }
652 $this->getResult()->setIndexedTagName( $data, 'lang' );
653
654 return $this->getResult()->addValue( 'query', $property, $data );
655 }
656
657 public function appendSkins( $property ) {
658 $data = array();
659 $usable = Skin::getUsableSkins();
660 $default = Skin::normalizeKey( 'default' );
661 foreach ( Skin::getSkinNames() as $name => $displayName ) {
662 $skin = array( 'code' => $name );
663 ApiResult::setContent( $skin, $displayName );
664 if ( !isset( $usable[$name] ) ) {
665 $skin['unusable'] = '';
666 }
667 if ( $name === $default ) {
668 $skin['default'] = '';
669 }
670 $data[] = $skin;
671 }
672 $this->getResult()->setIndexedTagName( $data, 'skin' );
673
674 return $this->getResult()->addValue( 'query', $property, $data );
675 }
676
677 public function appendExtensionTags( $property ) {
678 global $wgParser;
679 $wgParser->firstCallInit();
680 $tags = array_map( array( $this, 'formatParserTags' ), $wgParser->getTags() );
681 $this->getResult()->setIndexedTagName( $tags, 't' );
682
683 return $this->getResult()->addValue( 'query', $property, $tags );
684 }
685
686 public function appendFunctionHooks( $property ) {
687 global $wgParser;
688 $wgParser->firstCallInit();
689 $hooks = $wgParser->getFunctionHooks();
690 $this->getResult()->setIndexedTagName( $hooks, 'h' );
691
692 return $this->getResult()->addValue( 'query', $property, $hooks );
693 }
694
695 public function appendVariables( $property ) {
696 $variables = MagicWord::getVariableIDs();
697 $this->getResult()->setIndexedTagName( $variables, 'v' );
698
699 return $this->getResult()->addValue( 'query', $property, $variables );
700 }
701
702 public function appendProtocols( $property ) {
703 global $wgUrlProtocols;
704 // Make a copy of the global so we don't try to set the _element key of it - bug 45130
705 $protocols = array_values( $wgUrlProtocols );
706 $this->getResult()->setIndexedTagName( $protocols, 'p' );
707
708 return $this->getResult()->addValue( 'query', $property, $protocols );
709 }
710
711 public function appendDefaultOptions( $property ) {
712 return $this->getResult()->addValue( 'query', $property, User::getDefaultOptions() );
713 }
714
715 private function formatParserTags( $item ) {
716 return "<{$item}>";
717 }
718
719 public function appendSubscribedHooks( $property ) {
720 global $wgHooks;
721 $myWgHooks = $wgHooks;
722 ksort( $myWgHooks );
723
724 $data = array();
725 foreach ( $myWgHooks as $hook => $hooks ) {
726 $arr = array(
727 'name' => $hook,
728 'subscribers' => array_map( array( 'SpecialVersion', 'arrayToString' ), $hooks ),
729 );
730
731 $this->getResult()->setIndexedTagName( $arr['subscribers'], 's' );
732 $data[] = $arr;
733 }
734
735 $this->getResult()->setIndexedTagName( $data, 'hook' );
736
737 return $this->getResult()->addValue( 'query', $property, $data );
738 }
739
740 public function getCacheMode( $params ) {
741 return 'public';
742 }
743
744 public function getAllowedParams() {
745 return array(
746 'prop' => array(
747 ApiBase::PARAM_DFLT => 'general',
748 ApiBase::PARAM_ISMULTI => true,
749 ApiBase::PARAM_TYPE => array(
750 'general',
751 'namespaces',
752 'namespacealiases',
753 'specialpagealiases',
754 'magicwords',
755 'interwikimap',
756 'dbrepllag',
757 'statistics',
758 'usergroups',
759 'extensions',
760 'fileextensions',
761 'rightsinfo',
762 'restrictions',
763 'languages',
764 'skins',
765 'extensiontags',
766 'functionhooks',
767 'showhooks',
768 'variables',
769 'protocols',
770 'defaultoptions',
771 )
772 ),
773 'filteriw' => array(
774 ApiBase::PARAM_TYPE => array(
775 'local',
776 '!local',
777 )
778 ),
779 'showalldb' => false,
780 'numberingroup' => false,
781 'inlanguagecode' => null,
782 );
783 }
784
785 public function getParamDescription() {
786 $p = $this->getModulePrefix();
787
788 return array(
789 'prop' => array(
790 'Which sysinfo properties to get:',
791 ' general - Overall system information',
792 ' namespaces - List of registered namespaces and their canonical names',
793 ' namespacealiases - List of registered namespace aliases',
794 ' specialpagealiases - List of special page aliases',
795 ' magicwords - List of magic words and their aliases',
796 ' statistics - Returns site statistics',
797 ' interwikimap - Returns interwiki map ' .
798 "(optionally filtered, (optionally localised by using {$p}inlanguagecode))",
799 ' dbrepllag - Returns database server with the highest replication lag',
800 ' usergroups - Returns user groups and the associated permissions',
801 ' extensions - Returns extensions installed on the wiki',
802 ' fileextensions - Returns list of file extensions allowed to be uploaded',
803 ' rightsinfo - Returns wiki rights (license) information if available',
804 ' restrictions - Returns information on available restriction (protection) types',
805 ' languages - Returns a list of languages MediaWiki supports' .
806 "(optionally localised by using {$p}inlanguagecode)",
807 ' skins - Returns a list of all enabled skins',
808 ' extensiontags - Returns a list of parser extension tags',
809 ' functionhooks - Returns a list of parser function hooks',
810 ' showhooks - Returns a list of all subscribed hooks (contents of $wgHooks)',
811 ' variables - Returns a list of variable IDs',
812 ' protocols - Returns a list of protocols that are allowed in external links.',
813 ' defaultoptions - Returns the default values for user preferences.',
814 ),
815 'filteriw' => 'Return only local or only nonlocal entries of the interwiki map',
816 'showalldb' => 'List all database servers, not just the one lagging the most',
817 'numberingroup' => 'Lists the number of users in user groups',
818 'inlanguagecode' => 'Language code for localised language names ' .
819 '(best effort, use CLDR extension)',
820 );
821 }
822
823 public function getDescription() {
824 return 'Return general information about the site';
825 }
826
827 public function getPossibleErrors() {
828 return array_merge( parent::getPossibleErrors(), array( array(
829 'code' => 'includeAllDenied',
830 'info' => 'Cannot view all servers info unless $wgShowHostnames is true'
831 ), ) );
832 }
833
834 public function getExamples() {
835 return array(
836 'api.php?action=query&meta=siteinfo&siprop=general|namespaces|namespacealiases|statistics',
837 'api.php?action=query&meta=siteinfo&siprop=interwikimap&sifilteriw=local',
838 'api.php?action=query&meta=siteinfo&siprop=dbrepllag&sishowalldb=',
839 );
840 }
841
842 public function getHelpUrls() {
843 return 'https://www.mediawiki.org/wiki/API:Meta#siteinfo_.2F_si';
844 }
845 }