From: Tim Starling Date: Fri, 3 Jul 2009 06:19:39 +0000 (+0000) Subject: * Re-added $wgMessageCache->addMessages(), there are still some extensions (in and... X-Git-Tag: 1.31.0-rc.0~41124 X-Git-Url: http://git.cyclocoop.org/%27.%28%24current%20%3E%202?a=commitdiff_plain;h=1f79ae389d441d319c6fc2d8048c495231d0e9e7;p=lhc%2Fweb%2Fwiklou.git * Re-added $wgMessageCache->addMessages(), there are still some extensions (in and out of subversion) that rely on it. Call wfDeprecated(). * Made wfDeprecated() issue a notice only once for each function name instead of every time the function is called. * Added exceptions for malformed keys input to $wgMessageCache->get(), per CR comments on r52503 * Fixed notice from MWException::useMessageCache() --- diff --git a/RELEASE-NOTES b/RELEASE-NOTES index db1ad7993b..19b6c4e162 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -50,6 +50,8 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN to true * Removed $wgEnableSerializedMessages and $wgCheckSerialized. Similar functionality is now available via $wgLocalisationCacheConf. +* $wgMessageCache->addMessages() is deprecated. Messages added via this + interface will not appear in Special:AllMessages. === New features in 1.16 === diff --git a/includes/Exception.php b/includes/Exception.php index b2d668c804..f6bc6f87fc 100644 --- a/includes/Exception.php +++ b/includes/Exception.php @@ -26,7 +26,7 @@ class MWException extends Exception { function useMessageCache() { global $wgLang; foreach ( $this->getTrace() as $frame ) { - if ( $frame['class'] == 'LocalisationCache' ) { + if ( isset( $frame['class'] ) && $frame['class'] === 'LocalisationCache' ) { return false; } } diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php index 1f6002c08d..e75786b885 100644 --- a/includes/GlobalFunctions.php +++ b/includes/GlobalFunctions.php @@ -2975,7 +2975,11 @@ function wfMaxlagError( $host, $lag, $maxLag ) { * @return null */ function wfDeprecated( $function ) { - wfWarn( "Use of $function is deprecated.", 2 ); + static $functionsWarned = array(); + if ( !isset( $functionsWarned[$function] ) ) { + $functionsWarned[$function] = true; + wfWarn( "Use of $function is deprecated.", 2 ); + } } function wfWarn( $msg, $callerOffset = 1, $level = E_USER_NOTICE ) { diff --git a/includes/LocalisationCache.php b/includes/LocalisationCache.php index 142dc2cc8b..d5ad4241de 100644 --- a/includes/LocalisationCache.php +++ b/includes/LocalisationCache.php @@ -77,6 +77,12 @@ class LocalisationCache { */ var $recachedLangs = array(); + /** + * Data added by extensions using the deprecated $wgMessageCache->addMessages() + * interface. + */ + var $legacyData = array(); + /** * All item keys */ @@ -137,10 +143,6 @@ class LocalisationCache { global $wgCacheDirectory; $this->conf = $conf; - $this->data = array(); - $this->loadedItems = array(); - $this->loadedSubitems = array(); - $this->initialisedLangs = array(); if ( !empty( $conf['storeClass'] ) ) { $storeClass = $conf['storeClass']; } else { @@ -208,6 +210,9 @@ class LocalisationCache { * Get a subitem, for instance a single message for a given language. */ public function getSubitem( $code, $key, $subkey ) { + if ( isset( $this->legacyData[$code][$key][$subkey] ) ) { + return $this->legacyData[$code][$key][$subkey]; + } if ( !isset( $this->loadedSubitems[$code][$key][$subkey] ) ) { if ( isset( $this->loadedItems[$code][$key] ) ) { if ( isset( $this->data[$code][$key][$subkey] ) ) { @@ -619,12 +624,30 @@ class LocalisationCache { unset( $this->loadedItems[$code] ); unset( $this->loadedSubitems[$code] ); unset( $this->initialisedLangs[$code] ); + // We don't unload legacyData because there's no way to get it back + // again, it's not really a cache foreach ( $this->shallowFallbacks as $shallowCode => $fbCode ) { if ( $fbCode === $code ) { $this->unload( $shallowCode ); } } } + + /** + * Add messages to the cache, from an extension that has not yet been + * migrated to $wgExtensionMessages or the LocalisationCacheRecache hook. + * Called by deprecated function $wgMessageCache->addMessages(). + */ + public function addLegacyMessages( $messages ) { + foreach ( $messages as $lang => $langMessages ) { + if ( isset( $this->legacyData[$lang]['messages'] ) ) { + $this->legacyData[$lang]['messages'] = + $langMessages + $this->legacyData[$lang]['messages']; + } else { + $this->legacyData[$lang]['messages'] = $langMessages; + } + } + } } /** diff --git a/includes/MessageCache.php b/includes/MessageCache.php index b354b3b236..458ec8fd80 100644 --- a/includes/MessageCache.php +++ b/includes/MessageCache.php @@ -501,6 +501,12 @@ class MessageCache { function get( $key, $useDB = true, $langcode = true, $isFullKey = false ) { global $wgContLanguageCode, $wgContLang; + if ( !is_string( $key ) ) { + throw new MWException( __METHOD__.': Invalid message key of type ' . gettype( $key ) ); + } elseif ( $key === '' ) { + throw new MWException( __METHOD__.': Invaild message key: empty string' ); + } + $lang = wfGetLangObj( $langcode ); $langcode = $lang->getCode(); @@ -701,6 +707,52 @@ class MessageCache { } } + /** + * Add a message to the cache + * @deprecated Use $wgExtensionMessagesFiles + * + * @param mixed $key + * @param mixed $value + * @param string $lang The messages language, English by default + */ + function addMessage( $key, $value, $lang = 'en' ) { + wfDeprecated( __METHOD__ ); + $lc = Language::getLocalisationCache(); + $lc->addLegacyMessages( array( $lang => array( $key => $value ) ) ); + } + + /** + * Add an associative array of message to the cache + * @deprecated Use $wgExtensionMessagesFiles + * + * @param array $messages An associative array of key => values to be added + * @param string $lang The messages language, English by default + */ + function addMessages( $messages, $lang = 'en' ) { + wfDeprecated( __METHOD__ ); + $lc = Language::getLocalisationCache(); + $lc->addLegacyMessages( array( $lang => $messages ) ); + } + + /** + * Add a 2-D array of messages by lang. Useful for extensions. + * @deprecated Use $wgExtensionMessagesFiles + * + * @param array $messages The array to be added + */ + function addMessagesByLang( $messages ) { + wfDeprecated( __METHOD__ ); + $lc = Language::getLocalisationCache(); + $lc->addLegacyMessages( $messages ); + } + + /** + * Set a hook for addMessagesByLang() + */ + function setExtensionMessagesHook( $callback ) { + $this->mAddMessagesHook = $callback; + } + /** * @deprecated */