Last modified: 2012-03-19 13:51:15 UTC
Since a few days ago I started noticing the following message on error console (on Google Chrome 17.0.963.79, on Ubuntu): Failed to load resource: the server responded with a status of 404 (Not Found) https://pt.wikibooks.org/function%20(selector,context)%7Breturn%20new%20jQuery.fn.init(selector,context,rootjQuery);%7D When I asked on IRC, Roan said it was as if "someone used mw.wikiScript( $ ) or something", and that "the part after /w/ is equal to $.toString()" (which is indeed the case, except for the URL encoding) After some debugging, I found the error was being caused by one of my user scripts: https://pt.wikibooks.org/?oldid=234535 and then I tried to reduce the code as much as I could, to isolate the problem, and the simplified version can be found here: https://pt.wikibooks.org/?oldid=234559&action=edit When I'm using it, with all gadgets disabled, I get the error on that page itself, right after my debug message is shown: > "$( addButton )" was executed inside of mw.loader.using( 'ext.wikiEditor.toolbar'... In debug mode, https://pt.wikibooks.org/?oldid=234540&action=edit&debug=1 The "URL" in the error message is a little different: GET https://pt.wikibooks.org/function%20(%20selector,%20context%20)%20%7B//%20The%20jQuery%20object%20is%20actually%20just%20the%20init%20constructor%20'enhanced'return%20new%20jQuery.fn.init(%20selector,%20context,%20rootjQuery%20);%7D 404 (Not Found) (and it also happens right after "$( addButton )" was executed inside of mw.loader.using( 'ext.wikiEditor.toolbar'...), which is the encoded form of "function ( selector, context ) {// The jQuery object is actually just the init constructor 'enhanced'return new jQuery.fn.init( selector, context, rootjQuery );}" The error also happens on pages such as these: https://pt.wikibooks.org/wiki/Special:Random?action=edit&debug=1 https://pt.wikibooks.org/wiki/JustAnEmptyPage?action=edit&debug=1 and also on Firefox 9.0.1 on Windows XP: GET https://pt.wikibooks.org/w/function%20(selector,%20context)%20%7B%20%20%20%20return%20new%20jQuery.fn.init(selector,%20context,%20rootjQuery);%7D [HTTP/1.1 404 Not Found 578ms] What could be causing this? Did I do something wrong on that script, or there is a bug in some of the functions used?
Bugzilla is not a help forum. Try the village pumps, especially WP:VP/T on en.wiki, you'll get much more attention for your question there. If they do determine that it's an issue with MediaWiki, let us know.
Basically what is happening: Your function addButton's name conflicts with the builtin addButton (aka mw.toolbar.addButton ) (from mediawiki.action.edit module). So what happens is: $(addButton) -> addButton( $ ) -> mw.toolbar.addButon( $) -> mw.toolbar.insertButon( $ ) Which in turns inserts a toolbar button, where the url for the image to use is the $ function (since that's what first arg of insertButton is), and $.toString() is the url you see loaded.
Hmm.. I though ResourceLoader was wrapping user scripts into a function, but it seems I was wrong, per bug 32537 comment 5. Thanks for clarifying this.
All resource loader modules loaded via mw.loader are executed from a closure, that is correct. However the 'site' (common.js & <skinname>.js) module and 'user' module (common.js & <skinname>.js) are not loaded via mw.loader.load. This was done to allow shared caching of the default load batch queue. But the site and user module aren't just loaded outside the default queue, they aren't loaded via mw.loader.load at all. They are loaded with a separate <script> tag directly to load.php?module=user&only=scripts This allows 2 things: * separating styles into a different load (namely a <link rel=stylesheet> on top of the page, before the content to avoid a Flash Of Unstyled Content (FOUC)) * executing JS in the global scope for backwards compatibility (many gadgets ask users to put 'var foobar = 123;' in the user script to set certain variables. Those would have to be updated to 'window.foobar = 123;' to do the same.