Page MenuHomePhabricator

gallery syntax claims to require 'px' for widths/heights attributes, but actually discards all strings after the number
Closed, ResolvedPublic

Description

Gallery syntax claims that widths/heights should be written as <gallery widths="150px", but the code shows the attribute is just cast to an integer, so "150em", "150%" and "150" would all give the same result.

Image syntax also requires "px" but fails to parse if "px" is omitted. We should either update the documentation to recommend no units, or only parse when "px" is present (if we want to support more units in the future).

Event Timeline

Change 295116 had a related patch set uploaded (by Prtksxna):
Gallery: Add numHasPxUnit method

https://gerrit.wikimedia.org/r/295116

While I like the idea of supporting the other units in the future, applying this patch might break galleries that aren't using any units. I know I've seen a few, is there a way to query how many such are there?

A documentation change might be easier at this point.

This would definitely be a breaking change.

I know I've seen a few, is there a way to query how many such are there?

It's common. [[ https://en.wikipedia.org/w/index.php?title=Special:Search&profile=default&fulltext=Search&search=insource%3A%2F%5C%3Cgallery+widths%3D%5B%22%27%5D%3F%5B0-9%5D%2B%5B%22%27+%3E%5D%2F| Searching enwiki for insource:/\<gallery widths=["']?[0-9]+["' >]/ ]] apparently gives 2,805 results (this doesn't count instances with parameters in different order, obviously, and in the past I've found results from Special:Search to be incomplete – you'd have to use a better regexp and scan the database dump to get the real numbers).

I've also searched a few wikis for insource:/\<gallery widths=["']?[0-9]+[^0-9p"' >]/ ('widths' parameter containing a number, followed by anything that is not "p" or end of the attribute).

I checked all of our wikis using a neat little script.

So I think this will have very little impact, except for pl.wp and de.wp, where we might want to ask somebody to run a bot or something. (I can do pl.wp myself.)

91https://pl.wikipedia.org/w/index.php?search=insource%3A%2F%5C%3Cgallery+widths%3D%5B%22%27%5D%3F%5B0-9%5D%2B%5B%5E0-9p%22%27+%3E%5D%2F
64https://de.wikipedia.org/w/index.php?search=insource%3A%2F%5C%3Cgallery+widths%3D%5B%22%27%5D%3F%5B0-9%5D%2B%5B%5E0-9p%22%27+%3E%5D%2F
7https://ru.wikipedia.org/w/index.php?search=insource%3A%2F%5C%3Cgallery+widths%3D%5B%22%27%5D%3F%5B0-9%5D%2B%5B%5E0-9p%22%27+%3E%5D%2F
5https://da.wikipedia.org/w/index.php?search=insource%3A%2F%5C%3Cgallery+widths%3D%5B%22%27%5D%3F%5B0-9%5D%2B%5B%5E0-9p%22%27+%3E%5D%2F
4https://ja.wikipedia.org/w/index.php?search=insource%3A%2F%5C%3Cgallery+widths%3D%5B%22%27%5D%3F%5B0-9%5D%2B%5B%5E0-9p%22%27+%3E%5D%2F
3https://sv.wikipedia.org/w/index.php?search=insource%3A%2F%5C%3Cgallery+widths%3D%5B%22%27%5D%3F%5B0-9%5D%2B%5B%5E0-9p%22%27+%3E%5D%2F
3https://nl.wikipedia.org/w/index.php?search=insource%3A%2F%5C%3Cgallery+widths%3D%5B%22%27%5D%3F%5B0-9%5D%2B%5B%5E0-9p%22%27+%3E%5D%2F
3https://fr.wikipedia.org/w/index.php?search=insource%3A%2F%5C%3Cgallery+widths%3D%5B%22%27%5D%3F%5B0-9%5D%2B%5B%5E0-9p%22%27+%3E%5D%2F
2https://jbo.wikipedia.org/w/index.php?search=insource%3A%2F%5C%3Cgallery+widths%3D%5B%22%27%5D%3F%5B0-9%5D%2B%5B%5E0-9p%22%27+%3E%5D%2F
2https://fr.wikibooks.org/w/index.php?search=insource%3A%2F%5C%3Cgallery+widths%3D%5B%22%27%5D%3F%5B0-9%5D%2B%5B%5E0-9p%22%27+%3E%5D%2F
2https://en.wikipedia.org/w/index.php?search=insource%3A%2F%5C%3Cgallery+widths%3D%5B%22%27%5D%3F%5B0-9%5D%2B%5B%5E0-9p%22%27+%3E%5D%2F
2https://commons.wikimedia.org/w/index.php?search=insource%3A%2F%5C%3Cgallery+widths%3D%5B%22%27%5D%3F%5B0-9%5D%2B%5B%5E0-9p%22%27+%3E%5D%2F
1https://zh.wikivoyage.org/w/index.php?search=insource%3A%2F%5C%3Cgallery+widths%3D%5B%22%27%5D%3F%5B0-9%5D%2B%5B%5E0-9p%22%27+%3E%5D%2F
1https://www.mediawiki.org/w/index.php?search=insource%3A%2F%5C%3Cgallery+widths%3D%5B%22%27%5D%3F%5B0-9%5D%2B%5B%5E0-9p%22%27+%3E%5D%2F
1https://uk.wikipedia.org/w/index.php?search=insource%3A%2F%5C%3Cgallery+widths%3D%5B%22%27%5D%3F%5B0-9%5D%2B%5B%5E0-9p%22%27+%3E%5D%2F
1https://sv.wikivoyage.org/w/index.php?search=insource%3A%2F%5C%3Cgallery+widths%3D%5B%22%27%5D%3F%5B0-9%5D%2B%5B%5E0-9p%22%27+%3E%5D%2F
1https://sh.wikipedia.org/w/index.php?search=insource%3A%2F%5C%3Cgallery+widths%3D%5B%22%27%5D%3F%5B0-9%5D%2B%5B%5E0-9p%22%27+%3E%5D%2F
1https://ru.wikivoyage.org/w/index.php?search=insource%3A%2F%5C%3Cgallery+widths%3D%5B%22%27%5D%3F%5B0-9%5D%2B%5B%5E0-9p%22%27+%3E%5D%2F
1https://ru.wikisource.org/w/index.php?search=insource%3A%2F%5C%3Cgallery+widths%3D%5B%22%27%5D%3F%5B0-9%5D%2B%5B%5E0-9p%22%27+%3E%5D%2F
1https://ru.wikinews.org/w/index.php?search=insource%3A%2F%5C%3Cgallery+widths%3D%5B%22%27%5D%3F%5B0-9%5D%2B%5B%5E0-9p%22%27+%3E%5D%2F
1https://no.wikipedia.org/w/index.php?search=insource%3A%2F%5C%3Cgallery+widths%3D%5B%22%27%5D%3F%5B0-9%5D%2B%5B%5E0-9p%22%27+%3E%5D%2F
1https://nl.wikivoyage.org/w/index.php?search=insource%3A%2F%5C%3Cgallery+widths%3D%5B%22%27%5D%3F%5B0-9%5D%2B%5B%5E0-9p%22%27+%3E%5D%2F
1https://meta.wikimedia.org/w/index.php?search=insource%3A%2F%5C%3Cgallery+widths%3D%5B%22%27%5D%3F%5B0-9%5D%2B%5B%5E0-9p%22%27+%3E%5D%2F
1https://lb.wikipedia.org/w/index.php?search=insource%3A%2F%5C%3Cgallery+widths%3D%5B%22%27%5D%3F%5B0-9%5D%2B%5B%5E0-9p%22%27+%3E%5D%2F
1https://krc.wikipedia.org/w/index.php?search=insource%3A%2F%5C%3Cgallery+widths%3D%5B%22%27%5D%3F%5B0-9%5D%2B%5B%5E0-9p%22%27+%3E%5D%2F
1https://hr.wikipedia.org/w/index.php?search=insource%3A%2F%5C%3Cgallery+widths%3D%5B%22%27%5D%3F%5B0-9%5D%2B%5B%5E0-9p%22%27+%3E%5D%2F
1https://he.wikipedia.org/w/index.php?search=insource%3A%2F%5C%3Cgallery+widths%3D%5B%22%27%5D%3F%5B0-9%5D%2B%5B%5E0-9p%22%27+%3E%5D%2F
1https://et.wikipedia.org/w/index.php?search=insource%3A%2F%5C%3Cgallery+widths%3D%5B%22%27%5D%3F%5B0-9%5D%2B%5B%5E0-9p%22%27+%3E%5D%2F
1https://de.wikivoyage.org/w/index.php?search=insource%3A%2F%5C%3Cgallery+widths%3D%5B%22%27%5D%3F%5B0-9%5D%2B%5B%5E0-9p%22%27+%3E%5D%2F
1https://bg.wikipedia.org/w/index.php?search=insource%3A%2F%5C%3Cgallery+widths%3D%5B%22%27%5D%3F%5B0-9%5D%2B%5B%5E0-9p%22%27+%3E%5D%2F

@matmarex, wow, thanks for the script! Do you think the same bot could be run for both pl and de?

@cscott Do you think this change makes sense?

Legoktm subscribed.

Adding Parsing-Team--ARCHIVED since this is apparently blocked on them reviewing the patch.

Change 406248 had a related patch set uploaded (by Arlolra; owner: Arlolra):
[mediawiki/services/parsoid@master] Match core's parsing of gallery dimensions

https://gerrit.wikimedia.org/r/406248

Change 295116 merged by jenkins-bot:
[mediawiki/core@master] Gallery: Use Parser::parseWidthParam() for gallery dimensions

https://gerrit.wikimedia.org/r/295116

So I think this will have very little impact, except for pl.wp and de.wp, where we might want to ask somebody to run a bot or something. (I can do pl.wp myself.)

@matmarex Still want to take that on?

So I think this will have very little impact, except for pl.wp and de.wp, where we might want to ask somebody to run a bot or something. (I can do pl.wp myself.)

@matmarex Still want to take that on?

Is linting support required? May not be -- I am asking that question without context.

So I think this will have very little impact, except for pl.wp and de.wp, where we might want to ask somebody to run a bot or something. (I can do pl.wp myself.)

@matmarex Still want to take that on?

Thanks for the reminder, I can do it right now actually.

I am using AutoWikiBrowser and doing the following:

  • Make list using "Wiki search" with the query insource:/(widths|heights)=["']?[0-9]+[^0-9p"' >]/
  • Apply "Find and replace" from (widths|heights)=(["']?[0-9]+)[^0-9p"' >] to $1=$2 (regexp) – this simply removes any unexpected characters after the number
  • My edit summary is fix syntax of <gallery widths=… heights=…> ([[phab:T129372]]) (translated to Polish)

You can do the same for your favorite wiki using your favorite bot toolkit.

Is linting support required? May not be -- I am asking that question without context.

Not specifically for this case, but I think some better validation of <gallery> parameters and displaying some errors when they are invalid would be useful. For example, I found a few articles during this bot run that had 'widths' misspelled as 'widhts'. That is probably a bigger task though.

Change 406248 merged by jenkins-bot:
[mediawiki/services/parsoid@master] Match core's parsing of gallery dimensions

https://gerrit.wikimedia.org/r/406248

Arlolra claimed this task.

The merged patches aren't exactly as in the description here, they restrict valid values to either no units, or px, which is the same for image syntax.