$this->loadItem( $code, $key );
wfProfileOut( __METHOD__.'-load' );
}
+
if ( $key === 'fallback' && isset( $this->shallowFallbacks[$code] ) ) {
return $this->shallowFallbacks[$code];
}
+
return $this->data[$code][$key];
}
$this->loadSubitem( $code, $key, $subkey );
wfProfileOut( __METHOD__.'-load' );
}
+
if ( isset( $this->data[$code][$key][$subkey] ) ) {
return $this->data[$code][$key][$subkey];
} else {
if ( !isset( $this->initialisedLangs[$code] ) ) {
$this->initLanguage( $code );
}
+
// Check to see if initLanguage() loaded it for us
if ( isset( $this->loadedItems[$code][$key] ) ) {
return;
}
+
if ( isset( $this->shallowFallbacks[$code] ) ) {
$this->loadItem( $this->shallowFallbacks[$code], $key );
return;
}
+
if ( in_array( $key, self::$splitKeys ) ) {
$subkeyList = $this->getSubitem( $code, 'list', $key );
foreach ( $subkeyList as $subkey ) {
} else {
$this->data[$code][$key] = $this->store->get( $code, $key );
}
+
$this->loadedItems[$code][$key] = true;
}
$this->loadItem( $code, $key );
return;
}
+
if ( !isset( $this->initialisedLangs[$code] ) ) {
$this->initLanguage( $code );
}
+
// Check to see if initLanguage() loaded it for us
if ( isset( $this->loadedItems[$code][$key] )
|| isset( $this->loadedSubitems[$code][$key][$subkey] ) )
{
return;
}
+
if ( isset( $this->shallowFallbacks[$code] ) ) {
$this->loadSubitem( $this->shallowFallbacks[$code], $key, $subkey );
return;
}
+
$value = $this->store->get( $code, "$key:$subkey" );
$this->data[$code][$key][$subkey] = $value;
$this->loadedSubitems[$code][$key][$subkey] = true;
wfDebug( __METHOD__."($code): cache missing, need to make one\n" );
return true;
}
+
foreach ( $deps as $dep ) {
// Because we're unserializing stuff from cache, we
// could receive objects of classes that don't exist
return true;
}
}
+
return false;
}
if ( isset( $this->initialisedLangs[$code] ) ) {
return;
}
+
$this->initialisedLangs[$code] = true;
# If the code is of the wrong form for a Messages*.php file, do a shallow fallback
} else {
throw new MWException( __METHOD__.": Invalid file type: $_fileType" );
}
+
return $data;
}
if ( !empty( $value['inherit'] ) ) {
$value = array_merge( $fallbackValue, $value );
}
+
if ( isset( $value['inherit'] ) ) {
unset( $value['inherit'] );
}
$used = true;
}
}
+
return $used;
}
} else {
$coreData['fallbackSequence'] = array_map( 'trim', explode( ',', $coreData['fallback'] ) );
$len = count( $coreData['fallbackSequence'] );
+
# Ensure that the sequence ends at en
if ( $coreData['fallbackSequence'][$len - 1] !== 'en' ) {
$coreData['fallbackSequence'][] = 'en';
# Load the fallback localisation item by item and merge it
foreach ( $coreData['fallbackSequence'] as $fbCode ) {
-
# Load the secondary localisation from the source file to
# avoid infinite cycles on cyclic fallbacks
$fbFilename = Language::getMessagesFileName( $fbCode );
- if ( !file_exists( $fbFilename ) ) continue;
+
+ if ( !file_exists( $fbFilename ) ) {
+ continue;
+ }
$deps[] = new FileDependency( $fbFilename );
$fbData = $this->readPHPFile( $fbFilename, 'core' );
+
foreach ( self::$allKeys as $key ) {
- if ( !isset( $fbData[$key] ) ) continue;
+ if ( !isset( $fbData[$key] ) ) {
+ continue;
+ }
+
if ( is_null( $coreData[$key] ) || $this->isMergeableKey( $key ) ) {
$this->mergeItem( $key, $coreData[$key], $fbData[$key] );
}
foreach ( $wgExtensionMessagesFiles as $fileName ) {
$data = $this->readPHPFile( $fileName, 'extension' );
$used = false;
+
foreach ( $data as $key => $item ) {
if( $this->mergeExtensionItem( $codeSequence, $key, $allData[$key], $item ) ) {
$used = true;
}
}
+
if ( $used ) {
$deps[] = new FileDependency( $fileName );
}
# Load deprecated $wgExtensionAliasesFiles
foreach ( $wgExtensionAliasesFiles as $fileName ) {
$data = $this->readPHPFile( $fileName, 'aliases' );
+
if ( !isset( $data['aliases'] ) ) {
continue;
}
+
$used = $this->mergeExtensionItem( $codeSequence, 'specialPageAliases',
$allData['specialPageAliases'], $data['aliases'] );
+
if ( $used ) {
$deps[] = new FileDependency( $fileName );
}
foreach ( self::$preloadedKeys as $key ) {
$preload[$key] = $data[$key];
}
+
foreach ( $data['preloadedMessages'] as $subkey ) {
if ( isset( $data['messages'][$subkey] ) ) {
$subitem = $data['messages'][$subkey];
}
$preload['messages'][$subkey] = $subitem;
}
+
return $preload;
}
unset( $this->loadedItems[$code] );
unset( $this->loadedSubitems[$code] );
unset( $this->initialisedLangs[$code] );
+
foreach ( $this->shallowFallbacks as $shallowCode => $fbCode ) {
if ( $fbCode === $code ) {
$this->unload( $shallowCode );
* is called, and finishWrite() must be called afterwards.
*/
function set( $key, $value );
-
}
/**
if ( $this->readOnly ) {
return;
}
+
if ( !$code ) {
throw new MWException( __METHOD__.": Invalid language \"$code\"" );
}
+
$this->dbw = wfGetDB( DB_MASTER );
try {
$this->dbw->begin();
throw $e;
}
}
+
$this->currentLang = $code;
$this->batch = array();
}
if ( $this->readOnly ) {
return;
}
+
if ( $this->batch ) {
$this->dbw->insert( 'l10n_cache', $this->batch, __METHOD__ );
}
+
$this->dbw->commit();
$this->currentLang = null;
$this->dbw = null;
if ( $this->readOnly ) {
return;
}
+
if ( is_null( $this->currentLang ) ) {
throw new MWException( __CLASS__.': must call startWrite() before calling set()' );
}
+
$this->batch[] = array(
'lc_lang' => $this->currentLang,
'lc_key' => $key,
'lc_value' => serialize( $value ) );
+
if ( count( $this->batch ) >= 100 ) {
$this->dbw->insert( 'l10n_cache', $this->batch, __METHOD__ );
$this->batch = array();
function __construct( $conf = array() ) {
global $wgCacheDirectory;
+
if ( isset( $conf['directory'] ) ) {
$this->directory = $conf['directory'];
} else {
public function get( $code, $key ) {
if ( !isset( $this->readers[$code] ) ) {
$fileName = $this->getFileName( $code );
+
if ( !file_exists( $fileName ) ) {
$this->readers[$code] = false;
} else {
$this->readers[$code] = CdbReader::open( $fileName );
}
}
+
if ( !$this->readers[$code] ) {
return null;
} else {
$value = $this->readers[$code]->get( $key );
+
if ( $value === false ) {
return null;
}
"directory \"{$this->directory}\"" );
}
}
+
// Close reader to stop permission errors on write
if( !empty($this->readers[$code]) ) {
$this->readers[$code]->close();
}
+
$this->writer = CdbWriter::open( $this->getFileName( $code ) );
$this->currentLang = $code;
}
$serialize = $fileType === 'core';
if ( !isset( $this->fileCache[$fileName][$fileType] ) ) {
$data = parent::readPHPFile( $fileName, $fileType );
+
if ( $serialize ) {
$encData = serialize( $data );
} else {
$encData = $data;
}
+
$this->fileCache[$fileName][$fileType] = $encData;
+
return $data;
} elseif ( $serialize ) {
return unserialize( $this->fileCache[$fileName][$fileType] );