Last modified: 2014-01-10 18:43:27 UTC

Wikimedia Bugzilla is closed!

Wikimedia migrated from Bugzilla to Phabricator. Bug reports are handled in Wikimedia Phabricator.
This static website is read-only and for historical purposes. It is not possible to log in and except for displaying bug reports and their history, links might be broken. See T27962, the corresponding Phabricator task for complete and up-to-date bug report information.
Bug 25962 - Add support for URLs to mw.loader.using or callback to mw.loader.load
Add support for URLs to mw.loader.using or callback to mw.loader.load
Status: REOPENED
Product: MediaWiki
Classification: Unclassified
ResourceLoader (Other open bugs)
unspecified
All All
: Lowest enhancement with 2 votes (vote)
: ---
Assigned To: Nobody - You can work on this!
:
Depends on: 27023
Blocks:
  Show dependency treegraph
 
Reported: 2010-11-16 23:24 UTC by Helder
Modified: 2014-01-10 18:43 UTC (History)
7 users (show)

See Also:
Web browser: ---
Mobile Platform: ---
Assignee Huggle Beta Tester: ---


Attachments

Description Helder 2010-11-16 23:24:52 UTC
Hi!

It would be useful if RL could have a function similar to importScript() but which accepted two parameters:
1) the page where the script is; and
2) a callback function which is executed after the script is imported

It could be something like: mw.loadPageScript( title, callback )
Comment 1 Michael Dale 2010-11-16 23:41:54 UTC
to refine on that proposal, maybe resource loader supports name-spaced wikititles so its easy to load lots of them at once via the existing mw.load function. The old resource loader supported wiki titles by looking for the pretext "WT:" followed by the Title Name ... so you can do something like mw.load( ['WT:PageA', 'WT:PageB' ], callback ); and get all those wiki titles in a single resource loader request.
Comment 2 Helder 2010-11-18 12:57:24 UTC
Would that work also for importing in one request scripts from two wikis, say one from wikisource.org and other from en.wikipedia.org?
Comment 3 Michael Dale 2010-11-18 14:37:06 UTC
I suppose you could namespace the wikititles... but that could become complicated to maintain and be a bit of a security nightmear. ie an admin on wiki X is not nessesarally an admin on wiki Y if script Z breaks on X wiki coming from Y wiki admin X cant update script :P

If we ever get to the point of having a "wikidata" site that hosts shared templates, then it would probably be a good place to host shared scripts as well. ( and limit shared user scripts to that domain ) ... Since interfaces and interactions could be built around the interconnection of templates with named dynamic named dom elements so it makes sense if we are sharing templates to be able to share user scripts as well. 

In the mean time we could potentially make "commons" the shared host for scripts since most of the types of user scripts you would want to share currently scripts have to do with media files ( image Annotator, mwEmbed video subtitles etc )
Comment 4 Trevor Parscal 2010-11-18 19:16:33 UTC
I think this functionality will be best at home in the planned changes to mediaWiki.loader.load, which currently accepts one or more module names or a url (must start with http://) but is planned to be changed to accept one or more module names or an object which contains information about what to load, such as a url, wiki page, etc.
Comment 5 Krinkle 2010-11-18 19:36:17 UTC
Back in the present live deployed environment, it's possible to use jQuery's getScript() which is comparable to importScriptURI(), but with a callback function.

Example:

$.getScript('http://meta.wikimedia.org/?title=User:Krinkle/Scripts/Countervandalism.js&action=raw&ctype=text/javascript', function() {
  alert('Hello, script load was performed.');
});
See also: http://api.jquery.com/jQuery.getScript/

As for ResourceLoader, I don't know exactly what is going to change but the following works for modules that are defined:

mw.loader.using( 'module.name', funciton(){
  // script loaded OK
}, function(){
 // script loaded with Error
});

If not already the case, perhaps we can expand using() to also accept a URL and remember which urls are loaded already

mw.loader.using( 'http://meta.wikimedia.org/?title=User:Krinkle/Scripts/Countervandalism.js&action=raw&ctype=text/javascript', funciton(){
  // script loaded OK
}, function(){
 // script loaded with Error
});

Or, if not already, allow registering of new modules in the front-end and then load them with callback using using() like:

mw.loader.registerModle( 'krinkle.sample', 'http://meta.wikimedia.org/?title=User:Krinkle/Sample.js&action=raw&ctype=text/javascript', 'jquery.ui');
// jquery.ui being the dependancy

mw.loader.using( 'krinkle.sample', funciton(){
  // script loaded OK
}, function(){
 // script loaded with Error
});

Lots of ideas :)
Comment 6 Trevor Parscal 2010-11-18 21:05:12 UTC
There's already a complete system for registering modules, we just need to extend it to support loading external scripts too. All the dependency and versioning is already setup though.
Comment 7 Roan Kattouw 2010-11-27 20:15:00 UTC
The callback stuff is already in mediaWiki.loader.using( [ 'module1', 'module2' ], function() { callback code } ); . We'd just need to extend that to somehow accept URLs too.
Comment 8 Michael Dale 2011-02-01 18:10:10 UTC
Per Roan's latest comment, added 27023 as a dependent since loader.using callback will have to work for mediaWiki.loader.using to be useful in this context.
Comment 9 Krinkle 2011-05-17 22:06:54 UTC
* bug 27023 has been fixed (callback on loader functions is working now)
* r88053 rewrote the structure the loading structure

