From 8e3967d0a954dd96e81a7af2191c3333467f82ca Mon Sep 17 00:00:00 2001 From: Robert Leverington Date: Sat, 26 Apr 2008 18:05:43 +0000 Subject: [PATCH] * 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(). --- includes/GlobalFunctions.php | 11 ++++++++--- includes/MessageCache.php | 9 ++++++++- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php index 94a1508488..3d77f8b557 100644 --- a/includes/GlobalFunctions.php +++ b/includes/GlobalFunctions.php @@ -447,15 +447,17 @@ function wfMsgWeirdKey ( $key ) { * @param string $langcode Code of the language to get the message for, or * behaves as a content language switch if it is a * boolean. + * @param bool $fallback Whether or not to fallback to a different language if + * it is not found in the selected one. * @return string * @private */ -function wfMsgGetKey( $key, $useDB, $langCode = false, $transform = true ) { +function wfMsgGetKey( $key, $useDB, $langCode = false, $transform = true, $fallback = true ) { global $wgParser, $wgContLang, $wgMessageCache, $wgLang; # If $wgMessageCache isn't initialised yet, try to return something sensible. if( is_object( $wgMessageCache ) ) { - $message = $wgMessageCache->get( $key, $useDB, $langCode ); + $message = $wgMessageCache->get( $key, $useDB, $langCode, false, $fallback ); if ( $transform ) { $message = $wgMessageCache->transform( $message ); } @@ -564,6 +566,7 @@ function wfMsgWikiHtml( $key ) { * replaceafter: parameters are substituted after parsing or escaping * parsemag: transform the message using magic phrases * content: fetch message for content language instead of interface + * nofallback: do not fallback to a different language * language: language code to fetch message for (overriden by content), its behaviour * with parser, parseinline and parsemag is undefined. * Behavior for conflicting options (e.g., parse+parseinline) is undefined. @@ -594,7 +597,9 @@ function wfMsgExt( $key, $options ) { $langCode = false; } - $string = wfMsgGetKey( $key, /*DB*/true, $langCode, /*Transform*/false ); + $fallback = !in_array('nofallback', $options); + + $string = wfMsgGetKey( $key, /*DB*/true, $langCode, /*Transform*/false, /*Fallback*/$fallback ); if( !in_array('replaceafter', $options) ) { $string = wfMsgReplaceArgs( $string, $args ); diff --git a/includes/MessageCache.php b/includes/MessageCache.php index bbea94abe0..7637fcbac0 100644 --- a/includes/MessageCache.php +++ b/includes/MessageCache.php @@ -407,8 +407,10 @@ class MessageCache { * use the wikis content language (also as a * fallback). * @param bool $isFullKey Specifies whether $key is a two part key "lang/msg". + * @param bool $fallback Whether or not to fallback to a different language if + * it is not found in the selected one. */ - function get( $key, $useDB = true, $langcode = true, $isFullKey = false ) { + function get( $key, $useDB = true, $langcode = true, $isFullKey = false, $fallback = true ) { global $wgContLanguageCode, $wgContLang, $wgLang; # Identify which language to get or create a language object for. @@ -476,6 +478,11 @@ class MessageCache { } } + # Don't fall back if asked not to. + if( !$fallback ) { + return '<' . htmlspecialchars($key) . '>'; + } + # Try the array of another language $pos = strrpos( $lckey, '/' ); if( $message === false && $pos !== false) { -- 2.20.1