Skip to content

Fix tooltips and links in the carousel gallery mode - #134

Merged
malberts merged 1 commit into
masterfrom
fix/gallery-carousel-tooltip-and-link
Oct 29, 2026
Merged

malberts merged 1 commit into
masterfrom
fix/gallery-carousel-tooltip-and-link

Conversation

@malberts

@malberts malberts commented Oct 29, 2026 •

Copy link
Copy Markdown
Collaborator

Follows-up to #133

<gallery mode="carousel"> rebuilds each image as [[File:...]] wikitext from what core passes to ImageGalleryBase::add(), and it mishandled two parts of that data. Core adds a targetlang handler option to every gallery image. It is not an image option, so the image parser read targetlang=en as the caption, which became every slide's tooltip and the alt text of a captionless slide. And core passes a per-image link= in the image options (link-url, link-title or no-link), while the carousel read add()'s $link argument, which core leaves empty, so every slide linked to its file page. The carousel now drops targetlang, which makeImage sets again when the slide is parsed, and writes link= from the image options. Other handler options, such as page= and lang=, pass through as before. On MediaWiki 1.47 and later, where <gallery> accepts a per-image class= and passes it in the image options, that class is added to img-fluid. {{#bootstrap_carousel:}} is unchanged.

CarouselGalleryTest fed the gallery a link in $link, no targetlang and no image options, a shape core never produces, which is how both bugs passed CI. Its data sets now use core's shape, and the new CarouselGalleryRenderingTest parses <gallery mode="carousel"> with the wiki's own parser.

Human input

Goal and shape: Claude's proposal from its review of #133, approved by @malberts: drop targetlang, honour the link options core passes, and add a test fed by the data core passes. Claude made the technical design within it.

Outcome: not reviewed by a human yet. Left for you: the code, and the lines from the evidence table in a <gallery mode="carousel"> on a test wiki, hovering for the tooltip and clicking for the link.

Claude's calls

  • Not discussed with @malberts:
    • A per-image class= is honoured on MediaWiki 1.47 and later.
    • add()'s $link argument is no longer read. Core's own TraditionalImageGallery reads it only when a caller passes no image options, and the core callers that do (category pages and Special:NewFiles with ?gallerymode=carousel) already end in an exception in this mode.
  • Considered by Claude, omitted:
    • Escaping link and class values before writing them into the wikitext. Only contrived values break the markup, such as link=Main Page#a]]b, and they come from the same line of wikitext, so a broken result gives the editor nothing they could not write directly.
    • Rendering each slide from core's data the way TraditionalImageGallery does, instead of rebuilding wikitext, which would remove this class of bug but is a larger change to Carousel.
    • A parser-fed test for class=: it would only run on the MediaWiki 1.47 and master CI rows, which are allowed to fail, so a CarouselGalleryTest data set covers it.
    • Parser-fed tests for page= and lang=: CI imports PNGs only.
  • Not verified: page= on a PDF.
  • Where your judgment helps: whether to keep $link as a fallback for callers that pass no image options.

Not in this PR

All predate this PR; the first was hidden behind the targetlang tooltip until now.

  • A caption containing a link loses the link text in the tooltip: File:Serenity.png|See [[Main Page]] now gives "See now", where a plain <gallery> gives "See Main Page now".
  • A caption that is an image option keyword is still read as that option: File:Shuttle.png|thumb gives a thumbnail with an empty caption and the alt text "thumb", where a plain <gallery> shows "thumb" as the caption.
  • Slide images sit at the carousel's left edge, under the previous control, which covers 15% of the carousel's width. An image narrower than that, such as File:Shuttle.png (94px) in a 752px carousel, cannot be hovered or clicked with a mouse; its link still works from the keyboard. {{#bootstrap_carousel:}} behaves the same.
Verification evidence

Test wiki: MediaWiki 1.43.11, PHP 8.3.36, Extension:Bootstrap 6.0.0.

  • Without the src/ change, the CarouselGalleryRenderingTest tests and the simple and no local attributes data sets of CarouselGalleryTest::testToHtml fail. Without the no-link branch, testSlideImageWithEmptyLinkIsNotClickable fails. The new tests run on every CI row.
  • action=parse before and after the fix:
Line in <gallery mode="carousel"> Before: link href / title / img alt After Plain <gallery>
File:Serenity.png|Serenity caption file page / targetlang=en / Serenity caption file page / Serenity caption / Serenity caption same as after
File:Shuttle.png file page / targetlang=en / targetlang=en file page / none / none same as after
File:Serenity.png|Internal|link=Main Page file page /index.php/Main_Page same
File:Shuttle.png|External|link=https://example.org/x file page https://example.org/x same
File:Serenity.png|Nolink|link= file page no link same
File:Shuttle.png|Fragment|link=Main Page#Crew not checked /index.php/Main_Page#Crew same
File:Serenity.png|Interwiki|link=wikipedia:Serenity not checked https://en.wikipedia.org/wiki/Serenity same
File:Languages.svg|Greeting|lang=de not checked langde- thumbnail same
  • MediaWiki 1.47.0-beta, parsed from the command line: File:Serenity.png|Serenity caption|class=foo gives the slide's wrapper class="mw-default-size foo img-fluid", the same <span> a plain <gallery> puts foo on, and class=bar baz|link=Main Page gives both classes and the link. With the CarouselGallery.php from before this PR, both classes are dropped.
  • UI (Playwright, Vector 2022, real mouse and keyboard input): hovering the Serenity slide's image puts its tooltip, "Serenity caption", under the pointer; clicking the slides with link=Main Page and link= goes to Main Page and stays on the page; the link=https://example.org/x slide (File:Shuttle.png, under the previous control) goes to example.org from the keyboard.
  • An AI review found no blocking issue.

AI-authored — Claude Code, Opus 5.5, on a Professional Wiki account

@malberts
malberts force-pushed the fix/gallery-carousel-tooltip-and-link branch from a812ab6 to 8800c61 Compare October 29, 2026 09:47
Follows-up to #133

`<gallery mode="carousel">` rebuilds each image as `[[File:...]]`
wikitext from what core passes to `ImageGalleryBase::add()`, and it
mishandled two parts of that data. Core adds a `targetlang` handler
option to every gallery image. It is not an image option, so the image
parser read `targetlang=en` as the caption, which became every slide's
tooltip and the alt text of a captionless slide. And core passes a
per-image `link=` in the image options (`link-url`, `link-title` or
`no-link`), while the carousel read `add()`'s `$link` argument, which
core leaves empty, so every slide linked to its file page.

The carousel now drops `targetlang`, which `makeImage` sets again when
the slide is parsed, and writes `link=` from the image options. Other
handler options, such as `page=` and `lang=`, pass through as before.
On MediaWiki 1.47 and later, where `<gallery>` accepts a per-image
`class=` and passes it in the image options, that class is added to
`img-fluid`. `{{#bootstrap_carousel:}}` is unchanged.

`CarouselGalleryTest` fed the gallery a link in `$link`, no
`targetlang` and no image options, a shape core never produces, which
is how both bugs passed CI. Its data sets now use core's shape, and the
new `CarouselGalleryRenderingTest` parses `<gallery mode="carousel">`
with the wiki's own parser.

Not in this change: a caption containing a link loses the link text in
the tooltip, and a caption that is an image option keyword, such as
`thumb`, is still read as that option.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@malberts
malberts force-pushed the fix/gallery-carousel-tooltip-and-link branch from 8800c61 to a2eb513 Compare October 29, 2026 10:25
@malberts
malberts marked this pull request as ready for review October 29, 2026 10:41
@malberts
malberts merged commit 27ebc73 into master Oct 29, 2026
6 of 7 checks passed
@malberts malberts mentioned this pull request Oct 29, 2026
@malberts
malberts deleted the fix/gallery-carousel-tooltip-and-link branch October 29, 2026 12:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant