r68337 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r68336‎ | r68337 | r68338 >
Date:18:48, 20 June 2010
Author:reedy
Status:ok (Comments)
Tags:
Comment:
Per http://www.mediawiki.org/wiki/Special:Code/MediaWiki/66168#c7252 switch while ( $row = $db->fectchObject( $res ) ) to foreach ( $res as row )

On ApiQueryUsers switch $r to row, and remove nested brackets
Modified paths:
  • /trunk/phase3/includes/api/ApiPageSet.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQueryAllCategories.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQueryAllLinks.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQueryAllimages.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQueryAllpages.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQueryBacklinks.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQueryCategories.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQueryCategoryInfo.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQueryCategoryMembers.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQueryDeletedrevs.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQueryDuplicateFiles.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQueryExtLinksUsage.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQueryExternalLinks.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQueryFilearchive.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQueryIWBacklinks.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQueryIWLinks.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQueryImages.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQueryInfo.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQueryLangLinks.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQueryLinks.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQueryLogEvents.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQueryProtectedTitles.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQueryRandom.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQueryRecentChanges.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQueryRevisions.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQuerySiteinfo.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQueryUserContributions.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQueryUsers.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQueryWatchlist.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQueryWatchlistRaw.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/api/ApiQueryProtectedTitles.php
