/**
* 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;
* 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,
);
global $wgCacheDirectory;
$this->conf = $conf;
+ $storeConf = array();
if ( !empty( $conf['storeClass'] ) ) {
$storeClass = $conf['storeClass'];
} else {
}
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];
* 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 );
}
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;
}
}
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";
}
}