Index: trunk/phase3/includes/CacheManager.php |
— | — | @@ -1,159 +0,0 @@ |
2 | | -<?php |
3 | | -/** |
4 | | - * Contain the CacheManager class |
5 | | - * @package MediaWiki |
6 | | - * @subpackage Cache |
7 | | - */ |
8 | | - |
9 | | -/** |
10 | | - * Handles talking to the file cache, putting stuff in and taking it back out. |
11 | | - * Mostly called from Article.php, also from DatabaseFunctions.php for the |
12 | | - * emergency abort/fallback to cache. |
13 | | - * |
14 | | - * Global options that affect this module: |
15 | | - * $wgCachePages |
16 | | - * $wgCacheEpoch |
17 | | - * $wgUseFileCache |
18 | | - * $wgFileCacheDirectory |
19 | | - * $wgUseGzip |
20 | | - * @package MediaWiki |
21 | | - */ |
22 | | -class CacheManager { |
23 | | - var $mTitle, $mFileCache; |
24 | | - |
25 | | - function CacheManager( &$title ) { |
26 | | - $this->mTitle =& $title; |
27 | | - $this->mFileCache = ''; |
28 | | - } |
29 | | - |
30 | | - function fileCacheName() { |
31 | | - global $wgFileCacheDirectory; |
32 | | - if( !$this->mFileCache ) { |
33 | | - $key = $this->mTitle->getPrefixedDbkey(); |
34 | | - $hash = md5( $key ); |
35 | | - $key = str_replace( '.', '%2E', urlencode( $key ) ); |
36 | | - |
37 | | - $hash1 = substr( $hash, 0, 1 ); |
38 | | - $hash2 = substr( $hash, 0, 2 ); |
39 | | - $this->mFileCache = "{$wgFileCacheDirectory}/{$hash1}/{$hash2}/{$key}.html"; |
40 | | - |
41 | | - if($this->useGzip()) |
42 | | - $this->mFileCache .= '.gz'; |
43 | | - |
44 | | - wfDebug( " fileCacheName() - {$this->mFileCache}\n" ); |
45 | | - } |
46 | | - return $this->mFileCache; |
47 | | - } |
48 | | - |
49 | | - function isFileCached() { |
50 | | - return file_exists( $this->fileCacheName() ); |
51 | | - } |
52 | | - |
53 | | - function fileCacheTime() { |
54 | | - return wfTimestamp( TS_MW, filemtime( $this->fileCacheName() ) ); |
55 | | - } |
56 | | - |
57 | | - function isFileCacheGood( $timestamp ) { |
58 | | - global $wgCacheEpoch; |
59 | | - |
60 | | - if( !$this->isFileCached() ) return false; |
61 | | - |
62 | | - $cachetime = $this->fileCacheTime(); |
63 | | - $good = (( $timestamp <= $cachetime ) && |
64 | | - ( $wgCacheEpoch <= $cachetime )); |
65 | | - |
66 | | - wfDebug(" isFileCacheGood() - cachetime $cachetime, touched {$timestamp} epoch {$wgCacheEpoch}, good $good\n"); |
67 | | - return $good; |
68 | | - } |
69 | | - |
70 | | - function useGzip() { |
71 | | - global $wgUseGzip; |
72 | | - return $wgUseGzip; |
73 | | - } |
74 | | - |
75 | | - /* In handy string packages */ |
76 | | - function fetchRawText() { |
77 | | - return file_get_contents( $this->fileCacheName() ); |
78 | | - } |
79 | | - |
80 | | - function fetchPageText() { |
81 | | - if( $this->useGzip() ) { |
82 | | - /* Why is there no gzfile_get_contents() or gzdecode()? */ |
83 | | - return implode( '', gzfile( $this->fileCacheName() ) ); |
84 | | - } else { |
85 | | - return $this->fetchRawText(); |
86 | | - } |
87 | | - } |
88 | | - |
89 | | - /* Working directory to/from output */ |
90 | | - function loadFromFileCache() { |
91 | | - global $wgOut, $wgMimeType, $wgOutputEncoding, $wgContLanguageCode; |
92 | | - wfDebug(" loadFromFileCache()\n"); |
93 | | - |
94 | | - $filename=$this->fileCacheName(); |
95 | | - $wgOut->sendCacheControl(); |
96 | | - |
97 | | - header( "Content-type: $wgMimeType; charset={$wgOutputEncoding}" ); |
98 | | - header( "Content-language: $wgContLanguageCode" ); |
99 | | - |
100 | | - if( $this->useGzip() ) { |
101 | | - if( wfClientAcceptsGzip() ) { |
102 | | - header( 'Content-Encoding: gzip' ); |
103 | | - } else { |
104 | | - /* Send uncompressed */ |
105 | | - readgzfile( $filename ); |
106 | | - return; |
107 | | - } |
108 | | - } |
109 | | - readfile( $filename ); |
110 | | - } |
111 | | - |
112 | | - function checkCacheDirs() { |
113 | | - $filename = $this->fileCacheName(); |
114 | | - $mydir2=substr($filename,0,strrpos($filename,'/')); # subdirectory level 2 |
115 | | - $mydir1=substr($mydir2,0,strrpos($mydir2,'/')); # subdirectory level 1 |
116 | | - |
117 | | - if(!file_exists($mydir1)) { mkdir($mydir1,0775); } # create if necessary |
118 | | - if(!file_exists($mydir2)) { mkdir($mydir2,0775); } |
119 | | - } |
120 | | - |
121 | | - function saveToFileCache( $origtext ) { |
122 | | - $text = $origtext; |
123 | | - if(strcmp($text,'') == 0) return ''; |
124 | | - |
125 | | - wfDebug(" saveToFileCache()\n", false); |
126 | | - |
127 | | - $this->checkCacheDirs(); |
128 | | - |
129 | | - $f = fopen( $this->fileCacheName(), 'w' ); |
130 | | - if($f) { |
131 | | - $now = wfTimestampNow(); |
132 | | - if( $this->useGzip() ) { |
133 | | - $rawtext = str_replace( '</html>', |
134 | | - '<!-- Cached/compressed '.$now." -->\n</html>", |
135 | | - $text ); |
136 | | - $text = gzencode( $rawtext ); |
137 | | - } else { |
138 | | - $text = str_replace( '</html>', |
139 | | - '<!-- Cached '.$now." -->\n</html>", |
140 | | - $text ); |
141 | | - } |
142 | | - fwrite( $f, $text ); |
143 | | - fclose( $f ); |
144 | | - if( $this->useGzip() ) { |
145 | | - if( wfClientAcceptsGzip() ) { |
146 | | - header( 'Content-Encoding: gzip' ); |
147 | | - return $text; |
148 | | - } else { |
149 | | - return $rawtext; |
150 | | - } |
151 | | - } else { |
152 | | - return $text; |
153 | | - } |
154 | | - } |
155 | | - return $text; |
156 | | - } |
157 | | - |
158 | | -} |
159 | | - |
160 | | -?> |
Index: trunk/phase3/includes/Article.php |
— | — | @@ -9,7 +9,7 @@ |
10 | 10 | * |
11 | 11 | * See design.txt for an overview. |
12 | 12 | * Note: edit user interface and cache support functions have been |
13 | | - * moved to separate EditPage and CacheManager classes. |
| 13 | + * moved to separate EditPage and HTMLFileCache classes. |
14 | 14 | * |
15 | 15 | * @package MediaWiki |
16 | 16 | */ |
— | — | @@ -2250,7 +2250,7 @@ |
2251 | 2251 | $called = true; |
2252 | 2252 | if($this->isFileCacheable()) { |
2253 | 2253 | $touched = $this->mTouched; |
2254 | | - $cache = new CacheManager( $this->mTitle ); |
| 2254 | + $cache = new HTMLFileCache( $this->mTitle ); |
2255 | 2255 | if($cache->isFileCacheGood( $touched )) { |
2256 | 2256 | wfDebug( "Article::tryFileCache(): about to load file\n" ); |
2257 | 2257 | $cache->loadFromFileCache(); |
— | — | @@ -2438,7 +2438,7 @@ |
2439 | 2439 | |
2440 | 2440 | # File cache |
2441 | 2441 | if ( $wgUseFileCache ) { |
2442 | | - $cm = new CacheManager( $title ); |
| 2442 | + $cm = new HTMLFileCache( $title ); |
2443 | 2443 | @unlink( $cm->fileCacheName() ); |
2444 | 2444 | } |
2445 | 2445 | |
— | — | @@ -2464,7 +2464,7 @@ |
2465 | 2465 | |
2466 | 2466 | # Clear file cache |
2467 | 2467 | if ( $wgUseFileCache ) { |
2468 | | - $cm = new CacheManager( $title ); |
| 2468 | + $cm = new HTMLFileCache( $title ); |
2469 | 2469 | @unlink( $cm->fileCacheName() ); |
2470 | 2470 | } |
2471 | 2471 | } |
Index: trunk/phase3/includes/AutoLoader.php |
— | — | @@ -22,7 +22,7 @@ |
23 | 23 | 'eAccelBagOStuff' => 'includes/BagOStuff.php', |
24 | 24 | 'DBABagOStuff' => 'includes/BagOStuff.php', |
25 | 25 | 'Block' => 'includes/Block.php', |
26 | | - 'CacheManager' => 'includes/CacheManager.php', |
| 26 | + 'HTMLFileCache' => 'includes/HTMLFileCache.php', |
27 | 27 | 'CategoryPage' => 'includes/CategoryPage.php', |
28 | 28 | 'CategoryViewer' => 'includes/CategoryPage.php', |
29 | 29 | 'Categoryfinder' => 'includes/Categoryfinder.php', |
Index: trunk/phase3/includes/Title.php |
— | — | @@ -540,7 +540,7 @@ |
541 | 541 | |
542 | 542 | foreach ( $titles as $title ) { |
543 | 543 | if ( $wgUseFileCache ) { |
544 | | - $cm = new CacheManager($title); |
| 544 | + $cm = new HTMLFileCache($title); |
545 | 545 | @unlink($cm->fileCacheName()); |
546 | 546 | } |
547 | 547 | |
— | — | @@ -1366,7 +1366,7 @@ |
1367 | 1367 | ); |
1368 | 1368 | |
1369 | 1369 | if ($wgUseFileCache) { |
1370 | | - $cache = new CacheManager($this); |
| 1370 | + $cache = new HTMLFileCache($this); |
1371 | 1371 | @unlink($cache->fileCacheName()); |
1372 | 1372 | } |
1373 | 1373 | |
Index: trunk/phase3/includes/HTMLFileCache.php |
— | — | @@ -0,0 +1,159 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * Contain the HTMLFileCache class |
| 5 | + * @package MediaWiki |
| 6 | + * @subpackage Cache |
| 7 | + */ |
| 8 | + |
| 9 | +/** |
| 10 | + * Handles talking to the file cache, putting stuff in and taking it back out. |
| 11 | + * Mostly called from Article.php, also from DatabaseFunctions.php for the |
| 12 | + * emergency abort/fallback to cache. |
| 13 | + * |
| 14 | + * Global options that affect this module: |
| 15 | + * $wgCachePages |
| 16 | + * $wgCacheEpoch |
| 17 | + * $wgUseFileCache |
| 18 | + * $wgFileCacheDirectory |
| 19 | + * $wgUseGzip |
| 20 | + * @package MediaWiki |
| 21 | + */ |
| 22 | +class HTMLFileCache { |
| 23 | + var $mTitle, $mFileCache; |
| 24 | + |
| 25 | + function HTMLFileCache( &$title ) { |
| 26 | + $this->mTitle =& $title; |
| 27 | + $this->mFileCache = ''; |
| 28 | + } |
| 29 | + |
| 30 | + function fileCacheName() { |
| 31 | + global $wgFileCacheDirectory; |
| 32 | + if( !$this->mFileCache ) { |
| 33 | + $key = $this->mTitle->getPrefixedDbkey(); |
| 34 | + $hash = md5( $key ); |
| 35 | + $key = str_replace( '.', '%2E', urlencode( $key ) ); |
| 36 | + |
| 37 | + $hash1 = substr( $hash, 0, 1 ); |
| 38 | + $hash2 = substr( $hash, 0, 2 ); |
| 39 | + $this->mFileCache = "{$wgFileCacheDirectory}/{$hash1}/{$hash2}/{$key}.html"; |
| 40 | + |
| 41 | + if($this->useGzip()) |
| 42 | + $this->mFileCache .= '.gz'; |
| 43 | + |
| 44 | + wfDebug( " fileCacheName() - {$this->mFileCache}\n" ); |
| 45 | + } |
| 46 | + return $this->mFileCache; |
| 47 | + } |
| 48 | + |
| 49 | + function isFileCached() { |
| 50 | + return file_exists( $this->fileCacheName() ); |
| 51 | + } |
| 52 | + |
| 53 | + function fileCacheTime() { |
| 54 | + return wfTimestamp( TS_MW, filemtime( $this->fileCacheName() ) ); |
| 55 | + } |
| 56 | + |
| 57 | + function isFileCacheGood( $timestamp ) { |
| 58 | + global $wgCacheEpoch; |
| 59 | + |
| 60 | + if( !$this->isFileCached() ) return false; |
| 61 | + |
| 62 | + $cachetime = $this->fileCacheTime(); |
| 63 | + $good = (( $timestamp <= $cachetime ) && |
| 64 | + ( $wgCacheEpoch <= $cachetime )); |
| 65 | + |
| 66 | + wfDebug(" isFileCacheGood() - cachetime $cachetime, touched {$timestamp} epoch {$wgCacheEpoch}, good $good\n"); |
| 67 | + return $good; |
| 68 | + } |
| 69 | + |
| 70 | + function useGzip() { |
| 71 | + global $wgUseGzip; |
| 72 | + return $wgUseGzip; |
| 73 | + } |
| 74 | + |
| 75 | + /* In handy string packages */ |
| 76 | + function fetchRawText() { |
| 77 | + return file_get_contents( $this->fileCacheName() ); |
| 78 | + } |
| 79 | + |
| 80 | + function fetchPageText() { |
| 81 | + if( $this->useGzip() ) { |
| 82 | + /* Why is there no gzfile_get_contents() or gzdecode()? */ |
| 83 | + return implode( '', gzfile( $this->fileCacheName() ) ); |
| 84 | + } else { |
| 85 | + return $this->fetchRawText(); |
| 86 | + } |
| 87 | + } |
| 88 | + |
| 89 | + /* Working directory to/from output */ |
| 90 | + function loadFromFileCache() { |
| 91 | + global $wgOut, $wgMimeType, $wgOutputEncoding, $wgContLanguageCode; |
| 92 | + wfDebug(" loadFromFileCache()\n"); |
| 93 | + |
| 94 | + $filename=$this->fileCacheName(); |
| 95 | + $wgOut->sendCacheControl(); |
| 96 | + |
| 97 | + header( "Content-type: $wgMimeType; charset={$wgOutputEncoding}" ); |
| 98 | + header( "Content-language: $wgContLanguageCode" ); |
| 99 | + |
| 100 | + if( $this->useGzip() ) { |
| 101 | + if( wfClientAcceptsGzip() ) { |
| 102 | + header( 'Content-Encoding: gzip' ); |
| 103 | + } else { |
| 104 | + /* Send uncompressed */ |
| 105 | + readgzfile( $filename ); |
| 106 | + return; |
| 107 | + } |
| 108 | + } |
| 109 | + readfile( $filename ); |
| 110 | + } |
| 111 | + |
| 112 | + function checkCacheDirs() { |
| 113 | + $filename = $this->fileCacheName(); |
| 114 | + $mydir2=substr($filename,0,strrpos($filename,'/')); # subdirectory level 2 |
| 115 | + $mydir1=substr($mydir2,0,strrpos($mydir2,'/')); # subdirectory level 1 |
| 116 | + |
| 117 | + if(!file_exists($mydir1)) { mkdir($mydir1,0775); } # create if necessary |
| 118 | + if(!file_exists($mydir2)) { mkdir($mydir2,0775); } |
| 119 | + } |
| 120 | + |
| 121 | + function saveToFileCache( $origtext ) { |
| 122 | + $text = $origtext; |
| 123 | + if(strcmp($text,'') == 0) return ''; |
| 124 | + |
| 125 | + wfDebug(" saveToFileCache()\n", false); |
| 126 | + |
| 127 | + $this->checkCacheDirs(); |
| 128 | + |
| 129 | + $f = fopen( $this->fileCacheName(), 'w' ); |
| 130 | + if($f) { |
| 131 | + $now = wfTimestampNow(); |
| 132 | + if( $this->useGzip() ) { |
| 133 | + $rawtext = str_replace( '</html>', |
| 134 | + '<!-- Cached/compressed '.$now." -->\n</html>", |
| 135 | + $text ); |
| 136 | + $text = gzencode( $rawtext ); |
| 137 | + } else { |
| 138 | + $text = str_replace( '</html>', |
| 139 | + '<!-- Cached '.$now." -->\n</html>", |
| 140 | + $text ); |
| 141 | + } |
| 142 | + fwrite( $f, $text ); |
| 143 | + fclose( $f ); |
| 144 | + if( $this->useGzip() ) { |
| 145 | + if( wfClientAcceptsGzip() ) { |
| 146 | + header( 'Content-Encoding: gzip' ); |
| 147 | + return $text; |
| 148 | + } else { |
| 149 | + return $rawtext; |
| 150 | + } |
| 151 | + } else { |
| 152 | + return $text; |
| 153 | + } |
| 154 | + } |
| 155 | + return $text; |
| 156 | + } |
| 157 | + |
| 158 | +} |
| 159 | + |
| 160 | +?> |
Property changes on: trunk/phase3/includes/HTMLFileCache.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 161 | + native |
Added: svn:keywords |
2 | 162 | + Author Date Id Revision |
Index: trunk/phase3/includes/HTMLCacheUpdate.php |
— | — | @@ -176,7 +176,7 @@ |
177 | 177 | # Update file cache |
178 | 178 | if ( $wgUseFileCache ) { |
179 | 179 | foreach ( $titles as $title ) { |
180 | | - $cm = new CacheManager($title); |
| 180 | + $cm = new HTMLFileCache($title); |
181 | 181 | @unlink($cm->fileCacheName()); |
182 | 182 | } |
183 | 183 | } |
Index: trunk/phase3/includes/Database.php |
— | — | @@ -152,7 +152,7 @@ |
153 | 153 | } |
154 | 154 | } |
155 | 155 | |
156 | | - $cache = new CacheManager( $t ); |
| 156 | + $cache = new HTMLFileCache( $t ); |
157 | 157 | if( $cache->isFileCached() ) { |
158 | 158 | $msg = '<p style="color: red"><b>'.$msg."<br />\n" . |
159 | 159 | $cachederror . "</b></p>\n"; |