$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;
$pageLatest, $pageLength;
private $protections, $restrictionTypes, $watched, $watchers, $visitingwatchers,
- $notificationtimestamps, $talkids, $subjectids, $displaytitles;
+ $notificationtimestamps, $talkids, $subjectids, $displaytitles, $variantTitles;
private $showZeroWatchers = false;
private $tokenFunctions;
$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();
$this->getDisplayTitle();
}
+ if ( $this->fld_varianttitles ) {
+ $this->getVariantTitles();
+ }
+
/** @var Title $title */
foreach ( $this->everything as $pageid => $title ) {
$pageInfo = $this->extractPageInfo( $pageid, $title );
}
}
+ 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 ) {
}
}
+ 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
'url',
'preload',
'displaytitle',
+ 'varianttitles',
];
if ( array_diff( (array)$params['prop'], $publicProps ) ) {
return 'private';
'readable', # private
'preload',
'displaytitle',
+ 'varianttitles',
// If you add more properties here, please consider whether they
// need to be added to getCacheMode()
],
"apihelp-query+info-paramvalue-prop-readable": "Whether the user can read this page.",
"apihelp-query+info-paramvalue-prop-preload": "Gives the text returned by EditFormPreloadText.",
"apihelp-query+info-paramvalue-prop-displaytitle": "Gives the manner in which the page title is actually displayed.",
+ "apihelp-query+info-paramvalue-prop-varianttitles": "Gives the display title in all variants of the site content language.",
"apihelp-query+info-param-testactions": "Test whether the current user can perform certain actions on the page.",
"apihelp-query+info-param-token": "Use [[Special:ApiHelp/query+tokens|action=query&meta=tokens]] instead.",
"apihelp-query+info-example-simple": "Get information about the page <kbd>Main Page</kbd>.",
"apihelp-query+info-paramvalue-prop-readable": "{{doc-apihelp-paramvalue|query+info|prop|readable}}",
"apihelp-query+info-paramvalue-prop-preload": "{{doc-apihelp-paramvalue|query+info|prop|preload}}",
"apihelp-query+info-paramvalue-prop-displaytitle": "{{doc-apihelp-paramvalue|query+info|prop|displaytitle}}",
+ "apihelp-query+info-paramvalue-prop-varianttitles": "{{doc-apihelp-paramvalue|query+info|prop|varianttitles}}",
"apihelp-query+info-param-testactions": "{{doc-apihelp-param|query+info|testactions}}",
"apihelp-query+info-param-token": "{{doc-apihelp-param|query+info|token}}",
"apihelp-query+info-example-simple": "{{doc-apihelp-example|query+info}}",
return $this->mConverter;
}
+ /**
+ * convert text to a variant
+ *
+ * @param string $text text to convert
+ * @param string|bool $variant variant to convert to, or false to use the user's preferred
+ * variant (if logged in), or the project default variant
+ * @return string the converted string
+ */
+ public function autoConvert( $text, $variant = false ) {
+ return $this->mConverter->autoConvert( $text, $variant );
+ }
+
/**
* convert text to all supported variants
*
/**
* Convert a namespace index to a string in the preferred variant
*
- * @param int $ns
- * @return string
+ * @param int $ns namespace index (https://www.mediawiki.org/wiki/Manual:Namespace)
+ * @param string|null $variant variant to convert to, or null to use the user's preferred
+ * variant (if logged in), or the project default variant
+ * @return string a string representation of the namespace
*/
- public function convertNamespace( $ns ) {
- return $this->mConverter->convertNamespace( $ns );
+ public function convertNamespace( $ns, $variant = null ) {
+ return $this->mConverter->convertNamespace( $ns, $variant );
}
/**