Page MenuHomePhabricator

Table of contents doesn't update correctly on pages with < 4 sections
Closed, ResolvedPublic3 Estimated Story Points

Description

Expected: a table of contents appears!
Actual: No table of contents, however refresh the page and you'll see one.

(Please undo your edit once you've performed this test so others can try it!)

QA steps

  • Create an article or find an existing article with 2 sections e.g. https://en.wikipedia.beta.wmflabs.org/wiki/T328802
  • Check the table of contents doesn't appear in Monobook, Timeless. Modern. CologneBlue, Vector, Minerva
  • Check the table of contents appears in Vector 2022.

QA Results - Beta

QA Results - Prod

Event Timeline

There are a very large number of changes, so older changes are hidden. Show Older Changes

There are issues with the current version when editing using visual editor:

  • If headings are added to an article that previously had less than 4, the TOC should be shown, but it isn't (until you reload the page)
  • If headings are removed from an article that previously had at least 4, the TOC should be hidden, but it isn't (until you reload the page)

Has there been a discussion among designers / general public as to whether there is a need to hide the sidebar TOC when there is less than 4 sections? It would seem to me that since the TOC is not part of the content anymore, there is no reason to fine-tune its presence in such a way.

@alexhollender_WMF should we change this behaviour?

ovasileva subscribed.

There are issues with the current version when editing using visual editor:

  • If headings are added to an article that previously had less than 4, the TOC should be shown, but it isn't (until you reload the page)
  • If headings are removed from an article that previously had at least 4, the TOC should be hidden, but it isn't (until you reload the page)

Has there been a discussion among designers / general public as to whether there is a need to hide the sidebar TOC when there is less than 4 sections? It would seem to me that since the TOC is not part of the content anymore, there is no reason to fine-tune its presence in such a way.

@alexhollender_WMF should we change this behaviour?

Is this behavior constant across wikis or do communities set this per wiki?

ovasileva lowered the priority of this task from High to Medium.

It's hardcoded in the parser: https://gerrit.wikimedia.org/g/mediawiki/core/+/c7099b957afae584dfdd4c2a0c814ca847bd4763/includes/parser/Parser.php#4176
It can be overridden by __FORCETOC__.

I think if we wanted to, new Vector could always force the table of contents to be on regardless of the number of headings. Presumably there is value in showing a table of contents for an article with only one heading as it provides a means to jump between beginning and first heading, which may be useful on pages with long lead sections?

If you display the table of contents anyway regardless of the per-page preference, you will end up with two ToCs on pages that have a manually generated one. Example: https://en.wikipedia.org/wiki/List_of_automobile_manufacturers

If you display the table of contents anyway regardless of the per-page preference, you will end up with two ToCs on pages that have a manually generated one. Example: https://en.wikipedia.org/wiki/List_of_automobile_manufacturers

I was only suggesting we'd turn it on for pages with < 4 headings. NOTOC and FORCETOC would still be respected. Added a paragraph to make that less confusing.

I've started a discussion here in an attempt to learn more about why we currently hide the TOC on pages with less than 4 sections: https://en.wikipedia.org/wiki/Help_talk:Section#Why_is_the_TOC_automatically_hidden_if_the_page_has_less_than_4_sections?

On Help:Section I see

For each page with at least four headings, a table of contents (TOC) is automatically generated from the section headings unless...

but am not finding any reasoning there.

I've updated the prototype to show the TOC regardless of how many sections are in the article. Here are a few examples of articles with less than 3 sections with the TOC showing:

3 sections
https://di-collapsible-menus.web.app/Johnny_Miqueiro
https://di-collapsible-menus.web.app/Hurkett
https://di-collapsible-menus.web.app/Polycystine

2 sections
https://di-collapsible-menus.web.app/Yusuke_Yachi
https://di-collapsible-menus.web.app/Henning_Elbirk
https://di-collapsible-menus.web.app/Norway_Ski_Club

1 section
https://di-collapsible-menus.web.app/Rhytiphora_vicaria
https://di-collapsible-menus.web.app/Hecyra_marmorata
https://di-collapsible-menus.web.app/Freedom_List

This is a prototype but hopefully close enough to the real thing for us to get a sense. What do people think?

Change 826551 had a related patch set uploaded (by Jdlrobson; author: Mabualruz):

[mediawiki/skins/Vector@master] Table of contents doesn't respect NOTOC after an edit

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

When testing https://gerrit.wikimedia.org/r/826551 I noticed it fixes the issue, so presumably the question about whether to show table of content when < 4 headings is a separate question for a later date. Suggest capturing that in a new task if needed.

Change 826551 merged by jenkins-bot:

[mediawiki/skins/Vector@master] Table of contents doesn't respect NOTOC after an edit

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

Jdlrobson set the point value for this task to 0.Aug 29 2022, 5:46 PM

Skipping estimation as was fixed by T315863.

This still does not work in my testing. (Only T315863 is fixed.)

Jdlrobson removed the point value for this task.

Weird. Thanks for double checking.

Some of the new SHOW_TOC code hasn't been merged yet, it was waiting for me to return from vacation so that if things broke I'd be around to fix them: https://gerrit.wikimedia.org/r/q/topic:parser-toc

In the new code, the ParserOutput::getSections() will always be set to the section data, however many there are (unless the "suppressTOC" parser options is set), and the ParserOutputFlags::SHOW_TOC mirrors the legacy idea of whether the TOC "should" be shown, including not only the "hide if less than 4 sections" heuristic but also the NOTOC wikitext flag (as well as the same "suppressTOC" ParserOption for JavaScript/CSS pages which suppresses setSections() data).

So it should be harmless to experiment with other heuristics based on the section data, ignoring SHOW_TOC, except that you will need to fetch notoc from the page properties to determine if __NOTOC__ is used on the page.

@ovasileva the content transform team does not plan to work on this so if we want to do anything here, this would be work by the web team.

Change 831143 had a related patch set uploaded (by Jdlrobson; author: Jdlrobson):

[mediawiki/core@master] Skin: Table of contents is set for pages with < 4 sections

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

Above patch confirms this is possible and how we'd do it. We would need to adjust Vector's handling of the table of contents rendering after an edit. Looks relatively straight forward though.

Change 831143 abandoned by Jdlrobson:

[mediawiki/core@master] Skin: Table of contents is set for pages with < 4 sections

Reason:

(Not working on this right now)

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

Change 831143 restored by Jdlrobson:

[mediawiki/core@master] Skin: Table of contents is set for pages with < 4 sections

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

The patch https://gerrit.wikimedia.org/r/831143 should be unblocked now. We'll want to QA the editing workflow aspect of this change before merging and report back to the content transform team if we encounter any issues.

LGoto set the point value for this task to 3.Feb 9 2023, 6:29 PM
Jdlrobson removed the point value for this task.
Jdlrobson set the point value for this task to 3.

Change 831143 merged by jenkins-bot:

[mediawiki/core@master] Skin: Table of contents is set for pages with < 4 sections

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

Test Result - Beta

Status: ✅ PASS
Environment: beta
OS: macOS Ventura
Browser: Chrome
Device: MBP
Emulated Device:NA

Test Artifact(s):

QA Steps

Create an article or find an existing article with 2 sections e.g. https://en.wikipedia.beta.wmflabs.org/wiki/T328802
✅ AC1: Check the table of contents doesn't appear in Monobook, Timeless. Modern. CologneBlue, Vector, Minerva

MonobookTimelessModernCologneBlueVectorMinerva
Screenshot 2023-02-22 at 6.33.23 PM.png (819×1 px, 160 KB)
Screenshot 2023-02-22 at 6.33.38 PM.png (819×1 px, 138 KB)
Screenshot 2023-02-22 at 6.38.29 PM.png (819×1 px, 139 KB)
Screenshot 2023-02-22 at 6.33.52 PM.png (819×1 px, 176 KB)
Screenshot 2023-02-22 at 6.34.04 PM.png (819×1 px, 188 KB)
Screenshot 2023-02-22 at 6.34.25 PM.png (819×1 px, 116 KB)

✅ AC2: Check the table of contents appears in Vector 2022.

Vector 2002
Screenshot 2023-02-22 at 6.32.26 PM.png (819×1 px, 128 KB)

Create an article or find an existing article with 2 sections and NOTOC in the wikitext. e.g. https://en.wikipedia.beta.wmflabs.org/wiki/T328802_NOTOC
✅ AC3: Table of contents should not display in any skin.

Vector 2002MonobookTimelessModernCologneBlueVectorMinerva
Screenshot 2023-02-22 at 6.39.54 PM.png (819×1 px, 126 KB)
Screenshot 2023-02-22 at 6.40.07 PM.png (819×1 px, 162 KB)
Screenshot 2023-02-22 at 6.40.17 PM.png (819×1 px, 140 KB)
Screenshot 2023-02-22 at 6.40.28 PM.png (819×1 px, 141 KB)
Screenshot 2023-02-22 at 6.40.38 PM.png (819×1 px, 178 KB)
Screenshot 2023-02-22 at 6.40.46 PM.png (819×1 px, 191 KB)
Screenshot 2023-02-22 at 6.40.54 PM.png (819×1 px, 115 KB)

Create an article with 10+ sections and add __NOTOC_ e.g. https://en.wikipedia.beta.wmflabs.org/wiki/T328802_10SectionsNOTOC
✅ AC4: Table of contents should not display in any skin.

Vector 2002MonobookTimelessModernCologneBlueVectorMinerva
Screenshot 2023-02-22 at 6.43.25 PM.png (819×1 px, 105 KB)
Screenshot 2023-02-22 at 6.43.42 PM.png (819×1 px, 187 KB)
Screenshot 2023-02-22 at 6.43.57 PM.png (819×1 px, 154 KB)
Screenshot 2023-02-22 at 6.44.08 PM.png (819×1 px, 138 KB)
Screenshot 2023-02-22 at 6.44.18 PM.png (819×1 px, 169 KB)
Screenshot 2023-02-22 at 6.44.27 PM.png (819×1 px, 171 KB)
Screenshot 2023-02-22 at 6.44.37 PM.png (819×1 px, 80 KB)

Test Result - Prod

Status: ✅ PASS
Environment: enwiki, testwiki
OS: macOS Ventura
Browser: Chrome
Device: MBP
Emulated Device:NA

Test Artifact(s):

QA Steps

Create an article or find an existing article with 2 sections e.g. https://en.wikipedia.beta.wmflabs.org/wiki/T328802
✅ AC1: Check the table of contents doesn't appear in Monobook, Timeless. Modern. CologneBlue, Vector, Minerva

MonobookTimelessModernCologneBlueVectorMinerva
Screenshot 2023-02-28 at 6.27.54 PM.png (929×1 px, 491 KB)
Screenshot 2023-02-28 at 6.28.09 PM.png (929×1 px, 551 KB)
Screenshot 2023-02-28 at 6.28.17 PM.png (929×1 px, 453 KB)
Screenshot 2023-02-28 at 6.28.31 PM.png (929×1 px, 496 KB)
Screenshot 2023-02-28 at 6.28.42 PM.png (929×1 px, 492 KB)
Screenshot 2023-02-28 at 6.28.54 PM.png (929×1 px, 450 KB)

✅ AC2: Check the table of contents appears in Vector 2022.

Vector 2002
Screenshot 2023-02-28 at 6.29.08 PM.png (929×1 px, 448 KB)

Create an article or find an existing article with 2 sections and NOTOC in the wikitext. e.g. https://en.wikipedia.beta.wmflabs.org/wiki/T328802_NOTOC
✅ AC3: Table of contents should not display in any skin.

Vector 2002MonobookTimelessModernCologneBlueVectorMinerva
Screenshot 2023-02-28 at 6.37.25 PM.png (929×1 px, 139 KB)
Screenshot 2023-02-28 at 6.37.48 PM.png (929×1 px, 177 KB)
Screenshot 2023-02-28 at 6.38.02 PM.png (929×1 px, 189 KB)
Screenshot 2023-02-28 at 6.38.12 PM.png (929×1 px, 151 KB)
Screenshot 2023-02-28 at 6.38.28 PM.png (929×1 px, 182 KB)
Screenshot 2023-02-28 at 6.38.37 PM.png (929×1 px, 195 KB)
Screenshot 2023-02-28 at 6.39.08 PM.png (929×1 px, 125 KB)

Create an article with 10+ sections and add __NOTOC_ e.g. https://en.wikipedia.beta.wmflabs.org/wiki/T328802_10SectionsNOTOC
✅ AC4: Table of contents should not display in any skin.

Vector 2002MonobookTimelessModernCologneBlueVectorMinerva
Screenshot 2023-02-28 at 6.43.02 PM.png (929×1 px, 163 KB)
Screenshot 2023-02-28 at 6.43.11 PM.png (929×1 px, 205 KB)
Screenshot 2023-02-28 at 6.43.22 PM.png (929×1 px, 196 KB)
Screenshot 2023-02-28 at 6.43.34 PM.png (929×1 px, 173 KB)
Screenshot 2023-02-28 at 6.43.43 PM.png (929×1 px, 215 KB)
Screenshot 2023-02-28 at 6.43.52 PM.png (929×1 px, 199 KB)
Screenshot 2023-02-28 at 6.44.01 PM.png (929×1 px, 94 KB)