Don't pass $this by reference
[lhc/web/wiklou.git] / includes / api / ApiPageSet.php
index ada8543..dc7ea95 100644 (file)
@@ -1,9 +1,8 @@
 <?php
-
 /**
- * Created on Sep 24, 2006
  *
- * API for MediaWiki 1.8+
+ *
+ * Created on Sep 24, 2006
  *
  * Copyright © 2006 Yuri Astrakhan <Firstname><Lastname>@gmail.com
  *
@@ -21,6 +20,8 @@
  * 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' ) ) {
@@ -80,7 +81,7 @@ class ApiPageSet extends ApiQueryBase {
                if ( $resolveRedirects ) {
                        $this->mPendingRedirectIDs = array();
                }
-               
+
                $this->mConvertTitles = $convertTitles;
                $this->mConvertedTitles = array();
 
@@ -225,12 +226,12 @@ class ApiPageSet extends ApiQueryBase {
        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;
        }
@@ -259,7 +260,7 @@ class ApiPageSet extends ApiQueryBase {
        public function getMissingRevisionIDs() {
                return $this->mMissingRevIDs;
        }
-       
+
        /**
         * Get the list of titles with negative namespace
         * @return array Title
@@ -346,11 +347,11 @@ class ApiPageSet extends ApiQueryBase {
        /**
         * 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();
        }
 
@@ -429,7 +430,7 @@ class ApiPageSet extends ApiQueryBase {
                $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();
@@ -457,7 +458,7 @@ class ApiPageSet extends ApiQueryBase {
                $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();
@@ -466,15 +467,14 @@ class ApiPageSet extends ApiQueryBase {
        /**
         * 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' );
                }
@@ -500,7 +500,7 @@ class ApiPageSet extends ApiQueryBase {
                        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;
@@ -588,7 +588,7 @@ class ApiPageSet extends ApiQueryBase {
                                $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 );
                        }
                }
        }
@@ -667,7 +667,7 @@ class ApiPageSet extends ApiQueryBase {
                                continue; // There's nothing else we can do
                        }
                        $unconvertedTitle = $titleObj->getPrefixedText();
-                       $titleWasConverted = false;                     
+                       $titleWasConverted = false;
                        $iw = $titleObj->getInterwiki();
                        if ( strval( $iw ) !== '' ) {
                                // This title is an interwiki link.
@@ -677,14 +677,13 @@ class ApiPageSet extends ApiQueryBase {
                                global $wgContLang;
                                if ( $this->mConvertTitles &&
                                                count( $wgContLang->getVariants() ) > 1  &&
-                                               $titleObj->getArticleID() == 0 ) {
-                                       // Language::findVariantLink will modify titleObj into 
+                                               !$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();