X-Git-Url: https://git.cyclocoop.org/%7B%24admin_url%7Dmembres/fiche.php?a=blobdiff_plain;f=includes%2Fcache%2FLocalisationCache.php;h=83da4afcd265c185dc7fc831a527c9420b541528;hb=ea9fcc1e4d3b572199d82c426024e3e5efe23879;hp=276e84aaa9c598dc28b528477d66d2940f2d4e45;hpb=e8e8670e7ce6837e0331c8565cd390fca04152e5;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/cache/LocalisationCache.php b/includes/cache/LocalisationCache.php index 276e84aaa9..83da4afcd2 100644 --- a/includes/cache/LocalisationCache.php +++ b/includes/cache/LocalisationCache.php @@ -23,6 +23,7 @@ use Cdb\Exception as CdbException; use Cdb\Reader as CdbReader; use Cdb\Writer as CdbWriter; +use CLDRPluralRuleParser\Evaluator; /** * Class for caching the contents of localisation files, Messages*.php @@ -37,7 +38,7 @@ use Cdb\Writer as CdbWriter; * as grammatical transformation, is done by the caller. */ class LocalisationCache { - const VERSION = 3; + const VERSION = 4; /** Configuration associative array */ private $conf; @@ -122,7 +123,7 @@ class LocalisationCache { * by a fallback sequence. */ static public $mergeableMapKeys = array( 'messages', 'namespaceNames', - 'dateFormats', 'imageFiles', 'preloadedMessages' + 'namespaceAliases', 'dateFormats', 'imageFiles', 'preloadedMessages' ); /** @@ -208,7 +209,17 @@ class LocalisationCache { $storeClass = 'LCStoreStaticArray'; break; case 'detect': - $storeClass = $wgCacheDirectory ? 'LCStoreCDB' : 'LCStoreDB'; + if ( !empty( $conf['storeDirectory'] ) ) { + $storeClass = 'LCStoreCDB'; + } else { + $cacheDir = $wgCacheDirectory ?: wfTempDir(); + if ( $cacheDir ) { + $storeConf['directory'] = $cacheDir; + $storeClass = 'LCStoreCDB'; + } else { + $storeClass = 'LCStoreDB'; + } + } break; default: throw new MWException( @@ -576,7 +587,7 @@ class LocalisationCache { return null; } try { - $compiledRules = CLDRPluralRuleEvaluator::compile( $rules ); + $compiledRules = Evaluator::compile( $rules ); } catch ( CLDRPluralRuleError $e ) { wfDebugLog( 'l10n', $e->getMessage() ); @@ -815,9 +826,7 @@ class LocalisationCache { $this->recachedLangs[$code] = true; # Initial values - $initialData = array_combine( - self::$allKeys, - array_fill( 0, count( self::$allKeys ), null ) ); + $initialData = array_fill_keys( self::$allKeys, null ); $coreData = $initialData; $deps = array(); @@ -855,9 +864,7 @@ class LocalisationCache { $messageDirs = $this->getMessagesDirs(); # Load non-JSON localisation data for extensions - $extensionData = array_combine( - $codeSequence, - array_fill( 0, count( $codeSequence ), $initialData ) ); + $extensionData = array_fill_keys( $codeSequence, $initialData ); foreach ( $wgExtensionMessagesFiles as $extension => $fileName ) { if ( isset( $messageDirs[$extension] ) ) { # This extension has JSON message data; skip the PHP shim @@ -1140,29 +1147,32 @@ interface LCStore { * This will work on any MediaWiki installation. */ class LCStoreDB implements LCStore { + /** @var string */ private $currentLang; + /** @var bool */ private $writesDone = false; - - /** @var DatabaseBase */ + /** @var IDatabase */ private $dbw; /** @var array */ private $batch = array(); - + /** @var bool */ private $readOnly = false; public function get( $code, $key ) { - if ( $this->writesDone ) { - $db = wfGetDB( DB_MASTER ); + if ( $this->writesDone && $this->dbw ) { + $db = $this->dbw; // see the changes in finishWrite() } else { $db = wfGetDB( DB_SLAVE ); } - $row = $db->selectRow( 'l10n_cache', array( 'lc_value' ), - array( 'lc_lang' => $code, 'lc_key' => $key ), __METHOD__ ); - if ( $row ) { - return unserialize( $db->decodeBlob( $row->lc_value ) ); - } else { - return null; - } + + $value = $db->selectField( + 'l10n_cache', + 'lc_value', + array( 'lc_lang' => $code, 'lc_key' => $key ), + __METHOD__ + ); + + return ( $value !== false ) ? unserialize( $db->decodeBlob( $value ) ) : null; } public function startWrite( $code ) { @@ -1173,6 +1183,7 @@ class LCStoreDB implements LCStore { } $this->dbw = wfGetDB( DB_MASTER ); + $this->readOnly = $this->dbw->isReadOnly(); $this->currentLang = $code; $this->batch = array(); @@ -1185,10 +1196,13 @@ class LCStoreDB implements LCStore { throw new MWException( __CLASS__ . ': must call startWrite() before finishWrite()' ); } - $this->dbw->begin( __METHOD__ ); + $this->dbw->startAtomic( __METHOD__ ); try { - $this->dbw->delete( 'l10n_cache', - array( 'lc_lang' => $this->currentLang ), __METHOD__ ); + $this->dbw->delete( + 'l10n_cache', + array( 'lc_lang' => $this->currentLang ), + __METHOD__ + ); foreach ( array_chunk( $this->batch, 500 ) as $rows ) { $this->dbw->insert( 'l10n_cache', $rows, __METHOD__ ); } @@ -1200,7 +1214,7 @@ class LCStoreDB implements LCStore { throw $e; } } - $this->dbw->commit( __METHOD__ ); + $this->dbw->endAtomic( __METHOD__ ); $this->currentLang = null; $this->batch = array(); @@ -1216,7 +1230,8 @@ class LCStoreDB implements LCStore { $this->batch[] = array( 'lc_lang' => $this->currentLang, 'lc_key' => $key, - 'lc_value' => $this->dbw->encodeBlob( serialize( $value ) ) ); + 'lc_value' => $this->dbw->encodeBlob( serialize( $value ) ) + ); } }