Merge "resourceloader: Add version to ResourceLoaderImage urls for long-cache"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Sat, 28 Sep 2019 20:20:32 +0000 (20:20 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Sat, 28 Sep 2019 20:20:32 +0000 (20:20 +0000)
includes/resourceloader/ResourceLoaderImage.php
includes/resourceloader/ResourceLoaderImageModule.php
tests/phpunit/unit/includes/resourceloader/ResourceLoaderImageTest.php

index 2b0f5ed..3878205 100644 (file)
@@ -55,8 +55,9 @@ class ResourceLoaderImage {
        private $extension;
 
        /**
-        * @param string $name Image name
-        * @param string $module Module name
+        * @param string $name Self-name of the image as known to ResourceLoaderImageModule.
+        * @param string $module Self-name of the module containing this image.
+        *  Used to find the image in the registry e.g. through a load.php url.
         * @param string|array $descriptor Path to image file, or array structure containing paths
         * @param string $basePath Directory to which paths in descriptor refer
         * @param array $variants
@@ -217,7 +218,7 @@ class ResourceLoaderImage {
         * @param string $script URL to load.php
         * @param string|null $variant Variant to get the URL for
         * @param string $format Format to get the URL for, 'original' or 'rasterized'
-        * @return string
+        * @return string URL
         */
        public function getUrl( ResourceLoaderContext $context, $script, $variant, $format ) {
                $query = [
@@ -231,7 +232,8 @@ class ResourceLoaderImage {
                }
                // The following parameters are at the end to keep the original order of the parameters.
                $query['skin'] = $context->getSkin();
-               $query['version'] = $context->getVersion();
+               $rl = $context->getResourceLoader();
+               $query['version'] = $rl->makeVersionQuery( $context, [ $this->getModule() ] );
 
                return wfAppendQuery( $script, $query );
        }
index 0585cfd..d46d26f 100644 (file)
@@ -358,6 +358,10 @@ class ResourceLoaderImageModule extends ResourceLoaderModule {
        }
 
        /**
+        * This method must not be used by getDefinitionSummary as doing so would cause
+        * an infinite loop (we use ResourceLoaderImage::getUrl below which calls
+        * Module:getVersionHash, which calls Module::getDefinitionSummary).
+        *
         * @param ResourceLoaderContext $context
         * @param ResourceLoaderImage $image Image to get the style for
         * @param string $script URL to load.php
index 5265b3e..02042b8 100644 (file)
@@ -2,6 +2,7 @@
 
 /**
  * @group ResourceLoader
+ * @covers ResourceLoaderImage
  */
 class ResourceLoaderImageTest extends MediaWikiUnitTestCase {
 
@@ -53,7 +54,6 @@ class ResourceLoaderImageTest extends MediaWikiUnitTestCase {
        }
 
        /**
-        * @covers ResourceLoaderImage::getPath
         * @dataProvider provideGetPath
         */
        public function testGetPath( $imageName, $languageCode, $path ) {
@@ -84,10 +84,6 @@ class ResourceLoaderImageTest extends MediaWikiUnitTestCase {
                $this->assertEquals( $image->getPath( $context ), $this->imagesPath . '/' . $path );
        }
 
-       /**
-        * @covers ResourceLoaderImage::getExtension
-        * @covers ResourceLoaderImage::getMimeType
-        */
        public function testGetExtension() {
                $image = $this->getTestImage( 'def' );
                $this->assertEquals( $image->getExtension(), 'svg' );
@@ -99,11 +95,6 @@ class ResourceLoaderImageTest extends MediaWikiUnitTestCase {
                $this->assertEquals( $image->getExtension( 'rasterized' ), 'gif' );
        }
 
-       /**
-        * @covers ResourceLoaderImage::getImageData
-        * @covers ResourceLoaderImage::variantize
-        * @covers ResourceLoaderImage::massageSvgPathdata
-        */
        public function testGetImageData() {
                $context = $this->createMock( ResourceLoaderContext::class );
 
@@ -124,9 +115,6 @@ class ResourceLoaderImageTest extends MediaWikiUnitTestCase {
                $this->assertEquals( $image->getImageData( $context, null, 'rasterized' ), $data );
        }
 
-       /**
-        * @covers ResourceLoaderImage::massageSvgPathdata
-        */
        public function testMassageSvgPathdata() {
                $image = $this->getTestImage( 'ghi' );
                $data = file_get_contents( $this->imagesPath . '/ghi.svg' );