Last modified: 2012-11-01 22:01:20 UTC
After I openned the page https://pt.wikipedia.org/wiki/MediaWiki:Edittools.js on Google Chrome (16.0.912.77 m) and typed the commands below I got the following results: ---- > typeof EditTools "undefined" > mw.loader.load(mw.config.get( 'wgScript' ) + '?title=MediaWiki:Edittools.js&action=raw&ctype=text/javascript&nocache=005'); true > typeof EditTools "undefined" > importScriptURI(mw.config.get( 'wgScript' ) + '?title=MediaWiki:Edittools.js&action=raw&ctype=text/javascript&nocache=005'); <script src="/w/index.php?title=MediaWiki:Edittools.js&action=raw&ctype=text/javascript&nocache=005" type="text/javascript"></script> > typeof EditTools "object" ---- So, although mw.loader.load is supposed to be a replacement for importScriptURI, it doesn't woks in every case where importScriptURI worked. For comparison, notice that it works if I use the full URL like this: ---- > typeof EditTools "undefined" > mw.loader.load('https://pt.wikipedia.org/w/index.php?title=MediaWiki:Edittools.js&action=raw&ctype=text/javascript&nocache=005') true > typeof EditTools "object" ---- or a protocol relative URL like this: ---- > typeof EditTools "undefined" > mw.loader.load('//pt.wikipedia.org/w/index.php?title=MediaWiki:Edittools.js&action=raw&ctype=text/javascript&nocache=005') true > typeof EditTools "object" ----
Created attachment 9924 [details] Proposed change to resources/mediawiki/mediawiki.js I believe a change like this would be enough.
mw.loader.load, as documented takes one ore more modules or a full url. Relative urls do not work, this is not a regression as is never worked. importScriptURI is still an unvalidated, raw way of adding a <script> tag for whatever is passed in. That hasn't changed. If some script is using a relative path to index.php and using importScriptURI, then that script will continue to work exactly as is. No regression. mw.loader.load can be used if you decide to migrate your script. In that case one should make sure that the url is complete, this is a requirement of mw.loader.loader because the path to which the url is relative to is dynamic because the script will be executed from load.php instead of where you write it. So in the case of index.php, you'd prefix it with wgServer. I don't think we should be adding exceptions for index.php. What about api.php, load.php, or extension files and resources ? There is need to add exceptions for everything, a full url will work.
For the record, this behavior made (at least) two more victims since then: * https://pt.wikipedia.org/wiki/MediaWiki:Common.js/watchlist.js?diff=31466296 * https://en.wikipedia.org/wiki/MediaWiki:Common.js/sandbox?curid=22846519&diff=519258118&oldid=519249503
(In reply to comment #3) > For the record, this behavior made (at least) two more victims since then: No, this behaviour hasn't made any victims. No where does it nor has it ever said that mw.loader.load supports relative paths. Writing code that does will fail, and that is, with all due respect, a mistake by the writer. If you expect a function to do something it doesn't, the function is most certainly not at fault unless the function previously met your expectations if documentation suggests so. Please read the documentation and don't write code without testing that it works :-)