Last modified: 2012-11-01 22:01:20 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 T36036, the corresponding Phabricator task for complete and up-to-date bug report information.
Bug 34036 - Add support for relative paths to mw.loader.load
Add support for relative paths to mw.loader.load
Status: RESOLVED WONTFIX
Product: MediaWiki
Classification: Unclassified
JavaScript (Other open bugs)
1.17.x
All All
: Low enhancement (vote)
: 1.19.0 release
Assigned To: Nobody - You can work on this!
https://pt.wikipedia.org/w/index.php?...
: patch, patch-reviewed
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2012-01-30 11:20 UTC by Helder
Modified: 2012-11-01 22:01 UTC (History)
3 users (show)

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


Attachments
Proposed change to resources/mediawiki/mediawiki.js (926 bytes, patch)
2012-01-30 11:53 UTC, Helder
Details

Description Helder 2012-01-30 11:20:15 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"
----
Comment 1 Helder 2012-01-30 11:53:13 UTC
Created attachment 9924 [details]
Proposed change to resources/mediawiki/mediawiki.js

I believe a change like this would be enough.
Comment 2 Krinkle 2012-01-30 23:21:45 UTC
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.
Comment 4 Krinkle 2012-10-22 23:27:00 UTC
(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 :-)

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


Navigation
Links