Send cache purges for action=raw after editing user css/js
authorBrian Wolff <bawolff+wn@gmail.com>
Wed, 13 Nov 2013 03:00:07 +0000 (23:00 -0400)
committerKrinkle <krinklemail@gmail.com>
Fri, 3 Jan 2014 18:43:23 +0000 (18:43 +0000)
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
includes/actions/RawAction.php
skins/common/wikibits.js

index 88268bb..23c7c4b 100644 (file)
@@ -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;
        }
index a0116fb..bab2f93 100644 (file)
@@ -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 );
index d28ca0a..9cfcd7f 100644 (file)
@@ -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 ) {