Page MenuHomePhabricator

Add hook fired when sidebar TOC is updated
Closed, ResolvedPublicFeature

Description

When the section list in the sidebar TOC is updated (thanks to T307251), a hook should fire so that gadgets and user scripts that modify the TOC could do their job.

A current workaround would be to await mw.loader.using('mediawiki.template.mustache'); (mediawiki.template.mustache module is requested when the wikipage.tableOfContents hook is fired), but that is unstable and unclear to developers.

Event Timeline

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

[mediawiki/skins/Vector@master] SectionObserver should be updated at certain points in MediaWiki lifecycle

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

Change 889652 merged by jenkins-bot:

[mediawiki/skins/Vector@master] SectionObserver should be updated at certain points in MediaWiki lifecycle

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

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

[mediawiki/skins/Vector@master] Table of contents: FIXME cleanup

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

Jdlrobson claimed this task.
Jdlrobson subscribed.

The hook wikipage.tableOfContents.vector is now available.

Change 889653 merged by jenkins-bot:

[mediawiki/skins/Vector@master] Table of contents: FIXME cleanup

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

@Jack_who_built_the_house FYI the hook wikipage.tableOfContents.vector does not seem to have been adopted by any gadgets or code so we are considering removing it. As the person who requested it can you confirm if any code you have written uses it, so we can consider it as part of its deprecation.

Please reply as soon as you can if I'm mistaken in any way.

Edit: I removed code and amended my question now I understand the hook a little more.

I completely missed the moment when this was implemented, so my code still uses a hack. I'll check out the hook shortly.

@Jack_who_built_the_house FYI the hook wikipage.tableOfContents.vector does not seem to have been adopted by any gadgets or code so we are considering removing it. As the person who requested it can you confirm if any code you have written uses it, so we can consider it as part of its deprecation.

If you remove it, that would mean user scripts would have no official way to do anything with the TOC that works when the page is refreshed asynchronously, so no reliable user scripts that modify the TOC would be possible, if my understanding is correct. So why you would deprecate it is completely incomprehensible to me.

So, if "the hook wikipage.tableOfContents.vector does not seem to have been adopted by any gadgets or code" that basically means that either

  1. there are no user scripts in nature that modify the TOC
  2. or their maintainers are unaware of the creation of the hook => their user scripts work unreliably in Vector 2022.

The second seems more realistic to me, so I would look for such user scripts and inform their maintainers.

@Jdlrobson Convenient-Discussions now uses the hook, thank you for implementing it.

Okay thanks for the confirmation that it's serving a purpose. Thanks for offering to inform maintainers.