Make mapName deterministic so it can be tested

Change-Id: Ia906b46fbe8d84ae1482f8efaeb609d08c53bfa8
This commit is contained in:
Ed Sanders 2019-03-30 20:57:12 +00:00
parent d7f715635e
commit b024fddb4d
2 changed files with 17 additions and 3 deletions

View file

@ -279,9 +279,11 @@ class ImageMap {
if ( $realmap ) {
// Construct the map
// Add random number to avoid breaking cached HTML fragments that are
// later joined together on the one page (bug 16471)
$mapName = "ImageMap_" . ++self::$id . '_' . mt_rand( 0, 0x7fffffff );
// Add a hash of the map HTML to avoid breaking cached HTML fragments that are
// later joined together on the one page (T18471).
// The only way these hashes can clash is if the map is identical, in which
// case it wouldn't matter that the "wrong" map was used.
$mapName = 'ImageMap_' . substr( md5( $mapHTML ), 0, 16 );
$mapHTML = "<map name=\"$mapName\">\n$mapHTML</map>\n";
// Alter the image tag

View file

@ -7,3 +7,15 @@ Image:Foobar.jpg
!! result
<div class="noresize" style="height: 220px; width: 1941px; "><img alt="Foobar.jpg" src="http://example.com/images/3/3a/Foobar.jpg" decoding="async" width="1941" height="220"></img><div style="margin-left: 1921px; margin-top: -20px; text-align: left;"><a href="/wiki/File:Foobar.jpg" title="About this image"><img alt="About this image" src="/extensions/ImageMap/resources/desc-20.png?15600" style="border: none;"></img></a></div></div>
!! end
!! test
dummy test
!! input
<imagemap>
File:Foobar.jpg
poly 10.1 10.9 10 30 -30 15 [[Main Page]]
</imagemap>
!! result
<div class="noresize" style="height: 220px; width: 1941px; "><map name="ImageMap_79ccc6c89d422b0c"><area href="/wiki/Main_Page" shape="poly" coords="10,11,10,30,-30,15" alt="Main Page" title="Main Page"></area></map><img alt="Foobar.jpg" src="http://example.com/images/3/3a/Foobar.jpg" decoding="async" width="1941" height="220" usemap="#ImageMap_79ccc6c89d422b0c"></img><div style="margin-left: 1921px; margin-top: -20px; text-align: left;"><a href="/wiki/File:Foobar.jpg" title="About this image"><img alt="About this image" src="/extensions/ImageMap/resources/desc-20.png?15600" style="border: none;"></img></a></div></div>
!! end