From e1bc89771d1c4a84cbfcebab1bef58c0de0d36a8 Mon Sep 17 00:00:00 2001 From: Tim Starling Date: Fri, 3 Jul 2009 08:02:55 +0000 Subject: [PATCH] * Added the ability to set the localisation cache directory specifically, overriding $wgCacheDirectory. * Documented the issues with having multiple wikis share a localisation cache: they will fight each other if they have a different set of extensions. --- includes/DefaultSettings.php | 24 ++++++++++++++++-------- includes/LocalisationCache.php | 29 ++++++++++++++++++++++++----- 2 files changed, 40 insertions(+), 13 deletions(-) diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index 5e3df009d9..1214435ac1 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -166,7 +166,11 @@ $wgUploadBaseUrl = ""; /** * Directory for caching data in the local filesystem. Should not be accessible - * from the web.Set this to false to not use any local caches. + * from the web. Set this to false to not use any local caches. + * + * Note: if multiple wikis share the same localisation cache directory, they + * must all have the same set of extensions. You can set a directory just for + * the localisation cache using $wgLocalisationCacheConf['storeDirectory']. */ $wgCacheDirectory = false; @@ -778,22 +782,26 @@ $wgLocalMessageCacheSerialized = true; * class: The class to use. May be overridden by extensions. * * store: The location to store cache data. May be 'files', 'db' or - * 'detect'. If set to "files", data will be in CDB files in - * the directory specified by $wgCacheDirectory. If set to "db", - * data will be stored to the database. If set to "detect", files - * will be used if $wgCacheDirectory is set, otherwise the - * database will be used. + * 'detect'. If set to "files", data will be in CDB files. If set + * to "db", data will be stored to the database. If set to + * "detect", files will be used if $wgCacheDirectory is set, + * otherwise the database will be used. * * storeClass: The class name for the underlying storage. If set to a class * name, it overrides the "store" setting. * - * manualRecache: Set this to true to disable cache updates on web requests. - * Use maintenance/rebuildLocalisationCache.php instead. + * storeDirectory: If the store class puts its data in files, this is the + * directory it will use. If this is false, $wgCacheDirectory + * will be used. + * + * manualRecache: Set this to true to disable cache updates on web requests. + * Use maintenance/rebuildLocalisationCache.php instead. */ $wgLocalisationCacheConf = array( 'class' => 'LocalisationCache', 'store' => 'detect', 'storeClass' => false, + 'storeDirectory' => false, 'manualRecache' => false, ); diff --git a/includes/LocalisationCache.php b/includes/LocalisationCache.php index 0974f4ad92..6195d735fb 100644 --- a/includes/LocalisationCache.php +++ b/includes/LocalisationCache.php @@ -143,6 +143,7 @@ class LocalisationCache { global $wgCacheDirectory; $this->conf = $conf; + $storeConf = array(); if ( !empty( $conf['storeClass'] ) ) { $storeClass = $conf['storeClass']; } else { @@ -164,7 +165,11 @@ class LocalisationCache { } wfDebug( get_class( $this ) . ": using store $storeClass\n" ); - $this->store = new $storeClass; + if ( !empty( $conf['storeDirectory'] ) ) { + $storeConf['directory'] = $conf['storeDirectory']; + } + + $this->store = new $storeClass( $storeConf ); foreach ( array( 'manualRecache', 'forceRecache' ) as $var ) { if ( isset( $conf[$var] ) ) { $this->$var = $conf[$var]; @@ -775,8 +780,17 @@ class LCStore_DB implements LCStore { * See Cdb.php and http://cr.yp.to/cdb.html */ class LCStore_CDB implements LCStore { - var $readers, $writer, $currentLang; - + var $readers, $writer, $currentLang, $directory; + + function __construct( $conf = array() ) { + global $wgCacheDirectory; + if ( isset( $conf['directory'] ) ) { + $this->directory = $conf['directory']; + } else { + $this->directory = $wgCacheDirectory; + } + } + public function get( $code, $key ) { if ( !isset( $this->readers[$code] ) ) { $fileName = $this->getFileName( $code ); @@ -798,6 +812,12 @@ class LCStore_CDB implements LCStore { } public function startWrite( $code ) { + if ( !file_exists( $this->directory ) ) { + if ( !wfMkdirParents( $this->directory ) ) { + throw new MWException( "Unable to create the localisation store " . + "directory \"{$this->directory}\"" ); + } + } $this->writer = CdbWriter::open( $this->getFileName( $code ) ); $this->currentLang = $code; } @@ -823,11 +843,10 @@ class LCStore_CDB implements LCStore { } protected function getFileName( $code ) { - global $wgCacheDirectory; if ( !$code || strpos( $code, '/' ) !== false ) { throw new MWException( __METHOD__.": Invalid language \"$code\"" ); } - return "$wgCacheDirectory/l10n_cache-$code.cdb"; + return "{$this->directory}/l10n_cache-$code.cdb"; } } -- 2.20.1