(bug 12797) Allow adjusting of default gallery display options
[lhc/web/wiklou.git] / includes / HTMLFileCache.php
index 5745de4..53af1e6 100644 (file)
@@ -14,6 +14,7 @@
  * - $wgCachePages
  * - $wgCacheEpoch
  * - $wgUseFileCache
+ * - $wgCacheDirectory
  * - $wgFileCacheDirectory
  * - $wgUseGzip
  *
@@ -30,7 +31,16 @@ class HTMLFileCache {
 
        public function fileCacheName() {
                if( !$this->mFileCache ) {
-                       global $wgFileCacheDirectory, $wgRequest;
+                       global $wgCacheDirectory, $wgFileCacheDirectory, $wgRequest;
+
+                       if ( $wgFileCacheDirectory ) {
+                               $dir = $wgFileCacheDirectory;
+                       } elseif ( $wgCacheDirectory ) {
+                               $dir = "$wgCacheDirectory/html";
+                       } else {
+                               throw new MWException( 'Please set $wgCacheDirectory in LocalSettings.php if you wish to use the HTML file cache' );
+                       }
+
                        # Store raw pages (like CSS hits) elsewhere
                        $subdir = ($this->mType === 'raw') ? 'raw/' : '';
                        $key = $this->mTitle->getPrefixedDbkey();
@@ -45,7 +55,7 @@ class HTMLFileCache {
                        if( $this->useGzip() )
                                $this->mFileCache .= '.gz';
 
-                       wfDebug( " fileCacheName() - {$this->mFileCache}\n" );
+                       wfDebug( __METHOD__ . ": {$this->mFileCache}\n" );
                }
                return $this->mFileCache;
        }
@@ -96,12 +106,11 @@ class HTMLFileCache {
                global $wgCacheEpoch;
 
                if( !$this->isFileCached() ) return false;
-               if( !$timestamp ) return true; // should be invalidated on change
 
                $cachetime = $this->fileCacheTime();
                $good = $timestamp <= $cachetime && $wgCacheEpoch <= $cachetime;
 
-               wfDebug(" isFileCacheGood() - cachetime $cachetime, touched '{$timestamp}' epoch {$wgCacheEpoch}, good $good\n");
+               wfDebug( __METHOD__ . ": cachetime $cachetime, touched '{$timestamp}' epoch {$wgCacheEpoch}, good $good\n");
                return $good;
        }
 
@@ -127,8 +136,7 @@ class HTMLFileCache {
        /* Working directory to/from output */
        public function loadFromFileCache() {
                global $wgOut, $wgMimeType, $wgOutputEncoding, $wgContLanguageCode;
-               wfDebug(" loadFromFileCache()\n");
-
+               wfDebug( __METHOD__ . "()\n");
                $filename = $this->fileCacheName();
                // Raw pages should handle cache control on their own,
                // even when using file cache. This reduces hits from clients.
@@ -148,6 +156,7 @@ class HTMLFileCache {
                        }
                }
                readfile( $filename );
+               $wgOut->disable(); // tell $wgOut that output is taken care of
        }
 
        protected function checkCacheDirs() {
@@ -166,7 +175,7 @@ class HTMLFileCache {
                        return $text;
                }
 
-               wfDebug(" saveToFileCache()\n", false);
+               wfDebug( __METHOD__ . "()\n", false);
 
                $this->checkCacheDirs();