Bump version from rc.0 to rc.2
[lhc/web/wiklou.git] / includes / api / ApiQueryInfo.php
index 5294b1d..1d3c110 100644 (file)
@@ -34,7 +34,7 @@ class ApiQueryInfo extends ApiQueryBase {
                $fld_readable = false, $fld_watched = false,
                $fld_watchers = false, $fld_visitingwatchers = false,
                $fld_notificationtimestamp = false,
-               $fld_preload = false, $fld_displaytitle = false;
+               $fld_preload = false, $fld_displaytitle = false, $fld_varianttitles = false;
 
        private $params;
 
@@ -49,7 +49,7 @@ class ApiQueryInfo extends ApiQueryBase {
                $pageLatest, $pageLength;
 
        private $protections, $restrictionTypes, $watched, $watchers, $visitingwatchers,
-               $notificationtimestamps, $talkids, $subjectids, $displaytitles;
+               $notificationtimestamps, $talkids, $subjectids, $displaytitles, $variantTitles;
        private $showZeroWatchers = false;
 
        private $tokenFunctions;
@@ -306,6 +306,7 @@ class ApiQueryInfo extends ApiQueryBase {
                        $this->fld_readable = isset( $prop['readable'] );
                        $this->fld_preload = isset( $prop['preload'] );
                        $this->fld_displaytitle = isset( $prop['displaytitle'] );
+                       $this->fld_varianttitles = isset( $prop['varianttitles'] );
                }
 
                $pageSet = $this->getPageSet();
@@ -368,6 +369,10 @@ class ApiQueryInfo extends ApiQueryBase {
                        $this->getDisplayTitle();
                }
 
+               if ( $this->fld_varianttitles ) {
+                       $this->getVariantTitles();
+               }
+
                /** @var Title $title */
                foreach ( $this->everything as $pageid => $title ) {
                        $pageInfo = $this->extractPageInfo( $pageid, $title );
@@ -510,6 +515,12 @@ class ApiQueryInfo extends ApiQueryBase {
                        }
                }
 
+               if ( $this->fld_varianttitles ) {
+                       if ( isset( $this->variantTitles[$pageid] ) ) {
+                               $pageInfo['varianttitles'] = $this->variantTitles[$pageid];
+                       }
+               }
+
                if ( $this->params['testactions'] ) {
                        $limit = $this->getMain()->canApiHighLimits() ? self::LIMIT_SML1 : self::LIMIT_SML2;
                        if ( $this->countTestedActions >= $limit ) {
@@ -740,6 +751,32 @@ class ApiQueryInfo extends ApiQueryBase {
                }
        }
 
+       private function getVariantTitles() {
+               if ( !count( $this->titles ) ) {
+                       return;
+               }
+               $this->variantTitles = [];
+               foreach ( $this->titles as $pageId => $t ) {
+                       $this->variantTitles[$pageId] = isset( $this->displaytitles[$pageId] )
+                               ? $this->getAllVariants( $this->displaytitles[$pageId] )
+                               : $this->getAllVariants( $t->getText(), $t->getNamespace() );
+               }
+       }
+
+       private function getAllVariants( $text, $ns = NS_MAIN ) {
+               global $wgContLang;
+               $result = [];
+               foreach ( $wgContLang->getVariants() as $variant ) {
+                       $convertTitle = $wgContLang->autoConvert( $text, $variant );
+                       if ( $ns !== NS_MAIN ) {
+                               $convertNs = $wgContLang->convertNamespace( $ns, $variant );
+                               $convertTitle = $convertNs . ':' . $convertTitle;
+                       }
+                       $result[$variant] = $convertTitle;
+               }
+               return $result;
+       }
+
        /**
         * Get information about watched status and put it in $this->watched
         * and $this->notificationtimestamps
@@ -879,6 +916,7 @@ class ApiQueryInfo extends ApiQueryBase {
                        'url',
                        'preload',
                        'displaytitle',
+                       'varianttitles',
                ];
                if ( array_diff( (array)$params['prop'], $publicProps ) ) {
                        return 'private';
@@ -912,6 +950,7 @@ class ApiQueryInfo extends ApiQueryBase {
                                        'readable', # private
                                        'preload',
                                        'displaytitle',
+                                       'varianttitles',
                                        // If you add more properties here, please consider whether they
                                        // need to be added to getCacheMode()
                                ],