From 23c430f64affa694f06fe7d4c6d2e5ab4737e20e Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Sat, 24 Sep 2011 01:17:04 +0000 Subject: [PATCH] Added filecache support for history pages --- includes/HistoryPage.php | 13 +++++++++++-- includes/cache/HTMLFileCache.php | 16 ++++++++++------ 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/includes/HistoryPage.php b/includes/HistoryPage.php index 935adf7aaa..670fe3e6ee 100644 --- a/includes/HistoryPage.php +++ b/includes/HistoryPage.php @@ -64,16 +64,25 @@ class HistoryPage { * @return nothing */ function history() { - global $wgOut, $wgRequest, $wgScript; + global $wgOut, $wgRequest, $wgScript, $wgUseFileCache; /** * Allow client caching. */ - if ( $wgOut->checkLastModified( $this->article->getTouched() ) ) + if ( $wgOut->checkLastModified( $this->article->getTouched() ) ) { return; // Client cache fresh and headers sent, nothing more to do. + } wfProfileIn( __METHOD__ ); + # Fill in the file cache if not set already + if ( $wgUseFileCache && HTMLFileCache::useFileCache() ) { + $cache = new HTMLFileCache( $this->title, 'history' ); + if ( !$cache->isFileCacheGood( /* Assume up to date */ ) ) { + ob_start( array( &$cache, 'saveToFileCache' ) ); + } + } + // Setup page variables. $wgOut->setPageTitle( wfMsg( 'history-title', $this->title->getPrefixedText() ) ); $wgOut->setPageTitleActionText( wfMsg( 'history_short' ) ); diff --git a/includes/cache/HTMLFileCache.php b/includes/cache/HTMLFileCache.php index 9b63e2cd50..59a8ea7719 100644 --- a/includes/cache/HTMLFileCache.php +++ b/includes/cache/HTMLFileCache.php @@ -29,10 +29,14 @@ class HTMLFileCache { public function __construct( $title, $type = 'view' ) { $this->mTitle = $title; - $this->mType = ( $type == 'view' ) ? $type : false; + $this->mType = in_array( $type, self::cacheableActions() ) ? $type : false; $this->fileCacheName(); // init name } + protected static function cacheableActions() { + return array( 'view', 'history' ); + } + public function fileCacheName() { if( !$this->mFileCache ) { global $wgCacheDirectory, $wgFileCacheDirectory, $wgFileCacheDepth; @@ -95,7 +99,7 @@ class HTMLFileCache { continue; // note: curid sets title // Normal page view in query form can have action=view. // Raw hits for pages also stored, like .css pages for example. - } elseif( $query == 'action' && $val == 'view' ) { + } elseif( $query == 'action' && in_array( $val, self::cacheableActions() ) ) { continue; // Below are header setting params } elseif( $query == 'maxage' || $query == 'smaxage' ) { @@ -229,10 +233,10 @@ class HTMLFileCache { } wfSuppressWarnings(); - - $fc = new self( $title, 'view' ); - unlink( $fc->fileCacheName() ); - + foreach( self::cacheableActions() as $type ) { + $fc = new self( $title, $type ); + unlink( $fc->fileCacheName() ); + } wfRestoreWarnings(); return true; -- 2.20.1