r74745 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r74744‎ | r74745 | r74746 >
Date:23:11, 13 October 2010
Author:reedy
Status:resolved (Comments)
Tags:
Comment:
Assignment in loop conditions suck

while ( $row = $dbw->fetchObject( $res ) ) { to foreach ( $res as $row ) in includes

Add some braces
Modified paths:
  • /trunk/phase3/includes/Article.php (modified) (history)
  • /trunk/phase3/includes/Block.php (modified) (history)
  • /trunk/phase3/includes/CacheDependency.php (modified) (history)
  • /trunk/phase3/includes/Categoryfinder.php (modified) (history)
  • /trunk/phase3/includes/ChangeTags.php (modified) (history)
  • /trunk/phase3/includes/EditPage.php (modified) (history)
  • /trunk/phase3/includes/Export.php (modified) (history)
  • /trunk/phase3/includes/LinkBatch.php (modified) (history)
  • /trunk/phase3/includes/LinksUpdate.php (modified) (history)
  • /trunk/phase3/includes/LogEventsList.php (modified) (history)
  • /trunk/phase3/includes/QueryPage.php (modified) (history)
  • /trunk/phase3/includes/SquidUpdate.php (modified) (history)
  • /trunk/phase3/includes/Title.php (modified) (history)
  • /trunk/phase3/includes/User.php (modified) (history)
  • /trunk/phase3/includes/UserMailer.php (modified) (history)
  • /trunk/phase3/includes/UserRightsProxy.php (modified) (history)
  • /trunk/phase3/includes/WatchedItem.php (modified) (history)
  • /trunk/phase3/includes/WatchlistEditor.php (modified) (history)
  • /trunk/phase3/includes/Wiki.php (modified) (history)
  • /trunk/phase3/includes/api/ApiDelete.php (modified) (history)
  • /trunk/phase3/includes/db/Database.php (modified) (history)
  • /trunk/phase3/includes/db/DatabaseMssql.php (modified) (history)
  • /trunk/phase3/includes/db/DatabaseMysql.php (modified) (history)
  • /trunk/phase3/includes/db/DatabasePostgres.php (modified) (history)
  • /trunk/phase3/includes/diff/DifferenceEngine.php (modified) (history)
  • /trunk/phase3/includes/filerepo/File.php (modified) (history)
  • /trunk/phase3/includes/filerepo/LocalFile.php (modified) (history)
  • /trunk/phase3/includes/filerepo/LocalRepo.php (modified) (history)
  • /trunk/phase3/includes/installer/PostgresUpdater.php (modified) (history)
  • /trunk/phase3/includes/parser/LinkHolderArray.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialAllmessages.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialCategories.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialDisambiguations.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialExport.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialIpblocklist.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialListfiles.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialMergeHistory.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialMostlinked.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialMostlinkedcategories.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialMostlinkedtemplates.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialNewimages.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialNewpages.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialProtectedpages.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialProtectedtitles.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialStatistics.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialTags.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialUndelete.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialWatchlist.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialWhatlinkshere.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/LogEventsList.php
@@ -971,7 +971,7 @@
972972 # Do a link batch query
973973 if( $this->getNumRows() > 0 ) {
974974 $lb = new LinkBatch;
975 - while( $row = $this->mResult->fetchObject() ) {
 975+ foreach ( $this->mResult as $row ) {
976976 $lb->add( $row->log_namespace, $row->log_title );
977977 $lb->addObj( Title::makeTitleSafe( NS_USER, $row->user_name ) );
978978 $lb->addObj( Title::makeTitleSafe( NS_USER_TALK, $row->user_name ) );
Index: trunk/phase3/includes/Wiki.php
@@ -108,7 +108,7 @@
109109 if( $wgRequest->getVal( 'printable' ) === 'yes' ) {
110110 $wgOut->setPrintable();
111111 }
112 - $ret = null;
 112+
113113 if( $curid = $wgRequest->getInt( 'curid' ) ) {
114114 // URLs like this are generated by RC, because rc_title isn't always accurate
115115 $ret = Title::newFromID( $curid );
Index: trunk/phase3/includes/installer/PostgresUpdater.php
@@ -280,7 +280,7 @@
281281 }
282282
283283 $cols = array();
284 - while ( $r = $this->db->fetchRow( $res ) ) {
 284+ foreach ( $res as $r ) {
285285 $cols[] = array(
286286 "name" => $r[0],
287287 "ord" => $r[1],
Index: trunk/phase3/includes/Export.php
@@ -300,7 +300,7 @@
301301 */
302302 protected function outputPageStream( $resultset ) {
303303 $last = null;
304 - while( $row = $resultset->fetchObject() ) {
 304+ foreach ( $resultset as $row ) {
305305 if( is_null( $last ) ||
306306 $last->page_namespace != $row->page_namespace ||
307307 $last->page_title != $row->page_title ) {
@@ -331,7 +331,7 @@
332332 }
333333
334334 protected function outputLogStream( $resultset ) {
335 - while( $row = $resultset->fetchObject() ) {
 335+ foreach ( $resultset as $row ) {
336336 $output = $this->writer->writeLogItem( $row );
337337 $this->sink->writeLogItem( $row, $output );
338338 }
Index: trunk/phase3/includes/diff/DifferenceEngine.php
@@ -312,12 +312,13 @@
313313 continue;
314314 $matches = $ymatches[$line];
315315 reset($matches);
316 - while (list ($junk, $y) = each($matches))
317 - if (empty($this->in_seq[$y])) {
318 - $k = $this->_lcs_pos($y);
319 - assert($k > 0);
320 - $ymids[$k] = $ymids[$k-1];
321 - break;
 316+ while ( list( $junk, $y ) = each( $matches ) ) {
 317+ if ( empty( $this->in_seq[$y] ) ) {
 318+ $k = $this->_lcs_pos( $y );
 319+ assert( $k > 0 );
 320+ $ymids[$k] = $ymids[$k-1];
 321+ break;
 322+ }
322323 }
323324 while (list ( /* $junk */, $y) = each($matches)) {
324325 if ($y > $this->seq[$k-1]) {
Index: trunk/phase3/includes/SquidUpdate.php
@@ -40,8 +40,7 @@
4141 __METHOD__ );
4242 $blurlArr = $title->getSquidURLs();
4343 if ( $dbr->numRows( $res ) <= $wgMaxSquidPurgeTitles ) {
44 - while ( $BL = $dbr->fetchObject ( $res ) )
45 - {
 44+ foreach ( $res as $BL ) {
4645 $tobj = Title::makeTitle( $BL->page_namespace, $BL->page_title ) ;
4746 $blurlArr[] = $tobj->getInternalURL();
4847 }
Index: trunk/phase3/includes/WatchlistEditor.php
@@ -186,7 +186,7 @@
187187 __METHOD__
188188 );
189189 if( $res->numRows() > 0 ) {
190 - while( $row = $res->fetchObject() ) {
 190+ foreach ( $res as $row ) {
191191 $title = Title::makeTitleSafe( $row->wl_namespace, $row->wl_title );
192192 if( $title instanceof Title && !$title->isTalkPage() )
193193 $list[] = $title->getPrefixedText();
@@ -218,7 +218,7 @@
219219 $res = $dbr->query( $sql, __METHOD__ );
220220 if( $res && $dbr->numRows( $res ) > 0 ) {
221221 $cache = LinkCache::singleton();
222 - while( $row = $dbr->fetchObject( $res ) ) {
 222+ foreach ( $res as $row ) {
223223 $title = Title::makeTitleSafe( $row->wl_namespace, $row->wl_title );
224224 if( $title instanceof Title ) {
225225 // Update the link cache while we're at it
Index: trunk/phase3/includes/specials/SpecialWatchlist.php
@@ -341,7 +341,7 @@
342342
343343 /* Do link batch query */
344344 $linkBatch = new LinkBatch;
345 - while ( $row = $dbr->fetchObject( $res ) ) {
 345+ foreach ( $res as $row ) {
346346 $userNameUnderscored = str_replace( ' ', '_', $row->rc_user_text );
347347 if ( $row->rc_user != 0 ) {
348348 $linkBatch->add( NS_USER, $userNameUnderscored );
@@ -358,7 +358,7 @@
359359
360360 $s = $list->beginRecentChangesList();
361361 $counter = 1;
362 - while ( $obj = $dbr->fetchObject( $res ) ) {
 362+ foreach ( $res as $obj ) {
363363 # Make RC entry
364364 $rc = RecentChange::newFromRow( $obj );
365365 $rc->counter = $counter++;
Index: trunk/phase3/includes/specials/SpecialUndelete.php
@@ -739,7 +739,7 @@
740740 $sk = $wgUser->getSkin();
741741 $undelete = $this->getTitle();
742742 $wgOut->addHTML( "<ul>\n" );
743 - while( $row = $result->fetchObject() ) {
 743+ foreach ( $result as $row ) {
744744 $title = Title::makeTitleSafe( $row->ar_namespace, $row->ar_title );
745745 $link = $sk->linkKnown(
746746 $undelete,
@@ -1059,7 +1059,7 @@
10601060 # Batch existence check on user and talk pages
10611061 if( $haveRevisions ) {
10621062 $batch = new LinkBatch();
1063 - while( $row = $revisions->fetchObject() ) {
 1063+ foreach ( $revisions as $row ) {
10641064 $batch->addObj( Title::makeTitleSafe( NS_USER, $row->ar_user_text ) );
10651065 $batch->addObj( Title::makeTitleSafe( NS_USER_TALK, $row->ar_user_text ) );
10661066 }
@@ -1068,7 +1068,7 @@
10691069 }
10701070 if( $haveFiles ) {
10711071 $batch = new LinkBatch();
1072 - while( $row = $files->fetchObject() ) {
 1072+ foreach ( $files as $row ) {
10731073 $batch->addObj( Title::makeTitleSafe( NS_USER, $row->fa_user_text ) );
10741074 $batch->addObj( Title::makeTitleSafe( NS_USER_TALK, $row->fa_user_text ) );
10751075 }
@@ -1146,7 +1146,7 @@
11471147 $remaining = $revisions->numRows();
11481148 $earliestLiveTime = $this->mTargetObj->getEarliestRevTime();
11491149
1150 - while( $row = $revisions->fetchObject() ) {
 1150+ foreach ( $revisions as $row ) {
11511151 $remaining--;
11521152 $wgOut->addHTML( $this->formatRevisionRow( $row, $earliestLiveTime, $remaining, $sk ) );
11531153 }
@@ -1159,7 +1159,7 @@
11601160 if( $haveFiles ) {
11611161 $wgOut->addHTML( Xml::element( 'h2', null, wfMsg( 'filehist' ) ) . "\n" );
11621162 $wgOut->addHTML( "<ul>" );
1163 - while( $row = $files->fetchObject() ) {
 1163+ foreach ( $files as $row ) {
11641164 $wgOut->addHTML( $this->formatFileRow( $row, $sk ) );
11651165 }
11661166 $files->free();
Index: trunk/phase3/includes/specials/SpecialNewpages.php
@@ -511,7 +511,7 @@
512512 function getStartBody() {
513513 # Do a batch existence check on pages
514514 $linkBatch = new LinkBatch();
515 - while( $row = $this->mResult->fetchObject() ) {
 515+ foreach ( $this->mResult as $row ) {
516516 $linkBatch->add( NS_USER, $row->rc_user_text );
517517 $linkBatch->add( NS_USER_TALK, $row->rc_user_text );
518518 $linkBatch->add( $row->rc_namespace, $row->rc_title );
Index: trunk/phase3/includes/specials/SpecialProtectedtitles.php
@@ -196,7 +196,7 @@
197197 $this->mResult->seek( 0 );
198198 $lb = new LinkBatch;
199199
200 - while ( $row = $this->mResult->fetchObject() ) {
 200+ foreach ( $this->mResult as $row ) {
201201 $lb->add( $row->pt_namespace, $row->pt_title );
202202 }
203203
Index: trunk/phase3/includes/specials/SpecialNewimages.php
@@ -117,7 +117,7 @@
118118 * We have to flip things around to get the last N after a certain date
119119 */
120120 $images = array();
121 - while ( $s = $dbr->fetchObject( $res ) ) {
 121+ foreach ( $res as $s ) {
122122 if( $invertSort ) {
123123 array_unshift( $images, $s );
124124 } else {
Index: trunk/phase3/includes/specials/SpecialMostlinkedtemplates.php
@@ -92,7 +92,7 @@
9393 */
9494 public function preprocessResults( $db, $res ) {
9595 $batch = new LinkBatch();
96 - while( $row = $db->fetchObject( $res ) ) {
 96+ foreach ( $res as $row ) {
9797 $batch->add( $row->namespace, $row->title );
9898 }
9999 $batch->execute();
Index: trunk/phase3/includes/specials/SpecialMostlinked.php
@@ -73,8 +73,9 @@
7474 function preprocessResults( $db, $res ) {
7575 if( $db->numRows( $res ) > 0 ) {
7676 $linkBatch = new LinkBatch();
77 - while( $row = $db->fetchObject( $res ) )
 77+ foreach ( $res as $row ) {
7878 $linkBatch->add( $row->namespace, $row->title );
 79+ }
7980 $db->dataSeek( $res, 0 );
8081 $linkBatch->execute();
8182 }
Index: trunk/phase3/includes/specials/SpecialProtectedpages.php
@@ -309,7 +309,7 @@
310310 function getStartBody() {
311311 # Do a link batch query
312312 $lb = new LinkBatch;
313 - while( $row = $this->mResult->fetchObject() ) {
 313+ foreach ( $this->mResult as $row ) {
314314 $lb->add( $row->page_namespace, $row->page_title );
315315 }
316316 $lb->execute();
Index: trunk/phase3/includes/specials/SpecialListfiles.php
@@ -139,7 +139,7 @@
140140 if ( $this->mResult->numRows() ) {
141141 $lb = new LinkBatch;
142142 $this->mResult->seek( 0 );
143 - while ( $row = $this->mResult->fetchObject() ) {
 143+ foreach ( $this->mResult as $row ) {
144144 if ( $row->img_user ) {
145145 $lb->add( NS_USER, str_replace( ' ', '_', $row->img_user_text ) );
146146 }
Index: trunk/phase3/includes/specials/SpecialWhatlinkshere.php
@@ -187,21 +187,21 @@
188188 // templatelinks comes second so that the templatelinks row overwrites the
189189 // pagelinks row, so we get (inclusion) rather than nothing
190190 if( $fetchlinks ) {
191 - while ( $row = $dbr->fetchObject( $plRes ) ) {
 191+ foreach ( $plRes as $row ) {
192192 $row->is_template = 0;
193193 $row->is_image = 0;
194194 $rows[$row->page_id] = $row;
195195 }
196196 }
197197 if( !$hidetrans ) {
198 - while ( $row = $dbr->fetchObject( $tlRes ) ) {
 198+ foreach ( $tlRes as $row ) {
199199 $row->is_template = 1;
200200 $row->is_image = 0;
201201 $rows[$row->page_id] = $row;
202202 }
203203 }
204204 if( !$hideimages ) {
205 - while ( $row = $dbr->fetchObject( $ilRes ) ) {
 205+ foreach ( $ilRes as $row ) {
206206 $row->is_template = 0;
207207 $row->is_image = 1;
208208 $rows[$row->page_id] = $row;
Index: trunk/phase3/includes/specials/SpecialExport.php
@@ -315,7 +315,7 @@
316316
317317 $pages = array();
318318
319 - while ( $row = $dbr->fetchObject( $res ) ) {
 319+ foreach ( $res as $row ) {
320320 $n = $row->page_title;
321321 if ($row->page_namespace) {
322322 $ns = $wgContLang->getNsText( $row->page_namespace );
@@ -341,7 +341,7 @@
342342
343343 $pages = array();
344344
345 - while ( $row = $dbr->fetchObject( $res ) ) {
 345+ foreach ( $res as $row ) {
346346 $n = $row->page_title;
347347
348348 if ( $row->page_namespace ) {
Index: trunk/phase3/includes/specials/SpecialCategories.php
@@ -104,7 +104,7 @@
105105
106106 $this->mResult->rewind();
107107
108 - while ( $row = $this->mResult->fetchObject() ) {
 108+ foreach ( $this->mResult as $row ) {
109109 $batch->addObj( Title::makeTitleSafe( NS_CATEGORY, $row->cat_title ) );
110110 }
111111 $batch->execute();
Index: trunk/phase3/includes/specials/SpecialStatistics.php
@@ -278,7 +278,7 @@
279279 $text .= Xml::openElement( 'tr' );
280280 $text .= Xml::tags( 'th', array( 'colspan' => '2' ), wfMsgExt( 'statistics-mostpopular', array( 'parseinline' ) ) );
281281 $text .= Xml::closeElement( 'tr' );
282 - while( $row = $res->fetchObject() ) {
 282+ foreach ( $res as $row ) {
283283 $title = Title::makeTitleSafe( $row->page_namespace, $row->page_title );
284284 if( $title instanceof Title ) {
285285 $text .= $this->formatRow( $sk->link( $title ),
Index: trunk/phase3/includes/specials/SpecialTags.php
@@ -50,7 +50,7 @@
5151 $dbr = wfGetDB( DB_SLAVE );
5252 $res = $dbr->select( 'change_tag', array( 'ct_tag', 'count(*) as hitcount' ), array(), __METHOD__, array( 'GROUP BY' => 'ct_tag', 'ORDER BY' => 'hitcount DESC' ) );
5353
54 - while ( $row = $res->fetchObject() ) {
 54+ foreach ( $res as $row ) {
5555 $html .= $this->doTagRow( $row->ct_tag, $row->hitcount );
5656 }
5757
Index: trunk/phase3/includes/specials/SpecialAllmessages.php
@@ -227,7 +227,7 @@
228228
229229 $pageFlags = $talkFlags = array();
230230
231 - while( $s = $dbr->fetchObject( $res ) ) {
 231+ foreach ( $res as $s ) {
232232 if( $s->page_namespace == NS_MEDIAWIKI ) {
233233 if( $this->foreign ) {
234234 $title = explode( '/', $s->page_title );
Index: trunk/phase3/includes/specials/SpecialIpblocklist.php
@@ -544,7 +544,7 @@
545545 # Faster way
546546 # Usernames and titles are in fact related by a simple substitution of space -> underscore
547547 # The last few lines of Title::secureAndSplit() tell the story.
548 - while ( $row = $this->mResult->fetchObject() ) {
 548+ foreach ( $this->mResult as $row ) {
549549 $name = str_replace( ' ', '_', $row->ipb_by_text );
550550 $lb->add( NS_USER, $name );
551551 $lb->add( NS_USER_TALK, $name );
Index: trunk/phase3/includes/specials/SpecialMostlinkedcategories.php
@@ -58,8 +58,9 @@
5959 */
6060 function preprocessResults( $db, $res ) {
6161 $batch = new LinkBatch;
62 - while ( $row = $db->fetchObject( $res ) )
 62+ foreach ( $res as $row ) {
6363 $batch->add( $row->namespace, $row->title );
 64+ }
6465 $batch->execute();
6566
6667 // Back to start for display
Index: trunk/phase3/includes/specials/SpecialMergeHistory.php
@@ -438,7 +438,7 @@
439439 $batch = new LinkBatch();
440440 # Give some pointers to make (last) links
441441 $this->mForm->prevId = array();
442 - while( $row = $this->mResult->fetchObject() ) {
 442+ foreach ( $this->mResult as $row ) {
443443 $batch->addObj( Title::makeTitleSafe( NS_USER, $row->rev_user_text ) );
444444 $batch->addObj( Title::makeTitleSafe( NS_USER_TALK, $row->rev_user_text ) );
445445
Index: trunk/phase3/includes/specials/SpecialDisambiguations.php
@@ -69,7 +69,7 @@
7070 'page_namespace' => $disPageObj->getNamespace(), 'page_title' => $disPageObj->getDBkey()),
7171 __METHOD__ );
7272
73 - while ( $row = $dbr->fetchObject( $res ) ) {
 73+ foreach ( $res as $row ) {
7474 $linkBatch->addObj( Title::makeTitle( NS_TEMPLATE, $row->pl_title ));
7575 }
7676 }
Index: trunk/phase3/includes/Title.php
@@ -2106,9 +2106,8 @@
21072107 */
21082108 private function loadRestrictionsFromResultWrapper( $res, $oldFashionedRestrictions = null ) {
21092109 $rows = array();
2110 - $dbr = wfGetDB( DB_SLAVE );
21112110
2112 - while ( $row = $dbr->fetchObject( $res ) ) {
 2111+ foreach ( $res as $row ) {
21132112 $rows[] = $row;
21142113 }
21152114
Index: trunk/phase3/includes/LinkBatch.php
@@ -109,7 +109,7 @@
110110
111111 $ids = array();
112112 $remaining = $this->data;
113 - while ( $row = $res->fetchObject() ) {
 113+ foreach ( $res as $row ) {
114114 $title = Title::makeTitle( $row->page_namespace, $row->page_title );
115115 $cache->addGoodLinkObj( $row->page_id, $title, $row->page_len, $row->page_is_redirect, $row->page_latest );
116116 $ids[$title->getPrefixedDBkey()] = $row->page_id;
Index: trunk/phase3/includes/CacheDependency.php
@@ -280,7 +280,7 @@
281281 __METHOD__
282282 );
283283
284 - while ( $row = $dbr->fetchObject( $res ) ) {
 284+ foreach ( $res as $row ) {
285285 $timestamps[$row->page_namespace][$row->page_title] = $row->page_touched;
286286 }
287287 }
Index: trunk/phase3/includes/EditPage.php
@@ -1079,7 +1079,7 @@
10801080 ),
10811081 __METHOD__,
10821082 array( 'ORDER BY' => 'rev_timestamp ASC', 'LIMIT' => 50 ) );
1083 - while( $row = $res->fetchObject() ) {
 1083+ foreach ( $res as $row ) {
10841084 if( $row->rev_user != $id ) {
10851085 return false;
10861086 }
Index: trunk/phase3/includes/api/ApiDelete.php
@@ -232,7 +232,7 @@
233233 ApiBase::PARAM_DFLT => false,
234234 ApiBase::PARAM_DEPRECATED => true,
235235 ),
236 - 'oldimage' => null
 236+ 'oldimage' => null,
237237 );
238238 }
239239
Index: trunk/phase3/includes/Block.php
@@ -531,7 +531,7 @@
532532 # No results, don't autoblock anything
533533 wfDebug( "No IP found to retroactively autoblock\n" );
534534 } else {
535 - while ( $row = $dbr->fetchObject( $res ) ) {
 535+ foreach ( $res as $row ) {
536536 if ( $row->rc_ip ) {
537537 $this->doAutoblock( $row->rc_ip );
538538 }
Index: trunk/phase3/includes/parser/LinkHolderArray.php
@@ -204,7 +204,7 @@
205205
206206 # Fetch data and form into an associative array
207207 # non-existent = broken
208 - while ( $s = $dbr->fetchObject($res) ) {
 208+ foreach ( $res as $s ) {
209209 $title = Title::makeTitle( $s->page_namespace, $s->page_title );
210210 $pdbk = $title->getPrefixedDBkey();
211211 $linkCache->addGoodLinkObj( $s->page_id, $title, $s->page_len, $s->page_is_redirect, $s->page_latest );
@@ -337,9 +337,9 @@
338338 foreach ( $titlesAllVariants as &$titlesVariant ) {
339339 $titlesVariant = explode( "\0", $titlesVariant );
340340 }
341 -
 341+ $l = count( $titlesAttrs );
342342 // Then add variants of links to link batch
343 - for ( $i = 0; $l = count( $titlesAttrs ), $i < $l; $i ++ ) {
 343+ for ( $i = 0; $i < $l; $i ++ ) {
344344 foreach ( $allVariantsName as $variantName ) {
345345 $textVariant = $titlesAllVariants[$variantName][$i];
346346 extract( $titlesAttrs[$i] );
@@ -381,7 +381,7 @@
382382 $linkcolour_ids = array();
383383
384384 // for each found variants, figure out link holders and replace
385 - while ( $s = $dbr->fetchObject($varRes) ) {
 385+ foreach ( $varRes as $s ) {
386386
387387 $variantTitle = Title::makeTitle( $s->page_namespace, $s->page_title );
388388 $varPdbk = $variantTitle->getPrefixedDBkey();
Index: trunk/phase3/includes/WatchedItem.php
@@ -143,7 +143,7 @@
144144 );
145145 # Construct array to replace into the watchlist
146146 $values = array();
147 - while ( $s = $dbw->fetchObject( $res ) ) {
 147+ foreach ( $res as $s ) {
148148 $values[] = array(
149149 'wl_user' => $s->wl_user,
150150 'wl_namespace' => $newnamespace,
Index: trunk/phase3/includes/ChangeTags.php
@@ -181,15 +181,16 @@
182182 global $wgMemc;
183183 $key = wfMemcKey( 'valid-tags' );
184184
185 - if ( $tags = $wgMemc->get( $key ) )
 185+ if ( $tags = $wgMemc->get( $key ) ) {
186186 return $tags;
 187+ }
187188
188189 $emptyTags = array();
189190
190191 // Some DB stuff
191192 $dbr = wfGetDB( DB_SLAVE );
192193 $res = $dbr->select( 'valid_tag', 'vt_tag', array(), __METHOD__ );
193 - while( $row = $res->fetchObject() ) {
 194+ foreach ( $res as $row ) {
194195 $emptyTags[] = $row->vt_tag;
195196 }
196197
Index: trunk/phase3/includes/UserMailer.php
@@ -306,7 +306,7 @@
307307 'wl_notificationtimestamp IS NULL',
308308 ), __METHOD__
309309 );
310 - while ($row = $dbw->fetchObject( $res ) ) {
 310+ foreach ( $res as $row ) {
311311 $watchers[] = intval( $row->wl_user );
312312 }
313313 if ($watchers) {
Index: trunk/phase3/includes/User.php
@@ -976,7 +976,7 @@
977977 array( 'ug_user' => $this->mId ),
978978 __METHOD__ );
979979 $this->mGroups = array();
980 - while( $row = $dbr->fetchObject( $res ) ) {
 980+ foreach ( $res as $row ) {
981981 $this->mGroups[] = $row->ug_group;
982982 }
983983 }
@@ -3633,7 +3633,7 @@
36343634 __METHOD__
36353635 );
36363636
3637 - while( $row = $dbr->fetchObject( $res ) ) {
 3637+ foreach ( $res as $row ) {
36383638 $this->mOptionOverrides[$row->up_property] = $row->up_value;
36393639 $this->mOptions[$row->up_property] = $row->up_value;
36403640 }
Index: trunk/phase3/includes/UserRightsProxy.php
@@ -157,7 +157,7 @@
158158 array( 'ug_user' => $this->id ),
159159 __METHOD__ );
160160 $groups = array();
161 - while( $row = $this->db->fetchObject( $res ) ) {
 161+ foreach ( $res as $row ) {
162162 $groups[] = $row->ug_group;
163163 }
164164 return $groups;
Index: trunk/phase3/includes/Categoryfinder.php
@@ -154,7 +154,7 @@
155155 /* WHERE */ array( 'cl_from' => $this->next ),
156156 __METHOD__ . '-1'
157157 );
158 - while ( $o = $this->dbr->fetchObject( $res ) ) {
 158+ foreach ( $res as $o ) {
159159 $k = $o->cl_to;
160160
161161 # Update parent tree
@@ -186,7 +186,7 @@
187187 /* WHERE */ array( 'page_namespace' => NS_CATEGORY , 'page_title' => $layer ),
188188 __METHOD__ . '-2'
189189 );
190 - while ( $o = $this->dbr->fetchObject( $res ) ) {
 190+ foreach ( $res as $o ) {
191191 $id = $o->page_id;
192192 $name = $o->page_title;
193193 $this->name2id[$name] = $id;
Index: trunk/phase3/includes/filerepo/File.php
@@ -892,7 +892,7 @@
893893
894894 $retVal = array();
895895 if ( $db->numRows( $res ) ) {
896 - while ( $row = $db->fetchObject( $res ) ) {
 896+ foreach ( $res as $row ) {
897897 if ( $titleObj = Title::newFromRow( $row ) ) {
898898 $linkCache->addGoodLinkObj( $row->page_id, $titleObj, $row->page_len, $row->page_is_redirect, $row->page_latest );
899899 $retVal[] = $titleObj;
Index: trunk/phase3/includes/filerepo/LocalRepo.php
@@ -164,9 +164,10 @@
165165 );
166166
167167 $result = array();
168 - while ( $row = $res->fetchObject() )
 168+ foreach ( $res as $row ) {
169169 $result[] = $this->newFileFromRow( $row );
170 - $res->free();
 170+ }
 171+
171172 return $result;
172173 }
173174
Index: trunk/phase3/includes/filerepo/LocalFile.php
@@ -713,7 +713,7 @@
714714 $res = $dbr->select( $tables, $fields, $conds, __METHOD__, $opts, $join_conds );
715715 $r = array();
716716
717 - while ( $row = $dbr->fetchObject( $res ) ) {
 717+ foreach ( $res as $row ) {
718718 if ( $this->repo->oldFileFromRowFactory ) {
719719 $r[] = call_user_func( $this->repo->oldFileFromRowFactory, $row, $this->repo );
720720 } else {
@@ -1127,7 +1127,7 @@
11281128 $result = $dbw->select( 'oldimage',
11291129 array( 'oi_archive_name' ),
11301130 array( 'oi_name' => $this->getName() ) );
1131 - while ( $row = $dbw->fetchObject( $result ) ) {
 1131+ foreach ( $result as $row ) {
11321132 $batch->addOld( $row->oi_archive_name );
11331133 }
11341134 $status = $batch->execute();
@@ -1341,7 +1341,7 @@
13421342 __METHOD__
13431343 );
13441344
1345 - while ( $row = $dbw->fetchObject( $res ) ) {
 1345+ foreach ( $res as $row ) {
13461346 if ( rtrim( $row->oi_sha1, "\0" ) === '' ) {
13471347 // Get the hash from the file
13481348 $oldUrl = $this->file->getArchiveVirtualUrl( $row->oi_archive_name );
@@ -1504,7 +1504,7 @@
15051505 $dbw->bitAnd( 'oi_deleted', File::DELETED_FILE ) => File::DELETED_FILE ),
15061506 __METHOD__ );
15071507
1508 - while ( $row = $dbw->fetchObject( $res ) ) {
 1508+ foreach ( $res as $row ) {
15091509 $privateFiles[$row->oi_archive_name] = 1;
15101510 }
15111511 }
@@ -1674,7 +1674,7 @@
16751675 $first = true;
16761676 $archiveNames = array();
16771677
1678 - while ( $row = $dbw->fetchObject( $result ) ) {
 1678+ foreach ( $result as $row ) {
16791679 $idsPresent[] = $row->fa_id;
16801680
16811681 if ( $row->fa_name != $this->file->getName() ) {
@@ -1958,7 +1958,7 @@
19591959 __METHOD__
19601960 );
19611961
1962 - while ( $row = $this->db->fetchObject( $result ) ) {
 1962+ foreach ( $result as $row ) {
19631963 $oldName = $row->oi_archive_name;
19641964 $bits = explode( '!', $oldName, 2 );
19651965
Index: trunk/phase3/includes/LinksUpdate.php
@@ -247,7 +247,7 @@
248248 'page_touched < ' . $this->mDb->addQuotes( $now )
249249 ), __METHOD__
250250 );
251 - while ( $row = $this->mDb->fetchObject( $res ) ) {
 251+ foreach ( $res as $row ) {
252252 $ids[] = $row->page_id;
253253 }
254254 if ( !count( $ids ) ) {
@@ -628,7 +628,7 @@
629629 $res = $this->mDb->select( 'pagelinks', array( 'pl_namespace', 'pl_title' ),
630630 array( 'pl_from' => $this->mId ), __METHOD__, $this->mOptions );
631631 $arr = array();
632 - while ( $row = $this->mDb->fetchObject( $res ) ) {
 632+ foreach ( $res as $row ) {
633633 if ( !isset( $arr[$row->pl_namespace] ) ) {
634634 $arr[$row->pl_namespace] = array();
635635 }
@@ -645,7 +645,7 @@
646646 $res = $this->mDb->select( 'templatelinks', array( 'tl_namespace', 'tl_title' ),
647647 array( 'tl_from' => $this->mId ), __METHOD__, $this->mOptions );
648648 $arr = array();
649 - while ( $row = $this->mDb->fetchObject( $res ) ) {
 649+ foreach ( $res as $row ) {
650650 if ( !isset( $arr[$row->tl_namespace] ) ) {
651651 $arr[$row->tl_namespace] = array();
652652 }
@@ -662,7 +662,7 @@
663663 $res = $this->mDb->select( 'imagelinks', array( 'il_to' ),
664664 array( 'il_from' => $this->mId ), __METHOD__, $this->mOptions );
665665 $arr = array();
666 - while ( $row = $this->mDb->fetchObject( $res ) ) {
 666+ foreach ( $res as $row ) {
667667 $arr[$row->il_to] = 1;
668668 }
669669 return $arr;
@@ -676,7 +676,7 @@
677677 $res = $this->mDb->select( 'externallinks', array( 'el_to' ),
678678 array( 'el_from' => $this->mId ), __METHOD__, $this->mOptions );
679679 $arr = array();
680 - while ( $row = $this->mDb->fetchObject( $res ) ) {
 680+ foreach ( $res as $row ) {
681681 $arr[$row->el_to] = 1;
682682 }
683683 return $arr;
@@ -690,7 +690,7 @@
691691 $res = $this->mDb->select( 'categorylinks', array( 'cl_to', 'cl_sortkey' ),
692692 array( 'cl_from' => $this->mId ), __METHOD__, $this->mOptions );
693693 $arr = array();
694 - while ( $row = $this->mDb->fetchObject( $res ) ) {
 694+ foreach ( $res as $row ) {
695695 $arr[$row->cl_to] = $row->cl_sortkey;
696696 }
697697 return $arr;
@@ -705,7 +705,7 @@
706706 $res = $this->mDb->select( 'langlinks', array( 'll_lang', 'll_title' ),
707707 array( 'll_from' => $this->mId ), __METHOD__, $this->mOptions );
708708 $arr = array();
709 - while ( $row = $this->mDb->fetchObject( $res ) ) {
 709+ foreach ( $res as $row ) {
710710 $arr[$row->ll_lang] = $row->ll_title;
711711 }
712712 return $arr;
@@ -719,7 +719,7 @@
720720 $res = $this->mDb->select( 'iwlinks', array( 'iwl_prefix', 'iwl_title' ),
721721 array( 'iwl_from' => $this->mId ), __METHOD__, $this->mOptions );
722722 $arr = array();
723 - while ( $row = $this->mDb->fetchObject( $res ) ) {
 723+ foreach ( $res as $row ) {
724724 if ( !isset( $arr[$row->iwl_prefix] ) ) {
725725 $arr[$row->iwl_prefix] = array();
726726 }
@@ -736,7 +736,7 @@
737737 $res = $this->mDb->select( 'page_props', array( 'pp_propname', 'pp_value' ),
738738 array( 'pp_page' => $this->mId ), __METHOD__, $this->mOptions );
739739 $arr = array();
740 - while ( $row = $this->mDb->fetchObject( $res ) ) {
 740+ foreach ( $res as $row ) {
741741 $arr[$row->pp_propname] = $row->pp_value;
742742 }
743743 return $arr;
Index: trunk/phase3/includes/QueryPage.php
@@ -482,9 +482,11 @@
483483 $sql = $this->getSQL() . $this->getOrder();
484484 $sql = $dbr->limitResult( $sql, $limit, 0 );
485485 $res = $dbr->query( $sql, 'QueryPage::doFeed' );
486 - while( $obj = $dbr->fetchObject( $res ) ) {
 486+ foreach ( $res as $obj ) {
487487 $item = $this->feedResult( $obj );
488 - if( $item ) $feed->outItem( $item );
 488+ if( $item ) {
 489+ $feed->outItem( $item );
 490+ }
489491 }
490492
491493 $feed->outFooter();
@@ -567,8 +569,9 @@
568570 */
569571 function preprocessResults( $db, $res ) {
570572 $batch = new LinkBatch;
571 - while ( $row = $db->fetchObject( $res ) )
 573+ foreach ( $res as $row ) {
572574 $batch->add( $row->namespace, $row->title );
 575+ }
573576 $batch->execute();
574577
575578 // Back to start for display
Index: trunk/phase3/includes/Article.php
@@ -1590,7 +1590,7 @@
15911591 }
15921592
15931593 $tbtext = "";
1594 - while ( $o = $dbr->fetchObject( $tbs ) ) {
 1594+ foreach ( $tbs as $o ) {
15951595 $rmvtxt = "";
15961596
15971597 if ( $wgUser->isAllowed( 'trackback' ) ) {
@@ -2992,7 +2992,7 @@
29932993
29942994 $authors = array( $row->rev_user_text );
29952995
2996 - while ( $row = $db->fetchObject( $res ) ) {
 2996+ foreach ( $res as $row ) {
29972997 $authors[] = $row->rev_user_text;
29982998 }
29992999
Index: trunk/phase3/includes/db/Database.php
@@ -1217,7 +1217,7 @@
12181218
12191219 $result = array();
12201220
1221 - while ( $row = $this->fetchObject( $res ) ) {
 1221+ foreach ( $res as $row ) {
12221222 if ( $row->Key_name == $index ) {
12231223 $result[] = $row;
12241224 }
@@ -2332,7 +2332,7 @@
23332333 $res = $this->query( "SHOW STATUS LIKE '{$which}'" );
23342334 $status = array();
23352335
2336 - while ( $row = $this->fetchObject( $res ) ) {
 2336+ foreach ( $res as $row ) {
23372337 $status[$row->Variable_name] = $row->Value;
23382338 }
23392339
Index: trunk/phase3/includes/db/DatabaseMssql.php
@@ -347,7 +347,7 @@
348348 }
349349
350350 $result = array();
351 - while ( $row = $res->FetchNextObj() ) {
 351+ foreach ( $res as $row ) {
352352 if ( $row->index_name == $index ) {
353353 $row->Non_unique = !stristr( $row->index_description, "unique" );
354354 $cols = explode( ", ", $row->index_keys );
@@ -784,8 +784,9 @@
785785 print( "Error in fieldInfo query: " . $this->getErrors() );
786786 return false;
787787 }
788 - if ( $meta = $this->fetchRow( $res ) )
 788+ if ( $meta = $this->fetchRow( $res ) ) {
789789 return new MssqlField( $meta );
 790+ }
790791 return false;
791792 }
792793
Index: trunk/phase3/includes/db/DatabaseMysql.php
@@ -260,7 +260,7 @@
261261 }
262262
263263 $rows = 1;
264 - while( $plan = $this->fetchObject( $res ) ) {
 264+ foreach ( $res as $plan ) {
265265 $rows *= $plan->rows > 0 ? $plan->rows : 1; // avoid resetting to zero
266266 }
267267 return $rows;
Index: trunk/phase3/includes/db/DatabasePostgres.php
@@ -737,7 +737,7 @@
738738 if ( !$res ) {
739739 return null;
740740 }
741 - while ( $row = $this->fetchObject( $res ) ) {
 741+ foreach ( $res as $row ) {
742742 if ( $row->indexname == $this->indexName( $index ) ) {
743743 return $row;
744744 }
@@ -754,7 +754,7 @@
755755 if ( !$res ) {
756756 return null;
757757 }
758 - while ( $row = $this->fetchObject( $res ) ) {
 758+ foreach ( $res as $row ) {
759759 return true;
760760 }
761761 return false;

Follow-up revisions

RevisionCommit summaryAuthorDate
r76185reinsert some statements removed by r74745...hashar11:30, 6 November 2010

Comments

#Comment by Hashar (talk | contribs)   11:30, 6 November 2010

You removed a free() statement in filerepo/LocalRepo.php In Wiki.php the explicit $ret = null was welcomed

Status & tagging log