From 8637bac8ca527368fc9d33cd408b67f526e66785 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Sat, 27 May 2006 23:25:32 +0000 Subject: [PATCH] Move parameter replacement before brace transformations in most of the wfMsg() family (except for wfMsgHtml). This allows things like {{plural:}}, {{urlencode:}}, and {{fullurl:}} to be used in most cases correctly. The content or UI language will be used accordingly for (forContent)?. --- RELEASE-NOTES | 4 ++++ includes/GlobalFunctions.php | 35 ++++++++++++++++++++++++++++++++++- 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 8980380ea4..d96db46031 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -359,6 +359,10 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN under HTML-compatible browsers. * (bug 5077) Added hook 'BeforePageDisplay' to SkinTemplate::outputPage * Replace fatally changed 'uploadnewversion' with 'uploadnewversion-linktext' +* Move parameter replacement before brace transformations in most of the + wfMsg() family (except for wfMsgHtml). This allows things like {{plural:}}, + {{urlencode:}}, and {{fullurl:}} to be used in most cases correctly. + The content or UI language will be used accordingly for (forContent)?. == Compatibility == diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php index cbd58214de..7498a35f2a 100644 --- a/includes/GlobalFunctions.php +++ b/includes/GlobalFunctions.php @@ -310,6 +310,10 @@ function wfReadOnly() { * addWikiText will do the escaping for you. Use wfMsgHtml() * if you need an escaped message. * + * Brace transformation is done *after* parameter replacement, so + * constructs like {{plural:$1}} may be used. Be aware this may + * have security implications for HTML message output. + * * @param $key String: lookup key for the message, usually * defined in languages/Language.php */ @@ -347,6 +351,10 @@ function wfMsgNoTrans( $key ) { * customize over 70 messages in order to, e.g., fix a link in every * possible language. * + * Brace transformation is done *after* parameter replacement, so + * constructs like {{plural:$1}} may be used. Be aware this may + * have security implications for HTML message output. + * * @param $key String: lookup key for the message, usually * defined in languages/Language.php */ @@ -377,6 +385,10 @@ function wfMsgForContentNoTrans( $key ) { /** * Get a message from the language file, for the UI elements + * + * Brace transformation is done *after* parameter replacement, so + * constructs like {{plural:$1}} may be used. Be aware this may + * have security implications for HTML message output. */ function wfMsgNoDB( $key ) { $args = func_get_args(); @@ -386,6 +398,10 @@ function wfMsgNoDB( $key ) { /** * Get a message from the language file, for the content + * + * Brace transformation is done *after* parameter replacement, so + * constructs like {{plural:$1}} may be used. Be aware this may + * have security implications for HTML message output. */ function wfMsgNoDBForContent( $key ) { global $wgForceUIMsgAsContentMsg; @@ -401,6 +417,11 @@ function wfMsgNoDBForContent( $key ) { /** * Really get a message + * + * Brace transformation is done *after* parameter replacement, so + * constructs like {{plural:$1}} may be used. Be aware this may + * have security implications for HTML message output. + * * @return $key String: key to get. * @return $args * @return $useDB Boolean @@ -409,8 +430,14 @@ function wfMsgNoDBForContent( $key ) { function wfMsgReal( $key, $args, $useDB, $forContent=false, $transform = true ) { $fname = 'wfMsgReal'; - $message = wfMsgGetKey( $key, $useDB, $forContent, $transform ); + $message = wfMsgGetKey( $key, $useDB, $forContent, false ); $message = wfMsgReplaceArgs( $message, $args ); + if( $transform && strstr( $message, '{{' ) !== false ) { + global $wgParser, $wgMsgParserOptions; + $old = $wgMsgParserOptions->setInterfaceMessage( !$forContent ); + $message = $wgParser->transformMsg($message, $wgMsgParserOptions); + $wgMsgParserOptions->setInterfaceMessage( $old ); + } return $message; } @@ -516,6 +543,9 @@ function wfMsgReplaceArgs( $message, $args ) { * to pre-escape them if you really do want plaintext, or just wrap * the whole thing in htmlspecialchars(). * + * Brace transformation is done *before* parameter replacement, so + * constructs like {{plural:$1}} will not work. + * * @param string $key * @param string ... parameters * @return string @@ -533,6 +563,9 @@ function wfMsgHtml( $key ) { * to pre-escape them if you really do want plaintext, or just wrap * the whole thing in htmlspecialchars(). * + * Brace transformation is done *before* parameter replacement, so + * constructs like {{plural:$1}} will not work. + * * @param string $key * @param string ... parameters * @return string -- 2.20.1