I ask this question specifically in the context of the English Wikipedia, but I suppose it's equally valid for any MediaWiki installation. I originally asked these questions here, and copy them here in the hope of more support.
I'm starting to try and work with userscripts a little, and, probably due to my inexperience with both javascript and with mediawiki, I'm running in to a couple of questions. The questions all have to do with loading and dependencies.
- I would like to use some functions/objects in multiple scripts. What is the suggested way to inject the dependencies into the executing script? There are the functions
importScript
,mw.loader.load
andmw.loader.using
(). I can't figure out how to inject the dependencies in to the executing script however, other than injecting them into the global namespace and picking them up from there, which can't be the intention.mw.loader.using
takes a callback as an argument, but that callback doesn't have parameters for the dependencies. It returns a promise, but I can't find what the promise contains (it looks like nothing).
- Scripts that actually do something other than providing functions tend to depend on the DOM, which may be built asynchronously. The mediawiki guidelines advice to use the mw.hook events rather than document.ready, which seems reasonable, but the three listed events there seem to be rather sparse. My specific usecase for now is adding a portlet link. I'd like it to be general, but I'd settle for it only working on Vector. On which event should I add that?