r82723 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r82722‎ | r82723 | r82724 >
Date:14:32, 24 February 2011
Author:reedy
Status:ok
Tags:
Comment:
Don't reinvent the wheel to do an explode with formatting
Modified paths:
  • /trunk/extensions/Narayam/Narayam.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Narayam/Narayam.php
@@ -129,6 +129,10 @@
130130 return true;
131131 }
132132
 133+ function formatSchemes( $str ) {
 134+ return sprintf( 'tr_%s', $str );
 135+ }
 136+
133137 /**
134138 * Generate JavaScript code according to configuration settings
135139 *
@@ -153,12 +157,12 @@
154158 // $str .= 'Narayam.default_state = ' . Narayam::boolToString($wgNarayamConfig['default_state']) . ";\n";
155159 $str .= "Narayam.schemes = [\n";
156160 $schemeCount = count( $wgNarayamConfig['schemes'] );
157 - for ( $i = 0; $i < $schemeCount; $i++ ) {
158 - $str .= sprintf( 'tr_%s', $wgNarayamConfig['schemes'][$i] );
159 - if ( $i < ( $schemeCount - 1 ) ) {
160 - $str .= ', ';
161 - }
 161+
 162+ if ( $schemeCount > 0 ) {
 163+ $transformed = array_map( array( $this, 'formatSchemes' ) , $wgNarayamConfig['schemes'] );
 164+ $str .= implode( ',', $transformed );
162165 }
 166+
163167 $str .= "];\n";
164168 $str .= sprintf( "Narayam.default_scheme_index = %d;", $wgNarayamConfig['default_scheme_index'] );
165169 for ( $i = 0; $i < $schemeCount; $i++ ) {

Status & tagging log