r33918 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r33917‎ | r33918 | r33919 >
Date:18:05, 26 April 2008
Author:minuteelectron
Status:old
Tags:
Comment:
* Add parameter to MessageCache::get() to allow prevention of using a fallback language (default: false).
* Add option to wfMsgExt() 'nofallback' as an interface to the new parameter added to MessageCache::get().
Modified paths:
  • /trunk/phase3/includes/GlobalFunctions.php (modified) (history)
  • /trunk/phase3/includes/MessageCache.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/GlobalFunctions.php
@@ -447,15 +447,17 @@
448448 * @param string $langcode Code of the language to get the message for, or
449449 * behaves as a content language switch if it is a
450450 * boolean.
 451+ * @param bool $fallback Whether or not to fallback to a different language if
 452+ * it is not found in the selected one.
451453 * @return string
452454 * @private
453455 */
454 -function wfMsgGetKey( $key, $useDB, $langCode = false, $transform = true ) {
 456+function wfMsgGetKey( $key, $useDB, $langCode = false, $transform = true, $fallback = true ) {
455457 global $wgParser, $wgContLang, $wgMessageCache, $wgLang;
456458
457459 # If $wgMessageCache isn't initialised yet, try to return something sensible.
458460 if( is_object( $wgMessageCache ) ) {
459 - $message = $wgMessageCache->get( $key, $useDB, $langCode );
 461+ $message = $wgMessageCache->get( $key, $useDB, $langCode, false, $fallback );
460462 if ( $transform ) {
461463 $message = $wgMessageCache->transform( $message );
462464 }
@@ -564,6 +566,7 @@
565567 * <i>replaceafter</i>: parameters are substituted after parsing or escaping
566568 * <i>parsemag</i>: transform the message using magic phrases
567569 * <i>content</i>: fetch message for content language instead of interface
 570+ * <i>nofallback</i>: do not fallback to a different language
568571 * <i>language</i>: language code to fetch message for (overriden by <i>content</i>), its behaviour
569572 * with parser, parseinline and parsemag is undefined.
570573 * Behavior for conflicting options (e.g., parse+parseinline) is undefined.
@@ -594,8 +597,10 @@
595598 $langCode = false;
596599 }
597600
598 - $string = wfMsgGetKey( $key, /*DB*/true, $langCode, /*Transform*/false );
 601+ $fallback = !in_array('nofallback', $options);
599602
 603+ $string = wfMsgGetKey( $key, /*DB*/true, $langCode, /*Transform*/false, /*Fallback*/$fallback );
 604+
600605 if( !in_array('replaceafter', $options) ) {
601606 $string = wfMsgReplaceArgs( $string, $args );
602607 }
Index: trunk/phase3/includes/MessageCache.php
@@ -407,8 +407,10 @@
408408 * use the wikis content language (also as a
409409 * fallback).
410410 * @param bool $isFullKey Specifies whether $key is a two part key "lang/msg".
 411+ * @param bool $fallback Whether or not to fallback to a different language if
 412+ * it is not found in the selected one.
411413 */
412 - function get( $key, $useDB = true, $langcode = true, $isFullKey = false ) {
 414+ function get( $key, $useDB = true, $langcode = true, $isFullKey = false, $fallback = true ) {
413415 global $wgContLanguageCode, $wgContLang, $wgLang;
414416
415417 # Identify which language to get or create a language object for.
@@ -476,6 +478,11 @@
477479 }
478480 }
479481
 482+ # Don't fall back if asked not to.
 483+ if( !$fallback ) {
 484+ return '&lt;' . htmlspecialchars($key) . '&gt;';
 485+ }
 486+
480487 # Try the array of another language
481488 $pos = strrpos( $lckey, '/' );
482489 if( $message === false && $pos !== false) {

Follow-up revisions

RevisionCommit summaryAuthorDate
r33938Revert r33918, no longer works given new fallback caching and there are alter...minuteelectron14:50, 27 April 2008

Status & tagging log