Page MenuHomePhabricator

Gallery does not allow lowercase "center" "left" or "right" as a caption for a gallery image
Open, MediumPublic


This was initially reported as a false linter error on T266406 but further debugging revealed that Parsoid and Gallery are "eating" the words left, center or right (which make no sense anyway in the context of a Gallery image). Parsoid and Gallery provides a default halign value of none which when followed with a left, center or right word is parsed as an alignment, instead of passing through. These words get detected early on as an halign values and are consumed - so no longer available as a caption. They are also seen as a duplicate alignment parameter and flagged as a bogus parameter which the linter finds and reports erroneously.
The following wikitext demonstrates the issue:


Event Timeline

For clarification, in case people are looking at this without context: Sometimes editors use "Center" as the caption for a gallery image, typically for an image showing the central area of buildings in a municipality. That caption is erroneously hidden by the MediaWiki software. It should be displayed.

Jonesey, this is a bug, and it will be fixed, not put off for years. It was
just more than a Linter bug, which is what I am focussing on, and after
debugging it, I determined that the problem occurs fairly early in the
parsing stages far removed from the Linter and is going to be tricky to
fix. I confirmed with my team mates that we will not deem this an annoying
quirk that we ignore, but fixing it was outside the scope of my current
tasks. I'll keep an eye on this task. Thanks for the additional insight as
to how editors might use Center more often than one might imagine.

Arlolra renamed this task from Gallery does not allow "center" "left" or "right" as a caption for a gallery image to Gallery does not allow lowercase "center" "left" or "right" as a caption for a gallery image.Aug 24 2021, 3:14 PM

This bug may have been fixed at some point. I am seeing proper behavior, with no Linter errors reported, with the following code:


This bug may have been fixed at some point.

Nah, T266406 fixed some of it but it's still an issue

See the captions aren't rendered here,

And the lint is lost because it's considered a valid option {"ck":"left","ak":"left"} much like T214601,

> php bin/parse.php --restURL --linting

<ul class="gallery mw-gallery-traditional" typeof="mw:Extension/gallery" about="#mwt2" data-parsoid='{"dsr":[0,206,9,10]}' data-mw='{"name":"gallery","attrs":{},"body":{}}'>
<li class="gallerybox" style="width: 155px;" data-parsoid="{}"><div class="thumb" style="width: 150px; height: 150px;" data-parsoid="{}"><span typeof="mw:Image" data-parsoid='{"optList":[{"ck":"width","ak":"120x120px"},{"ck":"left","ak":"left"}]}'><a href="./File:Foobar.jpg" data-parsoid="{}"><img resource="./File:Foobar.jpg" src="//" decoding="async" data-file-width="240" data-file-height="28" data-file-type="bitmap" height="14" width="120" srcset="// 1.5x, // 2x" data-parsoid='{"a":{"resource":"./File:Foobar.jpg","height":"14","width":"120"},"sa":{"resource":"File:Foobar.jpg"}}'/></a></span></div><div class="gallerytext" data-parsoid="{}"></div></li>