From: Tim Starling Date: Wed, 11 Oct 2006 08:25:26 +0000 (+0000) Subject: Renamed CacheManager to HTMLFileCache, to avoid confusion with the other sort of... X-Git-Tag: 1.31.0-rc.0~55539 X-Git-Url: http://git.cyclocoop.org/%7B%24www_url%7Dadmin/password.php?a=commitdiff_plain;h=d411e0b1e0a23dc54e1d39573e5ee4b9f3019141;p=lhc%2Fweb%2Fwiklou.git Renamed CacheManager to HTMLFileCache, to avoid confusion with the other sort of cache. --- diff --git a/includes/Article.php b/includes/Article.php index 8c07b06c51..8bd114ee68 100644 --- a/includes/Article.php +++ b/includes/Article.php @@ -9,7 +9,7 @@ * * See design.txt for an overview. * Note: edit user interface and cache support functions have been - * moved to separate EditPage and CacheManager classes. + * moved to separate EditPage and HTMLFileCache classes. * * @package MediaWiki */ @@ -2250,7 +2250,7 @@ class Article { $called = true; if($this->isFileCacheable()) { $touched = $this->mTouched; - $cache = new CacheManager( $this->mTitle ); + $cache = new HTMLFileCache( $this->mTitle ); if($cache->isFileCacheGood( $touched )) { wfDebug( "Article::tryFileCache(): about to load file\n" ); $cache->loadFromFileCache(); @@ -2438,7 +2438,7 @@ class Article { # File cache if ( $wgUseFileCache ) { - $cm = new CacheManager( $title ); + $cm = new HTMLFileCache( $title ); @unlink( $cm->fileCacheName() ); } @@ -2464,7 +2464,7 @@ class Article { # Clear file cache if ( $wgUseFileCache ) { - $cm = new CacheManager( $title ); + $cm = new HTMLFileCache( $title ); @unlink( $cm->fileCacheName() ); } } diff --git a/includes/AutoLoader.php b/includes/AutoLoader.php index 810a448ea8..fb8a394f78 100644 --- a/includes/AutoLoader.php +++ b/includes/AutoLoader.php @@ -22,7 +22,7 @@ function __autoload($className) { 'eAccelBagOStuff' => 'includes/BagOStuff.php', 'DBABagOStuff' => 'includes/BagOStuff.php', 'Block' => 'includes/Block.php', - 'CacheManager' => 'includes/CacheManager.php', + 'HTMLFileCache' => 'includes/HTMLFileCache.php', 'CategoryPage' => 'includes/CategoryPage.php', 'CategoryViewer' => 'includes/CategoryPage.php', 'Categoryfinder' => 'includes/Categoryfinder.php', diff --git a/includes/CacheManager.php b/includes/CacheManager.php deleted file mode 100644 index b9e307f44f..0000000000 --- a/includes/CacheManager.php +++ /dev/null @@ -1,159 +0,0 @@ -mTitle =& $title; - $this->mFileCache = ''; - } - - function fileCacheName() { - global $wgFileCacheDirectory; - if( !$this->mFileCache ) { - $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; - } - - function isFileCached() { - return file_exists( $this->fileCacheName() ); - } - - function fileCacheTime() { - 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; - } - - function useGzip() { - 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()? */ - return implode( '', gzfile( $this->fileCacheName() ) ); - } else { - return $this->fetchRawText(); - } - } - - /* Working directory to/from output */ - function loadFromFileCache() { - 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' ); - } else { - /* Send uncompressed */ - readgzfile( $filename ); - return; - } - } - 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(); - if( $this->useGzip() ) { - $rawtext = str_replace( '', - '\n", - $text ); - $text = gzencode( $rawtext ); - } else { - $text = str_replace( '', - '\n", - $text ); - } - fwrite( $f, $text ); - fclose( $f ); - if( $this->useGzip() ) { - if( wfClientAcceptsGzip() ) { - header( 'Content-Encoding: gzip' ); - return $text; - } else { - return $rawtext; - } - } else { - return $text; - } - } - return $text; - } - -} - -?> diff --git a/includes/Database.php b/includes/Database.php index 53e5996872..9225d94ff9 100644 --- a/includes/Database.php +++ b/includes/Database.php @@ -152,7 +152,7 @@ border=\"0\" ALT=\"Google\"> } } - $cache = new CacheManager( $t ); + $cache = new HTMLFileCache( $t ); if( $cache->isFileCached() ) { $msg = '

'.$msg."
\n" . $cachederror . "

\n"; diff --git a/includes/HTMLCacheUpdate.php b/includes/HTMLCacheUpdate.php index 47703b2005..f76bcd6874 100644 --- a/includes/HTMLCacheUpdate.php +++ b/includes/HTMLCacheUpdate.php @@ -176,7 +176,7 @@ class HTMLCacheUpdate # Update file cache if ( $wgUseFileCache ) { foreach ( $titles as $title ) { - $cm = new CacheManager($title); + $cm = new HTMLFileCache($title); @unlink($cm->fileCacheName()); } } diff --git a/includes/HTMLFileCache.php b/includes/HTMLFileCache.php new file mode 100644 index 0000000000..d85a441106 --- /dev/null +++ b/includes/HTMLFileCache.php @@ -0,0 +1,159 @@ +mTitle =& $title; + $this->mFileCache = ''; + } + + function fileCacheName() { + global $wgFileCacheDirectory; + if( !$this->mFileCache ) { + $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; + } + + function isFileCached() { + return file_exists( $this->fileCacheName() ); + } + + function fileCacheTime() { + 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; + } + + function useGzip() { + 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()? */ + return implode( '', gzfile( $this->fileCacheName() ) ); + } else { + return $this->fetchRawText(); + } + } + + /* Working directory to/from output */ + function loadFromFileCache() { + 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' ); + } else { + /* Send uncompressed */ + readgzfile( $filename ); + return; + } + } + 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(); + if( $this->useGzip() ) { + $rawtext = str_replace( '', + '\n", + $text ); + $text = gzencode( $rawtext ); + } else { + $text = str_replace( '', + '\n", + $text ); + } + fwrite( $f, $text ); + fclose( $f ); + if( $this->useGzip() ) { + if( wfClientAcceptsGzip() ) { + header( 'Content-Encoding: gzip' ); + return $text; + } else { + return $rawtext; + } + } else { + return $text; + } + } + return $text; + } + +} + +?> diff --git a/includes/Title.php b/includes/Title.php index 0e86063ee4..e8ce66930c 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -540,7 +540,7 @@ class Title { foreach ( $titles as $title ) { if ( $wgUseFileCache ) { - $cm = new CacheManager($title); + $cm = new HTMLFileCache($title); @unlink($cm->fileCacheName()); } @@ -1366,7 +1366,7 @@ class Title { ); if ($wgUseFileCache) { - $cache = new CacheManager($this); + $cache = new HTMLFileCache($this); @unlink($cache->fileCacheName()); }