Merge "Revert "Adding sanity check to Title::isRedirect().""
[lhc/web/wiklou.git] / includes / api / ApiPageSet.php
index 3b49647..598f9ad 100644 (file)
  * @file
  */
 
-if ( !defined( 'MEDIAWIKI' ) ) {
-       // Eclipse helper - will be ignored in production
-       require_once( 'ApiQueryBase.php' );
-}
-
 /**
  * This class contains a list of pages that the client has requested.
  * Initially, when the client passes in titles=, pageids=, or revisions=
@@ -57,7 +52,7 @@ class ApiPageSet extends ApiQueryBase {
 
        /**
         * Constructor
-        * @param $query ApiQuery
+        * @param $query ApiQueryBase
         * @param $resolveRedirects bool Whether redirects should be resolved
         * @param $convertTitles bool
         */
@@ -347,7 +342,7 @@ class ApiPageSet extends ApiQueryBase {
 
        /**
         * Populate this PageSet from a rowset returned from the database
-        * @param $db Database object
+        * @param $db DatabaseBase object
         * @param $queryResult ResultWrapper Query result object
         */
        public function populateFromQueryResult( $db, $queryResult ) {
@@ -451,6 +446,7 @@ class ApiPageSet extends ApiQueryBase {
 
                $pageids = self::getPositiveIntegers( $pageids );
 
+               $res = null;
                if ( count( $pageids ) ) {
                        $set = array(
                                'page_id' => $pageids
@@ -463,7 +459,7 @@ class ApiPageSet extends ApiQueryBase {
                                                __METHOD__ );
                        $this->profileDBOut();
                }
-               
+
                $this->initFromQueryResult( $res, $remaining, false );  // process PageIDs
 
                // Resolve any found redirects
@@ -485,20 +481,28 @@ class ApiPageSet extends ApiQueryBase {
                        ApiBase::dieDebug( __METHOD__, 'Missing $processTitles parameter when $remaining is provided' );
                }
 
-               foreach ( $res as $row ) {
-                       $pageId = intval( $row->page_id );
+               $usernames = array();
+               if ( $res ) {
+                       foreach ( $res as $row ) {
+                               $pageId = intval( $row->page_id );
+
+                               // Remove found page from the list of remaining items
+                               if ( isset( $remaining ) ) {
+                                       if ( $processTitles ) {
+                                               unset( $remaining[$row->page_namespace][$row->page_title] );
+                                       } else {
+                                               unset( $remaining[$pageId] );
+                                       }
+                               }
 
-                       // Remove found page from the list of remaining items
-                       if ( isset( $remaining ) ) {
-                               if ( $processTitles ) {
-                                       unset( $remaining[$row->page_namespace][$row->page_title] );
-                               } else {
-                                       unset( $remaining[$pageId] );
+                               // Store any extra fields requested by modules
+                               $this->processDbRow( $row );
+
+                               // Need gender information
+                               if( MWNamespace::hasGenderDistinction( $row->page_namespace ) ) {
+                                       $usernames[] = $row->page_title;
                                }
                        }
-
-                       // Store any extra fields requested by modules
-                       $this->processDbRow( $row );
                }
 
                if ( isset( $remaining ) ) {
@@ -512,6 +516,11 @@ class ApiPageSet extends ApiQueryBase {
                                                $this->mMissingTitles[$this->mFakePageId] = $title;
                                                $this->mFakePageId--;
                                                $this->mTitles[] = $title;
+
+                                               // need gender information
+                                               if( MWNamespace::hasGenderDistinction( $ns ) ) {
+                                                       $usernames[] = $dbkey;
+                                               }
                                        }
                                }
                        } else {
@@ -523,6 +532,10 @@ class ApiPageSet extends ApiQueryBase {
                                }
                        }
                }
+
+               // Get gender information
+               $genderCache = GenderCache::singleton();
+               $genderCache->doQuery( $usernames, __METHOD__ );
        }
 
        /**
@@ -642,8 +655,8 @@ class ApiPageSet extends ApiQueryBase {
                        // We found pages that aren't in the redirect table
                        // Add them
                        foreach ( $this->mPendingRedirectIDs as $id => $title ) {
-                               $article = new Article( $title );
-                               $rt = $article->insertRedirect();
+                               $page = WikiPage::factory( $title );
+                               $rt = $page->insertRedirect();
                                if ( !$rt ) {
                                        // What the hell. Let's just ignore this
                                        continue;
@@ -666,6 +679,9 @@ class ApiPageSet extends ApiQueryBase {
         * @return LinkBatch
         */
        private function processTitlesArray( $titles ) {
+               $genderCache = GenderCache::singleton();
+               $genderCache->doTitlesArray( $titles, __METHOD__ );
+
                $linkBatch = new LinkBatch();
 
                foreach ( $titles as $title ) {
@@ -740,7 +756,7 @@ class ApiPageSet extends ApiQueryBase {
                return $array;
        }
 
-       protected function getAllowedParams() {
+       public function getAllowedParams() {
                return array(
                        'titles' => array(
                                ApiBase::PARAM_ISMULTI => true
@@ -756,7 +772,7 @@ class ApiPageSet extends ApiQueryBase {
                );
        }
 
-       protected function getParamDescription() {
+       public function getParamDescription() {
                return array(
                        'titles' => 'A list of titles to work on',
                        'pageids' => 'A list of page IDs to work on',