Page MenuHomePhabricator

Pages without a first section header should not show navigation images
Open, Needs TriagePublicFeature

Description

Steps to replicate the issue (include links if applicable):

The following steps are just one example of this going wrong, but the specific example of countries could be applied to any other navbox featuring images as well.

  • Create a {{countries}} navbox, and include an icon of each country's flags in front of the country link.
  • Create a page about Exampleland, a fairly obscure country for which the page currently only fills two paragraphs, and which lacks any section headers.
    • Exampleland, just like Northern Ireland, has no country flag, but is relevant enough to have an article about it.
  • Add the {{countries}} navbox at the bottom of the Exampleland page, but do not include a ==Navigation== section per your wiki's style guide.
  • Now search for "Exampleland" in order to make the PageImage appear

What happens?:
An image of a random flag from the navbox is selected as the PageImage, since there are no images in the lead section, and there is no first section header which indicates the end of the lead section

What should have happened instead?:
No image should have been shown (given that $wgPageImagesLeadSectionOnly is set to true), since the navbox is obviously not part of the lead section, meaning the function onParserAfterTidy should have filtered it out.

Software version (on Special:Version page; skip for WMF-hosted wikis like Wikipedia): 609bdad

Other information (browser name/version, screenshots, etc.):

While this won't be a big issue on enwp, other wikis (especially game-related wikis) may include larger images in navboxes, while also having pages with no images on them (such as Exampleland above). This means several articles that lack a first section header or a fitting image on the page may end up with a completely mismatched PageImage in front of it.

I suggest several possible approaches to resolve this issue. My first proposed solution is to specifically target navboxes, since those are by far the most likely cause of this issue. This can be done, for example, by changing ParserFileProcessingHookHandlers.php:141 to:

			$leadEndPos = strpos( $text, '<mw:editsection' ) ?: strpos( $text, 'navbox' );

This could be made more robust by implementing some way to concretely detect a navbox class at some earlier point, and inserting a special comment at that place.

Another approach would be to implement some way to manually indicate the end of the lead section, by introducing a class similar to the existing notpageimage. For example. implementing a marker pageimageleadend to indicate the images beyond that point would need to be omitted, This could use the exact same approach as the code given above.

Finally, another approach could be to make the notpageimage class apply to containers as well. For example, adding this class to a table would omit all images within that table. However, based on some digging and some discussion with some of my friends, this seems to be way too computationally complex, since this would require parsing the parent HTML of the images, considering the extension is currently agnostic about the classes assigned to all parent elements. However, if this is somehow possible without parsing all parent HTML, this would be a nice and clean solution to the issue.

Event Timeline

I have had it on my action plan to write something in the relevant Lua modules for Navbox/Sidebar (which is another case) which adds notpageimage to internal images, and just haven't gotten around to it (and because while it's probably not hard, it's probably not totally trivial either, see also T301588#7705129).

I definitely don't think special behavior needs to be introduced to the PHP side.

based on some digging and some discussion with some of my friends

Yes, I would prefer that solution as well, but that was also deemed too difficult at the time (T301588#7708857).

I think if someone just wrote the module (or function in-module) that I think should exist, we wouldn't need effort like this. Probably we can make a simplifying assumption that there won't be internal links for the kinds of images that end up in navboxes/sidebars, that images will be in the requisite parameter (that is, |image= or equivalent name) and then just find() something along the lines of (using regex because that's what I think in) [[(Image|File)[^\]*?\| *class *=(.*?)]], find on the capture group for notpageimage, insert at |class= if not found. And a similar regex/pattern for classless images, probably inserting after the end of the image/filename.

Aklapper renamed this task from Pages without a first section header may select navigation images to Pages without a first section header should not show navigation images.Aug 28 2024, 6:33 AM
Aklapper changed the subtype of this task from "Bug Report" to "Feature Request".