From e29274ca9d05a55c7525c627279131ab422a72c8 Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Thu, 25 Sep 2008 23:02:35 +0000 Subject: [PATCH] FileCache cleanup: * Make isFileCacheable() more reliable and explicit * Do not cache uncacheable content * Specify tryFileCache() return values --- includes/Article.php | 54 ++++++++++++++++++-------------------- includes/HTMLFileCache.php | 6 ++++- 2 files changed, 30 insertions(+), 30 deletions(-) diff --git a/includes/Article.php b/includes/Article.php index ced850ac93..fd063ecc90 100644 --- a/includes/Article.php +++ b/includes/Article.php @@ -2985,13 +2985,13 @@ class Article { static $called = false; if( $called ) { wfDebug( "Article::tryFileCache(): called twice!?\n" ); - return; + return false; } $called = true; - if($this->isFileCacheable()) { + if( $this->isFileCacheable() ) { $touched = $this->mTouched; $cache = new HTMLFileCache( $this->mTitle ); - if($cache->isFileCacheGood( $touched )) { + if( $cache->isFileCacheGood( $touched ) ) { wfDebug( "Article::tryFileCache(): about to load file\n" ); $cache->loadFromFileCache(); return true; @@ -3002,6 +3002,7 @@ class Article { } else { wfDebug( "Article::tryFileCache(): not cacheable\n" ); } + return false; } /** @@ -3010,40 +3011,31 @@ class Article { */ function isFileCacheable() { global $wgUser, $wgUseFileCache, $wgShowIPinHeader, $wgRequest, $wgLang, $wgContLang; - $action = $wgRequest->getVal( 'action' ); - $oldid = $wgRequest->getVal( 'oldid' ); - $diff = $wgRequest->getVal( 'diff' ); - $redirect = $wgRequest->getVal( 'redirect' ); - $printable = $wgRequest->getVal( 'printable' ); - $page = $wgRequest->getVal( 'page' ); - $useskin = $wgRequest->getVal( 'useskin' ); - - //check for non-standard user language; this covers uselang, - //and extensions for auto-detecting user language. - $ulang = $wgLang->getCode(); - $clang = $wgContLang->getCode(); + // Get all query values + $queryVals = $wgRequest->getValues(); + foreach( $queryVals as $query => $val ) { + if( $query == 'title' || ($query == 'action' && $val == 'view') ) { + // Normal page view in query form + } else { + return false; + } + } + // Check for non-standard user language; this covers uselang, + // and extensions for auto-detecting user language. + $ulang = $wgLang->getCode(); + $clang = $wgContLang->getCode(); $cacheable = $wgUseFileCache && (!$wgShowIPinHeader) - && ($this->getID() != 0) + && ($this->getID() > 0) && ($wgUser->isAnon()) && (!$wgUser->getNewtalk()) - && ($this->mTitle->getNamespace() != NS_SPECIAL ) - && (!isset($useskin)) - && (empty( $action ) || $action == 'view') - && (!isset($oldid)) - && (!isset($diff)) - && (!isset($redirect)) - && (!isset($printable)) - && !isset($page) && (!$this->mRedirectedFrom) && ($ulang === $clang); - - if ( $cacheable ) { - //extension may have reason to disable file caching on some pages. + // Extension may have reason to disable file caching on some pages. + if( $cacheable ) { $cacheable = wfRunHooks( 'IsFileCacheable', array( &$this ) ); } - return $cacheable; } @@ -3473,7 +3465,7 @@ class Article { * @param bool $cache */ public function outputWikiText( $text, $cache = true ) { - global $wgParser, $wgUser, $wgOut, $wgEnableParserCache; + global $wgParser, $wgUser, $wgOut, $wgEnableParserCache, $wgUseFileCache; $popts = $wgOut->parserOptions(); $popts->setTidy(true); @@ -3486,6 +3478,10 @@ class Article { $parserCache = ParserCache::singleton(); $parserCache->save( $parserOutput, $this, $wgUser ); } + // Make sure file cache is not used on uncacheable content. + if( $wgUseFileCache && $parserOutput->getCacheTime() == -1 ) { + $wgUseFileCache = false; + } if ( !wfReadOnly() && $this->mTitle->areRestrictionsCascading() ) { // templatelinks table may have become out of sync, diff --git a/includes/HTMLFileCache.php b/includes/HTMLFileCache.php index ae797fb320..3edddc9bd2 100644 --- a/includes/HTMLFileCache.php +++ b/includes/HTMLFileCache.php @@ -119,8 +119,12 @@ class HTMLFileCache { } function saveToFileCache( $origtext ) { + global $wgUseFileCache; + if( !$wgUseFileCache ) { + return $origtext; // return to output + } $text = $origtext; - if(strcmp($text,'') == 0) return ''; + if( strcmp($text,'') == 0 ) return ''; wfDebug(" saveToFileCache()\n", false); -- 2.20.1