5 * Created on Sep 25, 2006
7 * Copyright © 2006 Yuri Astrakhan "<Firstname><Lastname>@gmail.com"
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.
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.
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
26 use MediaWiki\MediaWikiServices
;
29 * A query action to return meta information about the wiki site.
33 class ApiQuerySiteinfo
extends ApiQueryBase
{
35 public function __construct( ApiQuery
$query, $moduleName ) {
36 parent
::__construct( $query, $moduleName, 'si' );
39 public function execute() {
40 $params = $this->extractRequestParams();
43 foreach ( $params['prop'] as $p ) {
46 $fit = $this->appendGeneralInfo( $p );
49 $fit = $this->appendNamespaces( $p );
51 case 'namespacealiases':
52 $fit = $this->appendNamespaceAliases( $p );
54 case 'specialpagealiases':
55 $fit = $this->appendSpecialPageAliases( $p );
58 $fit = $this->appendMagicWords( $p );
61 $filteriw = isset( $params['filteriw'] ) ?
$params['filteriw'] : false;
62 $fit = $this->appendInterwikiMap( $p, $filteriw );
65 $fit = $this->appendDbReplLagInfo( $p, $params['showalldb'] );
68 $fit = $this->appendStatistics( $p );
71 $fit = $this->appendUserGroups( $p, $params['numberingroup'] );
74 $fit = $this->appendInstalledLibraries( $p );
77 $fit = $this->appendExtensions( $p );
79 case 'fileextensions':
80 $fit = $this->appendFileExtensions( $p );
83 $fit = $this->appendRightsInfo( $p );
86 $fit = $this->appendRestrictions( $p );
89 $fit = $this->appendLanguages( $p );
91 case 'languagevariants':
92 $fit = $this->appendLanguageVariants( $p );
95 $fit = $this->appendSkins( $p );
98 $fit = $this->appendExtensionTags( $p );
100 case 'functionhooks':
101 $fit = $this->appendFunctionHooks( $p );
104 $fit = $this->appendSubscribedHooks( $p );
107 $fit = $this->appendVariables( $p );
110 $fit = $this->appendProtocols( $p );
112 case 'defaultoptions':
113 $fit = $this->appendDefaultOptions( $p );
116 $fit = $this->appendUploadDialog( $p );
119 ApiBase
::dieDebug( __METHOD__
, "Unknown prop=$p" );
122 // Abuse siprop as a query-continue parameter
123 // and set it to all unprocessed props
124 $this->setContinueEnumParameter( 'prop', implode( '|',
125 array_diff( $params['prop'], $done ) ) );
132 protected function appendGeneralInfo( $property ) {
135 $config = $this->getConfig();
138 $mainPage = Title
::newMainPage();
139 $data['mainpage'] = $mainPage->getPrefixedText();
140 $data['base'] = wfExpandUrl( $mainPage->getFullURL(), PROTO_CURRENT
);
141 $data['sitename'] = $config->get( 'Sitename' );
143 // wgLogo can either be a relative or an absolute path
144 // make sure we always return an absolute path
145 $data['logo'] = wfExpandUrl( $config->get( 'Logo' ), PROTO_RELATIVE
);
147 $data['generator'] = "MediaWiki {$config->get( 'Version' )}";
149 $data['phpversion'] = PHP_VERSION
;
150 $data['phpsapi'] = PHP_SAPI
;
151 if ( defined( 'HHVM_VERSION' ) ) {
152 $data['hhvmversion'] = HHVM_VERSION
;
154 $data['dbtype'] = $config->get( 'DBtype' );
155 $data['dbversion'] = $this->getDB()->getServerVersion();
158 $allowException = true;
159 if ( !$config->get( 'AllowExternalImages' ) ) {
160 $data['imagewhitelistenabled'] = (bool)$config->get( 'EnableImageWhitelist' );
161 $allowFrom = $config->get( 'AllowExternalImagesFrom' );
162 $allowException = !empty( $allowFrom );
164 if ( $allowException ) {
165 $data['externalimages'] = (array)$allowFrom;
166 ApiResult
::setIndexedTagName( $data['externalimages'], 'prefix' );
169 $data['langconversion'] = !$config->get( 'DisableLangConversion' );
170 $data['titleconversion'] = !$config->get( 'DisableTitleConversion' );
172 if ( $wgContLang->linkPrefixExtension() ) {
173 $linkPrefixCharset = $wgContLang->linkPrefixCharset();
174 $data['linkprefixcharset'] = $linkPrefixCharset;
175 // For backwards compatibility
176 $data['linkprefix'] = "/^((?>.*[^$linkPrefixCharset]|))(.+)$/sDu";
178 $data['linkprefixcharset'] = '';
179 $data['linkprefix'] = '';
182 $linktrail = $wgContLang->linkTrail();
183 $data['linktrail'] = $linktrail ?
: '';
185 $data['legaltitlechars'] = Title
::legalChars();
186 $data['invalidusernamechars'] = $config->get( 'InvalidUsernameCharacters' );
188 $data['allunicodefixes'] = (bool)$config->get( 'AllUnicodeFixes' );
189 $data['fixarabicunicode'] = (bool)$config->get( 'FixArabicUnicode' );
190 $data['fixmalayalamunicode'] = (bool)$config->get( 'FixMalayalamUnicode' );
193 $git = SpecialVersion
::getGitHeadSha1( $IP );
195 $data['git-hash'] = $git;
196 $data['git-branch'] =
197 SpecialVersion
::getGitCurrentBranch( $GLOBALS['IP'] );
200 // 'case-insensitive' option is reserved for future
201 $data['case'] = $config->get( 'CapitalLinks' ) ?
'first-letter' : 'case-sensitive';
202 $data['lang'] = $config->get( 'LanguageCode' );
205 foreach ( $wgContLang->getFallbackLanguages() as $code ) {
206 $fallbacks[] = [ 'code' => $code ];
208 $data['fallback'] = $fallbacks;
209 ApiResult
::setIndexedTagName( $data['fallback'], 'lang' );
211 if ( $wgContLang->hasVariants() ) {
213 foreach ( $wgContLang->getVariants() as $code ) {
216 'name' => $wgContLang->getVariantname( $code ),
219 $data['variants'] = $variants;
220 ApiResult
::setIndexedTagName( $data['variants'], 'lang' );
223 $data['rtl'] = $wgContLang->isRTL();
224 $data['fallback8bitEncoding'] = $wgContLang->fallback8bitEncoding();
226 $data['readonly'] = wfReadOnly();
227 if ( $data['readonly'] ) {
228 $data['readonlyreason'] = wfReadOnlyReason();
230 $data['writeapi'] = (bool)$config->get( 'EnableWriteAPI' );
232 $data['maxarticlesize'] = $config->get( 'MaxArticleSize' ) * 1024;
234 $tz = $config->get( 'Localtimezone' );
235 $offset = $config->get( 'LocalTZoffset' );
236 if ( is_null( $tz ) ) {
239 } elseif ( is_null( $offset ) ) {
242 $data['timezone'] = $tz;
243 $data['timeoffset'] = intval( $offset );
244 $data['articlepath'] = $config->get( 'ArticlePath' );
245 $data['scriptpath'] = $config->get( 'ScriptPath' );
246 $data['script'] = $config->get( 'Script' );
247 $data['variantarticlepath'] = $config->get( 'VariantArticlePath' );
248 $data[ApiResult
::META_BC_BOOLS
][] = 'variantarticlepath';
249 $data['server'] = $config->get( 'Server' );
250 $data['servername'] = $config->get( 'ServerName' );
251 $data['wikiid'] = wfWikiID();
252 $data['time'] = wfTimestamp( TS_ISO_8601
, time() );
254 $data['misermode'] = (bool)$config->get( 'MiserMode' );
256 $data['uploadsenabled'] = UploadBase
::isEnabled();
257 $data['maxuploadsize'] = UploadBase
::getMaxUploadSize();
258 $data['minuploadchunksize'] = (int)$config->get( 'MinUploadChunkSize' );
260 $data['galleryoptions'] = $config->get( 'GalleryOptions' );
262 $data['thumblimits'] = $config->get( 'ThumbLimits' );
263 ApiResult
::setArrayType( $data['thumblimits'], 'BCassoc' );
264 ApiResult
::setIndexedTagName( $data['thumblimits'], 'limit' );
265 $data['imagelimits'] = [];
266 ApiResult
::setArrayType( $data['imagelimits'], 'BCassoc' );
267 ApiResult
::setIndexedTagName( $data['imagelimits'], 'limit' );
268 foreach ( $config->get( 'ImageLimits' ) as $k => $limit ) {
269 $data['imagelimits'][$k] = [ 'width' => $limit[0], 'height' => $limit[1] ];
272 $favicon = $config->get( 'Favicon' );
273 if ( !empty( $favicon ) ) {
274 // wgFavicon can either be a relative or an absolute path
275 // make sure we always return an absolute path
276 $data['favicon'] = wfExpandUrl( $favicon, PROTO_RELATIVE
);
279 $data['centralidlookupprovider'] = $config->get( 'CentralIdLookupProvider' );
280 $providerIds = array_keys( $config->get( 'CentralIdLookupProviders' ) );
281 $data['allcentralidlookupproviders'] = $providerIds;
283 $data['interwikimagic'] = (bool)$config->get( 'InterwikiMagic' );
284 $data['magiclinks'] = $config->get( 'EnableMagicLinks' );
286 $data['categorycollation'] = $config->get( 'CategoryCollation' );
288 Hooks
::run( 'APIQuerySiteInfoGeneralInfo', [ $this, &$data ] );
290 return $this->getResult()->addValue( 'query', $property, $data );
293 protected function appendNamespaces( $property ) {
296 ApiResult
::META_TYPE
=> 'assoc',
298 foreach ( $wgContLang->getFormattedNamespaces() as $ns => $title ) {
300 'id' => intval( $ns ),
301 'case' => MWNamespace
::isCapitalized( $ns ) ?
'first-letter' : 'case-sensitive',
303 ApiResult
::setContentValue( $data[$ns], 'name', $title );
304 $canonical = MWNamespace
::getCanonicalName( $ns );
306 $data[$ns]['subpages'] = MWNamespace
::hasSubpages( $ns );
309 $data[$ns]['canonical'] = strtr( $canonical, '_', ' ' );
312 $data[$ns]['content'] = MWNamespace
::isContent( $ns );
313 $data[$ns]['nonincludable'] = MWNamespace
::isNonincludable( $ns );
315 $contentmodel = MWNamespace
::getNamespaceContentModel( $ns );
316 if ( $contentmodel ) {
317 $data[$ns]['defaultcontentmodel'] = $contentmodel;
321 ApiResult
::setArrayType( $data, 'assoc' );
322 ApiResult
::setIndexedTagName( $data, 'ns' );
324 return $this->getResult()->addValue( 'query', $property, $data );
327 protected function appendNamespaceAliases( $property ) {
329 $aliases = array_merge( $this->getConfig()->get( 'NamespaceAliases' ),
330 $wgContLang->getNamespaceAliases() );
331 $namespaces = $wgContLang->getNamespaces();
333 foreach ( $aliases as $title => $ns ) {
334 if ( $namespaces[$ns] == $title ) {
335 // Don't list duplicates
339 'id' => intval( $ns )
341 ApiResult
::setContentValue( $item, 'alias', strtr( $title, '_', ' ' ) );
347 ApiResult
::setIndexedTagName( $data, 'ns' );
349 return $this->getResult()->addValue( 'query', $property, $data );
352 protected function appendSpecialPageAliases( $property ) {
355 $aliases = $wgContLang->getSpecialPageAliases();
356 foreach ( SpecialPageFactory
::getNames() as $specialpage ) {
357 if ( isset( $aliases[$specialpage] ) ) {
358 $arr = [ 'realname' => $specialpage, 'aliases' => $aliases[$specialpage] ];
359 ApiResult
::setIndexedTagName( $arr['aliases'], 'alias' );
363 ApiResult
::setIndexedTagName( $data, 'specialpage' );
365 return $this->getResult()->addValue( 'query', $property, $data );
368 protected function appendMagicWords( $property ) {
371 foreach ( $wgContLang->getMagicWords() as $magicword => $aliases ) {
372 $caseSensitive = array_shift( $aliases );
373 $arr = [ 'name' => $magicword, 'aliases' => $aliases ];
374 $arr['case-sensitive'] = (bool)$caseSensitive;
375 ApiResult
::setIndexedTagName( $arr['aliases'], 'alias' );
378 ApiResult
::setIndexedTagName( $data, 'magicword' );
380 return $this->getResult()->addValue( 'query', $property, $data );
383 protected function appendInterwikiMap( $property, $filter ) {
385 if ( $filter === 'local' ) {
387 } elseif ( $filter === '!local' ) {
389 } elseif ( $filter ) {
390 ApiBase
::dieDebug( __METHOD__
, "Unknown filter=$filter" );
393 $params = $this->extractRequestParams();
394 $langCode = isset( $params['inlanguagecode'] ) ?
$params['inlanguagecode'] : '';
395 $langNames = Language
::fetchLanguageNames( $langCode );
397 $getPrefixes = MediaWikiServices
::getInstance()->getInterwikiLookup()->getAllPrefixes( $local );
398 $extraLangPrefixes = $this->getConfig()->get( 'ExtraInterlanguageLinkPrefixes' );
399 $localInterwikis = $this->getConfig()->get( 'LocalInterwikis' );
402 foreach ( $getPrefixes as $row ) {
403 $prefix = $row['iw_prefix'];
405 $val['prefix'] = $prefix;
406 if ( isset( $row['iw_local'] ) && $row['iw_local'] == '1' ) {
407 $val['local'] = true;
409 if ( isset( $row['iw_trans'] ) && $row['iw_trans'] == '1' ) {
410 $val['trans'] = true;
413 if ( isset( $langNames[$prefix] ) ) {
414 $val['language'] = $langNames[$prefix];
416 if ( in_array( $prefix, $localInterwikis ) ) {
417 $val['localinterwiki'] = true;
419 if ( in_array( $prefix, $extraLangPrefixes ) ) {
420 $val['extralanglink'] = true;
422 $linktext = wfMessage( "interlanguage-link-$prefix" );
423 if ( !$linktext->isDisabled() ) {
424 $val['linktext'] = $linktext->text();
427 $sitename = wfMessage( "interlanguage-link-sitename-$prefix" );
428 if ( !$sitename->isDisabled() ) {
429 $val['sitename'] = $sitename->text();
433 $val['url'] = wfExpandUrl( $row['iw_url'], PROTO_CURRENT
);
434 $val['protorel'] = substr( $row['iw_url'], 0, 2 ) == '//';
435 if ( isset( $row['iw_wikiid'] ) && $row['iw_wikiid'] !== '' ) {
436 $val['wikiid'] = $row['iw_wikiid'];
438 if ( isset( $row['iw_api'] ) && $row['iw_api'] !== '' ) {
439 $val['api'] = $row['iw_api'];
445 ApiResult
::setIndexedTagName( $data, 'iw' );
447 return $this->getResult()->addValue( 'query', $property, $data );
450 protected function appendDbReplLagInfo( $property, $includeAll ) {
452 $lb = MediaWikiServices
::getInstance()->getDBLoadBalancer();
453 $showHostnames = $this->getConfig()->get( 'ShowHostnames' );
455 if ( !$showHostnames ) {
456 $this->dieWithError( 'apierror-siteinfo-includealldenied', 'includeAllDenied' );
459 $lags = $lb->getLagTimes();
460 foreach ( $lags as $i => $lag ) {
462 'host' => $lb->getServerName( $i ),
467 list( , $lag, $index ) = $lb->getMaxLag();
469 'host' => $showHostnames
470 ?
$lb->getServerName( $index )
472 'lag' => intval( $lag )
476 ApiResult
::setIndexedTagName( $data, 'db' );
478 return $this->getResult()->addValue( 'query', $property, $data );
481 protected function appendStatistics( $property ) {
483 $data['pages'] = intval( SiteStats
::pages() );
484 $data['articles'] = intval( SiteStats
::articles() );
485 $data['edits'] = intval( SiteStats
::edits() );
486 $data['images'] = intval( SiteStats
::images() );
487 $data['users'] = intval( SiteStats
::users() );
488 $data['activeusers'] = intval( SiteStats
::activeUsers() );
489 $data['admins'] = intval( SiteStats
::numberingroup( 'sysop' ) );
490 $data['jobs'] = intval( SiteStats
::jobs() );
492 Hooks
::run( 'APIQuerySiteInfoStatisticsInfo', [ &$data ] );
494 return $this->getResult()->addValue( 'query', $property, $data );
497 protected function appendUserGroups( $property, $numberInGroup ) {
498 $config = $this->getConfig();
501 $result = $this->getResult();
502 $allGroups = array_values( User
::getAllGroups() );
503 foreach ( $config->get( 'GroupPermissions' ) as $group => $permissions ) {
506 'rights' => array_keys( $permissions, true ),
509 if ( $numberInGroup ) {
510 $autopromote = $config->get( 'Autopromote' );
512 if ( $group == 'user' ) {
513 $arr['number'] = SiteStats
::users();
514 // '*' and autopromote groups have no size
515 } elseif ( $group !== '*' && !isset( $autopromote[$group] ) ) {
516 $arr['number'] = SiteStats
::numberingroup( $group );
521 'add' => $config->get( 'AddGroups' ),
522 'remove' => $config->get( 'RemoveGroups' ),
523 'add-self' => $config->get( 'GroupsAddToSelf' ),
524 'remove-self' => $config->get( 'GroupsRemoveFromSelf' )
527 foreach ( $groupArr as $type => $rights ) {
528 if ( isset( $rights[$group] ) ) {
529 if ( $rights[$group] === true ) {
530 $groups = $allGroups;
532 $groups = array_intersect( $rights[$group], $allGroups );
535 $arr[$type] = $groups;
536 ApiResult
::setArrayType( $arr[$type], 'BCarray' );
537 ApiResult
::setIndexedTagName( $arr[$type], 'group' );
542 ApiResult
::setIndexedTagName( $arr['rights'], 'permission' );
546 ApiResult
::setIndexedTagName( $data, 'group' );
548 return $result->addValue( 'query', $property, $data );
551 protected function appendFileExtensions( $property ) {
553 foreach ( array_unique( $this->getConfig()->get( 'FileExtensions' ) ) as $ext ) {
554 $data[] = [ 'ext' => $ext ];
556 ApiResult
::setIndexedTagName( $data, 'fe' );
558 return $this->getResult()->addValue( 'query', $property, $data );
561 protected function appendInstalledLibraries( $property ) {
563 $path = "$IP/vendor/composer/installed.json";
564 if ( !file_exists( $path ) ) {
569 $installed = new ComposerInstalled( $path );
570 foreach ( $installed->getInstalledDependencies() as $name => $info ) {
571 if ( strpos( $info['type'], 'mediawiki-' ) === 0 ) {
572 // Skip any extensions or skins since they'll be listed
573 // in their proper section
578 'version' => $info['version'],
581 ApiResult
::setIndexedTagName( $data, 'library' );
583 return $this->getResult()->addValue( 'query', $property, $data );
586 protected function appendExtensions( $property ) {
588 foreach ( $this->getConfig()->get( 'ExtensionCredits' ) as $type => $extensions ) {
589 foreach ( $extensions as $ext ) {
591 $ret['type'] = $type;
592 if ( isset( $ext['name'] ) ) {
593 $ret['name'] = $ext['name'];
595 if ( isset( $ext['namemsg'] ) ) {
596 $ret['namemsg'] = $ext['namemsg'];
598 if ( isset( $ext['description'] ) ) {
599 $ret['description'] = $ext['description'];
601 if ( isset( $ext['descriptionmsg'] ) ) {
602 // Can be a string or [ key, param1, param2, ... ]
603 if ( is_array( $ext['descriptionmsg'] ) ) {
604 $ret['descriptionmsg'] = $ext['descriptionmsg'][0];
605 $ret['descriptionmsgparams'] = array_slice( $ext['descriptionmsg'], 1 );
606 ApiResult
::setIndexedTagName( $ret['descriptionmsgparams'], 'param' );
608 $ret['descriptionmsg'] = $ext['descriptionmsg'];
611 if ( isset( $ext['author'] ) ) {
612 $ret['author'] = is_array( $ext['author'] ) ?
613 implode( ', ', $ext['author'] ) : $ext['author'];
615 if ( isset( $ext['url'] ) ) {
616 $ret['url'] = $ext['url'];
618 if ( isset( $ext['version'] ) ) {
619 $ret['version'] = $ext['version'];
621 if ( isset( $ext['path'] ) ) {
622 $extensionPath = dirname( $ext['path'] );
623 $gitInfo = new GitInfo( $extensionPath );
624 $vcsVersion = $gitInfo->getHeadSHA1();
625 if ( $vcsVersion !== false ) {
626 $ret['vcs-system'] = 'git';
627 $ret['vcs-version'] = $vcsVersion;
628 $ret['vcs-url'] = $gitInfo->getHeadViewUrl();
629 $vcsDate = $gitInfo->getHeadCommitDate();
630 if ( $vcsDate !== false ) {
631 $ret['vcs-date'] = wfTimestamp( TS_ISO_8601
, $vcsDate );
635 if ( SpecialVersion
::getExtLicenseFileName( $extensionPath ) ) {
636 $ret['license-name'] = isset( $ext['license-name'] ) ?
$ext['license-name'] : '';
637 $ret['license'] = SpecialPage
::getTitleFor(
639 "License/{$ext['name']}"
643 if ( SpecialVersion
::getExtAuthorsFileName( $extensionPath ) ) {
644 $ret['credits'] = SpecialPage
::getTitleFor(
646 "Credits/{$ext['name']}"
654 ApiResult
::setIndexedTagName( $data, 'ext' );
656 return $this->getResult()->addValue( 'query', $property, $data );
659 protected function appendRightsInfo( $property ) {
660 $config = $this->getConfig();
661 $rightsPage = $config->get( 'RightsPage' );
662 if ( is_string( $rightsPage ) ) {
663 $title = Title
::newFromText( $rightsPage );
664 $url = wfExpandUrl( $title, PROTO_CURRENT
);
667 $url = $config->get( 'RightsUrl' );
669 $text = $config->get( 'RightsText' );
670 if ( !$text && $title ) {
671 $text = $title->getPrefixedText();
676 'text' => $text ?
: ''
679 return $this->getResult()->addValue( 'query', $property, $data );
682 protected function appendRestrictions( $property ) {
683 $config = $this->getConfig();
685 'types' => $config->get( 'RestrictionTypes' ),
686 'levels' => $config->get( 'RestrictionLevels' ),
687 'cascadinglevels' => $config->get( 'CascadingRestrictionLevels' ),
688 'semiprotectedlevels' => $config->get( 'SemiprotectedRestrictionLevels' ),
691 ApiResult
::setArrayType( $data['types'], 'BCarray' );
692 ApiResult
::setArrayType( $data['levels'], 'BCarray' );
693 ApiResult
::setArrayType( $data['cascadinglevels'], 'BCarray' );
694 ApiResult
::setArrayType( $data['semiprotectedlevels'], 'BCarray' );
696 ApiResult
::setIndexedTagName( $data['types'], 'type' );
697 ApiResult
::setIndexedTagName( $data['levels'], 'level' );
698 ApiResult
::setIndexedTagName( $data['cascadinglevels'], 'level' );
699 ApiResult
::setIndexedTagName( $data['semiprotectedlevels'], 'level' );
701 return $this->getResult()->addValue( 'query', $property, $data );
704 public function appendLanguages( $property ) {
705 $params = $this->extractRequestParams();
706 $langCode = isset( $params['inlanguagecode'] ) ?
$params['inlanguagecode'] : '';
707 $langNames = Language
::fetchLanguageNames( $langCode );
711 foreach ( $langNames as $code => $name ) {
712 $lang = [ 'code' => $code ];
713 ApiResult
::setContentValue( $lang, 'name', $name );
716 ApiResult
::setIndexedTagName( $data, 'lang' );
718 return $this->getResult()->addValue( 'query', $property, $data );
721 // Export information about which page languages will trigger
722 // language conversion. (T153341)
723 public function appendLanguageVariants( $property ) {
724 $langNames = LanguageConverter
::$languagesWithVariants;
725 if ( $this->getConfig()->get( 'DisableLangConversion' ) ) {
726 // Ensure result is empty if language conversion is disabled.
732 foreach ( $langNames as $langCode ) {
733 $lang = Language
::factory( $langCode );
734 if ( $lang->getConverter() instanceof FakeConverter
) {
735 // Only languages which do not return instances of
736 // FakeConverter implement language conversion.
739 $data[$langCode] = [];
740 ApiResult
::setIndexedTagName( $data[$langCode], 'variant' );
741 ApiResult
::setArrayType( $data[$langCode], 'kvp', 'code' );
743 $variants = $lang->getVariants();
745 foreach ( $variants as $v ) {
746 $fallbacks = $lang->getConverter()->getVariantFallbacks( $v );
747 if ( !is_array( $fallbacks ) ) {
748 $fallbacks = [ $fallbacks ];
750 $data[$langCode][$v] = [
751 'fallbacks' => $fallbacks,
753 ApiResult
::setIndexedTagName(
754 $data[$langCode][$v]['fallbacks'], 'variant'
758 ApiResult
::setIndexedTagName( $data, 'lang' );
759 ApiResult
::setArrayType( $data, 'kvp', 'code' );
761 return $this->getResult()->addValue( 'query', $property, $data );
764 public function appendSkins( $property ) {
766 $allowed = Skin
::getAllowedSkins();
767 $default = Skin
::normalizeKey( 'default' );
768 foreach ( Skin
::getSkinNames() as $name => $displayName ) {
769 $msg = $this->msg( "skinname-{$name}" );
770 $code = $this->getParameter( 'inlanguagecode' );
771 if ( $code && Language
::isValidCode( $code ) ) {
772 $msg->inLanguage( $code );
774 $msg->inContentLanguage();
776 if ( $msg->exists() ) {
777 $displayName = $msg->text();
779 $skin = [ 'code' => $name ];
780 ApiResult
::setContentValue( $skin, 'name', $displayName );
781 if ( !isset( $allowed[$name] ) ) {
782 $skin['unusable'] = true;
784 if ( $name === $default ) {
785 $skin['default'] = true;
789 ApiResult
::setIndexedTagName( $data, 'skin' );
791 return $this->getResult()->addValue( 'query', $property, $data );
794 public function appendExtensionTags( $property ) {
796 $wgParser->firstCallInit();
797 $tags = array_map( [ $this, 'formatParserTags' ], $wgParser->getTags() );
798 ApiResult
::setArrayType( $tags, 'BCarray' );
799 ApiResult
::setIndexedTagName( $tags, 't' );
801 return $this->getResult()->addValue( 'query', $property, $tags );
804 public function appendFunctionHooks( $property ) {
806 $wgParser->firstCallInit();
807 $hooks = $wgParser->getFunctionHooks();
808 ApiResult
::setArrayType( $hooks, 'BCarray' );
809 ApiResult
::setIndexedTagName( $hooks, 'h' );
811 return $this->getResult()->addValue( 'query', $property, $hooks );
814 public function appendVariables( $property ) {
815 $variables = MagicWord
::getVariableIDs();
816 ApiResult
::setArrayType( $variables, 'BCarray' );
817 ApiResult
::setIndexedTagName( $variables, 'v' );
819 return $this->getResult()->addValue( 'query', $property, $variables );
822 public function appendProtocols( $property ) {
823 // Make a copy of the global so we don't try to set the _element key of it - T47130
824 $protocols = array_values( $this->getConfig()->get( 'UrlProtocols' ) );
825 ApiResult
::setArrayType( $protocols, 'BCarray' );
826 ApiResult
::setIndexedTagName( $protocols, 'p' );
828 return $this->getResult()->addValue( 'query', $property, $protocols );
831 public function appendDefaultOptions( $property ) {
832 $options = User
::getDefaultOptions();
833 $options[ApiResult
::META_BC_BOOLS
] = array_keys( $options );
834 return $this->getResult()->addValue( 'query', $property, $options );
837 public function appendUploadDialog( $property ) {
838 $config = $this->getConfig()->get( 'UploadDialog' );
839 return $this->getResult()->addValue( 'query', $property, $config );
842 private function formatParserTags( $item ) {
846 public function appendSubscribedHooks( $property ) {
847 $hooks = $this->getConfig()->get( 'Hooks' );
852 foreach ( $myWgHooks as $name => $subscribers ) {
855 'subscribers' => array_map( [ 'SpecialVersion', 'arrayToString' ], $subscribers ),
858 ApiResult
::setArrayType( $arr['subscribers'], 'array' );
859 ApiResult
::setIndexedTagName( $arr['subscribers'], 's' );
863 ApiResult
::setIndexedTagName( $data, 'hook' );
865 return $this->getResult()->addValue( 'query', $property, $data );
868 public function getCacheMode( $params ) {
869 // Messages for $wgExtraInterlanguageLinkPrefixes depend on user language
871 count( $this->getConfig()->get( 'ExtraInterlanguageLinkPrefixes' ) ) &&
872 !is_null( $params['prop'] ) &&
873 in_array( 'interwikimap', $params['prop'] )
875 return 'anon-public-user-private';
881 public function getAllowedParams() {
884 ApiBase
::PARAM_DFLT
=> 'general',
885 ApiBase
::PARAM_ISMULTI
=> true,
886 ApiBase
::PARAM_TYPE
=> [
890 'specialpagealiases',
912 ApiBase
::PARAM_HELP_MSG_PER_VALUE
=> [],
915 ApiBase
::PARAM_TYPE
=> [
920 'showalldb' => false,
921 'numberingroup' => false,
922 'inlanguagecode' => null,
926 protected function getExamplesMessages() {
928 'action=query&meta=siteinfo&siprop=general|namespaces|namespacealiases|statistics'
929 => 'apihelp-query+siteinfo-example-simple',
930 'action=query&meta=siteinfo&siprop=interwikimap&sifilteriw=local'
931 => 'apihelp-query+siteinfo-example-interwiki',
932 'action=query&meta=siteinfo&siprop=dbrepllag&sishowalldb='
933 => 'apihelp-query+siteinfo-example-replag',
937 public function getHelpUrls() {
938 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Siteinfo';