*/
var $recachedLangs = array();
- /**
- * Data added by extensions using the deprecated $wgMessageCache->addMessages()
- * interface.
- */
- var $legacyData = array();
-
/**
* All item keys
*/
'defaultUserOptionOverrides', 'linkTrail', 'namespaceAliases',
'dateFormats', 'datePreferences', 'datePreferenceMigrationMap',
'defaultDateFormat', 'extraUserToggles', 'specialPageAliases',
- 'imageFiles', 'preloadedMessages',
+ 'imageFiles', 'preloadedMessages', 'namespaceGenderAliases',
);
/**
* by a fallback sequence.
*/
static public $mergeableMapKeys = array( 'messages', 'namespaceNames', 'mathNames',
- 'dateFormats', 'defaultUserOptionOverrides', 'magicWords', 'imageFiles',
+ 'dateFormats', 'defaultUserOptionOverrides', 'imageFiles',
'preloadedMessages',
);
*/
static public $optionalMergeKeys = array( 'bookstoreList' );
+ /**
+ * Keys for items that are formatted like $magicWords
+ */
+ static public $magicWordKeys = array( 'magicWords' );
+
/**
* Keys for items where the subitems are stored in the backend separately.
*/
self::$mergeableMapKeys,
self::$mergeableListKeys,
self::$mergeableAliasListKeys,
- self::$optionalMergeKeys
+ self::$optionalMergeKeys,
+ self::$magicWordKeys
) );
}
return isset( $this->mergeableKeys[$key] );
* 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] )
&& !isset( $this->loadedItems[$code][$key] ) )
{
}
$this->initialisedLangs[$code] = true;
+ # If the code is of the wrong form for a Messages*.php file, do a shallow fallback
+ if ( !Language::isValidBuiltInCode( $code ) ) {
+ $this->initShallowFallback( $code, 'en' );
+ return;
+ }
+
# Recache the data if necessary
if ( !$this->manualRecache && $this->isExpired( $code ) ) {
if ( file_exists( Language::getMessagesFileName( $code ) ) ) {
if ( isset( $value['inherit'] ) ) {
unset( $value['inherit'] );
}
+ } elseif ( in_array( $key, self::$magicWordKeys ) ) {
+ $this->mergeMagicWords( $value, $fallbackValue );
}
}
} else {
}
}
+ protected function mergeMagicWords( &$value, $fallbackValue ) {
+ foreach ( $fallbackValue as $magicName => $fallbackInfo ) {
+ if ( !isset( $value[$magicName] ) ) {
+ $value[$magicName] = $fallbackInfo;
+ } else {
+ $oldSynonyms = array_slice( $fallbackInfo, 1 );
+ $newSynonyms = array_slice( $value[$magicName], 1 );
+ $synonyms = array_values( array_unique( array_merge(
+ $newSynonyms, $oldSynonyms ) ) );
+ $value[$magicName] = array_merge( array( $fallbackInfo[0] ), $synonyms );
+ }
+ }
+ }
+
/**
* Given an array mapping language code to localisation value, such as is
* found in extension *.i18n.php files, iterate through a fallback sequence
$this->store->finishWrite();
# Clear out the MessageBlobStore
- MessageBlobStore::clear();
+ # HACK: If using a null (i.e. disabled) storage backend, we
+ # can't write to the MessageBlobStore either
+ if ( !$this->store instanceof LCStore_Null ) {
+ MessageBlobStore::clear();
+ }
wfProfileOut( __METHOD__ );
}
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;
- }
- }
- }
-
/**
* Disable the storage backend
*/
* @param $code Language code
* @param $key Cache key
*/
- public function get( $code, $key );
+ function get( $code, $key );
/**
* Start a write transaction.
* @param $code Language code
*/
- public function startWrite( $code );
+ function startWrite( $code );
/**
* Finish a write transaction.
*/
- public function finishWrite();
+ function finishWrite();
/**
* Set a key to a given value. startWrite() must be called before this
* is called, and finishWrite() must be called afterwards.
*/
- public function set( $key, $value );
+ function set( $key, $value );
}