+ 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' );
+