Hi,
it seems that wfMsg has a way of replacing the $1, $2 etc. Apparently
you only need to do something like this:
$a = wfMsg( 'messagename', $value1, $value2 );
and you'll have $1 and $2 replaced with the value of $value1 and $value2.
It seems that some people have used str_replace to achieve the same
effect, which makes the source code slightly less modular and stuff. I
propose changing all instances of this to wfMsg.
I have attempted to make all these changes; please review the attached
patch. :-)
Thanks!
Timwi
Index: includes/OutputPage.php
===================================================================
RCS file: /cvsroot/wikipedia/phase3/includes/OutputPage.php,v
retrieving revision 1.159
diff -u -r1.159 OutputPage.php
--- includes/OutputPage.php 24 Jul 2004 10:55:35 -0000 1.159
+++ includes/OutputPage.php 31 Jul 2004 15:28:48 -0000
@@ -538,16 +538,13 @@
$this->mRedirect = "";
if ( $wgCommandLineMode ) {
- $msg = wfMsgNoDB( "dberrortextcl" );
+ $msg = wfMsgNoDB( "dberrortextcl", htmlspecialchars( $sql ),
+ htmlspecialchars( $fname ), $errno, htmlspecialchars( $error ) );
} else {
- $msg = wfMsgNoDB( "dberrortext" );
+ $msg = wfMsgNoDB( "dberrortext", htmlspecialchars( $sql ),
+ htmlspecialchars( $fname ), $errno, htmlspecialchars( $error ) );
}
- $msg = str_replace( "$1", htmlspecialchars( $sql ), $msg );
- $msg = str_replace( "$2", htmlspecialchars( $fname ), $msg );
- $msg = str_replace( "$3", $errno, $msg );
- $msg = str_replace( "$4", htmlspecialchars( $error ), $msg );
-
if ( $wgCommandLineMode || !is_object( $wgUser )) {
print "$msg\n";
wfErrorExit();
Index: includes/Skin.php
===================================================================
RCS file: /cvsroot/wikipedia/phase3/includes/Skin.php,v
retrieving revision 1.235
diff -u -r1.235 Skin.php
--- includes/Skin.php 24 Jul 2004 13:18:14 -0000 1.235
+++ includes/Skin.php 31 Jul 2004 15:28:48 -0000
@@ -1858,7 +1858,7 @@
$u = $nt->escapeLocalURL();
if ( $url == '' )
{
- $s = str_replace( "$1", $img->getName(), wfMsg('missingimage') );
+ $s = wfMsg( 'missingimage', $img->getName() );
$s .= "<br>{$alt}<br>{$url}<br>\n";
} else {
$s = '<a href="'.$u.'" class="image" title="'.$alt.'">' .
@@ -1929,7 +1929,7 @@
$s = "<div class=\"thumb t{$align}\"><div style=\"width:{$oboxwidth}px;\">";
if ( $thumbUrl == '' ) {
- $s .= str_replace( "$1", $img->getName(), wfMsg('missingimage') );
+ $s .= wfMsg( 'missingimage', $img->getName() );
$zoomicon = '';
} else {
$s .= '<a href="'.$u.'" class="internal" title="'.$alt.'">'.
Index: includes/SpecialAllmessages.php
===================================================================
RCS file: /cvsroot/wikipedia/phase3/includes/SpecialAllmessages.php,v
retrieving revision 1.8
diff -u -r1.8 SpecialAllmessages.php
--- includes/SpecialAllmessages.php 5 Jul 2004 22:05:28 -0000 1.8
+++ includes/SpecialAllmessages.php 31 Jul 2004 15:28:48 -0000
@@ -6,7 +6,7 @@
$ot = $wgRequest->getText('ot');
$mwMsg =& MagicWord::get( MAG_MSG );
set_time_limit(0);
- $navText = str_replace( "$1", $mwMsg->getSynonym( 0 ), wfMsg("allmessagestext" ) );
+ $navText = wfMsg( 'allmessagestext', $mwMsg->getSynonym( 0 ) );
$first = true;
$sortedArray = $wgAllMessagesEn;
ksort( $sortedArray );
Index: includes/SpecialContributions.php
===================================================================
RCS file: /cvsroot/wikipedia/phase3/includes/SpecialContributions.php,v
retrieving revision 1.29
diff -u -r1.29 SpecialContributions.php
--- includes/SpecialContributions.php 31 Jul 2004 15:14:55 -0000 1.29
+++ includes/SpecialContributions.php 31 Jul 2004 15:28:48 -0000
@@ -146,7 +146,7 @@
# Validations
$val = new Validation ;
$val = $val->countUserValidations ( $id ) ;
- $val = str_replace ( "$1" , $val , wfMsg ( 'val_user_validations' ) ) ;
+ $val = wfMsg ( 'val_user_validations', $val ) ;
$wgOut->addHTML( $val );
}
Index: includes/SpecialValidate.php
===================================================================
RCS file: /cvsroot/wikipedia/phase3/includes/SpecialValidate.php,v
retrieving revision 1.15
diff -u -r1.15 SpecialValidate.php
--- includes/SpecialValidate.php 31 Jul 2004 15:14:55 -0000 1.15
+++ includes/SpecialValidate.php 31 Jul 2004 15:28:48 -0000
@@ -174,11 +174,11 @@
{
$tablestyle = "cellspacing=0 cellpadding=2" ;
if ( $article_time == $time ) $tablestyle .=" style='border: 2px solid red'" ;
- $html .= str_replace ( "$1" , gmdate("F d, Y H:i:s",wfTimestamp2Unix($time)) , wfMsg("val_version_of") ) ;
+ $html .= wfMsg( 'val_version_of', gmdate( "F d, Y H:i:s", wfTimestamp2Unix( $time ) ) ) ;
$html .= "<form method=post>\n" ;
$html .= "<input type=hidden name=oldtime value='{$time}'>" ;
$html .= "<table {$tablestyle}>\n" ;
- $html .= str_replace ( "$1" , $tabsep , wfMsg("val_table_header") ) ;
+ $html .= wfMsg( 'val_table_header', $tabsep ) ;
for ( $idx = 0 ; $idx < count ( $validationtypes) ; $idx++ )
{
$x = explode ( "|" , $validationtypes[$idx] , 4 ) ;
@@ -296,13 +296,11 @@
$average = 100 * $vcur[$idx] / $vmax[$idx] ;
$total_count += 1 ;
$total_percent += $average ;
- if ( $users[$idx] > 1 ) $h = wfMsg ( "val_percent" ) ;
- else $h = wfMsg ( "val_percent_single" ) ;
- $h = str_replace ( "$1" , number_format ( $average , 2 ) , $h ) ;
- $h = str_replace ( "$2" , $vcur[$idx] , $h ) ;
- $h = str_replace ( "$3" , $vmax[$idx] , $h ) ;
- $h = str_replace ( "$4" , $users[$idx] , $h ) ;
- $html .= "<td align=center valign=top>" . $h ;
+ if ( $users[$idx] > 1 ) $msgid = "val_percent" ;
+ else $msgid = "val_percent_single" ;
+ $html .= "<td align=center valign=top>" .
+ wfMsg ( $msgid, number_format ( $average , 2 ) ,
+ $vcur[$idx] , $vmax[$idx] , $users[$idx] ) ;
}
else
{