From a72a8363b646d163d3d922fbfbb274bfc30da6f1 Mon Sep 17 00:00:00 2001 From: Jan Gerber Date: Mon, 4 Mar 2013 21:22:14 +0000 Subject: [PATCH] (bug 45201) Add option to pass defaultNamespace to ApiPageSet Change-Id: I47f0ce18fcb877ae88e5eb26eef4c1c74a6d6755 --- includes/api/ApiPageSet.php | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/includes/api/ApiPageSet.php b/includes/api/ApiPageSet.php index 1bb7e47e04..c225b1ba7d 100644 --- a/includes/api/ApiPageSet.php +++ b/includes/api/ApiPageSet.php @@ -69,18 +69,21 @@ class ApiPageSet extends ApiBase { private $mFakePageId = -1; private $mCacheMode = 'public'; private $mRequestedPageFields = array(); + private $mDefaultNamespace = NS_MAIN; /** * Constructor * @param $dbSource ApiBase Module implementing getDB(). * Allows PageSet to reuse existing db connection from the shared state like ApiQuery. * @param $flags int Zero or more flags like DISABLE_GENERATORS + * @param $defaultNamespace int the namespace to use if none is specified by a prefix. * @since 1.21 accepts $flags instead of two boolean values */ - public function __construct( ApiBase $dbSource, $flags = 0 ) { + public function __construct( ApiBase $dbSource, $flags = 0, $defaultNamespace = NS_MAIN ) { parent::__construct( $dbSource->getMain(), $dbSource->getModuleName() ); $this->mDbSource = $dbSource; $this->mAllowGenerator = ( $flags & ApiPageSet::DISABLE_GENERATORS ) == 0; + $this->mDefaultNamespace = $defaultNamespace; $this->profileIn(); $this->mParams = $this->extractRequestParams(); @@ -883,13 +886,15 @@ class ApiPageSet extends ApiBase { * @return LinkBatch */ private function processTitlesArray( $titles ) { - $genderCache = GenderCache::singleton(); - $genderCache->doTitlesArray( $titles, __METHOD__ ); - + $usernames = array(); $linkBatch = new LinkBatch(); foreach ( $titles as $title ) { - $titleObj = is_string( $title ) ? Title::newFromText( $title ) : $title; + if ( is_string( $title ) ) { + $titleObj = Title::newFromText( $title, $this->mDefaultNamespace ); + } else { + $titleObj = $title; + } if ( !$titleObj ) { // Handle invalid titles gracefully $this->mAllpages[0][$title] = $this->mFakePageId; @@ -899,10 +904,9 @@ class ApiPageSet extends ApiBase { } $unconvertedTitle = $titleObj->getPrefixedText(); $titleWasConverted = false; - $iw = $titleObj->getInterwiki(); - if ( strval( $iw ) !== '' ) { + if ( $titleObj->isExternal() ) { // This title is an interwiki link. - $this->mInterwikiTitles[$titleObj->getPrefixedText()] = $iw; + $this->mInterwikiTitles[$unconvertedTitle] = $titleObj->getInterwiki(); } else { // Variants checking global $wgContLang; @@ -941,7 +945,15 @@ class ApiPageSet extends ApiBase { } elseif ( is_string( $title ) && $title !== $titleObj->getPrefixedText() ) { $this->mNormalizedTitles[$title] = $titleObj->getPrefixedText(); } + + // Need gender information + if ( MWNamespace::hasGenderDistinction( $titleObj->getNamespace() ) ) { + $usernames[] = $titleObj->getText(); + } } + // Get gender information + $genderCache = GenderCache::singleton(); + $genderCache->doQuery( $usernames, __METHOD__ ); return $linkBatch; } -- 2.20.1