Page MenuHomePhabricator

Parser function for loading gadgets
Open, Needs TriagePublic


A common subtype of community-maintained Javascript is one that adds interactive features to a certain template (examples include the Teahouse ask-a-question feature on enwiki, AddMe and FormWizard on meta, the tabbed interface used at mw:API:Login). These scripts are loaded and executed on every page and do some cheap test (such as checking whether some CSS class is present on the page) to determine whether to perform their main functionality. This is bad both for performance (all these scripts are loaded on all pages, even though they are only needed on a tiny fraction of pages, and usually ones that are only relevant for editors and as such never visited by most users of the wiki) and for robustness (bugs in these scripts would affect users viewing unrelated pages). Ideally scripts would only be loaded on pages where they are actually needed.

The infrastructure for that is mostly in place already - the Gadgets extension declares ResourceLoader modules for gadgets, gadgets can be marked as hidden (unavailable via the preferences page) and parser plugins such as tag extensions and parserfunctions can load ResourceLoader modules, so all that is needed is a parser function that does tell the parser to load the specified gadget, so it can be added to the relevant template. Something like {{#gadget:<gadget name>}} which would then load the ext.gadget.<gadget name> module.

Event Timeline

Tgr created this task.Dec 29 2019, 1:57 AM
Restricted Application added subscribers: Liuxinyu970226, Aklapper. · View Herald TranscriptDec 29 2019, 1:57 AM
Tgr added a comment.Dec 29 2019, 2:08 AM

Another advantage would be the easy handling of making sure these gadgets run in edit preview mode (e.g. when testing template changes) which most of these gadgets get wrong.