From 7452677213a14ef046144a03da2d017c696b950b Mon Sep 17 00:00:00 2001 From: Aryeh Gregor Date: Sun, 27 Jul 2008 18:59:46 +0000 Subject: [PATCH] * Add count() method to TitleArray and UserArray. * 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 | 22 ++++++++-------------- includes/PageHistory.php | 10 ++-------- includes/Title.php | 22 +++++++++++----------- includes/TitleArray.php | 4 ++++ includes/UserArray.php | 4 ++++ 5 files changed, 29 insertions(+), 33 deletions(-) diff --git a/includes/Article.php b/includes/Article.php index ad45b44e2d..5795fc0c9a 100644 --- a/includes/Article.php +++ b/includes/Article.php @@ -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 ; } } diff --git a/includes/PageHistory.php b/includes/PageHistory.php index 9c210cf5cd..482d93f6ac 100644 --- a/includes/PageHistory.php +++ b/includes/PageHistory.php @@ -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 */ diff --git a/includes/Title.php b/includes/Title.php index 9c546a7250..b6a59a3f09 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -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; diff --git a/includes/TitleArray.php b/includes/TitleArray.php index b2f3d2f379..f7a9e1dc64 100644 --- a/includes/TitleArray.php +++ b/includes/TitleArray.php @@ -51,6 +51,10 @@ class TitleArrayFromResult extends TitleArray { } } + public function count() { + return $this->res->numRows(); + } + function current() { return $this->current; } diff --git a/includes/UserArray.php b/includes/UserArray.php index 27847e6fe2..a2f54b7f27 100644 --- a/includes/UserArray.php +++ b/includes/UserArray.php @@ -36,6 +36,10 @@ class UserArrayFromResult extends UserArray { } } + public function count() { + return $this->res->numRows(); + } + function current() { return $this->current; } -- 2.20.1