r97981 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r97980‎ | r97981 | r97982 >
Date:01:17, 24 September 2011
Author:aaron
Status:ok
Tags:
Comment:
Added filecache support for history pages
Modified paths:
  • /trunk/phase3/includes/HistoryPage.php (modified) (history)
  • /trunk/phase3/includes/cache/HTMLFileCache.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/HistoryPage.php
@@ -64,16 +64,25 @@
6565 * @return nothing
6666 */
6767 function history() {
68 - global $wgOut, $wgRequest, $wgScript;
 68+ global $wgOut, $wgRequest, $wgScript, $wgUseFileCache;
6969
7070 /**
7171 * Allow client caching.
7272 */
73 - if ( $wgOut->checkLastModified( $this->article->getTouched() ) )
 73+ if ( $wgOut->checkLastModified( $this->article->getTouched() ) ) {
7474 return; // Client cache fresh and headers sent, nothing more to do.
 75+ }
7576
7677 wfProfileIn( __METHOD__ );
7778
 79+ # Fill in the file cache if not set already
 80+ if ( $wgUseFileCache && HTMLFileCache::useFileCache() ) {
 81+ $cache = new HTMLFileCache( $this->title, 'history' );
 82+ if ( !$cache->isFileCacheGood( /* Assume up to date */ ) ) {
 83+ ob_start( array( &$cache, 'saveToFileCache' ) );
 84+ }
 85+ }
 86+
7887 // Setup page variables.
7988 $wgOut->setPageTitle( wfMsg( 'history-title', $this->title->getPrefixedText() ) );
8089 $wgOut->setPageTitleActionText( wfMsg( 'history_short' ) );
Index: trunk/phase3/includes/cache/HTMLFileCache.php
@@ -29,10 +29,14 @@
3030
3131 public function __construct( $title, $type = 'view' ) {
3232 $this->mTitle = $title;
33 - $this->mType = ( $type == 'view' ) ? $type : false;
 33+ $this->mType = in_array( $type, self::cacheableActions() ) ? $type : false;
3434 $this->fileCacheName(); // init name
3535 }
3636
 37+ protected static function cacheableActions() {
 38+ return array( 'view', 'history' );
 39+ }
 40+
3741 public function fileCacheName() {
3842 if( !$this->mFileCache ) {
3943 global $wgCacheDirectory, $wgFileCacheDirectory, $wgFileCacheDepth;
@@ -95,7 +99,7 @@
96100 continue; // note: curid sets title
97101 // Normal page view in query form can have action=view.
98102 // Raw hits for pages also stored, like .css pages for example.
99 - } elseif( $query == 'action' && $val == 'view' ) {
 103+ } elseif( $query == 'action' && in_array( $val, self::cacheableActions() ) ) {
100104 continue;
101105 // Below are header setting params
102106 } elseif( $query == 'maxage' || $query == 'smaxage' ) {
@@ -229,10 +233,10 @@
230234 }
231235
232236 wfSuppressWarnings();
233 -
234 - $fc = new self( $title, 'view' );
235 - unlink( $fc->fileCacheName() );
236 -
 237+ foreach( self::cacheableActions() as $type ) {
 238+ $fc = new self( $title, $type );
 239+ unlink( $fc->fileCacheName() );
 240+ }
237241 wfRestoreWarnings();
238242
239243 return true;

Status & tagging log