From 9d70db7d8cf3d4dd3add54f4c2791f1bd3f73fd3 Mon Sep 17 00:00:00 2001 From: Domas Mituzas Date: Tue, 13 Nov 2007 13:24:51 +0000 Subject: [PATCH] Cache by default raw views for CSS & JS files for all users, controllable by $wgForcedRawSMaxage --- includes/DefaultSettings.php | 5 +++++ includes/RawPage.php | 22 +++++++++++++++++----- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index a79f3470c3..c487d7034e 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -1333,6 +1333,11 @@ $wgInternalServer = $wgServer; */ $wgSquidMaxage = 18000; +/** + * Default maximum age for raw CSS/JS accesses + */ +$wgForcedRawSMaxage = 300; + /** * List of proxy servers to purge on changes; default port is 80. Use IP addresses. * diff --git a/includes/RawPage.php b/includes/RawPage.php index defd74f287..22a5ac4e63 100644 --- a/includes/RawPage.php +++ b/includes/RawPage.php @@ -20,7 +20,7 @@ class RawPage { var $mContentType, $mExpandTemplates; function __construct( &$article, $request = false ) { - global $wgRequest, $wgInputEncoding, $wgSquidMaxage, $wgJsMimeType; + global $wgRequest, $wgInputEncoding, $wgSquidMaxage, $wgJsMimeType, $wgForcedRawSMaxage, $wgGroupPermissions; $allowedCTypes = array('text/x-wiki', $wgJsMimeType, 'text/css', 'application/x-zope-edit'); $this->mArticle =& $article; @@ -35,6 +35,7 @@ class RawPage { $ctype = $this->mRequest->getVal( 'ctype' ); $smaxage = $this->mRequest->getIntOrNull( 'smaxage', $wgSquidMaxage ); $maxage = $this->mRequest->getInt( 'maxage', $wgSquidMaxage ); + $this->mExpandTemplates = $this->mRequest->getVal( 'templates' ) === 'expand'; $this->mUseMessageCache = $this->mRequest->getBool( 'usemsgcache' ); @@ -81,12 +82,23 @@ class RawPage { $this->mGen = false; } $this->mCharset = $wgInputEncoding; - $this->mSmaxage = intval( $smaxage ); + + # Force caching for CSS and JS raw content, default: 5 minutes + if (is_null($smaxage) and ($ctype=='text/css' or $ctype==$wgJsMimeType)) { + $this->mSmaxage = intval($wgForcedRawSMaxage); + } else { + $this->mSmaxage = intval( $smaxage ); + } $this->mMaxage = $maxage; - // Output may contain user-specific data; vary for open sessions - $this->mPrivateCache = ( $this->mSmaxage == 0 ) || - ( session_id() != '' ); + # Output may contain user-specific data; + # vary generated content for open sessions and private wikis + if ($this->mGen or !$wgGroupPermissions['*']['read']) { + $this->mPrivateCache = ( $this->mSmaxage == 0 ) || + ( session_id() != '' ); + } else { + $this->mPrivateCache = false; + } if ( $ctype == '' or ! in_array( $ctype, $allowedCTypes ) ) { $this->mContentType = 'text/x-wiki'; -- 2.20.1