API:Siteinfo: Include wgCategoryCollation in Siteinfo response
[lhc/web/wiklou.git] / includes / api / ApiQuerySiteinfo.php
index 5093608..2e9e69c 100644 (file)
@@ -88,6 +88,9 @@ class ApiQuerySiteinfo extends ApiQueryBase {
                                case 'languages':
                                        $fit = $this->appendLanguages( $p );
                                        break;
+                               case 'languagevariants':
+                                       $fit = $this->appendLanguageVariants( $p );
+                                       break;
                                case 'skins':
                                        $fit = $this->appendSkins( $p );
                                        break;
@@ -280,6 +283,8 @@ class ApiQuerySiteinfo extends ApiQueryBase {
                $data['interwikimagic'] = (bool)$config->get( 'InterwikiMagic' );
                $data['magiclinks'] = $config->get( 'EnableMagicLinks' );
 
+               $data['categorycollation'] = $config->get( 'CategoryCollation' );
+
                Hooks::run( 'APIQuerySiteInfoGeneralInfo', [ $this, &$data ] );
 
                return $this->getResult()->addValue( 'query', $property, $data );
@@ -713,6 +718,49 @@ class ApiQuerySiteinfo extends ApiQueryBase {
                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();
@@ -772,7 +820,7 @@ class ApiQuerySiteinfo extends ApiQueryBase {
        }
 
        public function appendProtocols( $property ) {
-               // Make a copy of the global so we don't try to set the _element key of it - bug 45130
+               // 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' );
@@ -851,6 +899,7 @@ class ApiQuerySiteinfo extends ApiQueryBase {
                                        'rightsinfo',
                                        'restrictions',
                                        'languages',
+                                       'languagevariants',
                                        'skins',
                                        'extensiontags',
                                        'functionhooks',
@@ -886,6 +935,6 @@ class ApiQuerySiteinfo extends ApiQueryBase {
        }
 
        public function getHelpUrls() {
-               return 'https://www.mediawiki.org/wiki/API:Siteinfo';
+               return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Siteinfo';
        }
 }