Page MenuHomePhabricator

Parsoid adds section edit links to post-expansion where the preprocessor omitted them
Closed, ResolvedPublic

Description

We should rely on HeadingPFragment to set the index when inTemplate to avoid this issue


At a (vaguely educated) guess, it's plausible that the fact that we do have links on https://en.wikipedia.org/w/index.php?title=Template:YouTuber-bio-stub&oldid=1252778015&useparsoid=1 (and we don't on legacy) is related.

The headings are ultimately generated from Module:Article_stub_box and so there's no template source to associate them with

Event Timeline

From the visual diff from https://cbk-zam.wikipedia.org/wiki/Plantilla:Mapa_de_localizaci%C3%B3n_de_Espa%C3%B1a

In the legacy parser, headings from parserfunctions don't get section edit links, which Parsoid matches,
https://github.com/wikimedia/mediawiki-services-parsoid/blob/master/src/Wt2Html/DOM/Processors/WrapSectionsState.php#L131-L132

However, if the parserfunction is nested in a template, the section is treated as if coming from the outer template (the bug in this task) and so section edit links are added in Parsoid.

Isolated case from the page is putting the following in a template and including it in another page,

{{#if:1|
=== hi ===
|2}}

This is somewhat similar, the task should really be about cases where the legacy parser doesn't recognize a heading in the preprocessor but then Parsoid is assigning an index while tokenizing. That should be skipped entirely when inTemplate and using integrated mode and rely entirely on HeadingPFrament to set an index.

Hmm, post-deploy and purge, there's still a diff,
https://ar.wiktionary.org/w/index.php?title=%D9%85%D9%8E%D8%AB%D9%92%D9%88%D9%8E%D9%89&useparsoid=0
https://ar.wiktionary.org/w/index.php?title=%D9%85%D9%8E%D8%AB%D9%92%D9%88%D9%8E%D9%89&useparsoid=1

The patch in T384490#10697038 only handles the top-level case. For templated sections, the include directives will have been processed so Parsoid won't know if they occurred on a line with the headings

This is another similar case

ABreault-WMF renamed this task from Parsoid creates section edit links for headings from modules to Parsoid adds section edit links to post-expansion where the preprocessor omitted them.Jun 27 2026, 1:04 AM
ABreault-WMF triaged this task as Medium priority.
ABreault-WMF updated the task description. (Show Details)

Change #1306014 had a related patch set uploaded (by Arlolra; author: Arlolra):

[mediawiki/services/parsoid@master] [WIP] Rely on HeadingPFragment to set the index when inTemplate

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

Change #1306014 merged by jenkins-bot:

[mediawiki/services/parsoid@master] Rely on HeadingPFragment to set the index when inTemplate

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

Change #1307003 had a related patch set uploaded (by C. Scott Ananian; author: C. Scott Ananian):

[mediawiki/vendor@master] Bump wikimedia/parsoid to 0.24.0-a14

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

Change #1307003 merged by jenkins-bot:

[mediawiki/vendor@master] Bump wikimedia/parsoid to 0.24.0-a14

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

Change #1307059 had a related patch set uploaded (by C. Scott Ananian; author: C. Scott Ananian):

[mediawiki/vendor@wmf/1.47.0-wmf.9] Bump wikimedia/parsoid to 0.24.0-a14

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

Change #1307059 merged by jenkins-bot:

[mediawiki/vendor@wmf/1.47.0-wmf.9] Bump wikimedia/parsoid to 0.24.0-a14

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

Mentioned in SAL (#wikimedia-operations) [2026-07-02T08:13:59Z] <cscott@deploy1003> Started scap sync-world: Backport for [[gerrit:1307059|Bump wikimedia/parsoid to 0.24.0-a14 (T387374 T430186 T430367 T430501)]], [[gerrit:1307061|Bump wikimedia/parsoid to 0.24.0-a14 (T430501)]]

Mentioned in SAL (#wikimedia-operations) [2026-07-02T08:16:04Z] <cscott@deploy1003> cscott: Backport for [[gerrit:1307059|Bump wikimedia/parsoid to 0.24.0-a14 (T387374 T430186 T430367 T430501)]], [[gerrit:1307061|Bump wikimedia/parsoid to 0.24.0-a14 (T430501)]] synced to the testservers (see https://wikitech.wikimedia.org/wiki/Mwdebug). Changes can now be verified there.

Mentioned in SAL (#wikimedia-operations) [2026-07-02T08:25:44Z] <cscott@deploy1003> Finished scap sync-world: Backport for [[gerrit:1307059|Bump wikimedia/parsoid to 0.24.0-a14 (T387374 T430186 T430367 T430501)]], [[gerrit:1307061|Bump wikimedia/parsoid to 0.24.0-a14 (T430501)]] (duration: 11m 44s)

Include directives on a line (T384490#10731504)

Pre-deploy, https://mg.wiktionary.org/wiki/a?useparsoid=1 had a section link pointing https://mg.wiktionary.org/w/index.php?title=Endrika:-fanononana-&action=edit&section=T-1 but https://mg.wiktionary.org/w/index.php?title=Endrika:-fanononana-&action=edit doesn't have a section because of the include directive on the line there

Post-deploy and purge, the section link is gone and matches the legacy output,
https://mg.wiktionary.org/wiki/a?useparsoid=0
https://mg.wiktionary.org/wiki/a?useparsoid=1

Parser functions returning wikitext (T387520#10985986)

Pre-deploy, https://cbk-zam.wikipedia.org/wiki/Plantilla:Mapa_de_localizaci%C3%B3n_de_Espa%C3%B1a?useparsoid=1#Mapas_alternativos had a section link pointing to https://cbk-zam.wikipedia.org/w/index.php?title=Plantilla:Mapa_de_localizaci%C3%B3n/Info&action=edit&section=T-1 but the headings in https://cbk-zam.wikipedia.org/w/index.php?title=Plantilla:Mapa_de_localizaci%C3%B3n/Info&action=edit are nested in {{#if:1 parser functions

Post-deploy and purge, the section link is gone and matches the legacy output,
https://cbk-zam.wikipedia.org/wiki/Plantilla:Mapa_de_localizaci%C3%B3n_de_Espa%C3%B1a?useparsoid=0#Mapas_alternativos
https://cbk-zam.wikipedia.org/wiki/Plantilla:Mapa_de_localizaci%C3%B3n_de_Espa%C3%B1a?useparsoid=1#Mapas_alternativos

Modules (T387521#12060718)

Pre-deploy, https://en.wikipedia.org/wiki/Template:YouTuber-bio-stub?useparsoid=1#About_this_template had a section link pointing to https://en.wikipedia.org/w/index.php?title=Template:Asbox&action=edit&section=T-1 but https://en.wikipedia.org/w/index.php?title=Template:Asbox&action=edit is a redirect to Template:Article stub box which invokes a module, {{#invoke:Article stub box|main}}

Post-deploy and purge, the section link is gone and matches the legacy output,
https://en.wikipedia.org/wiki/Template:YouTuber-bio-stub?useparsoid=0#About_this_template
https://en.wikipedia.org/wiki/Template:YouTuber-bio-stub?useparsoid=1#About_this_template