r79592 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r79591‎ | r79592 | r79593 >
Date:19:44, 4 January 2011
Author:vyznev
Status:ok
Tags:
Comment:
Make getLinkColours() call wfMsgForContent() 5 times per batch, rather than 5 times per link.
XXX: I have *not* tested this code (except for php -l)! Please check that I haven't made any silly mistakes.
Modified paths:
  • /trunk/extensions/ProofreadPage/ProofreadPage_body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/ProofreadPage/ProofreadPage_body.php
@@ -440,28 +440,27 @@
441441 }
442442 }
443443
 444+ // Get the names of the quality categories. Replaces earlier
 445+ // code which called wfMsgForContent() 5 times for each page.
 446+ // ISSUE: Should the number of quality levels be adjustable?
 447+ // ISSUE 2: Should this array be saved as a member variable?
 448+ // How often is this code called anyway?
 449+ $qualityCategories = array();
 450+ for ( $i = 0; $i < 5; $i++ ) {
 451+ $cat = Title::makeTitleSafe( NS_CATEGORY, wfMsgForContent( "proofreadpage_quality{$i}_category" ) );
 452+ if ( $cat ) {
 453+ $qualityCategories[$cat->getDBkey()] = "quality$i";
 454+ }
 455+ }
 456+
444457 if ( count( $values ) ) {
445458 $query .= "SELECT cl_from, cl_to FROM $catlinks WHERE cl_from IN(" . implode( ",", $values ) . ")";
446459 $res = $dbr->query( $query, __METHOD__ );
447460
448461 foreach ( $res as $x ) {
449462 $pdbk = $page_ids[$x->cl_from];
450 - switch( $x->cl_to ) {
451 - case str_replace( ' ' , '_' , wfMsgForContent( 'proofreadpage_quality0_category' ) ):
452 - $colours[$pdbk] = 'quality0';
453 - break;
454 - case str_replace( ' ' , '_' , wfMsgForContent( 'proofreadpage_quality1_category' ) ):
455 - $colours[$pdbk] = 'quality1';
456 - break;
457 - case str_replace( ' ' , '_' , wfMsgForContent( 'proofreadpage_quality2_category' ) ):
458 - $colours[$pdbk] = 'quality2';
459 - break;
460 - case str_replace( ' ' , '_' , wfMsgForContent( 'proofreadpage_quality3_category' ) ):
461 - $colours[$pdbk] = 'quality3';
462 - break;
463 - case str_replace( ' ' , '_' , wfMsgForContent( 'proofreadpage_quality4_category' ) ):
464 - $colours[$pdbk] = 'quality4';
465 - break;
 463+ if ( array_key_exists( $x->cl_to, $qualityCategories ) ) {
 464+ $colours[$pdbk] = $qualityCategories[$x->cl_to];
466465 }
467466 }
468467 }

Status & tagging log