X-Git-Url: https://git.cyclocoop.org/%27.WWW_URL.%27admin/?a=blobdiff_plain;f=includes%2FCacheManager.php;h=0d116f72ad5d90cad4a47fa4f1a0ef3a7e7d4a81;hb=01c54587794f394845c32f282b100be66fa45bd2;hp=ab6c66d5e442f0b2a05cac7730f3a1dec50a7131;hpb=f84493db51656cee37c2d9f4f06ce80313198017;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/CacheManager.php b/includes/CacheManager.php index ab6c66d5e4..0d116f72ad 100644 --- a/includes/CacheManager.php +++ b/includes/CacheManager.php @@ -2,6 +2,7 @@ /** * Contain the CacheManager class * @package MediaWiki + * @subpackage Cache */ /** @@ -13,38 +14,37 @@ require_once( 'Title.php' ); * 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. - * + * * Global options that affect this module: * $wgCachePages * $wgCacheEpoch * $wgUseFileCache * $wgFileCacheDirectory * $wgUseGzip - * @package MediaWiki + * @package MediaWiki */ class CacheManager { var $mTitle, $mFileCache; - + function CacheManager( &$title ) { $this->mTitle =& $title; $this->mFileCache = ''; } - + function fileCacheName() { - global $wgFileCacheDirectory, $wgContLang; + global $wgFileCacheDirectory; if( !$this->mFileCache ) { - $hash = md5( $key = $this->mTitle->getDbkey() ); - if( $this->mTitle->getNamespace() ) - $key = $wgContLang->getNsText( $this->mTitle->getNamespace() ) . ":" . $key; + $key = $this->mTitle->getPrefixedDbkey(); + $hash = md5( $key ); $key = str_replace( '.', '%2E', urlencode( $key ) ); - + $hash1 = substr( $hash, 0, 1 ); $hash2 = substr( $hash, 0, 2 ); $this->mFileCache = "{$wgFileCacheDirectory}/{$hash1}/{$hash2}/{$key}.html"; - + if($this->useGzip()) $this->mFileCache .= '.gz'; - + wfDebug( " fileCacheName() - {$this->mFileCache}\n" ); } return $this->mFileCache; @@ -53,20 +53,20 @@ class CacheManager { function isFileCached() { return file_exists( $this->fileCacheName() ); } - + function fileCacheTime() { - return wfUnix2Timestamp( filemtime( $this->fileCacheName() ) ); + return wfTimestamp( TS_MW, filemtime( $this->fileCacheName() ) ); } - + function isFileCacheGood( $timestamp ) { global $wgCacheEpoch; - + if( !$this->isFileCached() ) return false; - + $cachetime = $this->fileCacheTime(); $good = (( $timestamp <= $cachetime ) && ( $wgCacheEpoch <= $cachetime )); - + wfDebug(" isFileCacheGood() - cachetime $cachetime, touched {$timestamp} epoch {$wgCacheEpoch}, good $good\n"); return $good; } @@ -75,12 +75,12 @@ class CacheManager { global $wgUseGzip; return $wgUseGzip; } - + /* In handy string packages */ function fetchRawText() { return file_get_contents( $this->fileCacheName() ); } - + function fetchPageText() { if( $this->useGzip() ) { /* Why is there no gzfile_get_contents() or gzdecode()? */ @@ -89,15 +89,18 @@ class CacheManager { return $this->fetchRawText(); } } - + /* Working directory to/from output */ function loadFromFileCache() { - global $wgOut; + global $wgOut, $wgMimeType, $wgOutputEncoding, $wgContLanguageCode; wfDebug(" loadFromFileCache()\n"); - + $filename=$this->fileCacheName(); $wgOut->sendCacheControl(); - + + header( "Content-type: $wgMimeType; charset={$wgOutputEncoding}" ); + header( "Content-language: $wgContLanguageCode" ); + if( $this->useGzip() ) { if( wfClientAcceptsGzip() ) { header( 'Content-Encoding: gzip' ); @@ -109,24 +112,24 @@ class CacheManager { } readfile( $filename ); } - + function checkCacheDirs() { $filename = $this->fileCacheName(); $mydir2=substr($filename,0,strrpos($filename,'/')); # subdirectory level 2 $mydir1=substr($mydir2,0,strrpos($mydir2,'/')); # subdirectory level 1 - + if(!file_exists($mydir1)) { mkdir($mydir1,0775); } # create if necessary if(!file_exists($mydir2)) { mkdir($mydir2,0775); } } - + function saveToFileCache( $origtext ) { $text = $origtext; if(strcmp($text,'') == 0) return ''; - + wfDebug(" saveToFileCache()\n", false); - + $this->checkCacheDirs(); - + $f = fopen( $this->fileCacheName(), 'w' ); if($f) { $now = wfTimestampNow();