Place tooltips if caption isn't visible

Matches Parsoid commit Icbc36b6e9aa1b9f4f27c23f4833c626a725cc154

Bug: T297443
Bug: T108380
Depends-On: I30eba0fb226971ddeda4eb240929e89ef7e5f45f
Change-Id: Ic0169d3914c5ce442b063f4bbbb6493966dbb302
This commit is contained in:
Arlo Breault 2022-05-16 17:58:52 -04:00
parent 04ce450e68
commit 75f95fbc1e
2 changed files with 17 additions and 2 deletions

View file

@ -370,6 +370,21 @@ class ImageMap {
}
$wrapper->insertBefore( $imageParent, $anchor );
$typeOf = $wrapper->getAttribute( 'typeof' ) ?? '';
preg_match( '#^mw:(?:Image|Video|Audio)(/|$)#', $typeOf, $match );
$format = $match[1] ?? '';
$hasVisibleMedia = in_array( $format, [ 'Thumb', 'Frame' ], true );
if ( !$hasVisibleMedia ) {
$xpath = new DOMXPath( $wrapper->ownerDocument );
$captions = $xpath->query( '//figcaption', $wrapper );
$caption = $captions->item( 0 );
$captionText = trim( $caption->textContent );
if ( $captionText ) {
$imageParent->setAttribute( 'title', $captionText );
}
}
if ( isset( $mapNode ) ) {
$wrapper->insertBefore( $mapNode, $anchor );
}

View file

@ -221,8 +221,8 @@ wgParserEnableLegacyMediaDOM=false
<imagemap>
File:Foobar.jpg|link=|Hi ho
</imagemap>
!! html/php+disabled
<figure class="mw-default-size noresize" typeof="mw:Image"><span><img alt="Hi ho" src="http://example.com/images/3/3a/Foobar.jpg" decoding="async" title="Hi ho" width="1941" height="220" /></span><figcaption>Hi ho</figcaption></figure>
!! html/php
<figure class="mw-default-size noresize" typeof="mw:Image"><span title="Hi ho"><img alt="Hi ho" src="http://example.com/images/3/3a/Foobar.jpg" decoding="async" width="1941" height="220" /></span><figcaption>Hi ho</figcaption></figure>
!! html/parsoid
<figure class="mw-default-size noresize" typeof="mw:Image mw:Extension/imagemap" about="#mwt2" data-mw='{"name":"imagemap","attrs":{},"body":{"extsrc":"\nFile:Foobar.jpg|link=|Hi ho\n"}}'><span><img resource="./File:Foobar.jpg" src="http://example.com/images/3/3a/Foobar.jpg" decoding="async" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="220" width="1941"/></span><figcaption>Hi ho</figcaption></figure>
!! end