r29943 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r29942‎ | r29943 | r29944 >
Date:06:06, 19 January 2008
Author:brion
Status:old
Tags:
Comment:
SiteConfiguration was smashing all variables into strings (or arrays of strings) with the str_replace.
This broke on things that wanted an actual 'false' or 'null' value exactly (or ints, though haven't run across such).
Changed to a type-safe replace that only does replaces on strings and strings in subarrays
Modified paths:
  • /trunk/phase3/includes/SiteConfiguration.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/SiteConfiguration.php
@@ -36,11 +36,25 @@
3737
3838 if ( !is_null( $retval ) && count( $params ) ) {
3939 foreach ( $params as $key => $value ) {
40 - $retval = str_replace( '$' . $key, $value, $retval );
 40+ $retval = $this->doReplace( '$' . $key, $value, $retval );
4141 }
4242 }
4343 return $retval;
4444 }
 45+
 46+ /** Type-safe string replace; won't do replacements on non-strings */
 47+ function doReplace( $from, $to, $in ) {
 48+ if( is_string( $in ) ) {
 49+ return str_replace( $from, $to, $in );
 50+ } elseif( is_array( $in ) ) {
 51+ foreach( $in as $key => $val ) {
 52+ $in[$key] = $this->doReplace( $from, $to, $in );
 53+ }
 54+ return $in;
 55+ } else {
 56+ return $in;
 57+ }
 58+ }
4559
4660 /** */
4761 function getAll( $wiki, $suffix, $params ) {

Status & tagging log