Page MenuHomePhabricator

Empty headings are missing edit-source button in parsoid read views
Closed, ResolvedPublic

Event Timeline

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

[mediawiki/services/parsoid@master] Add a test for empty headings

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

Effectively, an isolated test is,

=== ===

The legacy parser will set an empty anchor for that and Parsoid will too but, since the empty string isn't a valid id, Parsoid will generate a new id to attach data attributes to it when it's creating the pagebundle,
https://github.com/wikimedia/mediawiki-services-parsoid/blob/master/src/Utils/DOMDataUtils.php#L469-L472

which means it'll be lost when we try to find heading for the section, $dom->getElementById( $section->anchor ), based on the section metadata,
https://github.com/wikimedia/mediawiki/blob/master/includes/OutputTransform/Stages/HandleParsoidSectionLinks.php#L77-L84

Even if it was left as the empty string, getElementById probably wouldn't find it.

This is an edge case, section editing empty headings. Certainly this edit probably didn't mean to generate an empty heading,
https://en.wikivoyage.org/w/index.php?title=M%C3%A4ntt%C3%A4-Vilppula&diff=4897416&oldid=4897358

I made this edit and the parsers agree now,
https://en.wikivoyage.org/w/index.php?title=M%C3%A4ntt%C3%A4-Vilppula&diff=4902368&oldid=4897418

Could we change both Parsoid and the legacy parser to agree that === === is not a valid heading? That would avoid the whole "blank ID" issue.

Some of this stuff looks less convincing,
https://en.wikipedia.org/w/index.php?title=Sarajevo_International_School&diff=1053743782&oldid=1053741050
https://en.wikipedia.org/w/index.php?title=Generation_Italy&diff=1049016314&oldid=954035270

but I could see wanting to edit a section of the page without naming it, as a feature,
https://en.wikipedia.org/wiki/1983_Fenland_District_Council_election

It's not just that literal case though, it's any effectively empty heading. The anchor text is the normalized text content of the heading. Grepping for all that might be challenging.

For example, === _ === is also empty because of Sanitizer::normalizeSectionNameWhiteSpace

We could choose "_" as the id for an empty heading and probably at least wouldn't have any collisions.

but I could see wanting to edit a section of the page without naming it, as a feature,
https://en.wikipedia.org/wiki/1983_Fenland_District_Council_election

Blank headings have another visible negative output: the table of contents displays... lots of whitespace. If this were to be supported, I think that output needs to be fixed regardless. From my point of view, I think that's probably sufficient cause not to support this kind of wikitext.

The pattern of empty headings just to have edit buttons is probably not a common one either, due to someone noticing that issue.

Here's a search on English Wikipedia that has mostly false positives. (It excludes user namespace and talk namespaces, for clarity, as well as non-wikitext content model.) I fixed one and see just a couple others from a glance, so I think the pattern isn't high value. But other wikis may be doing something different. Tried to global search but got a timeout (which was not unexpected).

Emitting a lint error would be about the most you should have to do for wikis to adjust behavior, and that's me being conservative.

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

[mediawiki/core@master] Suppress error log for empty headings

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

From the commit message of T368722#10481825

Parsoid could eagerly assign a generated id when it runs into this
situation but that wouldn't match the legacy parser.

T368722 suggests either considering empty headings as invalid and
rendering the markup syntax or emitting a lint to have the uses cleaned
up.

I guess we need to pick one and T368722#10008311 seems to suggest an new empty-heading lint.

Change #1113209 merged by jenkins-bot:

[mediawiki/core@master] Suppress error log for empty headings

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

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

[mediawiki/extensions/Linter@master] Add a new lint category for empty headings

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

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

[mediawiki/core@master] Add i18n for empty heading lint category

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

Thank you for asking about this at en.WP. A brief discussion, linked from a couple relevant notice boards, has not surfaced any potential negatives regarding this new Linter "category".

The discussion recommends replacing the missing section header with "Untitled" unless there is a better, more appropriate option.

It looks like this should go ahead. As part of deployment, please go through your developers' checklist for adding a new Linter "category", including documenting the new "category" on the MediaWiki site and linking to it from the relevant MediaWiki pages.

It looks like this should go ahead. As part of deployment, please go through your developers' checklist for adding a new Linter "category", including documenting the new "category" on the MediaWiki site and linking to it from the relevant MediaWiki pages.

The checklist is at https://www.mediawiki.org/wiki/Parsoid/Adding_a_new_lint_category if you want to review it

ABreault-WMF renamed this task from Missing edit-source button rendered in parsoid read views (from visualdiff testing) to Empty headings are missing edit-source button in parsoid read views.Apr 10 2025, 8:16 PM

The discussion recommends replacing the missing section header with "Untitled" unless there is a better, more appropriate option.

I created https://www.mediawiki.org/wiki/Help:Lint_errors/empty-heading with that recommendation

Change #1135525 merged by jenkins-bot:

[mediawiki/extensions/Linter@master] Add a new lint category for empty headings

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

Change #1135528 merged by jenkins-bot:

[mediawiki/core@master] Add i18n for empty heading lint category

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

Nemoralis subscribed.

Two new linter categories have been added so I think it could be included in the Tech News

For Tech News (thanks for the suggested entry!) please could someone suggest (or improve my) draft wording, and confirm the best timing? I imagine it would be something like:

  • A new lint-error category has been created: [[Special:LintErrors/empty-heading | {{int:linter-category-empty-heading}} ]]. The Linter extension's purpose is to identify wikitext patterns that must or can be fixed in pages and provide some guidance about what the problems are with those patterns and how to fix them.

Question 1: What is the second new linter? [Thanks, Nemoralis!]
Question 2: I believe these will all be getting deployed with the 'train' this week, and thus will be linkable (blue-links) at all Wikimedia-wikis the following week, and have content very-soon after, and hence this proposed entry would be suitable for next week's edition (delivered April 21). --- If that is wrong, and you'd prefer it a week later (e.g. to give time for categories to automatically populate if that isn't instant? or UI-translations?), please correct me with the preferred announcement date.

Question 1: What is the second new linter?

I meant one category, sorry about that. It seems that when I translated Linter's strings on translatewiki, I thought one of them was a new category too.

If that is wrong, and you'd prefer it a week later (e.g. to give time for categories to automatically populate if that isn't instant? or UI-translations?), please correct me with the preferred announcement date.

Announcing next week sounds good, I've added it
https://meta.wikimedia.org/w/index.php?title=Tech%2FNews%2F2025%2F17&diff=28548044&oldid=28528314

Change #1051863 merged by jenkins-bot:

[mediawiki/services/parsoid@master] Lint empty headings

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

Can you say a bit more about how it's being used and why it's necessary?

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

[mediawiki/vendor@master] Bump wikimedia/parsoid to 0.21.0-a27

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

Change #1139521 merged by jenkins-bot:

[mediawiki/vendor@master] Bump wikimedia/parsoid to 0.21.0-a27

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

Can you say a bit more about how it's being used and why it's necessary?

Please reopen or file a new task if we need to refine these lint errors.