r45123 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r45122‎ | r45123 | r45124 >
Date:13:32, 28 December 2008
Author:aaron
Status:resolved (Comments)
Tags:
Comment:
Enable filecache for raw page hits if $wgUseFileCache is on
Modified paths:
  • /trunk/phase3/includes/HTMLFileCache.php (modified) (history)
  • /trunk/phase3/includes/RawPage.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/RawPage.php
@@ -149,6 +149,20 @@
150150 # allow the client to cache this for 24 hours
151151 $mode = $this->mPrivateCache ? 'private' : 'public';
152152 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+
153167 $text = $this->getRawText();
154168
155169 if( !wfRunHooks( 'RawPageViewBeforeOutput', array( &$this, &$text ) ) ) {
Index: trunk/phase3/includes/HTMLFileCache.php
@@ -28,15 +28,18 @@
2929 }
3030
3131 public function fileCacheName() {
32 - global $wgFileCacheDirectory;
3332 if( !$this->mFileCache ) {
 33+ global $wgFileCacheDirectory, $wgRequest;
3434 $key = $this->mTitle->getPrefixedDbkey();
3535 $hash = md5( $key );
 36+ # Avoid extension confusion
3637 $key = str_replace( '.', '%2E', urlencode( $key ) );
37 -
 38+ # Store raw pages (like CSS hits) elsewhere
 39+ $subdir = $wgRequest->getVal('action') == 'raw' ? 'raw/' : '';
 40+
3841 $hash1 = substr( $hash, 0, 1 );
3942 $hash2 = substr( $hash, 0, 2 );
40 - $this->mFileCache = "{$wgFileCacheDirectory}/{$hash1}/{$hash2}/{$key}.html";
 43+ $this->mFileCache = "{$wgFileCacheDirectory}/{$subdir}{$hash1}/{$hash2}/{$key}.html";
4144
4245 if( $this->useGzip() )
4346 $this->mFileCache .= '.gz';
@@ -60,21 +63,24 @@
6164 */
6265 public static function useFileCache() {
6366 global $wgUser, $wgUseFileCache, $wgShowIPinHeader, $wgRequest, $wgLang, $wgContLang;
64 - if( !$wgUseFileCache )
65 - return false;
 67+ if( !$wgUseFileCache ) return false;
6668 // Get all query values
6769 $queryVals = $wgRequest->getValues();
6870 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;
7379 }
7480 // Check for non-standard user language; this covers uselang,
7581 // and extensions for auto-detecting user language.
7682 $ulang = $wgLang->getCode();
7783 $clang = $wgContLang->getCode();
78 -
 84+ // Check that there are no other sources of variation
7985 return !$wgShowIPinHeader && !$wgUser->getId() && !$wgUser->getNewtalk() && $ulang == $clang;
8086 }
8187

Follow-up revisions

RevisionCommit summaryAuthorDate
r47139(bug 17420) Send the correct content type from action=raw when the HTML file ...tstarling15:07, 11 February 2009

Comments

#Comment by Aaron Schulz (talk | contribs)   21:35, 28 December 2008

Fixes in r45124

Status & tagging log