<?php
-
/**
- * Created on Sep 24, 2006
*
- * API for MediaWiki 1.8+
+ *
+ * Created on Sep 24, 2006
*
* Copyright © 2006 Yuri Astrakhan <Firstname><Lastname>@gmail.com
*
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
- * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
*/
if ( !defined( 'MEDIAWIKI' ) ) {
private $mAllPages; // [ns][dbkey] => page_id or negative when missing
private $mTitles, $mGoodTitles, $mMissingTitles, $mInvalidTitles;
- private $mMissingPageIDs, $mRedirectTitles;
+ 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->mInterwikiTitles = array();
$this->mGoodRevIDs = array();
$this->mMissingRevIDs = array();
+ $this->mSpecialTitles = array();
$this->mRequestedPageFields = array();
$this->mResolveRedirects = $resolveRedirects;
$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.
return $this->mMissingRevIDs;
}
+ /**
+ * Get the list of titles with negative namespace
+ * @return array Title
+ */
+ public function getSpecialTitles() {
+ return $this->mSpecialTitles;
+ }
+
/**
* Returns the number of revisions (requested with revids= parameter)\
* @return int
/**
* 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' );
}
- while ( $row = $db->fetchObject( $res ) ) {
+ foreach ( $res as $row ) {
$pageId = intval( $row->page_id );
// Remove found page from the list of remaining items
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;
// Get pageIDs data from the `page` table
$this->profileDBIn();
$res = $db->select( $tables, $fields, $where, __METHOD__ );
- while ( $row = $db->fetchObject( $res ) ) {
+ foreach ( $res as $row ) {
$revid = intval( $row->rev_id );
$pageid = intval( $row->rev_page );
$this->mGoodRevIDs[$revid] = $pageid;
$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->profileDBOut();
- while ( $row = $db->fetchObject( $res ) ) {
+ foreach ( $res as $row ) {
$rdfrom = intval( $row->rd_from );
$from = $this->mPendingRedirectIDs[$rdfrom]->getPrefixedText();
$to = Title::makeTitle( $row->rd_namespace, $row->rd_title )->getPrefixedText();
$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 {
- // Validation
+ // 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 ) {
- $this->setWarning( 'No support for special pages has been implemented' );
+ // 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();
}
}