Next step is to add support to mw.loader.using to use URLs right away.
Comment 10 Helder 2012-03-02 13:57:49 UTC
As of r112665:
* mw.loader.load accept a callback function[1]; and
* mw.loader.using[2] doesn't accept urls

Per comments on
http://thread.gmane.org/gmane.science.linguistics.wikipedia.technical/52291
and on bug 27281 comment 2, I also don't see the point in sending more code to the users to duplicate only part of jQuery.getScript functionality (which is already sent to them).
Maybe the use of full urls on mw.loader.load should just be deprecated in favor of jQuery.getScript and keep mw.loader.load only for modules...

[1] http://svn.wikimedia.org/viewvc/mediawiki/trunk/phase3/resources/mediawiki/mediawiki.js?revision=112665&view=markup#l1212

[2] http://svn.wikimedia.org/viewvc/mediawiki/trunk/phase3/resources/mediawiki/mediawiki.js?revision=112665&view=markup#l1173
Comment 11 Helder 2012-03-02 14:01:13 UTC
(In reply to comment #10)
> As of r112665:
> * mw.loader.load accept a callback function[1]; and
I mean, it DOESN'T.
Comment 12 Michael Dale 2012-03-02 16:31:16 UTC
(In reply to comment #10)
> Maybe the use of full urls on mw.loader.load should just be deprecated in favor
> of jQuery.getScript and keep mw.loader.load only for modules...

I think it would be valuable to use a single entry point, you never know in the future some usages of the resource loader ( ie for external plugins ) may want to support both minified and non-minified access to external urls. Think about a wiki loading some modules from mediaWiki.org and wanting to be able to debug and or load things minified via a resource loader flag that lets you load external resources.
Comment 13 Roger Lima 2012-08-25 18:28:40 UTC
And so then guys?(In reply to comment #9)
> * bug 27023 has been fixed (callback on loader functions is working now)
> * r88053 rewrote the structure the loading structure
> 
> Next step is to add support to mw.loader.using to use URLs right away.

Has passed more than a year. When the support URLs will be possible?
Comment 14 Krinkle 2012-08-26 01:06:21 UTC
As said before, it isn't a high priority because there is no need for it in the current ResourceLoader environment. Everything is module based.

Urls in mw.loader.load is only used by legacy wikibits.js code coming from importScriptURI and importStylesheetURI, with mw.loader.load(url, 'text/css').

And for anything that does need urls, $.getScript can be used with a nice Promise interface, which can be multiplexed with $.when to callback multiple urls.

(In reply to comment #10)
> Maybe the use of full urls on mw.loader.load should just be deprecated in favor
> of jQuery.getScript and keep mw.loader.load only for modules...
> 

We probably won't remove it in MediaWiki as there is no gain in removing it, as we'd need a replacement somewhere else to still cover legacy importScriptURI and importStylesheetURI. But discouraging use of it, sounds good to me.

Note You need to log in before you can comment on or make changes to this bug.


Navigation
Links