From: Aryeh Gregor Date: Thu, 11 Jan 2007 20:15:03 +0000 (+0000) Subject: * When both ' and " occur in a message, escape the less common of the two X-Git-Tag: 1.31.0-rc.0~54497 X-Git-Url: http://git.cyclocoop.org/%40spipnet%40?a=commitdiff_plain;h=9d8ef635c4cb0497174f7d0642a614286cedae78;p=lhc%2Fweb%2Fwiklou.git * When both ' and " occur in a message, escape the less common of the two * Use a couple of simpler constructs in place of fors/foreaches * Why don't we use this script routinely for all message files? --- diff --git a/maintenance/language/writeMessagesArray.inc b/maintenance/language/writeMessagesArray.inc index b0d17c59ca..cb0cb89c8f 100644 --- a/maintenance/language/writeMessagesArray.inc +++ b/maintenance/language/writeMessagesArray.inc @@ -79,12 +79,7 @@ function writeMessagesBlock( $name, $comment, $messages, $ignoredComments ) { } # Get max key length - $maxKeyLength = 0; - foreach( array_keys( $messages ) as $key ) { - if ( strlen( $key ) > $maxKeyLength ) { - $maxKeyLength = strlen( $key ); - } - } + $maxKeyLength = max( array_map( 'strlen', array_keys( $messages ) ) ); # Format the messages foreach( $messages as $key => $value ) { @@ -92,9 +87,7 @@ function writeMessagesBlock( $name, $comment, $messages, $ignoredComments ) { $blockText .= "'$key'"; # Add the appropriate block whitespace - for ( $i = 1; $i <= ( $maxKeyLength - strlen( $key ) ); $i++ ) { - $blockText .= ' '; - } + $blockText .= str_repeat( ' ', $maxKeyLength - strlen( $key ) ); # Refer to the value $blockText .= ' => '; @@ -105,7 +98,9 @@ function writeMessagesBlock( $name, $comment, $messages, $ignoredComments ) { } elseif ( strpos( $value, '"' ) === false && !in_array( $key, $wgMessagseWithDollarSigns ) ) { $blockText .= "\"$value\""; } else { - $blockText .= "'" . str_replace( "'", "\'", $value ) . "'"; + # Pick the less numerous one to escape + $quote = substr_count( $value, '"' ) >= substr_count( $value, "'" ) ? "'" : '"'; + $blockText .= $quote . str_replace( $quote, '\\'.$quote, $value ) . $quote; } # Comma