<?php
/**
- *
- *
- * Created on Sep 25, 2006
- *
* Copyright © 2006 Yuri Astrakhan "<Firstname><Lastname>@gmail.com"
*
* This program is free software; you can redistribute it and/or modify
$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->tokenFunctions = [
- 'edit' => [ 'ApiQueryInfo', 'getEditToken' ],
- 'delete' => [ 'ApiQueryInfo', 'getDeleteToken' ],
- 'protect' => [ 'ApiQueryInfo', 'getProtectToken' ],
- 'move' => [ 'ApiQueryInfo', 'getMoveToken' ],
- 'block' => [ 'ApiQueryInfo', 'getBlockToken' ],
- 'unblock' => [ 'ApiQueryInfo', 'getUnblockToken' ],
- 'email' => [ 'ApiQueryInfo', 'getEmailToken' ],
- 'import' => [ 'ApiQueryInfo', 'getImportToken' ],
- 'watch' => [ 'ApiQueryInfo', 'getWatchToken' ],
+ 'edit' => [ self::class, 'getEditToken' ],
+ 'delete' => [ self::class, 'getDeleteToken' ],
+ 'protect' => [ self::class, 'getProtectToken' ],
+ 'move' => [ self::class, 'getMoveToken' ],
+ 'block' => [ self::class, 'getBlockToken' ],
+ 'unblock' => [ self::class, 'getUnblockToken' ],
+ 'email' => [ self::class, 'getEmailToken' ],
+ 'import' => [ self::class, 'getImportToken' ],
+ 'watch' => [ self::class, 'getWatchToken' ],
];
Hooks::run( 'APIQueryInfoTokens', [ &$this->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->everything = $this->titles + $this->missing;
$result = $this->getResult();
- uasort( $this->everything, [ 'Title', 'compare' ] );
+ uasort( $this->everything, [ Title::class, 'compare' ] );
if ( !is_null( $this->params['continue'] ) ) {
// Throw away any titles we're gonna skip so they don't
// clutter queries
$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()
],