Weird GET requests in user script
Closed, InvalidPublic


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),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

After some debugging, I found the error was being caused by one of my
user scripts:
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:

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,
The "URL" in the error message is a little different:
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:
and also on Firefox 9.0.1 on Windows XP:
[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?

Version: 1.19
Severity: normal


bzimport set Reference to bz35273.
bzimport added a subscriber: Unknown Object (MLST).
He7d3r created this task.Mar 16 2012, 11:02 PM

EN.WP.ST47 wrote:

Bugzilla is not a help forum. Try the village pumps, especially WP:VP/T on, 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.

Add Comment