r41274 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r41273‎ | r41274 | r41275 >
Date:23:02, 25 September 2008
Author:aaron
Status:old
Tags:
Comment:
FileCache cleanup:
* Make isFileCacheable() more reliable and explicit
* Do not cache uncacheable content
* Specify tryFileCache() return values
Modified paths:
  • /trunk/phase3/includes/Article.php (modified) (history)
  • /trunk/phase3/includes/HTMLFileCache.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/Article.php
@@ -2985,13 +2985,13 @@
29862986 static $called = false;
29872987 if( $called ) {
29882988 wfDebug( "Article::tryFileCache(): called twice!?\n" );
2989 - return;
 2989+ return false;
29902990 }
29912991 $called = true;
2992 - if($this->isFileCacheable()) {
 2992+ if( $this->isFileCacheable() ) {
29932993 $touched = $this->mTouched;
29942994 $cache = new HTMLFileCache( $this->mTitle );
2995 - if($cache->isFileCacheGood( $touched )) {
 2995+ if( $cache->isFileCacheGood( $touched ) ) {
29962996 wfDebug( "Article::tryFileCache(): about to load file\n" );
29972997 $cache->loadFromFileCache();
29982998 return true;
@@ -3002,6 +3002,7 @@
30033003 } else {
30043004 wfDebug( "Article::tryFileCache(): not cacheable\n" );
30053005 }
 3006+ return false;
30063007 }
30073008
30083009 /**
@@ -3010,40 +3011,31 @@
30113012 */
30123013 function isFileCacheable() {
30133014 global $wgUser, $wgUseFileCache, $wgShowIPinHeader, $wgRequest, $wgLang, $wgContLang;
3014 - $action = $wgRequest->getVal( 'action' );
3015 - $oldid = $wgRequest->getVal( 'oldid' );
3016 - $diff = $wgRequest->getVal( 'diff' );
3017 - $redirect = $wgRequest->getVal( 'redirect' );
3018 - $printable = $wgRequest->getVal( 'printable' );
3019 - $page = $wgRequest->getVal( 'page' );
3020 - $useskin = $wgRequest->getVal( 'useskin' );
 3015+ // Get all query values
 3016+ $queryVals = $wgRequest->getValues();
 3017+ foreach( $queryVals as $query => $val ) {
 3018+ if( $query == 'title' || ($query == 'action' && $val == 'view') ) {
 3019+ // Normal page view in query form
 3020+ } else {
 3021+ return false;
 3022+ }
 3023+ }
 3024+ // Check for non-standard user language; this covers uselang,
 3025+ // and extensions for auto-detecting user language.
 3026+ $ulang = $wgLang->getCode();
 3027+ $clang = $wgContLang->getCode();
30213028
3022 - //check for non-standard user language; this covers uselang,
3023 - //and extensions for auto-detecting user language.
3024 - $ulang = $wgLang->getCode();
3025 - $clang = $wgContLang->getCode();
3026 -
30273029 $cacheable = $wgUseFileCache
30283030 && (!$wgShowIPinHeader)
3029 - && ($this->getID() != 0)
 3031+ && ($this->getID() > 0)
30303032 && ($wgUser->isAnon())
30313033 && (!$wgUser->getNewtalk())
3032 - && ($this->mTitle->getNamespace() != NS_SPECIAL )
3033 - && (!isset($useskin))
3034 - && (empty( $action ) || $action == 'view')
3035 - && (!isset($oldid))
3036 - && (!isset($diff))
3037 - && (!isset($redirect))
3038 - && (!isset($printable))
3039 - && !isset($page)
30403034 && (!$this->mRedirectedFrom)
30413035 && ($ulang === $clang);
3042 -
3043 - if ( $cacheable ) {
3044 - //extension may have reason to disable file caching on some pages.
 3036+ // Extension may have reason to disable file caching on some pages.
 3037+ if( $cacheable ) {
30453038 $cacheable = wfRunHooks( 'IsFileCacheable', array( &$this ) );
30463039 }
3047 -
30483040 return $cacheable;
30493041 }
30503042
@@ -3473,7 +3465,7 @@
34743466 * @param bool $cache
34753467 */
34763468 public function outputWikiText( $text, $cache = true ) {
3477 - global $wgParser, $wgUser, $wgOut, $wgEnableParserCache;
 3469+ global $wgParser, $wgUser, $wgOut, $wgEnableParserCache, $wgUseFileCache;
34783470
34793471 $popts = $wgOut->parserOptions();
34803472 $popts->setTidy(true);
@@ -3486,6 +3478,10 @@
34873479 $parserCache = ParserCache::singleton();
34883480 $parserCache->save( $parserOutput, $this, $wgUser );
34893481 }
 3482+ // Make sure file cache is not used on uncacheable content.
 3483+ if( $wgUseFileCache && $parserOutput->getCacheTime() == -1 ) {
 3484+ $wgUseFileCache = false;
 3485+ }
34903486
34913487 if ( !wfReadOnly() && $this->mTitle->areRestrictionsCascading() ) {
34923488 // templatelinks table may have become out of sync,
Index: trunk/phase3/includes/HTMLFileCache.php
@@ -119,8 +119,12 @@
120120 }
121121
122122 function saveToFileCache( $origtext ) {
 123+ global $wgUseFileCache;
 124+ if( !$wgUseFileCache ) {
 125+ return $origtext; // return to output
 126+ }
123127 $text = $origtext;
124 - if(strcmp($text,'') == 0) return '';
 128+ if( strcmp($text,'') == 0 ) return '';
125129
126130 wfDebug(" saveToFileCache()\n", false);
127131

Follow-up revisions

RevisionCommit summaryAuthorDate
r41290Remove filecache check per r41274aaron18:47, 26 September 2008