Topic on Talk:ResourceLoader

Suggested feature: What links here?

4
Krinkle (talkcontribs)

I'm happy with your exercise and I'm really looking forward to see the delivery. If it is not too late, I have one suggestion:

  • The address may be enclosed in double brackets.
  • Reason: the code .load('[[User:Foo/helpful.js]]') generates entries on What links here?
  • Until now it has been common practice to ask users to add a comment   // [[User:Foo/helpful.js]]   in order to get knowledge about other users.
  • That might be helpful to be aware of the number of other people influenced by changes, if the script is developed for common usage. It might be necessary to Talk: to others if behaviour of script changes significantly.
  • To avoid caching problems after bugfixes, friends were to be informed and asked to clear the cache -- I understood that the RevID will be appended to the URL in the future.
  • Stripping off enclosing brackets seems to me quite easy.

This post was posted by Krinkle, but signed as PerfektesChaos.

Krinkle (talkcontribs)

Hi PerfektesChaos,

Thanks for taking the time to write up this feedback. It's most welcome!

To get right to the subject, right now ResourceLoader is not and can not be used to load user scripts. User scripts are a (powerful) invention by the community that has shown great results and makes sharing really easy, however they are currently not natively supported by the MediaWiki software. Scripts are stored on (technically article-like) normal wiki pages, and the method to load the raw wikitext (action=raw) is used to load it without rendering and thus, when the url is inserted into an HTML <script> tag, it is executed as javascript.

To make this easier to do for the community, the developers have added the popular importScript() function to the core software so that it doesn't have be created from scratch on each wiki.

Also Extension:Gadgets was created which makes writing scripts even easier and is ultimately how scripts should be managed. Since Gadgets are built as an extension and connect into the right MediaWiki hooks, all the native features are available for Gadgets. That includes

  • efficient loading of scripts and styles (combined and compacted into a small package, re-uses this cached package whenever possible, based on:
  • automatisch cache clearing (cache identified with a unique module name and timestamp of when it was last modified)
  • (and, soon also:) internationalization / translation (Gadgets 2.0 is on it's way, as part of the RL2 project).
  • "usage" tracking (through the preferences). See w:Wikipedia:Database_reports/User_preferences#Gadgets for example.
  • loading other modules as part of your module ('dependencies')
  • and more..

But what it can't do is create gadgets on a per-user level (only on a per-site level). This is a much requested feature, but currently not possible yet in an efficient and scalable way (requires a few other changes as well). But I expect that this will be implemented as part of Gadgets 3.0.

So to get back at your suggestion. Although you can use mw.loader.load() right now to load a url of choice (including, but not limited to, urls to the current wiki where your user script is stored), that is just loading it as a url (just like importScriptURI does), that is not really a feature of ResourceLoader. And as such, since user scripts technically don't exist as a feature, ResourceLoader can't create an alias for it in the existing system.

Since the environment in which user scripts are written has changed a lot in the past few months/years, I don't think it is a good idea to make any more changes that require (or motivate) a lot of changes (such as changing to format to .load('[[Page name]]'). Instead focus on keeping the environment stable, while developers work on a solution to migrate away from user scripts (the current scripts will continue to work, don't worry)... to a solution that allows the same (and more) functionality in a better way that

  • does integrate with ResourceLoader
  • allows creation and modification of gadgets on a user-level
  • easy sharing with other users (and other wikis)

..in other words: Gadgets 3.0, in which users can create their own fully-featured Gadgets!

So for now I'd recommend to stick with what already users know, use and will work fine:

// [[Namespace:Page name]]
importScript('Namespace:Page name')

/* or */

// [[Namespace:Page name]]
mw.loader.load('https://www.mediawiki.org/w/index.php?title=Namespace:Page_name&action=raw&ctype=text/javascript');
1.46.233.191 (talkcontribs)
1.46.233.191 (talkcontribs)
Reply to "Suggested feature: What links here?"