r17929 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r17928‎ | r17929 | r17930 >
Date:17:11, 25 November 2006
Author:tstarling
Status:old
Tags:
Comment:
Fixed inefficient use of array_keys() introduced by Nick in r17880. If this is setting off alarms, then fix the alarms.
Modified paths:
  • /trunk/phase3/includes/GlobalFunctions.php (modified) (history)
  • /trunk/phase3/includes/LinkBatch.php (modified) (history)
  • /trunk/phase3/includes/MessageCache.php (modified) (history)
  • /trunk/phase3/includes/OutputPage.php (modified) (history)
  • /trunk/phase3/includes/ProtectionForm.php (modified) (history)
  • /trunk/phase3/includes/api/ApiMain.php (modified) (history)
  • /trunk/phase3/includes/api/ApiPageSet.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQueryInfo.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/ProtectionForm.php
@@ -130,7 +130,7 @@
131131 $out .= "<table id='mwProtectSet'>";
132132 $out .= "<tbody>";
133133 $out .= "<tr>\n";
134 - foreach( array_keys($this->mRestrictions) as $action ) {
 134+ foreach( $this->mRestrictions as $action => $required ) {
135135 /* Not all languages have V_x <-> N_x relation */
136136 $out .= "<th>" . wfMsgHtml( 'restriction-' . $action ) . "</th>\n";
137137 }
Index: trunk/phase3/includes/GlobalFunctions.php
@@ -72,7 +72,7 @@
7373 */
7474 function array_diff_key( $left, $right ) {
7575 $result = $left;
76 - foreach ( array_keys($left) as $key ) {
 76+ foreach ( $left as $key => $unused ) {
7777 if ( isset( $right[$key] ) ) {
7878 unset( $result[$key] );
7979 }
Index: trunk/phase3/includes/LinkBatch.php
@@ -97,7 +97,7 @@
9898
9999 // The remaining links in $data are bad links, register them as such
100100 foreach ( $remaining as $ns => $dbkeys ) {
101 - foreach ( array_keys($dbkeys) as $dbkey ) {
 101+ foreach ( $dbkeys as $dbkey => $unused ) {
102102 $title = Title::makeTitle( $ns, $dbkey );
103103 $cache->addBadLinkObj( $title );
104104 $ids[$title->getPrefixedDBkey()] = 0;
@@ -160,7 +160,7 @@
161161 $sql .= "({$prefix}_namespace=$ns AND {$prefix}_title IN (";
162162
163163 $firstTitle = true;
164 - foreach( array_keys($dbkeys) as $dbkey ) {
 164+ foreach( $dbkeys as $dbkey => $unused ) {
165165 if ( $firstTitle ) {
166166 $firstTitle = false;
167167 } else {
Index: trunk/phase3/includes/MessageCache.php
@@ -313,7 +313,7 @@
314314 # Go through the language array and the extension array and make a note of
315315 # any keys missing from the cache
316316 $allMessages = Language::getMessagesFor( 'en' );
317 - foreach ( array_keys($allMessages) as $key ) {
 317+ foreach ( $allMessages as $key => $unused ) {
318318 $uckey = $wgLang->ucfirst( $key );
319319 if ( !array_key_exists( $uckey, $this->mCache ) ) {
320320 $this->mCache[$uckey] = false;
@@ -324,7 +324,7 @@
325325 MessageCache::loadAllMessages();
326326
327327 # Add them to the cache
328 - foreach ( array_keys($this->mExtensionMessages) as $key ) {
 328+ foreach ( $this->mExtensionMessages as $key => $unused ) {
329329 $uckey = $wgLang->ucfirst( $key );
330330 if ( !array_key_exists( $uckey, $this->mCache ) &&
331331 ( isset( $this->mExtensionMessages[$key][$wgLang->getCode()] ) || isset( $this->mExtensionMessages[$key]['en'] ) ) ) {
@@ -343,7 +343,7 @@
344344 if ( !$this->mKeys ) {
345345 $this->mKeys = array();
346346 $allMessages = Language::getMessagesFor( 'en' );
347 - foreach ( array_keys($allMessages) as $key ) {
 347+ foreach ( $allMessages as $key => $unused ) {
348348 $title = $wgContLang->ucfirst( $key );
349349 array_push( $this->mKeys, $title );
350350 }
Index: trunk/phase3/includes/OutputPage.php
@@ -243,7 +243,7 @@
244244 $lb->execute();
245245
246246 $sk =& $wgUser->getSkin();
247 - foreach ( array_keys($categories) as $category ) {
 247+ foreach ( $categories as $category => $unused ) {
248248 $title = Title::makeTitleSafe( NS_CATEGORY, $category );
249249 $text = $wgContLang->convertHtml( $title->getText() );
250250 $this->mCategoryLinks[] = $sk->makeLinkObj( $title, $text );
@@ -1011,7 +1011,7 @@
10121012 return;
10131013 }
10141014 foreach ( $links2d as $dbkeys ) {
1015 - foreach( array_keys($dbkeys) as $dbkey ) {
 1015+ foreach( $dbkeys as $dbkey => $unused ) {
10161016 $this->addKeyword( $dbkey );
10171017 if ( ++$count > 10 ) {
10181018 break 2;
Index: trunk/phase3/includes/api/ApiQueryInfo.php
@@ -52,7 +52,7 @@
5353 $pageTouched = $pageSet->getCustomField('page_touched');
5454 $pageLatest = $pageSet->getCustomField('page_latest');
5555
56 - foreach ( array_keys($titles) as $pageid) {
 56+ foreach ( $titles as $pageid => $unused ) {
5757 $pageInfo = array (
5858 'touched' => wfTimestamp(TS_ISO_8601, $pageTouched[$pageid]),
5959 'lastrevid' => intval($pageLatest[$pageid])
Index: trunk/phase3/includes/api/ApiMain.php
@@ -296,7 +296,7 @@
297297
298298 $astriks = str_repeat('*** ', 10);
299299 $msg .= "\n\n$astriks Modules $astriks\n\n";
300 - foreach( array_keys($this->mModules) as $moduleName ) {
 300+ foreach( $this->mModules as $moduleName => $unused ) {
301301 $msg .= "* action=$moduleName *";
302302 $module = new $this->mModules[$moduleName] ($this, $moduleName);
303303 $msg2 = $module->makeHelpMsg();
@@ -306,7 +306,7 @@
307307 }
308308
309309 $msg .= "\n$astriks Formats $astriks\n\n";
310 - foreach( array_keys($this->mFormats) as $formatName ) {
 310+ foreach( $this->mFormats as $formatName => $unused ) {
311311 $msg .= "* format=$formatName *";
312312 $module = $this->createPrinterByName($formatName);
313313 $msg2 = $module->makeHelpMsg();
@@ -363,4 +363,4 @@
364364 return "{$this->getCodeString()}: {$this->getMessage()}";
365365 }
366366 }
367 -?>
\ No newline at end of file
 367+?>
Index: trunk/phase3/includes/api/ApiPageSet.php
@@ -382,7 +382,7 @@
383383 if($processTitles) {
384384 // The remaining titles in $remaining are non-existant pages
385385 foreach ($remaining as $ns => $dbkeys) {
386 - foreach ( array_keys($dbkeys) as $dbkey ) {
 386+ foreach ( $dbkeys as $dbkey => $unused ) {
387387 $title = Title :: makeTitle($ns, $dbkey);
388388 $this->mMissingTitles[] = $title;
389389 $this->mAllPages[$ns][$dbkey] = 0;
@@ -595,4 +595,4 @@
596596 return __CLASS__ . ': $Id$';
597597 }
598598 }
599 -?>
\ No newline at end of file
 599+?>

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r17880Code housekeeping stuff (and barring any stuff-ups on my behalf, there should...nickj08:25, 23 November 2006