+ $allGroups = array_values( User::getAllGroups() );
+ foreach ( $config->get( 'GroupPermissions' ) as $group => $permissions ) {
+ $arr = [
+ 'name' => $group,
+ 'rights' => array_keys( $permissions, true ),
+ ];
+
+ if ( $numberInGroup ) {
+ $autopromote = $config->get( 'Autopromote' );
+
+ if ( $group == 'user' ) {
+ $arr['number'] = SiteStats::users();
+ // '*' and autopromote groups have no size
+ } elseif ( $group !== '*' && !isset( $autopromote[$group] ) ) {
+ $arr['number'] = SiteStats::numberingroup( $group );
+ }
+ }
+
+ $groupArr = [
+ 'add' => $config->get( 'AddGroups' ),
+ 'remove' => $config->get( 'RemoveGroups' ),
+ 'add-self' => $config->get( 'GroupsAddToSelf' ),
+ 'remove-self' => $config->get( 'GroupsRemoveFromSelf' )
+ ];
+
+ foreach ( $groupArr as $type => $rights ) {
+ if ( isset( $rights[$group] ) ) {
+ if ( $rights[$group] === true ) {
+ $groups = $allGroups;
+ } else {
+ $groups = array_intersect( $rights[$group], $allGroups );
+ }
+ if ( $groups ) {
+ $arr[$type] = $groups;
+ ApiResult::setArrayType( $arr[$type], 'BCarray' );
+ ApiResult::setIndexedTagName( $arr[$type], 'group' );
+ }
+ }
+ }
+
+ ApiResult::setIndexedTagName( $arr['rights'], 'permission' );
+ $data[] = $arr;
+ }
+
+ ApiResult::setIndexedTagName( $data, 'group' );
+
+ return $result->addValue( 'query', $property, $data );
+ }
+
+ protected function appendFileExtensions( $property ) {
+ $data = [];
+ foreach ( array_unique( $this->getConfig()->get( 'FileExtensions' ) ) as $ext ) {
+ $data[] = [ 'ext' => $ext ];
+ }
+ ApiResult::setIndexedTagName( $data, 'fe' );
+
+ return $this->getResult()->addValue( 'query', $property, $data );
+ }
+
+ protected function appendInstalledLibraries( $property ) {
+ global $IP;
+ $path = "$IP/vendor/composer/installed.json";
+ if ( !file_exists( $path ) ) {
+ return true;
+ }
+
+ $data = [];
+ $installed = new ComposerInstalled( $path );
+ foreach ( $installed->getInstalledDependencies() as $name => $info ) {
+ if ( strpos( $info['type'], 'mediawiki-' ) === 0 ) {
+ // Skip any extensions or skins since they'll be listed
+ // in their proper section
+ continue;
+ }
+ $data[] = [
+ 'name' => $name,
+ 'version' => $info['version'],
+ ];
+ }
+ ApiResult::setIndexedTagName( $data, 'library' );
+
+ return $this->getResult()->addValue( 'query', $property, $data );
+ }
+
+ protected function appendExtensions( $property ) {
+ $data = [];
+ foreach ( $this->getConfig()->get( 'ExtensionCredits' ) as $type => $extensions ) {
+ foreach ( $extensions as $ext ) {
+ $ret = [];
+ $ret['type'] = $type;
+ if ( isset( $ext['name'] ) ) {
+ $ret['name'] = $ext['name'];
+ }
+ if ( isset( $ext['namemsg'] ) ) {
+ $ret['namemsg'] = $ext['namemsg'];
+ }
+ if ( isset( $ext['description'] ) ) {
+ $ret['description'] = $ext['description'];
+ }
+ if ( isset( $ext['descriptionmsg'] ) ) {
+ // Can be a string or [ key, param1, param2, ... ]
+ if ( is_array( $ext['descriptionmsg'] ) ) {
+ $ret['descriptionmsg'] = $ext['descriptionmsg'][0];
+ $ret['descriptionmsgparams'] = array_slice( $ext['descriptionmsg'], 1 );
+ ApiResult::setIndexedTagName( $ret['descriptionmsgparams'], 'param' );
+ } else {
+ $ret['descriptionmsg'] = $ext['descriptionmsg'];
+ }
+ }
+ if ( isset( $ext['author'] ) ) {
+ $ret['author'] = is_array( $ext['author'] ) ?
+ implode( ', ', $ext['author'] ) : $ext['author'];
+ }
+ if ( isset( $ext['url'] ) ) {
+ $ret['url'] = $ext['url'];
+ }
+ if ( isset( $ext['version'] ) ) {
+ $ret['version'] = $ext['version'];
+ }
+ if ( isset( $ext['path'] ) ) {
+ $extensionPath = dirname( $ext['path'] );
+ $gitInfo = new GitInfo( $extensionPath );
+ $vcsVersion = $gitInfo->getHeadSHA1();
+ if ( $vcsVersion !== false ) {
+ $ret['vcs-system'] = 'git';
+ $ret['vcs-version'] = $vcsVersion;
+ $ret['vcs-url'] = $gitInfo->getHeadViewUrl();
+ $vcsDate = $gitInfo->getHeadCommitDate();
+ if ( $vcsDate !== false ) {
+ $ret['vcs-date'] = wfTimestamp( TS_ISO_8601, $vcsDate );
+ }
+ }
+
+ if ( SpecialVersion::getExtLicenseFileName( $extensionPath ) ) {
+ $ret['license-name'] = isset( $ext['license-name'] ) ? $ext['license-name'] : '';
+ $ret['license'] = SpecialPage::getTitleFor(
+ 'Version',
+ "License/{$ext['name']}"
+ )->getLinkURL();
+ }
+
+ if ( SpecialVersion::getExtAuthorsFileName( $extensionPath ) ) {
+ $ret['credits'] = SpecialPage::getTitleFor(
+ 'Version',
+ "Credits/{$ext['name']}"
+ )->getLinkURL();
+ }
+ }
+ $data[] = $ret;
+ }
+ }
+
+ ApiResult::setIndexedTagName( $data, 'ext' );
+
+ return $this->getResult()->addValue( 'query', $property, $data );
+ }
+
+ protected function appendRightsInfo( $property ) {
+ $config = $this->getConfig();
+ $rightsPage = $config->get( 'RightsPage' );
+ if ( is_string( $rightsPage ) ) {
+ $title = Title::newFromText( $rightsPage );
+ $url = wfExpandUrl( $title, PROTO_CURRENT );
+ } else {
+ $title = false;
+ $url = $config->get( 'RightsUrl' );
+ }
+ $text = $config->get( 'RightsText' );
+ if ( !$text && $title ) {
+ $text = $title->getPrefixedText();
+ }
+
+ $data = [
+ 'url' => $url ?: '',
+ 'text' => $text ?: ''
+ ];
+
+ return $this->getResult()->addValue( 'query', $property, $data );
+ }
+
+ protected function appendRestrictions( $property ) {
+ $config = $this->getConfig();
+ $data = [
+ 'types' => $config->get( 'RestrictionTypes' ),
+ 'levels' => $config->get( 'RestrictionLevels' ),
+ 'cascadinglevels' => $config->get( 'CascadingRestrictionLevels' ),
+ 'semiprotectedlevels' => $config->get( 'SemiprotectedRestrictionLevels' ),
+ ];
+
+ ApiResult::setArrayType( $data['types'], 'BCarray' );
+ ApiResult::setArrayType( $data['levels'], 'BCarray' );
+ ApiResult::setArrayType( $data['cascadinglevels'], 'BCarray' );
+ ApiResult::setArrayType( $data['semiprotectedlevels'], 'BCarray' );
+
+ ApiResult::setIndexedTagName( $data['types'], 'type' );
+ ApiResult::setIndexedTagName( $data['levels'], 'level' );
+ ApiResult::setIndexedTagName( $data['cascadinglevels'], 'level' );
+ ApiResult::setIndexedTagName( $data['semiprotectedlevels'], 'level' );
+
+ return $this->getResult()->addValue( 'query', $property, $data );
+ }
+
+ public function appendLanguages( $property ) {
+ $params = $this->extractRequestParams();
+ $langCode = isset( $params['inlanguagecode'] ) ? $params['inlanguagecode'] : '';
+ $langNames = Language::fetchLanguageNames( $langCode );
+
+ $data = [];
+
+ foreach ( $langNames as $code => $name ) {
+ $lang = [ 'code' => $code ];
+ ApiResult::setContentValue( $lang, 'name', $name );
+ $data[] = $lang;
+ }
+ ApiResult::setIndexedTagName( $data, 'lang' );
+
+ return $this->getResult()->addValue( 'query', $property, $data );
+ }
+
+ // Export information about which page languages will trigger
+ // language conversion. (T153341)
+ public function appendLanguageVariants( $property ) {
+ $langNames = LanguageConverter::$languagesWithVariants;
+ if ( $this->getConfig()->get( 'DisableLangConversion' ) ) {
+ // Ensure result is empty if language conversion is disabled.
+ $langNames = [];
+ }
+ sort( $langNames );
+
+ $data = [];
+ foreach ( $langNames as $langCode ) {
+ $lang = Language::factory( $langCode );
+ if ( $lang->getConverter() instanceof FakeConverter ) {
+ // Only languages which do not return instances of
+ // FakeConverter implement language conversion.
+ continue;
+ }
+ $data[$langCode] = [];
+ ApiResult::setIndexedTagName( $data[$langCode], 'variant' );
+ ApiResult::setArrayType( $data[$langCode], 'kvp', 'code' );
+
+ $variants = $lang->getVariants();
+ sort( $variants );
+ foreach ( $variants as $v ) {
+ $fallbacks = $lang->getConverter()->getVariantFallbacks( $v );
+ if ( !is_array( $fallbacks ) ) {
+ $fallbacks = [ $fallbacks ];
+ }
+ $data[$langCode][$v] = [
+ 'fallbacks' => $fallbacks,
+ ];
+ ApiResult::setIndexedTagName(
+ $data[$langCode][$v]['fallbacks'], 'variant'
+ );
+ }
+ }
+ ApiResult::setIndexedTagName( $data, 'lang' );
+ ApiResult::setArrayType( $data, 'kvp', 'code' );
+
+ return $this->getResult()->addValue( 'query', $property, $data );
+ }
+
+ public function appendSkins( $property ) {
+ $data = [];
+ $allowed = Skin::getAllowedSkins();
+ $default = Skin::normalizeKey( 'default' );
+ foreach ( Skin::getSkinNames() as $name => $displayName ) {
+ $msg = $this->msg( "skinname-{$name}" );
+ $code = $this->getParameter( 'inlanguagecode' );
+ if ( $code && Language::isValidCode( $code ) ) {
+ $msg->inLanguage( $code );
+ } else {
+ $msg->inContentLanguage();
+ }
+ if ( $msg->exists() ) {
+ $displayName = $msg->text();
+ }
+ $skin = [ 'code' => $name ];
+ ApiResult::setContentValue( $skin, 'name', $displayName );
+ if ( !isset( $allowed[$name] ) ) {
+ $skin['unusable'] = true;
+ }
+ if ( $name === $default ) {
+ $skin['default'] = true;
+ }
+ $data[] = $skin;
+ }
+ ApiResult::setIndexedTagName( $data, 'skin' );
+
+ return $this->getResult()->addValue( 'query', $property, $data );
+ }
+
+ public function appendExtensionTags( $property ) {
+ global $wgParser;
+ $wgParser->firstCallInit();
+ $tags = array_map( [ $this, 'formatParserTags' ], $wgParser->getTags() );
+ ApiResult::setArrayType( $tags, 'BCarray' );
+ ApiResult::setIndexedTagName( $tags, 't' );
+
+ return $this->getResult()->addValue( 'query', $property, $tags );
+ }
+
+ public function appendFunctionHooks( $property ) {
+ global $wgParser;
+ $wgParser->firstCallInit();
+ $hooks = $wgParser->getFunctionHooks();
+ ApiResult::setArrayType( $hooks, 'BCarray' );
+ ApiResult::setIndexedTagName( $hooks, 'h' );
+
+ return $this->getResult()->addValue( 'query', $property, $hooks );
+ }
+
+ public function appendVariables( $property ) {
+ $variables = MagicWord::getVariableIDs();
+ ApiResult::setArrayType( $variables, 'BCarray' );
+ ApiResult::setIndexedTagName( $variables, 'v' );
+
+ return $this->getResult()->addValue( 'query', $property, $variables );
+ }
+
+ public function appendProtocols( $property ) {
+ // Make a copy of the global so we don't try to set the _element key of it - T47130
+ $protocols = array_values( $this->getConfig()->get( 'UrlProtocols' ) );
+ ApiResult::setArrayType( $protocols, 'BCarray' );
+ ApiResult::setIndexedTagName( $protocols, 'p' );
+
+ return $this->getResult()->addValue( 'query', $property, $protocols );
+ }
+
+ public function appendDefaultOptions( $property ) {
+ $options = User::getDefaultOptions();
+ $options[ApiResult::META_BC_BOOLS] = array_keys( $options );
+ return $this->getResult()->addValue( 'query', $property, $options );
+ }
+
+ public function appendUploadDialog( $property ) {
+ $config = $this->getConfig()->get( 'UploadDialog' );
+ return $this->getResult()->addValue( 'query', $property, $config );
+ }
+
+ private function formatParserTags( $item ) {
+ return "<{$item}>";
+ }
+
+ public function appendSubscribedHooks( $property ) {
+ $hooks = $this->getConfig()->get( 'Hooks' );
+ $myWgHooks = $hooks;
+ ksort( $myWgHooks );
+
+ $data = [];
+ foreach ( $myWgHooks as $name => $subscribers ) {
+ $arr = [
+ 'name' => $name,
+ 'subscribers' => array_map( [ 'SpecialVersion', 'arrayToString' ], $subscribers ),
+ ];
+
+ ApiResult::setArrayType( $arr['subscribers'], 'array' );
+ ApiResult::setIndexedTagName( $arr['subscribers'], 's' );
+ $data[] = $arr;
+ }
+
+ ApiResult::setIndexedTagName( $data, 'hook' );
+
+ return $this->getResult()->addValue( 'query', $property, $data );
+ }
+
+ public function getCacheMode( $params ) {
+ // Messages for $wgExtraInterlanguageLinkPrefixes depend on user language
+ if (
+ count( $this->getConfig()->get( 'ExtraInterlanguageLinkPrefixes' ) ) &&
+ !is_null( $params['prop'] ) &&
+ in_array( 'interwikimap', $params['prop'] )
+ ) {
+ return 'anon-public-user-private';
+ }
+
+ return 'public';
+ }
+
+ public function getAllowedParams() {
+ return [
+ 'prop' => [
+ ApiBase::PARAM_DFLT => 'general',
+ ApiBase::PARAM_ISMULTI => true,
+ ApiBase::PARAM_TYPE => [