From: Trevor Parscal Date: Sat, 11 Sep 2010 08:22:32 +0000 (+0000) Subject: Added direction to ResourceLoaderContext hashing (prevents cache mangling), dropped... X-Git-Tag: 1.31.0-rc.0~35019 X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=commitdiff_plain;h=b9137a9cf2ed562f7fc11c84e7f2ae4c9e33e9a2 Added direction to ResourceLoaderContext hashing (prevents cache mangling), dropped it from the startup module (it's not being passed on anyways - it's really just for debugging). Also enforced sorting of parameters in URLs to make them easier to read and less likely to miss cache unnessecarily. --- diff --git a/includes/ResourceLoaderContext.php b/includes/ResourceLoaderContext.php index 1feb9fe6fd..c9b1bd3288 100644 --- a/includes/ResourceLoaderContext.php +++ b/includes/ResourceLoaderContext.php @@ -110,7 +110,8 @@ class ResourceLoaderContext { public function getHash() { return isset( $this->hash ) ? - $this->hash : $this->hash = - implode( '|', array( $this->language, $this->skin, $this->user, $this->debug, $this->only ) ); + $this->hash : $this->hash = implode( '|', array( + $this->language, $this->direction, $this->skin, $this->user, $this->debug, $this->only + ) ); } } \ No newline at end of file diff --git a/includes/ResourceLoaderModule.php b/includes/ResourceLoaderModule.php index afd4fada7f..cbe827eddc 100644 --- a/includes/ResourceLoaderModule.php +++ b/includes/ResourceLoaderModule.php @@ -967,23 +967,21 @@ class ResourceLoaderStartUpModule extends ResourceLoaderModule { // Add a well-known start-up function $scripts .= "window.startUp = function() { $registration mediaWiki.config.set( $config ); };"; // Build load query for jquery and mediawiki modules - $query = wfArrayToCGI( - array( - 'modules' => implode( '|', array( 'jquery', 'mediawiki' ) ), - 'only' => 'scripts', - 'lang' => $context->getLanguage(), - 'dir' => $context->getDirection(), - 'skin' => $context->getSkin(), - 'debug' => $context->getDebug(), - 'version' => wfTimestamp( TS_ISO_8601, round( max( - ResourceLoader::getModule( 'jquery' )->getModifiedTime( $context ), - ResourceLoader::getModule( 'mediawiki' )->getModifiedTime( $context ) - ), -2 ) ) - ) + $query = array( + 'modules' => implode( '|', array( 'jquery', 'mediawiki' ) ), + 'only' => 'scripts', + 'lang' => $context->getLanguage(), + 'skin' => $context->getSkin(), + 'debug' => $context->getDebug() ? 'true' : 'false', + 'version' => wfTimestamp( TS_ISO_8601, round( max( + ResourceLoader::getModule( 'jquery' )->getModifiedTime( $context ), + ResourceLoader::getModule( 'mediawiki' )->getModifiedTime( $context ) + ), -2 ) ) ); - + // Uniform query order + ksort( $query ); // Build HTML code for loading jquery and mediawiki modules - $loadScript = Html::linkedScript( "$wgLoadScript?$query" ); + $loadScript = Html::linkedScript( $wgLoadScript . '?' . wfArrayToCGI( $query ) ); // Add code to add jquery and mediawiki loading code; only if the current client is compatible $scripts .= "if ( isCompatible() ) { document.write( '$loadScript' ); }"; // Delete the compatible function - it's not needed anymore diff --git a/resources/mediawiki/mediawiki.js b/resources/mediawiki/mediawiki.js index a8bc2bda43..56d8f94c12 100644 --- a/resources/mediawiki/mediawiki.js +++ b/resources/mediawiki/mediawiki.js @@ -408,6 +408,20 @@ window.mediaWiki = new ( function( $ ) { that.work(); } + function sortQuery(o) { + var sorted = {}, key, a = []; + for ( key in o ) { + if ( o.hasOwnProperty( key ) ) { + a.push( key ); + } + } + a.sort(); + for ( key = 0; key < a.length; key++ ) { + sorted[a[key]] = o[a[key]]; + } + return sorted; + } + /* Public Methods */ /** @@ -468,6 +482,7 @@ window.mediaWiki = new ( function( $ ) { function request() { var html = ''; for ( var r = 0; r < requests.length; r++ ) { + requests[r] = sortQuery( requests[r] ); // Build out the HTML var src = mediaWiki.config.get( 'wgLoadScript' ) + '?' + $.param( requests[r] ); html += '';