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.