r52732 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r52731‎ | r52732 | r52733 >
Date:08:02, 3 July 2009
Author:tstarling
Status:ok
Tags:
Comment:
* 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.
Modified paths:
  • /trunk/phase3/includes/DefaultSettings.php (modified) (history)
  • /trunk/phase3/includes/LocalisationCache.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/LocalisationCache.php
@@ -143,6 +143,7 @@
144144 global $wgCacheDirectory;
145145
146146 $this->conf = $conf;
 147+ $storeConf = array();
147148 if ( !empty( $conf['storeClass'] ) ) {
148149 $storeClass = $conf['storeClass'];
149150 } else {
@@ -164,7 +165,11 @@
165166 }
166167
167168 wfDebug( get_class( $this ) . ": using store $storeClass\n" );
168 - $this->store = new $storeClass;
 169+ if ( !empty( $conf['storeDirectory'] ) ) {
 170+ $storeConf['directory'] = $conf['storeDirectory'];
 171+ }
 172+
 173+ $this->store = new $storeClass( $storeConf );
169174 foreach ( array( 'manualRecache', 'forceRecache' ) as $var ) {
170175 if ( isset( $conf[$var] ) ) {
171176 $this->$var = $conf[$var];
@@ -775,8 +780,17 @@
776781 * See Cdb.php and http://cr.yp.to/cdb.html
777782 */
778783 class LCStore_CDB implements LCStore {
779 - var $readers, $writer, $currentLang;
780 -
 784+ var $readers, $writer, $currentLang, $directory;
 785+
 786+ function __construct( $conf = array() ) {
 787+ global $wgCacheDirectory;
 788+ if ( isset( $conf['directory'] ) ) {
 789+ $this->directory = $conf['directory'];
 790+ } else {
 791+ $this->directory = $wgCacheDirectory;
 792+ }
 793+ }
 794+
781795 public function get( $code, $key ) {
782796 if ( !isset( $this->readers[$code] ) ) {
783797 $fileName = $this->getFileName( $code );
@@ -798,6 +812,12 @@
799813 }
800814
801815 public function startWrite( $code ) {
 816+ if ( !file_exists( $this->directory ) ) {
 817+ if ( !wfMkdirParents( $this->directory ) ) {
 818+ throw new MWException( "Unable to create the localisation store " .
 819+ "directory \"{$this->directory}\"" );
 820+ }
 821+ }
802822 $this->writer = CdbWriter::open( $this->getFileName( $code ) );
803823 $this->currentLang = $code;
804824 }
@@ -823,11 +843,10 @@
824844 }
825845
826846 protected function getFileName( $code ) {
827 - global $wgCacheDirectory;
828847 if ( !$code || strpos( $code, '/' ) !== false ) {
829848 throw new MWException( __METHOD__.": Invalid language \"$code\"" );
830849 }
831 - return "$wgCacheDirectory/l10n_cache-$code.cdb";
 850+ return "{$this->directory}/l10n_cache-$code.cdb";
832851 }
833852 }
834853
Index: trunk/phase3/includes/DefaultSettings.php
@@ -166,7 +166,11 @@
167167
168168 /**
169169 * Directory for caching data in the local filesystem. Should not be accessible
170 - * from the web.Set this to false to not use any local caches.
 170+ * from the web. Set this to false to not use any local caches.
 171+ *
 172+ * Note: if multiple wikis share the same localisation cache directory, they
 173+ * must all have the same set of extensions. You can set a directory just for
 174+ * the localisation cache using $wgLocalisationCacheConf['storeDirectory'].
171175 */
172176 $wgCacheDirectory = false;
173177
@@ -778,22 +782,26 @@
779783 * class: The class to use. May be overridden by extensions.
780784 *
781785 * store: The location to store cache data. May be 'files', 'db' or
782 - * 'detect'. If set to "files", data will be in CDB files in
783 - * the directory specified by $wgCacheDirectory. If set to "db",
784 - * data will be stored to the database. If set to "detect", files
785 - * will be used if $wgCacheDirectory is set, otherwise the
786 - * database will be used.
 786+ * 'detect'. If set to "files", data will be in CDB files. If set
 787+ * to "db", data will be stored to the database. If set to
 788+ * "detect", files will be used if $wgCacheDirectory is set,
 789+ * otherwise the database will be used.
787790 *
788791 * storeClass: The class name for the underlying storage. If set to a class
789792 * name, it overrides the "store" setting.
790793 *
791 - * manualRecache: Set this to true to disable cache updates on web requests.
792 - * Use maintenance/rebuildLocalisationCache.php instead.
 794+ * storeDirectory: If the store class puts its data in files, this is the
 795+ * directory it will use. If this is false, $wgCacheDirectory
 796+ * will be used.
 797+ *
 798+ * manualRecache: Set this to true to disable cache updates on web requests.
 799+ * Use maintenance/rebuildLocalisationCache.php instead.
793800 */
794801 $wgLocalisationCacheConf = array(
795802 'class' => 'LocalisationCache',
796803 'store' => 'detect',
797804 'storeClass' => false,
 805+ 'storeDirectory' => false,
798806 'manualRecache' => false,
799807 );
800808

Status & tagging log