r38107 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r38106‎ | r38107 | r38108 >
Date:18:59, 27 July 2008
Author:simetrical
Status:old
Tags:
Comment:
* 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.
Modified paths:
  • /trunk/phase3/includes/Article.php (modified) (history)
  • /trunk/phase3/includes/PageHistory.php (modified) (history)
  • /trunk/phase3/includes/Title.php (modified) (history)
  • /trunk/phase3/includes/TitleArray.php (modified) (history)
  • /trunk/phase3/includes/UserArray.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/Article.php
@@ -1977,7 +1977,7 @@
19781978 $row = $dbw->fetchObject($res);
19791979 $onlyAuthor = $row->rev_user_text;
19801980 // Try to find a second contributor
1981 - while( $row = $dbw->fetchObject($res) ) {
 1981+ foreach( $res as $row ) {
19821982 if($row->rev_user_text != $onlyAuthor) {
19831983 $onlyAuthor = false;
19841984 break;
@@ -3281,11 +3281,9 @@
32823282 array( 'tl_namespace', 'tl_title' ),
32833283 array( 'tl_from' => $id ),
32843284 __METHOD__ );
3285 - if ( false !== $res ) {
3286 - if ( $dbr->numRows( $res ) ) {
3287 - while ( $row = $dbr->fetchObject( $res ) ) {
3288 - $result[] = Title::makeTitle( $row->tl_namespace, $row->tl_title );
3289 - }
 3285+ if( false !== $res ) {
 3286+ foreach( $res as $row ) {
 3287+ $result[] = Title::makeTitle( $row->tl_namespace, $row->tl_title );
32903288 }
32913289 }
32923290 $dbr->freeResult( $res );
@@ -3312,10 +3310,8 @@
33133311 'page_namespace' => NS_CATEGORY, 'page_title=cl_to'),
33143312 __METHOD__ );
33153313 if ( false !== $res ) {
3316 - if ( $dbr->numRows( $res ) ) {
3317 - while ( $row = $dbr->fetchObject( $res ) ) {
3318 - $result[] = Title::makeTitle( NS_CATEGORY, $row->cl_to );
3319 - }
 3314+ foreach( $res as $row ) {
 3315+ $result[] = Title::makeTitle( NS_CATEGORY, $row->cl_to );
33203316 }
33213317 }
33223318 $dbr->freeResult( $res );
@@ -3413,10 +3409,8 @@
34143410 global $wgContLang;
34153411
34163412 if ( false !== $res ) {
3417 - if ( $dbr->numRows( $res ) ) {
3418 - while ( $row = $dbr->fetchObject( $res ) ) {
3419 - $tlTemplates[] = $wgContLang->getNsText( $row->tl_namespace ) . ':' . $row->tl_title ;
3420 - }
 3413+ foreach( $res as $row ) {
 3414+ $tlTemplates[] = $wgContLang->getNsText( $row->tl_namespace ) . ':' . $row->tl_title ;
34213415 }
34223416 }
34233417
Index: trunk/phase3/includes/TitleArray.php
@@ -51,6 +51,10 @@
5252 }
5353 }
5454
 55+ public function count() {
 56+ return $this->res->numRows();
 57+ }
 58+
5559 function current() {
5660 return $this->current;
5761 }
Index: trunk/phase3/includes/Title.php
@@ -209,7 +209,7 @@
210210 'page_id IN (' . $dbr->makeList( $ids ) . ')', __METHOD__ );
211211
212212 $titles = array();
213 - while ( $row = $dbr->fetchObject( $res ) ) {
 213+ foreach( $res as $row ) {
214214 $titles[] = Title::makeTitle( $row->page_namespace, $row->page_title );
215215 }
216216 return $titles;
@@ -1661,7 +1661,7 @@
16621662 $now = wfTimestampNow();
16631663 $purgeExpired = false;
16641664
1665 - while( $row = $dbr->fetchObject( $res ) ) {
 1665+ foreach( $res as $row ) {
16661666 $expiry = Block::decodeExpiry( $row->pr_expiry );
16671667 if( $expiry > $now ) {
16681668 if ($get_pages) {
@@ -1750,7 +1750,7 @@
17511751 $now = wfTimestampNow();
17521752 $purgeExpired = false;
17531753
1754 - while ($row = $dbr->fetchObject( $res ) ) {
 1754+ foreach( $res as $row ) {
17551755 # Cycle through all the restrictions.
17561756
17571757 // Don't take care of restrictions types that aren't in $wgRestrictionTypes
@@ -2277,12 +2277,12 @@
22782278 "{$prefix}_from=page_id",
22792279 "{$prefix}_namespace" => $this->getNamespace(),
22802280 "{$prefix}_title" => $this->getDBkey() ),
2281 - 'Title::getLinksTo',
 2281+ __METHOD__,
22822282 $options );
22832283
22842284 $retVal = array();
22852285 if ( $db->numRows( $res ) ) {
2286 - while ( $row = $db->fetchObject( $res ) ) {
 2286+ foreach( $res as $row ) {
22872287 if ( $titleObj = Title::makeTitle( $row->page_namespace, $row->page_title ) ) {
22882288 $linkCache->addGoodLinkObj( $row->page_id, $titleObj, $row->page_len, $row->page_is_redirect );
22892289 $retVal[] = $titleObj;
@@ -2342,7 +2342,7 @@
23432343
23442344 $retVal = array();
23452345 if ( $db->numRows( $res ) ) {
2346 - while ( $row = $db->fetchObject( $res ) ) {
 2346+ foreach( $res as $row ) {
23472347 $retVal[] = Title::makeTitle( $row->pl_namespace, $row->pl_title );
23482348 }
23492349 }
@@ -2890,9 +2890,9 @@
28912891 $res = $dbr->query( $sql );
28922892
28932893 if( $dbr->numRows( $res ) > 0 ) {
2894 - while( $x = $dbr->fetchObject( $res ) )
2895 - //$data[] = Title::newFromText($wgContLang->getNSText ( NS_CATEGORY ).':'.$x->cl_to);
2896 - $data[$wgContLang->getNSText( NS_CATEGORY ).':'.$x->cl_to] = $this->getFullText();
 2894+ foreach( $res as $row )
 2895+ //$data[] = Title::newFromText($wgContLang->getNSText ( NS_CATEGORY ).':'.$row->cl_to);
 2896+ $data[$wgContLang->getNSText( NS_CATEGORY ).':'.$row->cl_to] = $this->getFullText();
28972897 $dbr->freeResult( $res );
28982898 } else {
28992899 $data = array();
@@ -3205,7 +3205,7 @@
32063206 );
32073207 if ( !is_null($ns) ) $where['page_namespace'] = $ns;
32083208
3209 - $result = $dbr->select(
 3209+ $res = $dbr->select(
32103210 array( 'redirect', 'page' ),
32113211 array( 'page_namespace', 'page_title' ),
32123212 $where,
@@ -3213,7 +3213,7 @@
32143214 );
32153215
32163216
3217 - while( $row = $dbr->fetchObject( $result ) ) {
 3217+ foreach( $res as $row ) {
32183218 $redirs[] = self::newFromRow( $row );
32193219 }
32203220 return $redirs;
Index: trunk/phase3/includes/PageHistory.php
@@ -444,20 +444,14 @@
445445
446446 $page_id = $this->mTitle->getArticleID();
447447
448 - $res = $dbr->select(
 448+ return $dbr->select(
449449 'revision',
450450 Revision::selectFields(),
451451 array_merge(array("rev_page=$page_id"), $offsets),
452452 __METHOD__,
453453 array('ORDER BY' => "rev_timestamp $dirs",
454454 'USE INDEX' => 'page_timestamp', 'LIMIT' => $limit)
455 - );
456 -
457 - $result = array();
458 - while (($obj = $dbr->fetchObject($res)) != NULL)
459 - $result[] = $obj;
460 -
461 - return $result;
 455+ );
462456 }
463457
464458 /** @todo document */
Index: trunk/phase3/includes/UserArray.php
@@ -36,6 +36,10 @@
3737 }
3838 }
3939
 40+ public function count() {
 41+ return $this->res->numRows();
 42+ }
 43+
4044 function current() {
4145 return $this->current;
4246 }

Follow-up revisions

RevisionCommit summaryAuthorDate
r38166Merge r38165 and part of r38107 from trunk: I changed the interface of a hook...simetrical01:01, 29 July 2008

Status & tagging log