X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FHTMLFileCache.php;h=fd7d048bf49a44c37d9454bb80e62f173cc7ce79;hb=43c488ff2f96488fb9d94bd30f40c990b86cc74b;hp=ce4c11a57adb82d541bb939717cd193877469934;hpb=8d2c4c501955ab35305abb62506faddc1ddac34f;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/HTMLFileCache.php b/includes/HTMLFileCache.php index ce4c11a57a..fd7d048bf4 100644 --- a/includes/HTMLFileCache.php +++ b/includes/HTMLFileCache.php @@ -7,13 +7,13 @@ /** * Handles talking to the file cache, putting stuff in and taking it back out. - * Mostly called from Article.php, also from DatabaseFunctions.php for the - * emergency abort/fallback to cache. + * Mostly called from Article.php for the emergency abort/fallback to cache. * * Global options that affect this module: * - $wgCachePages * - $wgCacheEpoch * - $wgUseFileCache + * - $wgCacheDirectory * - $wgFileCacheDirectory * - $wgUseGzip * @@ -30,7 +30,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 +54,7 @@ class HTMLFileCache { if( $this->useGzip() ) $this->mFileCache .= '.gz'; - wfDebug( " fileCacheName() - {$this->mFileCache}\n" ); + wfDebug( __METHOD__ . ": {$this->mFileCache}\n" ); } return $this->mFileCache; } @@ -96,12 +105,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 +135,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 +155,7 @@ class HTMLFileCache { } } readfile( $filename ); + $wgOut->disable(); // tell $wgOut that output is taken care of } protected function checkCacheDirs() { @@ -159,18 +167,14 @@ class HTMLFileCache { wfMkdirParents( $mydir2 ); } - public function saveToFileCache( $origtext ) { + public function saveToFileCache( $text ) { global $wgUseFileCache; - if( !$wgUseFileCache ) { - return $origtext; // return to output + if( !$wgUseFileCache || strlen( $text ) < 512 ) { + // Disabled or empty/broken output (OOM and PHP errors) + return $text; } - $text = $origtext; - // Empty? - if( strcmp($text,'') == 0 ) return ''; - // Probably broken? (OOM and PHP errors) - if( mb_strlen($text) < 512 ) return $origtext; - wfDebug(" saveToFileCache()\n", false); + wfDebug( __METHOD__ . "()\n", false); $this->checkCacheDirs();