r75758 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r75757‎ | r75758 | r75759 >
Date:23:08, 31 October 2010
Author:reedy
Status:ok (Comments)
Tags:
Comment:
Switch last few uses of while loops to foreach in phase3
Modified paths:
  • /trunk/phase3/includes/Export.php (modified) (history)
  • /trunk/phase3/includes/ImagePage.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialContributions.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialListusers.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialNewpages.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialUndelete.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialVersion.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/ImagePage.php
@@ -644,7 +644,7 @@
645645 $sk = $wgUser->getSkin();
646646 $count = 0;
647647 $elements = array();
648 - while ( $s = $res->fetchObject() ) {
 648+ foreach ( $res as $s ) {
649649 $count++;
650650 if ( $count <= $limit ) {
651651 // We have not yet reached the extra one that tells us there is more to fetch
Index: trunk/phase3/includes/Export.php
@@ -167,7 +167,7 @@
168168 WHERE page_id=rev_page AND $nothidden AND " . $cond ;
169169 $result = $this->db->query( $sql, __METHOD__ );
170170 $resultset = $this->db->resultObject( $result );
171 - while( $row = $resultset->fetchObject() ) {
 171+ foreach ( $resultset as $row ) {
172172 $this->author_list .= "<contributor>" .
173173 "<username>" .
174174 htmlentities( $row->rev_user_text ) .
Index: trunk/phase3/includes/specials/SpecialUndelete.php
@@ -492,7 +492,7 @@
493493 $revision = null;
494494 $restored = 0;
495495
496 - while( $row = $ret->fetchObject() ) {
 496+ foreach ( $ret as $row ) {
497497 // Check for key dupes due to shitty archive integrity.
498498 if( $row->ar_rev_id ) {
499499 $exists = $dbw->selectField( 'revision', '1', array('rev_id' => $row->ar_rev_id), __METHOD__ );
Index: trunk/phase3/includes/specials/SpecialNewpages.php
@@ -366,7 +366,7 @@
367367
368368 $feed->outHeader();
369369 if( $pager->getNumRows() > 0 ) {
370 - while( $row = $pager->mResult->fetchObject() ) {
 370+ foreach ( $pager->mResult->fetchObject() as $row ) {
371371 $feed->outItem( $this->feedItem( $row ) );
372372 }
373373 }
Index: trunk/phase3/includes/specials/SpecialContributions.php
@@ -416,7 +416,7 @@
417417
418418 $feed->outHeader();
419419 if( $pager->getNumRows() > 0 ) {
420 - while( $row = $pager->mResult->fetchObject() ) {
 420+ foreach ( $pager->mResult as $row ) {
421421 $feed->outItem( $this->feedItem( $row ) );
422422 }
423423 }
Index: trunk/phase3/includes/specials/SpecialVersion.php
@@ -294,13 +294,14 @@
295295 }
296296
297297 if ( $cnt = count( $tags = $wgParser->getTags() ) ) {
298 - for ( $i = 0; $i < $cnt; ++$i )
 298+ for ( $i = 0; $i < $cnt; ++$i ) {
299299 $tags[$i] = "&lt;{$tags[$i]}&gt;";
 300+ }
300301 $out .= $this->openExtType( wfMsg( 'version-parser-extensiontags' ), 'parser-tags' );
301302 $out .= '<tr><td colspan="4">' . $this->listToText( $tags ). "</td></tr>\n";
302303 }
303304
304 - if( $cnt = count( $fhooks = $wgParser->getFunctionHooks() ) ) {
 305+ if( count( $fhooks = $wgParser->getFunctionHooks() ) ) {
305306 $out .= $this->openExtType( wfMsg( 'version-parser-function-hooks' ), 'parser-function-hooks' );
306307 $out .= '<tr><td colspan="4">' . $this->listToText( $fhooks ) . "</td></tr>\n";
307308 }
Index: trunk/phase3/includes/specials/SpecialListusers.php
@@ -167,7 +167,7 @@
168168 }
169169 $this->mResult->rewind();
170170 $batch = new LinkBatch;
171 - while ( $row = $this->mResult->fetchObject() ) {
 171+ foreach ( $this->mResult as $row ) {
172172 $batch->addObj( Title::makeTitleSafe( NS_USER, $row->user_name ) );
173173 }
174174 $batch->execute();

Follow-up revisions

RevisionCommit summaryAuthorDate
r75765Followup r75758, spaces to tabsreedy23:54, 31 October 2010

Comments

#Comment by Jack Phoenix (talk | contribs)   23:41, 31 October 2010
 				$tags[$i] = "<{$tags[$i]}>";
+            }

You're using spaces instead of tabs here for indentation.

-		if( $cnt = count( $fhooks = $wgParser->getFunctionHooks() ) ) {
+		if( count( $fhooks = $wgParser->getFunctionHooks() ) ) {

As per Manual:Coding conventions#Assignment expressions, this should probably be written as:

		$fhooks = $wgParser->getFunctionHooks();
		if( count( $fhooks ) ) {
#Comment by Reedy (talk | contribs)   23:54, 31 October 2010

Goddamnit for the spaces

Interesting for the latter. I'd not noticed about that. I was just removing the unused variable. See bug 25517 for my suggestion of doing that..

Status & tagging log