Page MenuHomePhabricator

Fire mw.hook when section is added to 2010 Wikieditor
Closed, ResolvedPublicFeature

Description

The 2010 Wikieditor currently fires a custom event when the default sections have been added (wikiEditor.toolbarReady) and a mw.hook event at the same time (wikiEditor-toolbar-doneInitialSections). It also fires a custom event (wikiEditor-toolbar-buildSection-sectionname) before adding a section to let other code modify the section before it is added. It would be nice if it also fired a mw.hook when it has added a section, so that code depending on that section knows when to run.

The immediate use case is for Wikisource, where ProofreadPage (and extension) adds a new section to the toolbar that we want to extend with additional buttons from a Gadget. There is currently no hook the Gadget can use to know whether the PRP section has been added to the toolbar, so now it's a race that sometimes the Gadget wins and sometimes it loses. The only workarounds are to use a fixed time delay, run a while loop looking for a DOM element with the semi-private class name and sleeping, or a MutationObserver to look for the internal markup structure for that section in the toolbar; none of which particularly appeal.

I've filed T370334 for a specific workaround for the PRP use case, but this event would be applicable for any use case where third-party code (an extension, a different gadget, etc.) adds a new section to the toolbar in which you need to add buttons etc.

Event Timeline

Change #1276616 had a related patch set uploaded (by Happy5214; author: Happy5214):

[mediawiki/extensions/WikiEditor@master] Restructure toolbar JavaScript hooks

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

Change #1276616 merged by jenkins-bot:

[mediawiki/extensions/WikiEditor@master] Restructure toolbar JavaScript hooks

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

happy5214 moved this task from Doing to Closed on the WikiEditor (2010) board.