private $mMissingPageIDs, $mRedirectTitles, $mSpecialTitles;
private $mNormalizedTitles, $mInterwikiTitles;
private $mResolveRedirects, $mPendingRedirectIDs;
+ private $mConvertTitles, $mConvertedTitles;
private $mGoodRevIDs, $mMissingRevIDs;
private $mFakePageId;
* @param $query ApiQuery
* @param $resolveRedirects bool Whether redirects should be resolved
*/
- public function __construct( $query, $resolveRedirects = false ) {
+ public function __construct( $query, $resolveRedirects = false, $convertTitles = false ) {
parent::__construct( $query, 'query' );
$this->mAllPages = array();
if ( $resolveRedirects ) {
$this->mPendingRedirectIDs = array();
}
+
+ $this->mConvertTitles = $convertTitles;
+ $this->mConvertedTitles = array();
$this->mFakePageId = - 1;
}
public function getNormalizedTitles() {
return $this->mNormalizedTitles;
}
+
+ /**
+ * Get a list of title conversions - maps a title to its converted
+ * version.
+ * @return array raw_prefixed_title (string) => prefixed_title (string)
+ */
+ public function getConvertedTitles() {
+ return $this->mConvertedTitles;
+ }
/**
* Get a list of interwiki titles - maps a title to its interwiki
$this->mFakePageId--;
continue; // There's nothing else we can do
}
+ $unconvertedTitle = $titleObj->getPrefixedText();
+ $titleWasConverted = false;
$iw = $titleObj->getInterwiki();
if ( strval( $iw ) !== '' ) {
// This title is an interwiki link.
$this->mInterwikiTitles[$titleObj->getPrefixedText()] = $iw;
} else {
+ // Variants checking
+ global $wgContLang;
+ if ( $this->mConvertTitles &&
+ count( $wgContLang->getVariants() ) > 1 &&
+ $titleObj->getArticleID() == 0 ) {
+ // Language::findVariantLink will modify titleObj into
+ // the canonical variant if possible
+ $wgContLang->findVariantLink( $title, $titleObj );
+ $titleWasConverted = $unconvertedTitle !== $titleObj->getPrefixedText();
+ }
+
+
if ( $titleObj->getNamespace() < 0 ) {
+ // Handle Special and Media pages
$titleObj = $titleObj->fixSpecialName();
$this->mSpecialTitles[$this->mFakePageId] = $titleObj;
$this->mFakePageId--;
} else {
+ // Regular page
$linkBatch->addObj( $titleObj );
}
}
// titles with the originally requested when e.g. the
// namespace is localized or the capitalization is
// different
- if ( is_string( $title ) && $title !== $titleObj->getPrefixedText() ) {
+ if ( $titleWasConverted ) {
+ $this->mConvertedTitles[$title] = $titleObj->getPrefixedText();
+ } elseif ( is_string( $title ) && $title !== $titleObj->getPrefixedText() ) {
$this->mNormalizedTitles[$title] = $titleObj->getPrefixedText();
}
}
public function execute() {
$this->params = $this->extractRequestParams();
$this->redirects = $this->params['redirects'];
+ $this->convertTitles = $this->params['converttitles'];
// Create PageSet
- $this->mPageSet = new ApiPageSet( $this, $this->redirects );
+ $this->mPageSet = new ApiPageSet( $this, $this->redirects, $this->convertTitles );
// Instantiate requested modules
$modules = array();
$result->setIndexedTagName( $normValues, 'n' );
$result->addValue( 'query', 'normalized', $normValues );
}
+
+ // Title conversions
+ $convValues = array();
+ foreach ( $pageSet->getConvertedTitles() as $rawTitleStr => $titleStr ) {
+ $convValues[] = array(
+ 'from' => $rawTitleStr,
+ 'to' => $titleStr
+ );
+ }
+
+ if ( count( $convValues ) ) {
+ $result->setIndexedTagName( $convValues, 'c' );
+ $result->addValue( 'query', 'converted', $convValues );
+ }
// Interwiki titles
$intrwValues = array();
}
// Generator results
- $resultPageSet = new ApiPageSet( $this, $this->redirects );
+ $resultPageSet = new ApiPageSet( $this, $this->redirects, $this->convertTitles );
// Create and execute the generator
$generator = new $className ( $this, $generatorName );
ApiBase::PARAM_TYPE => $this->mAllowedGenerators
),
'redirects' => false,
+ 'converttitles' => false,
'indexpageids' => false,
'export' => false,
'exportnowrap' => false,
'generator' => array( 'Use the output of a list as the input for other prop/list/meta items',
'NOTE: generator parameter names must be prefixed with a \'g\', see examples' ),
'redirects' => 'Automatically resolve redirects',
+ 'converttitles' => 'Automatically convert titles to their canonical form',
'indexpageids' => 'Include an additional pageids section listing all returned page IDs',
'export' => 'Export the current revisions of all given or generated pages',
'exportnowrap' => 'Return the export XML without wrapping it in an XML result (same format as Special:Export). Can only be used with export',