diff --git a/MultimediaViewer.php b/MultimediaViewer.php index c1548b4b0..5751abac8 100644 --- a/MultimediaViewer.php +++ b/MultimediaViewer.php @@ -109,6 +109,14 @@ if ( !isset( $wgMediaViewerEnableByDefaultForAnonymous ) ) { $wgMediaViewerEnableByDefaultForAnonymous = $wgMediaViewerEnableByDefault; } +if ( !isset( $wgMediaViewerImageQueryParameter ) ) { + /** + * If set, adds a query parameter to image requests made by Media Viewer + * @var string|bool + */ + $wgMediaViewerImageQueryParameter = false; +} + $wgMessagesDirs['MultimediaViewer'] = __DIR__ . '/i18n'; $wgExtensionMessagesFiles['MultimediaViewer'] = __DIR__ . '/MultimediaViewer.i18n.php'; @@ -300,6 +308,7 @@ $wgResourceModules += array( 'dependencies' => array( 'mediawiki.Title', + 'mediawiki.Uri', 'mmv.model', 'mmv.model.IwTitle', 'mmv.model.Image', diff --git a/MultimediaViewerHooks.php b/MultimediaViewerHooks.php index bf6d36fb8..5e87291be 100644 --- a/MultimediaViewerHooks.php +++ b/MultimediaViewerHooks.php @@ -142,7 +142,7 @@ class MultimediaViewerHooks { global $wgMediaViewerActionLoggingSamplingFactorMap, $wgNetworkPerformanceSamplingFactor, $wgMediaViewerDurationLoggingSamplingFactor, $wgMediaViewerDurationLoggingLoggedinSamplingFactor, $wgMediaViewerAttributionLoggingSamplingFactor, $wgMediaViewerDimensionLoggingSamplingFactor, - $wgMediaViewerIsInBeta, $wgMediaViewerUseThumbnailGuessing; + $wgMediaViewerIsInBeta, $wgMediaViewerUseThumbnailGuessing, $wgMediaViewerImageQueryParameter; $vars['wgMultimediaViewer'] = array( 'infoLink' => self::$infoLink, 'discussionLink' => self::$discussionLink, @@ -154,6 +154,7 @@ class MultimediaViewerHooks { 'actionLoggingSamplingFactorMap' => $wgMediaViewerActionLoggingSamplingFactorMap, 'attributionSamplingFactor' => $wgMediaViewerAttributionLoggingSamplingFactor, 'dimensionSamplingFactor' => $wgMediaViewerDimensionLoggingSamplingFactor, + 'imageQueryParameter' => $wgMediaViewerImageQueryParameter, 'tooltipDelay' => 1000, ); $vars['wgMediaViewer'] = true; diff --git a/resources/mmv/mmv.js b/resources/mmv/mmv.js index 0b1f8b45a..af4d381ef 100644 --- a/resources/mmv/mmv.js +++ b/resources/mmv/mmv.js @@ -32,7 +32,7 @@ * @property {mw.mmv.provider.Image} * @private */ - this.imageProvider = new mw.mmv.provider.Image(); + this.imageProvider = new mw.mmv.provider.Image( mw.config.get( 'wgMultimediaViewer' ).imageQueryParameter ); /** * @property {mw.mmv.provider.ImageInfo} diff --git a/resources/mmv/provider/mmv.provider.Image.js b/resources/mmv/provider/mmv.provider.Image.js index e2e1b2be7..58e4cf9f1 100644 --- a/resources/mmv/provider/mmv.provider.Image.js +++ b/resources/mmv/provider/mmv.provider.Image.js @@ -20,14 +20,18 @@ /** * Loads an image. * @class mw.mmv.provider.Image + * @constructor + * @param {string} imageQueryParameter When defined, is a query parameter to add to every image request */ - function Image() { + function Image( imageQueryParameter ) { /** * @property {mw.mmv.logging.Performance} * @private */ this.performance = new mw.mmv.logging.Performance(); + this.imageQueryParameter = imageQueryParameter; + /** * AJAX call cache. * @property {Object.} cache @@ -47,8 +51,16 @@ Image.prototype.get = function ( url ) { var provider = this, cacheKey = url, + extraParam = {}, start, - rawGet; + rawGet, + uri; + + if ( this.imageQueryParameter ) { + uri = new mw.Uri( url ); + extraParam[ this.imageQueryParameter ] = null; + url = uri.extend( extraParam ).toString(); + } if ( !this.cache[cacheKey] ) { if ( this.imagePreloadingSupported() ) { diff --git a/tests/qunit/mmv/provider/mmv.provider.Image.test.js b/tests/qunit/mmv/provider/mmv.provider.Image.test.js index 6879bf773..307b05b06 100644 --- a/tests/qunit/mmv/provider/mmv.provider.Image.test.js +++ b/tests/qunit/mmv/provider/mmv.provider.Image.test.js @@ -200,4 +200,17 @@ QUnit.start(); } ); } ); + + QUnit.test( 'imageQueryParameter', 1, function ( assert ) { + var imageProvider = new mw.mmv.provider.Image( 'foo' ); + + imageProvider.imagePreloadingSupported = function () { return false; }; + imageProvider.rawGet = function () { return $.Deferred().resolve(); }; + + imageProvider.performance.recordEntry = function ( type, total, url ) { + assert.strictEqual( url, 'http://www.wikipedia.org/?foo', 'Extra parameter added' ); + }; + + imageProvider.get( 'http://www.wikipedia.org/' ); + } ); }( mediaWiki, jQuery ) );