r14424 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r14423‎ | r14424 | r14425 >
Date:23:25, 27 May 2006
Author:brion
Status:old
Tags:
Comment:
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)?.
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/includes/GlobalFunctions.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/GlobalFunctions.php
@@ -310,6 +310,10 @@
311311 * addWikiText will do the escaping for you. Use wfMsgHtml()
312312 * if you need an escaped message.
313313 *
 314+ * Brace transformation is done *after* parameter replacement, so
 315+ * constructs like {{plural:$1}} may be used. Be aware this may
 316+ * have security implications for HTML message output.
 317+ *
314318 * @param $key String: lookup key for the message, usually
315319 * defined in languages/Language.php
316320 */
@@ -347,6 +351,10 @@
348352 * customize over 70 messages in order to, e.g., fix a link in every
349353 * possible language.
350354 *
 355+ * Brace transformation is done *after* parameter replacement, so
 356+ * constructs like {{plural:$1}} may be used. Be aware this may
 357+ * have security implications for HTML message output.
 358+ *
351359 * @param $key String: lookup key for the message, usually
352360 * defined in languages/Language.php
353361 */
@@ -377,6 +385,10 @@
378386
379387 /**
380388 * Get a message from the language file, for the UI elements
 389+ *
 390+ * Brace transformation is done *after* parameter replacement, so
 391+ * constructs like {{plural:$1}} may be used. Be aware this may
 392+ * have security implications for HTML message output.
381393 */
382394 function wfMsgNoDB( $key ) {
383395 $args = func_get_args();
@@ -386,6 +398,10 @@
387399
388400 /**
389401 * Get a message from the language file, for the content
 402+ *
 403+ * Brace transformation is done *after* parameter replacement, so
 404+ * constructs like {{plural:$1}} may be used. Be aware this may
 405+ * have security implications for HTML message output.
390406 */
391407 function wfMsgNoDBForContent( $key ) {
392408 global $wgForceUIMsgAsContentMsg;
@@ -401,6 +417,11 @@
402418
403419 /**
404420 * Really get a message
 421+ *
 422+ * Brace transformation is done *after* parameter replacement, so
 423+ * constructs like {{plural:$1}} may be used. Be aware this may
 424+ * have security implications for HTML message output.
 425+ *
405426 * @return $key String: key to get.
406427 * @return $args
407428 * @return $useDB Boolean
@@ -409,8 +430,14 @@
410431 function wfMsgReal( $key, $args, $useDB, $forContent=false, $transform = true ) {
411432 $fname = 'wfMsgReal';
412433
413 - $message = wfMsgGetKey( $key, $useDB, $forContent, $transform );
 434+ $message = wfMsgGetKey( $key, $useDB, $forContent, false );
414435 $message = wfMsgReplaceArgs( $message, $args );
 436+ if( $transform && strstr( $message, '{{' ) !== false ) {
 437+ global $wgParser, $wgMsgParserOptions;
 438+ $old = $wgMsgParserOptions->setInterfaceMessage( !$forContent );
 439+ $message = $wgParser->transformMsg($message, $wgMsgParserOptions);
 440+ $wgMsgParserOptions->setInterfaceMessage( $old );
 441+ }
415442 return $message;
416443 }
417444
@@ -516,6 +543,9 @@
517544 * to pre-escape them if you really do want plaintext, or just wrap
518545 * the whole thing in htmlspecialchars().
519546 *
 547+ * Brace transformation is done *before* parameter replacement, so
 548+ * constructs like {{plural:$1}} will not work.
 549+ *
520550 * @param string $key
521551 * @param string ... parameters
522552 * @return string
@@ -533,6 +563,9 @@
534564 * to pre-escape them if you really do want plaintext, or just wrap
535565 * the whole thing in htmlspecialchars().
536566 *
 567+ * Brace transformation is done *before* parameter replacement, so
 568+ * constructs like {{plural:$1}} will not work.
 569+ *
537570 * @param string $key
538571 * @param string ... parameters
539572 * @return string
Index: trunk/phase3/RELEASE-NOTES
@@ -359,6 +359,10 @@
360360 under HTML-compatible browsers.
361361 * (bug 5077) Added hook 'BeforePageDisplay' to SkinTemplate::outputPage
362362 * Replace fatally changed 'uploadnewversion' with 'uploadnewversion-linktext'
 363+* Move parameter replacement before brace transformations in most of the
 364+ wfMsg() family (except for wfMsgHtml). This allows things like {{plural:}},
 365+ {{urlencode:}}, and {{fullurl:}} to be used in most cases correctly.
 366+ The content or UI language will be used accordingly for (forContent)?.
363367
364368
365369 == Compatibility ==

Follow-up revisions

RevisionCommit summaryAuthorDate
r14431Had to revert the changes in r14424 / r14427 due to massive side-effect break...brion09:31, 28 May 2006

Status & tagging log