<?php
-
/**
- * Created on Sep 24, 2006
*
- * API for MediaWiki 1.8+
+ *
+ * Created on Sep 24, 2006
*
* Copyright © 2006 Yuri Astrakhan <Firstname><Lastname>@gmail.com
*
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
*/
if ( !defined( 'MEDIAWIKI' ) ) {
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();
$this->mPendingRedirectIDs = array();
}
+ $this->mConvertTitles = $convertTitles;
+ $this->mConvertedTitles = array();
+
$this->mFakePageId = - 1;
}
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
* prefix.
public function getMissingRevisionIDs() {
return $this->mMissingRevIDs;
}
-
+
/**
* Get the list of titles with negative namespace
* @return array Title
/**
* Populate this PageSet from a rowset returned from the database
* @param $db Database object
- * @param $queryResult Query result object
+ * @param $queryResult ResultWrapper Query result object
*/
public function populateFromQueryResult( $db, $queryResult ) {
$this->profileIn();
- $this->initFromQueryResult( $db, $queryResult );
+ $this->initFromQueryResult( $queryResult );
$this->profileOut();
}
$this->profileDBOut();
// Hack: get the ns:titles stored in array(ns => array(titles)) format
- $this->initFromQueryResult( $db, $res, $linkBatch->data, true ); // process Titles
+ $this->initFromQueryResult( $res, $linkBatch->data, true ); // process Titles
// Resolve any found redirects
$this->resolvePendingRedirects();
$this->profileDBOut();
$remaining = array_flip( $pageids );
- $this->initFromQueryResult( $db, $res, $remaining, false ); // process PageIDs
+ $this->initFromQueryResult( $res, $remaining, false ); // process PageIDs
// Resolve any found redirects
$this->resolvePendingRedirects();
/**
* Iterate through the result of the query on 'page' table,
* and for each row create and store title object and save any extra fields requested.
- * @param $db Database
- * @param $res DB Query result
+ * @param $res ResultWrapper DB Query result
* @param $remaining array of either pageID or ns/title elements (optional).
* If given, any missing items will go to $mMissingPageIDs and $mMissingTitles
* @param $processTitles bool Must be provided together with $remaining.
* If true, treat $remaining as an array of [ns][title]
* If false, treat it as an array of [pageIDs]
*/
- private function initFromQueryResult( $db, $res, &$remaining = null, $processTitles = null ) {
+ private function initFromQueryResult( $res, &$remaining = null, $processTitles = null ) {
if ( !is_null( $remaining ) && is_null( $processTitles ) ) {
ApiBase::dieDebug( __METHOD__, 'Missing $processTitles parameter when $remaining is provided' );
}
if ( $processTitles ) {
// The remaining titles in $remaining are non-existent pages
foreach ( $remaining as $ns => $dbkeys ) {
- foreach ( $dbkeys as $dbkey => $unused ) {
+ foreach ( array_keys( $dbkeys ) as $dbkey ) {
$title = Title::makeTitle( $ns, $dbkey );
$this->mAllPages[$ns][$dbkey] = $this->mFakePageId;
$this->mMissingTitles[$this->mFakePageId] = $title;
$this->profileDBOut();
// Hack: get the ns:titles stored in array(ns => array(titles)) format
- $this->initFromQueryResult( $db, $res, $linkBatch->data, true );
+ $this->initFromQueryResult( $res, $linkBatch->data, true );
}
}
}
$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->exists() ) {
+ // 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();
}
}