@@ -77,7 +77,7 @@
7878
7979 $count = 0;
8080 $result = $this->getResult();
81 - while ( $row = $db->fetchObject( $res ) ) {
 81+ foreach ( $res as $row ) {
8282 if ( ++ $count > $params['limit'] ) {
8383 // We've reached the one extra which shows that there are additional pages to be had. Stop here...
8484 $this->setContinueEnumParameter( 'start', wfTimestamp( TS_ISO_8601, $row->pt_timestamp ) );
Index: trunk/phase3/includes/api/ApiQueryAllCategories.php
@@ -86,7 +86,7 @@
8787 $categories = array();
8888 $result = $this->getResult();
8989 $count = 0;
90 - while ( $row = $db->fetchObject( $res ) ) {
 90+ foreach ( $res as $row ) {
9191 if ( ++ $count > $params['limit'] ) {
9292 // We've reached the one extra which shows that there are additional cats to be had. Stop here...
9393 // TODO: Security issue - if the user has no right to view next title, it will still be shown
Index: trunk/phase3/includes/api/ApiQueryIWLinks.php
@@ -84,7 +84,7 @@
8585
8686 $count = 0;
8787 $db = $this->getDB();
88 - while ( $row = $db->fetchObject( $res ) ) {
 88+ foreach ( $res as $row ) {
8989 if ( ++$count > $params['limit'] ) {
9090 // We've reached the one extra which shows that
9191 // there are additional pages to be had. Stop here...
Index: trunk/phase3/includes/api/ApiQueryLinks.php
@@ -143,7 +143,7 @@
144144
145145 if ( is_null( $resultPageSet ) ) {
146146 $count = 0;
147 - while ( $row = $db->fetchObject( $res ) ) {
 147+ foreach ( $res as $row ) {
148148 if ( ++$count > $params['limit'] ) {
149149 // We've reached the one extra which shows that
150150 // there are additional pages to be had. Stop here...
@@ -165,7 +165,7 @@
166166 } else {
167167 $titles = array();
168168 $count = 0;
169 - while ( $row = $db->fetchObject( $res ) ) {
 169+ foreach ( $res as $row ) {
170170 if ( ++$count > $params['limit'] ) {
171171 // We've reached the one extra which shows that
172172 // there are additional pages to be had. Stop here...
Index: trunk/phase3/includes/api/ApiQueryExtLinksUsage.php
@@ -113,7 +113,7 @@
114114
115115 $result = $this->getResult();
116116 $count = 0;
117 - while ( $row = $db->fetchObject( $res ) ) {
 117+ foreach ( $res as $row ) {
118118 if ( ++ $count > $limit ) {
119119 // We've reached the one extra which shows that there are additional pages to be had. Stop here...
120120 $this->setContinueEnumParameter( 'offset', $offset + $limit );
Index: trunk/phase3/includes/api/ApiQueryInfo.php
@@ -369,7 +369,7 @@
370370 $this->addWhereFld( 'pr_page', array_keys( $this->titles ) );
371371
372372 $res = $this->select( __METHOD__ );
373 - while ( $row = $db->fetchObject( $res ) ) {
 373+ foreach ( $res as $row ) {
374374 $a = array(
375375 'type' => $row->pr_type,
376376 'level' => $row->pr_level,
@@ -426,7 +426,7 @@
427427 $this->addFields( array( 'pt_title', 'pt_namespace', 'pt_create_perm', 'pt_expiry' ) );
428428 $this->addWhere( $lb->constructSet( 'pt', $db ) );
429429 $res = $this->select( __METHOD__ );
430 - while ( $row = $db->fetchObject( $res ) ) {
 430+ foreach ( $res as $row ) {
431431 $this->protections[$row->pt_namespace][$row->pt_title][] = array(
432432 'type' => 'create',
433433 'level' => $row->pt_create_perm,
@@ -459,7 +459,7 @@
460460 $this->addWhereFld( 'pr_cascade', 1 );
461461
462462 $res = $this->select( __METHOD__ );
463 - while ( $row = $db->fetchObject( $res ) ) {
 463+ foreach ( $res as $row ) {
464464 $source = Title::makeTitle( $row->page_namespace, $row->page_title );
465465 $this->protections[$row->tl_namespace][$row->tl_title][] = array(
466466 'type' => $row->pr_type,
@@ -482,7 +482,7 @@
483483 $this->addWhereFld( 'il_to', $images );
484484
485485 $res = $this->select( __METHOD__ );
486 - while ( $row = $db->fetchObject( $res ) ) {
 486+ foreach ( $res as $row ) {
487487 $source = Title::makeTitle( $row->page_namespace, $row->page_title );
488488 $this->protections[NS_FILE][$row->il_to][] = array(
489489 'type' => $row->pr_type,
@@ -522,7 +522,7 @@
523523 $this->addFields( array( 'page_title', 'page_namespace', 'page_id' ) );
524524 $this->addWhere( $lb->constructSet( 'page', $db ) );
525525 $res = $this->select( __METHOD__ );
526 - while ( $row = $db->fetchObject( $res ) ) {
 526+ foreach ( $res as $row ) {
527527 if ( MWNamespace::isTalk( $row->page_namespace ) ) {
528528 $this->talkids[MWNamespace::getSubject( $row->page_namespace )][$row->page_title] =
529529 intval( $row->page_id );
@@ -560,7 +560,7 @@
561561
562562 $res = $this->select( __METHOD__ );
563563
564 - while ( $row = $db->fetchObject( $res ) ) {
 564+ foreach ( $res as $row ) {
565565 $this->watched[$row->page_namespace][$row->page_title] = true;
566566 }
567567 }
Index: trunk/phase3/includes/api/ApiQueryIWBacklinks.php
@@ -87,7 +87,7 @@
8888
8989 $count = 0;
9090 $result = $this->getResult();
91 - while ( $row = $db->fetchObject( $res ) ) {
 91+ foreach ( $res as $row ) {
9292 if ( ++ $count > $params['limit'] ) {
9393 // We've reached the one extra which shows that there are additional pages to be had. Stop here...
9494 // Continue string preserved in case the redirect query doesn't pass the limit
Index: trunk/phase3/includes/api/ApiQueryBacklinks.php
@@ -213,7 +213,7 @@
214214 $this->pageMap = array(); // Maps ns and title to pageid
215215 $this->continueStr = null;
216216 $this->redirTitles = array();
217 - while ( $row = $db->fetchObject( $res ) ) {
 217+ foreach ( $res as $row ) {
218218 if ( ++ $count > $this->params['limit'] ) {
219219 // We've reached the one extra which shows that there are additional pages to be had. Stop here...
220220 // Continue string preserved in case the redirect query doesn't pass the limit
@@ -238,7 +238,7 @@
239239 $this->prepareSecondQuery( $resultPageSet );
240240 $res = $this->select( __METHOD__ . '::secondQuery' );
241241 $count = 0;
242 - while ( $row = $db->fetchObject( $res ) ) {
 242+ foreach ( $res as $row ) {
243243 if ( ++$count > $this->params['limit'] ) {
244244 // We've reached the one extra which shows that there are additional pages to be had. Stop here...
245245 // We need to keep the parent page of this redir in
Index: trunk/phase3/includes/api/ApiQueryAllLinks.php
@@ -111,7 +111,7 @@
112112 $pageids = array();
113113 $count = 0;
114114 $result = $this->getResult();
115 - while ( $row = $db->fetchObject( $res ) ) {
 115+ foreach ( $res as $row ) {
116116 if ( ++ $count > $limit ) {
117117 // We've reached the one extra which shows that there are additional pages to be had. Stop here...
118118 // TODO: Security issue - if the user has no right to view next title, it will still be shown
Index: trunk/phase3/includes/api/ApiQuerySiteinfo.php
@@ -257,7 +257,7 @@
258258
259259 $data = array();
260260 $langNames = Language::getLanguageNames();
261 - while ( $row = $db->fetchObject( $res ) ) {
 261+ foreach ( $res as $row ) {
262262 $val = array();
263263 $val['prefix'] = $row->iw_prefix;
264264 if ( $row->iw_local == '1' ) {
Index: trunk/phase3/includes/api/ApiQueryAllpages.php
@@ -150,7 +150,7 @@
151151
152152 $count = 0;
153153 $result = $this->getResult();
154 - while ( $row = $db->fetchObject( $res ) ) {
 154+ foreach ( $res as $row ) {
155155 if ( ++ $count > $limit ) {
156156 // We've reached the one extra which shows that there are additional pages to be had. Stop here...
157157 // TODO: Security issue - if the user has no right to view next title, it will still be shown
Index: trunk/phase3/includes/api/ApiQueryAllimages.php
@@ -113,7 +113,7 @@
114114 $titles = array();
115115 $count = 0;
116116 $result = $this->getResult();
117 - while ( $row = $db->fetchObject( $res ) ) {
 117+ foreach ( $res as $row ) {
118118 if ( ++ $count > $limit ) {
119119 // We've reached the one extra which shows that there are additional pages to be had. Stop here...
120120 // TODO: Security issue - if the user has no right to view next title, it will still be shown
Index: trunk/phase3/includes/api/ApiPageSet.php
@@ -457,7 +457,7 @@
458458 ApiBase::dieDebug( __METHOD__, 'Missing $processTitles parameter when $remaining is provided' );
459459 }
460460
461 - while ( $row = $db->fetchObject( $res ) ) {
 461+ foreach ( $res as $row ) {
462462 $pageId = intval( $row->page_id );
463463
464464 // Remove found page from the list of remaining items
@@ -519,7 +519,7 @@
520520 // Get pageIDs data from the `page` table
521521 $this->profileDBIn();
522522 $res = $db->select( $tables, $fields, $where, __METHOD__ );
523 - while ( $row = $db->fetchObject( $res ) ) {
 523+ foreach ( $res as $row ) {
524524 $revid = intval( $row->rev_id );
525525 $pageid = intval( $row->rev_page );
526526 $this->mGoodRevIDs[$revid] = $pageid;
@@ -594,7 +594,7 @@
595595 );
596596 $this->profileDBOut();
597597
598 - while ( $row = $db->fetchObject( $res ) ) {
 598+ foreach ( $res as $row ) {
599599 $rdfrom = intval( $row->rd_from );
600600 $from = $this->mPendingRedirectIDs[$rdfrom]->getPrefixedText();
601601 $to = Title::makeTitle( $row->rd_namespace, $row->rd_title )->getPrefixedText();
Index: trunk/phase3/includes/api/ApiQueryLogEvents.php
@@ -154,7 +154,7 @@
155155
156156 $count = 0;
157157 $res = $this->select( __METHOD__ );
158 - while ( $row = $db->fetchObject( $res ) ) {
 158+ foreach ( $res as $row ) {
159159 if ( ++ $count > $limit ) {
160160 // We've reached the one extra which shows that there are additional pages to be had. Stop here...
161161 $this->setContinueEnumParameter( 'start', wfTimestamp( TS_ISO_8601, $row->log_timestamp ) );
Index: trunk/phase3/includes/api/ApiQueryLangLinks.php
@@ -79,7 +79,7 @@
8080
8181 $count = 0;
8282 $db = $this->getDB();
83 - while ( $row = $db->fetchObject( $res ) ) {
 83+ foreach ( $res as $row ) {
8484 if ( ++$count > $params['limit'] ) {
8585 // We've reached the one extra which shows that
8686 // there are additional pages to be had. Stop here...
Index: trunk/phase3/includes/api/ApiQueryCategories.php
@@ -130,7 +130,7 @@
131131
132132 if ( is_null( $resultPageSet ) ) {
133133 $count = 0;
134 - while ( $row = $db->fetchObject( $res ) ) {
 134+ foreach ( $res as $row ) {
135135 if ( ++$count > $params['limit'] ) {
136136 // We've reached the one extra which shows that
137137 // there are additional pages to be had. Stop here...
@@ -161,7 +161,7 @@
162162 }
163163 } else {
164164 $titles = array();
165 - while ( $row = $db->fetchObject( $res ) ) {
 165+ foreach ( $res as $row ) {
166166 if ( ++$count > $params['limit'] ) {
167167 // We've reached the one extra which shows that
168168 // there are additional pages to be had. Stop here...
Index: trunk/phase3/includes/api/ApiQueryCategoryInfo.php
@@ -78,7 +78,7 @@
7979 $res = $this->select( __METHOD__ );
8080
8181 $catids = array_flip( $cattitles );
82 - while ( $row = $db->fetchObject( $res ) ) {
 82+ foreach ( $res as $row ) {
8383 $vals = array();
8484 $vals['size'] = intval( $row->cat_pages );
8585 $vals['pages'] = $row->cat_pages - $row->cat_subcats - $row->cat_files;
Index: trunk/phase3/includes/api/ApiQueryDuplicateFiles.php
@@ -92,7 +92,7 @@
9393 $db = $this->getDB();
9494 $count = 0;
9595 $titles = array();
96 - while ( $row = $db->fetchObject( $res ) ) {
 96+ foreach ( $res as $row ) {
9797 if ( ++$count > $params['limit'] ) {
9898 // We've reached the one extra which shows that
9999 // there are additional pages to be had. Stop here...
Index: trunk/phase3/includes/api/ApiQueryWatchlist.php
@@ -178,7 +178,7 @@
179179 $count = 0;
180180 $res = $this->select( __METHOD__ );
181181
182 - while ( $row = $db->fetchObject( $res ) ) {
 182+ foreach ( $res as $row ) {
183183 if ( ++ $count > $params['limit'] ) {
184184 // We've reached the one extra which shows that there are additional pages to be had. Stop here...
185185 $this->setContinueEnumParameter( 'start', wfTimestamp( TS_ISO_8601, $row->rc_timestamp ) );
Index: trunk/phase3/includes/api/ApiQueryImages.php
@@ -88,7 +88,7 @@
8989
9090 if ( is_null( $resultPageSet ) ) {
9191 $count = 0;
92 - while ( $row = $db->fetchObject( $res ) ) {
 92+ foreach ( $res as $row ) {
9393 if ( ++$count > $params['limit'] ) {
9494 // We've reached the one extra which shows that
9595 // there are additional pages to be had. Stop here...
@@ -108,7 +108,7 @@
109109 } else {
110110 $titles = array();
111111 $count = 0;
112 - while ( $row = $db->fetchObject( $res ) ) {
 112+ foreach ( $result as $row ) {
113113 if ( ++$count > $params['limit'] ) {
114114 // We've reached the one extra which shows that
115115 // there are additional pages to be had. Stop here...
Index: trunk/phase3/includes/api/ApiQueryDeletedrevs.php
@@ -182,7 +182,7 @@
183183 $pageMap = array(); // Maps ns&title to (fake) pageid
184184 $count = 0;
185185 $newPageID = 0;
186 - while ( $row = $db->fetchObject( $res ) ) {
 186+ foreach ( $res as $row ) {
187187 if ( ++$count > $limit ) {
188188 // We've had enough
189189 if ( $mode == 'all' || $mode == 'revs' ) {
Index: trunk/phase3/includes/api/ApiQueryWatchlistRaw.php
@@ -96,7 +96,7 @@
9797 $db = $this->getDB();
9898 $titles = array();
9999 $count = 0;
100 - while ( $row = $db->fetchObject( $res ) ) {
 100+ foreach ( $res as $row ) {
101101 if ( ++$count > $params['limit'] ) {
102102 // We've reached the one extra which shows that there are additional pages to be had. Stop here...
103103 $this->setContinueEnumParameter( 'continue', $row->wl_namespace . '|' .
Index: trunk/phase3/includes/api/ApiQueryRandom.php
@@ -67,7 +67,7 @@
6868 $db = $this->getDB();
6969 $res = $this->select( __METHOD__ );
7070 $count = 0;
71 - while ( $row = $db->fetchObject( $res ) ) {
 71+ foreach ( $res as $row ) {
7272 $count++;
7373 if ( is_null( $resultPageSet ) ) {
7474 // Prevent duplicates
Index: trunk/phase3/includes/api/ApiQueryRevisions.php
@@ -322,7 +322,7 @@
323323 $count = 0;
324324 $res = $this->select( __METHOD__ );
325325
326 - while ( $row = $db->fetchObject( $res ) ) {
 326+ foreach ( $res as $row ) {
327327 if ( ++ $count > $limit ) {
328328 // We've reached the one extra which shows that there are additional pages to be had. Stop here...
329329 if ( !$enumRevMode ) {
Index: trunk/phase3/includes/api/ApiQueryFilearchive.php
@@ -120,7 +120,7 @@
121121 $titles = array();
122122 $count = 0;
123123 $result = $this->getResult();
124 - while ( $row = $db->fetchObject( $res ) ) {
 124+ foreach ( $res as $row ) {
125125 if ( ++$count > $limit ) {
126126 // We've reached the one extra which shows that there are additional pages to be had. Stop here...
127127 // TODO: Security issue - if the user has no right to view next title, it will still be shown
Index: trunk/phase3/includes/api/ApiQueryExternalLinks.php
@@ -67,7 +67,7 @@
6868 $res = $this->select( __METHOD__ );
6969
7070 $count = 0;
71 - while ( $row = $db->fetchObject( $res ) ) {
 71+ foreach ( $res as $row ) {
7272 if ( ++$count > $params['limit'] ) {
7373 // We've reached the one extra which shows that
7474 // there are additional pages to be had. Stop here...
Index: trunk/phase3/includes/api/ApiQueryCategoryMembers.php
@@ -110,7 +110,7 @@
111111 $count = 0;
112112 $lastSortKey = null;
113113 $res = $this->select( __METHOD__ );
114 - while ( $row = $db->fetchObject( $res ) ) {
 114+ foreach ( $res as $row ) {
115115 if ( ++ $count > $limit ) {
116116 // We've reached the one extra which shows that there are additional pages to be had. Stop here...
117117 // TODO: Security issue - if the user has no right to view next title, it will still be shown
Index: trunk/phase3/includes/api/ApiQueryUsers.php
@@ -126,8 +126,8 @@
127127
128128 $data = array();
129129 $res = $this->select( __METHOD__ );
130 - while ( ( $r = $db->fetchObject( $res ) ) ) {
131 - $user = User::newFromRow( $r );
 130+ foreach ( $rowes as $row ) {
 131+ $user = User::newFromRow( $row );
132132 $name = $user->getName();
133133 $data[$name]['name'] = $name;
134134
@@ -139,14 +139,14 @@
140140 $data[$name]['registration'] = wfTimestampOrNull( TS_ISO_8601, $user->getRegistration() );
141141 }
142142
143 - if ( isset( $this->prop['groups'] ) && !is_null( $r->ug_group ) ) {
 143+ if ( isset( $this->prop['groups'] ) && !is_null( $row->ug_group ) ) {
144144 // This row contains only one group, others will be added from other rows
145 - $data[$name]['groups'][] = $r->ug_group;
 145+ $data[$name]['groups'][] = $row->ug_group;
146146 }
147147
148 - if ( isset( $this->prop['blockinfo'] ) && !is_null( $r->blocker_name ) ) {
149 - $data[$name]['blockedby'] = $r->blocker_name;
150 - $data[$name]['blockreason'] = $r->ipb_reason;
 148+ if ( isset( $this->prop['blockinfo'] ) && !is_null( $row->blocker_name ) ) {
 149+ $data[$name]['blockedby'] = $row->blocker_name;
 150+ $data[$name]['blockreason'] = $row->ipb_reason;
151151 }
152152
153153 if ( isset( $this->prop['emailable'] ) && $user->canReceiveEmail() ) {
Index: trunk/phase3/includes/api/ApiQueryUserContributions.php
@@ -91,7 +91,7 @@
9292 $limit = $this->params['limit'];
9393
9494 // Fetch each row
95 - while ( $row = $db->fetchObject( $res ) ) {
 95+ foreach ( $res as $row ) {
9696 if ( ++ $count > $limit ) {
9797 // We've reached the one extra which shows that there are additional pages to be had. Stop here...
9898 if ( $this->multiUserMode ) {
Index: trunk/phase3/includes/api/ApiQueryRecentChanges.php
@@ -252,7 +252,7 @@
253253 $res = $this->select( __METHOD__ );
254254
255255 /* Iterate through the rows, adding data extracted from them to our query result. */
256 - while ( $row = $db->fetchObject( $res ) ) {
 256+ foreach ( $res as $row ) {
257257 if ( ++ $count > $params['limit'] ) {
258258 // We've reached the one extra which shows that there are additional pages to be had. Stop here...
259259 $this->setContinueEnumParameter( 'start', wfTimestamp( TS_ISO_8601, $row->rc_timestamp ) );

Follow-up revisions

RevisionCommit summaryAuthorDate
r68338Do ApiQueryAllUsers per r68337 (was using while (true)..)reedy18:52, 20 June 2010
r73543Fix bug from r68337. The variable is called $res, not $resultplatonides16:50, 22 September 2010

Comments

#Comment by Platonides (talk | contribs)   17:18, 22 September 2010

ApiQueryImages.php fixed in r73543 and ApiQueryUsers.php fixed in r68391

Status & tagging log