Added filecache support for history pages
authorAaron Schulz <aaron@users.mediawiki.org>
Sat, 24 Sep 2011 01:17:04 +0000 (01:17 +0000)
committerAaron Schulz <aaron@users.mediawiki.org>
Sat, 24 Sep 2011 01:17:04 +0000 (01:17 +0000)
includes/HistoryPage.php
includes/cache/HTMLFileCache.php

index 935adf7..670fe3e 100644 (file)
@@ -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' ) );
index 9b63e2c..59a8ea7 100644 (file)
@@ -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;