X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fapi%2FApiQueryInfo.php;h=1d3c110c3a18080a8128bc2fbad6e73a2d9ac25a;hb=362a962c8db517f435843af45f0747ead6878252;hp=5294b1d8e78d3107bc4eaea672774349189ae096;hpb=92571d7c1a9c25604382f9c395e487e44cc442d5;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/api/ApiQueryInfo.php b/includes/api/ApiQueryInfo.php index 5294b1d8e7..1d3c110c3a 100644 --- a/includes/api/ApiQueryInfo.php +++ b/includes/api/ApiQueryInfo.php @@ -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() ],