* 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()
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 ===
function useMessageCache() {
global $wgLang;
foreach ( $this->getTrace() as $frame ) {
- if ( $frame['class'] == 'LocalisationCache' ) {
+ if ( isset( $frame['class'] ) && $frame['class'] === 'LocalisationCache' ) {
return false;
}
}
* @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 ) {
*/
var $recachedLangs = array();
+ /**
+ * Data added by extensions using the deprecated $wgMessageCache->addMessages()
+ * interface.
+ */
+ var $legacyData = array();
+
/**
* All item keys
*/
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 {
* 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] ) ) {
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;
+ }
+ }
+ }
}
/**
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();
}
}
+ /**
+ * 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
*/