From a339ab8ee1780ec08b76d4a4d3fa823857555ab7 Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Sun, 28 Dec 2008 13:32:32 +0000 Subject: [PATCH] Enable filecache for raw page hits if $wgUseFileCache is on --- includes/HTMLFileCache.php | 26 ++++++++++++++++---------- includes/RawPage.php | 14 ++++++++++++++ 2 files changed, 30 insertions(+), 10 deletions(-) diff --git a/includes/HTMLFileCache.php b/includes/HTMLFileCache.php index 299235aeb8..15037cc6f7 100644 --- a/includes/HTMLFileCache.php +++ b/includes/HTMLFileCache.php @@ -28,15 +28,18 @@ class HTMLFileCache { } public function fileCacheName() { - global $wgFileCacheDirectory; if( !$this->mFileCache ) { + global $wgFileCacheDirectory, $wgRequest; $key = $this->mTitle->getPrefixedDbkey(); $hash = md5( $key ); + # Avoid extension confusion $key = str_replace( '.', '%2E', urlencode( $key ) ); - + # Store raw pages (like CSS hits) elsewhere + $subdir = $wgRequest->getVal('action') == 'raw' ? 'raw/' : ''; + $hash1 = substr( $hash, 0, 1 ); $hash2 = substr( $hash, 0, 2 ); - $this->mFileCache = "{$wgFileCacheDirectory}/{$hash1}/{$hash2}/{$key}.html"; + $this->mFileCache = "{$wgFileCacheDirectory}/{$subdir}{$hash1}/{$hash2}/{$key}.html"; if( $this->useGzip() ) $this->mFileCache .= '.gz'; @@ -60,21 +63,24 @@ class HTMLFileCache { */ public static function useFileCache() { global $wgUser, $wgUseFileCache, $wgShowIPinHeader, $wgRequest, $wgLang, $wgContLang; - if( !$wgUseFileCache ) - return false; + if( !$wgUseFileCache ) return false; // Get all query values $queryVals = $wgRequest->getValues(); foreach( $queryVals as $query => $val ) { - // Normal page view in query form can have action=view - if( $query !== 'title' && $query !== 'curid' && !($query == 'action' && $val == 'view') ) { - return false; - } + if( $query == 'title' || $query == 'curid' ) continue; + // Normal page view in query form can have action=view. + // Raw hits for pages also stored, like .css pages for example. + if( $query == 'action' && ($val == 'view' || $val == 'raw') ) continue; + if( $query == 'usemsgcache' && $val == 'yes' ) continue; + // Below are header setting params + if( $query == 'maxage' || $query == 'smaxage' || $query == 'ctype' || $query == 'gen' ) + continue; } // Check for non-standard user language; this covers uselang, // and extensions for auto-detecting user language. $ulang = $wgLang->getCode(); $clang = $wgContLang->getCode(); - + // Check that there are no other sources of variation return !$wgShowIPinHeader && !$wgUser->getId() && !$wgUser->getNewtalk() && $ulang == $clang; } diff --git a/includes/RawPage.php b/includes/RawPage.php index 6c0c45889c..9640cee904 100644 --- a/includes/RawPage.php +++ b/includes/RawPage.php @@ -149,6 +149,20 @@ class RawPage { # allow the client to cache this for 24 hours $mode = $this->mPrivateCache ? 'private' : 'public'; header( 'Cache-Control: '.$mode.', s-maxage='.$this->mSmaxage.', max-age='.$this->mMaxage ); + + if( HTMLFileCache::useFileCache() ) { + $cache = new HTMLFileCache( $this->mTitle ); + if( $cache->isFileCacheGood( /* Assume up to date */ ) ) { + /* Check incoming headers to see if client has this cached */ + if( !$wgOut->checkLastModified( $cache->fileCacheTime() ) ) { + $cache->loadFromFileCache(); + } + return; + } else { + ob_start( array(&$cache, 'saveToFileCache' ) ); + } + } + $text = $this->getRawText(); if( !wfRunHooks( 'RawPageViewBeforeOutput', array( &$this, &$text ) ) ) { -- 2.20.1