Software version:
- MediaWiki 1.43.1
- Extension:Translate 2024-07-16 (3ebda29)
On our wiki (https://rainworld.miraheze.org), we occasionally include images or other complicated markup in headings, and MediaWiki has dedicated functionality to deal with this: all formatting is stripped from the heading and images are replaced with alt text when generating the TOC and the anchor for the headings.
You can see an example of this on this page: while the header markup is literally World Map {{Head|Monk|Survivor|Hunter|Gourmand}}, the sanitization logic for headers replaces the template which normally shows an image with the "alt text" of World Map As Monk, Survivor, Hunter, Gourmand. ("alt text" is in quotes because this isn't using the standard image markup, but the result shows up like alt text in headers.) MediaWiki clearly has a dedicated routine for sanitizing headings for both the TOC and the anchors.
Extension:Translate also outputs anchors for translations to ensure that translated links work correctly: the anchors for the source language should be added above each heading in the generated markup to ensure that both the source language anchor (in this case, English) and the destination language anchor work. Unfortunately, the anchor sanitizing code is not used here, and the heading contents verbatim are included in the anchor, as can be seen in this example translated page:
<languages/>
__TOC__
<span id="Map_{{Head|Survivor}}"></span>
= Carte {{Head|Survivor}} =
<span id="Map_{{NoHead|Survivor}}"></span>
= Carte {{NoHead|Survivor}} =
<span id="Map_for_{{Slugcat|Survivor}}"></span>
= Carte pour {{Slugcat|Survivor}} =Because of the presence of the markup inside the actual <span id>, this fails to actually work, and instead shows up as ugly markup on the page directly. This is confusing to consumers of translated pages and also prevents the anchors from working.
I would expect Extension:Translate to continue outputting the <span id> markup here, but using the proper heading sanitization code that MediaWiki uses normally.