* Added the ability to set the localisation cache directory specifically, overriding...
authorTim Starling <tstarling@users.mediawiki.org>
Fri, 3 Jul 2009 08:02:55 +0000 (08:02 +0000)
committerTim Starling <tstarling@users.mediawiki.org>
Fri, 3 Jul 2009 08:02:55 +0000 (08:02 +0000)
* 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
includes/LocalisationCache.php

index 5e3df00..1214435 100644 (file)
@@ -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,
 );
 
index 0974f4a..6195d73 100644 (file)
@@ -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";
        }
 }