Jump to content

Topic on Talk:ResourceLoader/Migration guide (users)

From IRC to think about - Must user-scripts add a dependency to mediawiki.legacy.wikibits?

3
Rillke (talkcontribs)

I'd like to add some information to mw: ResourceLoader/Migration_guide_(users) - "If I use importScript in my userscript, do I have to do mw.loader.using('mediawiki.legacy.wikibits', function() { /*code here*/ } or can I simply use it?"

Imagine I want to use importScript in my User:Rillke/Common.js

Will it be defined for sure or should I ensure mediawiki.legacy.wikibits is loaded by "using mw.loader.using('mediawiki.legacy.wikibits', function() { importScript(...) }"

If so, add to ResourceLoader/Migration guide (users)#Migrating user scripts:


But keep in mind they require the mediawiki.legacy.wikibits-module.

mw.loader.using('mediawiki.legacy.wikibits', function (){
  importScript(...);
});

Krinkle (talkcontribs)

This is an interesting case. Both yes and no.

No:
The legacy wikibits module is loaded in the top queue, which is "blocking state". Meaning other modules won't load until this is loaded (much like "jquery" and "mediawiki" base modules). This is done for legacy reasons so that old scripts using these deprecated functions will continue to work without having to add such a dependency.

Yes:
If you are using this from a newly-written script that isn't old/legacy, and this module is also loaded in the top "blocking" queue (as of writing, gadgets can't put themselves in this queue, this "Yes" answer only applies to MediaWiki core and extensions), then this dependency is required. However that should be a very rare case, since you shouldn't be using legacy code in new code in the first place. When writing new code, for importScript the replacement is essentially modules/gadgets. If you really must load a script raw and singular from a wiki page inline, then use mw.loader.load with the full action=raw url. That also improves portability by not depending on which wiki the code is ran.

So legacy gadgets that aren't migrated don't have to be "fixed" by adding such dependency on "legacy". But if you see a legacy gadget and willing to spend time on them, consider porting them for real so that they don't use any legacy code in the first place (i.e. merge them in a single script page, or keep them separate and use the 'pipe-separated' list syntax listing all page names on MediaWiki:Gadgets-definition so that all required scripts are loaded in the module (instead of lazy-loading unminified and asynchronously from inline code).

He7d3r (talkcontribs)
When writing new code, for importScript the replacement is essentially modules/gadgets.

For more information, see the bugs on the right side.