Index: trunk/phase3/includes/RawPage.php |
— | — | @@ -149,6 +149,20 @@ |
150 | 150 | # allow the client to cache this for 24 hours |
151 | 151 | $mode = $this->mPrivateCache ? 'private' : 'public'; |
152 | 152 | header( 'Cache-Control: '.$mode.', s-maxage='.$this->mSmaxage.', max-age='.$this->mMaxage ); |
| 153 | + |
| 154 | + if( HTMLFileCache::useFileCache() ) { |
| 155 | + $cache = new HTMLFileCache( $this->mTitle ); |
| 156 | + if( $cache->isFileCacheGood( /* Assume up to date */ ) ) { |
| 157 | + /* Check incoming headers to see if client has this cached */ |
| 158 | + if( !$wgOut->checkLastModified( $cache->fileCacheTime() ) ) { |
| 159 | + $cache->loadFromFileCache(); |
| 160 | + } |
| 161 | + return; |
| 162 | + } else { |
| 163 | + ob_start( array(&$cache, 'saveToFileCache' ) ); |
| 164 | + } |
| 165 | + } |
| 166 | + |
153 | 167 | $text = $this->getRawText(); |
154 | 168 | |
155 | 169 | if( !wfRunHooks( 'RawPageViewBeforeOutput', array( &$this, &$text ) ) ) { |
Index: trunk/phase3/includes/HTMLFileCache.php |
— | — | @@ -28,15 +28,18 @@ |
29 | 29 | } |
30 | 30 | |
31 | 31 | public function fileCacheName() { |
32 | | - global $wgFileCacheDirectory; |
33 | 32 | if( !$this->mFileCache ) { |
| 33 | + global $wgFileCacheDirectory, $wgRequest; |
34 | 34 | $key = $this->mTitle->getPrefixedDbkey(); |
35 | 35 | $hash = md5( $key ); |
| 36 | + # Avoid extension confusion |
36 | 37 | $key = str_replace( '.', '%2E', urlencode( $key ) ); |
37 | | - |
| 38 | + # Store raw pages (like CSS hits) elsewhere |
| 39 | + $subdir = $wgRequest->getVal('action') == 'raw' ? 'raw/' : ''; |
| 40 | + |
38 | 41 | $hash1 = substr( $hash, 0, 1 ); |
39 | 42 | $hash2 = substr( $hash, 0, 2 ); |
40 | | - $this->mFileCache = "{$wgFileCacheDirectory}/{$hash1}/{$hash2}/{$key}.html"; |
| 43 | + $this->mFileCache = "{$wgFileCacheDirectory}/{$subdir}{$hash1}/{$hash2}/{$key}.html"; |
41 | 44 | |
42 | 45 | if( $this->useGzip() ) |
43 | 46 | $this->mFileCache .= '.gz'; |
— | — | @@ -60,21 +63,24 @@ |
61 | 64 | */ |
62 | 65 | public static function useFileCache() { |
63 | 66 | global $wgUser, $wgUseFileCache, $wgShowIPinHeader, $wgRequest, $wgLang, $wgContLang; |
64 | | - if( !$wgUseFileCache ) |
65 | | - return false; |
| 67 | + if( !$wgUseFileCache ) return false; |
66 | 68 | // Get all query values |
67 | 69 | $queryVals = $wgRequest->getValues(); |
68 | 70 | foreach( $queryVals as $query => $val ) { |
69 | | - // Normal page view in query form can have action=view |
70 | | - if( $query !== 'title' && $query !== 'curid' && !($query == 'action' && $val == 'view') ) { |
71 | | - return false; |
72 | | - } |
| 71 | + if( $query == 'title' || $query == 'curid' ) continue; |
| 72 | + // Normal page view in query form can have action=view. |
| 73 | + // Raw hits for pages also stored, like .css pages for example. |
| 74 | + if( $query == 'action' && ($val == 'view' || $val == 'raw') ) continue; |
| 75 | + if( $query == 'usemsgcache' && $val == 'yes' ) continue; |
| 76 | + // Below are header setting params |
| 77 | + if( $query == 'maxage' || $query == 'smaxage' || $query == 'ctype' || $query == 'gen' ) |
| 78 | + continue; |
73 | 79 | } |
74 | 80 | // Check for non-standard user language; this covers uselang, |
75 | 81 | // and extensions for auto-detecting user language. |
76 | 82 | $ulang = $wgLang->getCode(); |
77 | 83 | $clang = $wgContLang->getCode(); |
78 | | - |
| 84 | + // Check that there are no other sources of variation |
79 | 85 | return !$wgShowIPinHeader && !$wgUser->getId() && !$wgUser->getNewtalk() && $ulang == $clang; |
80 | 86 | } |
81 | 87 | |