Clarify tooltips are set if captions aren't visible

Matches Parsoid commit Icbc36b6e9aa1b9f4f27c23f4833c626a725cc154

Bug: T297443
Bug: T108380
Depends-On: I896e2af2e8a712a36eb23a25cad08f53574fc044
Change-Id: I30eba0fb226971ddeda4eb240929e89ef7e5f45f
This commit is contained in:
Arlo Breault 2022-05-09 16:35:04 -04:00
parent 63c77060a0
commit e2752a0dcf
5 changed files with 21 additions and 21 deletions

View file

@ -279,6 +279,7 @@ class Linker {
* valign Vertical alignment (baseline, sub, super, top, text-top, middle,
* bottom, text-bottom)
* alt Alternate text for image (i.e. alt attribute). Plain text.
* title Used for tooltips if caption isn't visible.
* class HTML for image classes. Plain text.
* caption HTML for image caption.
* link-url URL to link to
@ -398,9 +399,12 @@ class Linker {
}
}
if ( isset( $frameParams['thumbnail'] ) || isset( $frameParams['manualthumb'] )
|| isset( $frameParams['framed'] )
) {
// Parser::makeImage has a similarly named variable
$hasVisibleCaption = isset( $frameParams['thumbnail'] ) ||
isset( $frameParams['manualthumb'] ) ||
isset( $frameParams['framed'] );
if ( $hasVisibleCaption ) {
if ( $enableLegacyMediaDOM ) {
// This is no longer needed in our new media output, since the
// default styling in content.media-common.less takes care of it;
@ -629,9 +633,6 @@ class Linker {
if ( !isset( $frameParams['alt'] ) ) {
$frameParams['alt'] = '';
}
if ( !isset( $frameParams['title'] ) ) {
$frameParams['title'] = '';
}
if ( !isset( $frameParams['caption'] ) ) {
$frameParams['caption'] = '';
}
@ -722,11 +723,6 @@ class Linker {
if ( !$exists ) {
$label = '';
if ( $enableLegacyMediaDOM ) {
// This is the information for tooltips for inline images which
// Parsoid stores in data-mw. See T273014
$label = $frameParams['title'];
}
$s .= self::makeBrokenImageLinkObj(
$title, $label, '', '', '', (bool)$time, $handlerParams
);
@ -746,7 +742,6 @@ class Linker {
}
$params = [
'alt' => $frameParams['alt'],
'title' => $frameParams['title'],
];
if ( $enableLegacyMediaDOM ) {
$params += [

View file

@ -243,7 +243,7 @@ abstract class MediaTransformOutput {
* @return string
*/
protected function linkWrap( $linkAttribs, $contents ) {
if ( $linkAttribs ) {
if ( isset( $linkAttribs['href'] ) ) {
return Xml::tags( 'a', $linkAttribs, $contents );
} else {
$parserEnableLegacyMediaDOM = MediaWikiServices::getInstance()
@ -251,7 +251,7 @@ abstract class MediaTransformOutput {
if ( $parserEnableLegacyMediaDOM ) {
return $contents;
} else {
return Xml::tags( 'span', null, $contents );
return Xml::tags( 'span', $linkAttribs ?: null, $contents );
}
}
}

View file

@ -121,6 +121,7 @@ class ThumbnailImage extends MediaTransformOutput {
$priorityHintsRatio = $mainConfig->get( MainConfigNames::PriorityHintsRatio );
$elementTiming = $mainConfig->get( MainConfigNames::ElementTiming );
$nativeImageLazyLoading = $mainConfig->get( MainConfigNames::NativeImageLazyLoading );
$enableLegacyMediaDOM = $mainConfig->get( MainConfigNames::ParserEnableLegacyMediaDOM );
if ( func_num_args() == 2 ) {
throw new MWException( __METHOD__ . ' called in the old style' );
@ -192,7 +193,11 @@ class ThumbnailImage extends MediaTransformOutput {
} else {
$linkAttribs = false;
if ( !empty( $options['title'] ) ) {
$attribs['title'] = $options['title'];
if ( $enableLegacyMediaDOM ) {
$attribs['title'] = $options['title'];
} else {
$linkAttribs = [ 'title' => $options['title'] ];
}
}
}

View file

@ -5480,7 +5480,7 @@ class Parser {
# Will the image be presented in a frame, with the caption below?
// @phan-suppress-next-line PhanImpossibleCondition
$imageIsFramed = isset( $params['frame']['framed'] )
$hasVisibleCaption = isset( $params['frame']['framed'] )
// @phan-suppress-next-line PhanImpossibleCondition
|| isset( $params['frame']['thumbnail'] )
// @phan-suppress-next-line PhanImpossibleCondition
@ -5500,16 +5500,16 @@ class Parser {
# named parameter entirely for images without a caption; adding an ex-
# plicit caption= parameter and preserving the old magic unnamed para-
# meter for BC; ...
if ( $imageIsFramed ) { # Framed image
if ( $hasVisibleCaption ) {
// @phan-suppress-next-line PhanImpossibleCondition
if ( $caption === '' && !isset( $params['frame']['alt'] ) ) {
# No caption or alt text, add the filename as the alt text so
# that screen readers at least get some description of the image
$params['frame']['alt'] = $link->getText();
}
# Do not set $params['frame']['title'] because tooltips don't make sense
# for framed images
} else { # Inline image
# Do not set $params['frame']['title'] because tooltips are unnecessary
# for framed images, the caption is visible
} else {
// @phan-suppress-next-line PhanImpossibleCondition
if ( !isset( $params['frame']['alt'] ) ) {
# No alt text, use the "caption" for the alt text

View file

@ -245,7 +245,7 @@ wgParserEnableLegacyMediaDOM=false
!! wikitext
[[File:Foobar.jpg|link=|stuff]]
!! html/php
<p><span class="mw-default-size" typeof="mw:Image"><span><img alt="stuff" src="http://example.com/images/3/3a/Foobar.jpg" decoding="async" title="stuff" width="1941" height="220" /></span></span>
<p><span class="mw-default-size" typeof="mw:Image"><span title="stuff"><img alt="stuff" src="http://example.com/images/3/3a/Foobar.jpg" decoding="async" width="1941" height="220" /></span></span>
</p>
!! html/parsoid
<p><span class="mw-default-size" typeof="mw:Image" data-mw='{"caption":"stuff"}'><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></span></p>