* Add count() method to TitleArray and UserArray.
authorAryeh Gregor <simetrical@users.mediawiki.org>
Sun, 27 Jul 2008 18:59:46 +0000 (18:59 +0000)
committerAryeh Gregor <simetrical@users.mediawiki.org>
Sun, 27 Jul 2008 18:59:46 +0000 (18:59 +0000)
* Change PageHistory::fetchRevisions() to return a result object instead of an array of rows.
* Stylistic issues: use foreach( $res as $row ) instead of while( $row = $dbr->fetchObject( $res ) ), change a couple of variable names, use __METHOD__.

There should be no functional changes.

includes/Article.php
includes/PageHistory.php
includes/Title.php
includes/TitleArray.php
includes/UserArray.php

index ad45b44..5795fc0 100644 (file)
@@ -1977,7 +1977,7 @@ class Article {
                $row = $dbw->fetchObject($res);
                $onlyAuthor = $row->rev_user_text;
                // Try to find a second contributor
-               while( $row = $dbw->fetchObject($res) ) {
+               foreach( $res as $row ) {
                        if($row->rev_user_text != $onlyAuthor) {
                                $onlyAuthor = false;
                                break;
@@ -3281,11 +3281,9 @@ class Article {
                        array( 'tl_namespace', 'tl_title' ),
                        array( 'tl_from' => $id ),
                        __METHOD__ );
-               if ( false !== $res ) {
-                       if ( $dbr->numRows( $res ) ) {
-                               while ( $row = $dbr->fetchObject( $res ) ) {
-                                       $result[] = Title::makeTitle( $row->tl_namespace, $row->tl_title );
-                               }
+               if( false !== $res ) {
+                       foreach( $res as $row ) {
+                               $result[] = Title::makeTitle( $row->tl_namespace, $row->tl_title );
                        }
                }
                $dbr->freeResult( $res );
@@ -3312,10 +3310,8 @@ class Article {
                                'page_namespace' => NS_CATEGORY, 'page_title=cl_to'),
                        __METHOD__ );
                if ( false !== $res ) {
-                       if ( $dbr->numRows( $res ) ) {
-                               while ( $row = $dbr->fetchObject( $res ) ) {
-                                       $result[] = Title::makeTitle( NS_CATEGORY, $row->cl_to );
-                               }
+                       foreach( $res as $row ) {
+                               $result[] = Title::makeTitle( NS_CATEGORY, $row->cl_to );
                        }
                }
                $dbr->freeResult( $res );
@@ -3413,10 +3409,8 @@ class Article {
                        global $wgContLang;
 
                        if ( false !== $res ) {
-                               if ( $dbr->numRows( $res ) ) {
-                                       while ( $row = $dbr->fetchObject( $res ) ) {
-                                               $tlTemplates[] = $wgContLang->getNsText( $row->tl_namespace ) . ':' . $row->tl_title ;
-                                       }
+                               foreach( $res as $row ) {
+                                       $tlTemplates[] = $wgContLang->getNsText( $row->tl_namespace ) . ':' . $row->tl_title ;
                                }
                        }
 
index 9c210cf..482d93f 100644 (file)
@@ -444,20 +444,14 @@ class PageHistory {
 
                $page_id = $this->mTitle->getArticleID();
 
-               $res = $dbr->select(
+               return $dbr->select(
                        'revision',
                        Revision::selectFields(),
                        array_merge(array("rev_page=$page_id"), $offsets),
                        __METHOD__,
                        array('ORDER BY' => "rev_timestamp $dirs",
                                'USE INDEX' => 'page_timestamp', 'LIMIT' => $limit)
-                       );
-
-               $result = array();
-               while (($obj = $dbr->fetchObject($res)) != NULL)
-                       $result[] = $obj;
-
-               return $result;
+               );
        }
 
        /** @todo document */
index 9c546a7..b6a59a3 100644 (file)
@@ -209,7 +209,7 @@ class Title {
                        'page_id IN (' . $dbr->makeList( $ids ) . ')', __METHOD__ );
 
                $titles = array();
-               while ( $row = $dbr->fetchObject( $res ) ) {
+               foreach( $res as $row ) {
                        $titles[] = Title::makeTitle( $row->page_namespace, $row->page_title );
                }
                return $titles;
@@ -1661,7 +1661,7 @@ class Title {
                $now = wfTimestampNow();
                $purgeExpired = false;
 
-               while( $row = $dbr->fetchObject( $res ) ) {
+               foreach( $res as $row ) {
                        $expiry = Block::decodeExpiry( $row->pr_expiry );
                        if( $expiry > $now ) {
                                if ($get_pages) {
@@ -1750,7 +1750,7 @@ class Title {
                        $now = wfTimestampNow();
                        $purgeExpired = false;
 
-                       while ($row = $dbr->fetchObject( $res ) ) {
+                       foreach( $res as $row ) {
                                # Cycle through all the restrictions.
 
                                // Don't take care of restrictions types that aren't in $wgRestrictionTypes
@@ -2277,12 +2277,12 @@ class Title {
                                "{$prefix}_from=page_id",
                                "{$prefix}_namespace" => $this->getNamespace(),
                                "{$prefix}_title"     => $this->getDBkey() ),
-                       'Title::getLinksTo',
+                       __METHOD__,
                        $options );
 
                $retVal = array();
                if ( $db->numRows( $res ) ) {
-                       while ( $row = $db->fetchObject( $res ) ) {
+                       foreach( $res as $row ) {
                                if ( $titleObj = Title::makeTitle( $row->page_namespace, $row->page_title ) ) {
                                        $linkCache->addGoodLinkObj( $row->page_id, $titleObj, $row->page_len, $row->page_is_redirect );
                                        $retVal[] = $titleObj;
@@ -2342,7 +2342,7 @@ class Title {
 
                $retVal = array();
                if ( $db->numRows( $res ) ) {
-                       while ( $row = $db->fetchObject( $res ) ) {
+                       foreach( $res as $row ) {
                                $retVal[] = Title::makeTitle( $row->pl_namespace, $row->pl_title );
                        }
                }
@@ -2890,9 +2890,9 @@ class Title {
                $res = $dbr->query( $sql );
 
                if( $dbr->numRows( $res ) > 0 ) {
-                       while( $x = $dbr->fetchObject( $res ) )
-                               //$data[] = Title::newFromText($wgContLang->getNSText ( NS_CATEGORY ).':'.$x->cl_to);
-                               $data[$wgContLang->getNSText( NS_CATEGORY ).':'.$x->cl_to] = $this->getFullText();
+                       foreach( $res as $row )
+                               //$data[] = Title::newFromText($wgContLang->getNSText ( NS_CATEGORY ).':'.$row->cl_to);
+                               $data[$wgContLang->getNSText( NS_CATEGORY ).':'.$row->cl_to] = $this->getFullText();
                        $dbr->freeResult( $res );
                } else {
                        $data = array();
@@ -3205,7 +3205,7 @@ class Title {
                );
                if ( !is_null($ns) ) $where['page_namespace'] = $ns;
                
-               $result = $dbr->select(
+               $res = $dbr->select(
                        array( 'redirect', 'page' ),
                        array( 'page_namespace', 'page_title' ),
                        $where,
@@ -3213,7 +3213,7 @@ class Title {
                );
 
 
-               while( $row = $dbr->fetchObject( $result ) ) {
+               foreach( $res as $row ) {
                        $redirs[] = self::newFromRow( $row );
                }
                return $redirs;
index b2f3d2f..f7a9e1d 100644 (file)
@@ -51,6 +51,10 @@ class TitleArrayFromResult extends TitleArray {
                }
        }
 
+       public function count() {
+               return $this->res->numRows();
+       }
+
        function current() {
                return $this->current;
        }
index 27847e6..a2f54b7 100644 (file)
@@ -36,6 +36,10 @@ class UserArrayFromResult extends UserArray {
                }
        }
 
+       public function count() {
+               return $this->res->numRows();
+       }
+
        function current() {
                return $this->current;
        }