From 6e2be46e82851acc787b82f8a5be694f46086897 Mon Sep 17 00:00:00 2001 From: Brian Wolff Date: Tue, 12 Nov 2013 23:00:07 -0400 Subject: [PATCH] Send cache purges for action=raw after editing user css/js These types of requests can be cached for a short time (~5 min) in Squid/Varnish. Change importScript to be consistent with importStylesheet in the query parameter order (title, action, ctype). We only send purges for the exact urls as used by importScript and importStylesheet. Note: ResourceLoader things have their cache handled separately and aren't affected by this change. Users like instant updating of scripts after having changed them. Bug: 56874 Change-Id: Idaa8552cf371dbafeb8b730f35b3b5c4fc339fb0 --- includes/Title.php | 7 +++++++ includes/actions/RawAction.php | 3 ++- skins/common/wikibits.js | 7 +++++-- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/includes/Title.php b/includes/Title.php index 88268bb746..23c7c4b10f 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -3538,6 +3538,13 @@ class Title { } } + // If we are looking at a css/js user subpage, purge the action=raw. + if ( $this->isJsSubpage() ) { + $urls[] = $this->getInternalUrl( 'action=raw&ctype=text/javascript' ); + } elseif ( $this->isCssSubpage() ) { + $urls[] = $this->getInternalUrl( 'action=raw&ctype=text/css' ); + } + wfRunHooks( 'TitleSquidURLs', array( $this, &$urls ) ); return $urls; } diff --git a/includes/actions/RawAction.php b/includes/actions/RawAction.php index a0116fbc14..bab2f931b7 100644 --- a/includes/actions/RawAction.php +++ b/includes/actions/RawAction.php @@ -77,7 +77,8 @@ class RawAction extends FormlessAction { $contentType = $this->getContentType(); - # Force caching for CSS and JS raw content, default: 5 minutes + # Force caching for CSS and JS raw content, default: 5 minutes. + # Note: If using a canonical url for userpage css/js, we send an HTCP purge. if ( $smaxage === null ) { if ( $contentType == 'text/css' || $contentType == 'text/javascript' ) { $smaxage = intval( $wgForcedRawSMaxage ); diff --git a/skins/common/wikibits.js b/skins/common/wikibits.js index d28ca0a3da..9cfcd7f314 100644 --- a/skins/common/wikibits.js +++ b/skins/common/wikibits.js @@ -226,8 +226,11 @@ win.importScriptURI = function ( url ) { return s; }; -win.importStylesheet = function( page ) { - return win.importStylesheetURI( mw.config.get( 'wgScript' ) + '?action=raw&ctype=text/css&title=' + mw.util.wikiUrlencode( page ) ); +win.importStylesheet = function ( page ) { + var uri = mw.config.get( 'wgScript' ) + '?title=' + + mw.util.wikiUrlencode( page ) + + '&action=raw&ctype=text/css'; + return win.importStylesheetURI( uri ); }; win.importStylesheetURI = function( url, media ) { -- 2.20.1