Topic on Talk:ResourceLoader/Legacy JavaScript

importScript(), importStylesheet()

4
קיפודנחש (talkcontribs)

depracation page declares these methods depracated, and claims that mw.loder replaces them.

however, there is no method in mw.loader that can replace these. of course, one can always use mw.util.wikiGetlink(page) and append the "?action=raw&ctype=text/javascript" manually, but this seems somwewhat pointless - this is exactly what importScript() and importStylesheet() do for you...

mw.loader.load() replaces both importScriptURI and importStylesheetURI() successfuly, but not importScript() and importStylesheet().

on a completely different note, i would love it if mw.util.wikiGetlink() would accept an additional, optional parameter of type "object" that would add parameters: so if i want to get a page with "?action=edit", i would use mw.util.wikiGetlink(pageName, {action: 'edit'}); etc. if the first parameter is an object, this means i want the current page (just like mw.util.wikiGetlink() with no parameters), but still append the parameters.

this would be in the spirit of most or all of jQuery, calls, and very much in synch with the way to do ajax in jquery.

He7d3r (talkcontribs)

Hi!

You may want to vote/watch the following bugs:

  • 25845 - Support loading wiki pages through mediaWiki.loader.load()
  • 27281 - Add support in the front-end for loading wiki pages as resources
  • 34743 - mw.util.wikiGetlink should accept URL parameters in its second parameter

I've added a link to the first two of them on the documentation page.

קיפודנחש (talkcontribs)

Thanks for pointing me to the first 2 bugs, and doubly thanks for opening the 3rd one per my comment.

however, i do believe that until the loader actually supports importScript()/importStylesheet(), we should not have them in the depracation list.

peace.

Krinkle (talkcontribs)

See also ResourceLoader/Migration_guide_(users)#mw.loader.

If you are looking to update your scripts to not use deprecated functions, and come across calls to "importScript" and "importStylesheet", you are free to just keep using those the way they are. You don't have to fear them being removed, that will not happen until after a better replacement exists.

mw.loader.load does not and will not support loading of wiki-pages directly. The whole concept of ResourceLoader is modularity. Right now that is only available to core/extensions and on wikis via Gadgets. User scripts cannot create modules directly, therefor it's currently not possible to migrate a non-Gadget user script to fully use mw.loader.

Advise:

  • Either make your script into a Gadget (in which case you shouldn't ever need to use importScript, since you either list other files in the Gadgets-definition or you use "dependencies" to load common/shared code).
  • Keep using importScript