From ae3ced88e535c7fd046f0ad6f0710cc87f0004ea Mon Sep 17 00:00:00 2001 From: Happy-melon Date: Thu, 25 Mar 2010 20:21:31 +0000 Subject: [PATCH] Make MessageCache::get() return false if the requested message does not exist, and handle setting the '<$key>' one layer further down in wfMsgGetKey(). Allows us to get away from that horrible string comparison in wfEmptyMsg(). --- includes/GlobalFunctions.php | 14 ++++++++------ includes/MessageCache.php | 4 ++-- languages/LanguageConverter.php | 5 +++++ 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php index 36860e38b0..a038fb0a03 100644 --- a/includes/GlobalFunctions.php +++ b/includes/GlobalFunctions.php @@ -750,7 +750,9 @@ function wfMsgGetKey( $key, $useDB, $langCode = false, $transform = true ) { # If $wgMessageCache isn't initialised yet, try to return something sensible. if( is_object( $wgMessageCache ) ) { $message = $wgMessageCache->get( $key, $useDB, $langCode ); - if ( $transform ) { + if( $message === false ){ + $message = '<' . htmlspecialchars( $key ) . '>'; + } elseif ( $transform ) { $message = $wgMessageCache->transform( $message ); } } else { @@ -2267,12 +2269,12 @@ function wfAppendToArrayIfNotDefault( $key, $value, $default, &$changed ) { * looked up didn't exist but a XHTML string, this function checks for the * nonexistance of messages by looking at wfMsg() output * - * @param $msg String: the message key looked up - * @param $wfMsgOut String: the output of wfMsg*() - * @return Boolean + * @param $key String: the message key looked up + * @return Boolean True if the message *doesn't* exist. */ -function wfEmptyMsg( $msg, $wfMsgOut ) { - return $wfMsgOut === htmlspecialchars( "<$msg>" ); +function wfEmptyMsg( $key ) { + global $wgMessageCache; + return $wgMessageCache->get( $key ) === false; } /** diff --git a/includes/MessageCache.php b/includes/MessageCache.php index 2c53430f4d..318d1de1e3 100644 --- a/includes/MessageCache.php +++ b/includes/MessageCache.php @@ -500,7 +500,7 @@ class MessageCache { if ( strval( $key ) === '' ) { # Shortcut: the empty key is always missing - return '<>'; + return false; } $lang = wfGetLangObj( $langcode ); @@ -558,7 +558,7 @@ class MessageCache { # Final fallback if( $message === false ) { - return '<' . htmlspecialchars($key) . '>'; + return false; } # Fix whitespace diff --git a/languages/LanguageConverter.php b/languages/LanguageConverter.php index 3f23fab986..9e188cebc9 100644 --- a/languages/LanguageConverter.php +++ b/languages/LanguageConverter.php @@ -834,6 +834,11 @@ class LanguageConverter { if ( strpos( $code, '/' ) === false ) { $txt = $wgMessageCache->get( 'Conversiontable', true, $code ); + if( $txt === false ){ + # FIXME: this method doesn't seem to be expecting + # this possible outcome... + $txt = '<Conversiontable>'; + } } else { $title = Title::makeTitleSafe( NS_MEDIAWIKI, "Conversiontable/$code" ); -- 2.20.1