Page MenuHomePhabricator

Possible issue with addOnloadHook in wikibits
Closed, InvalidPublic

Description

I'm adding some inline JS to the page head section, which uses the addOnloadHook function from wikibits. After the inclusion of wikibits moved to the resource loader, this broke - addOnloadHook is not available at the point where I'm using it. This is breaking all maps in the Maps and Semantic Maps extensions.

An example of the JS that is breaking: http://dpaste.org/uB7Q/

How should I modify my code, or is this a bug in the resource loader?


Version: 1.17.x
Severity: enhancement

Details

Reference
bz25322

Event Timeline

bzimport raised the priority of this task from to Medium.Nov 21 2014, 11:18 PM
bzimport set Reference to bz25322.

Exactly how are you adding the JS to the page? Adding JS inline (that is, at arbitrary locations in the <body>) is no longer supported. Instead, use $wgOut->addScript() or $wgOut->addScriptFile(). This previously used to put scripts in the <head>, but will now put them in the location where the resource loader expects them. Of course, porting your extension(s) to use the resource loader would be even nicer (but kills 1.16 compat).

PHP: http://dpaste.org/O2Eh/

Using $wgOut->addScript() instead seems to work fine at first try. IIRC, there was a reason for not using this though, as it didn't work correctly in all contexts. Unfortunately I can't remember the details.

I'll look into making Maps and Semantic Maps use the resource loader as soon as there is decent documentation.

Can this be closed then? It sounds like this was just unsupported behavior not a bug.

(In reply to comment #3)

Can this be closed then? It sounds like this was just unsupported behavior not
a bug.

It's unsupported behavior that I think should be supported in some way. Not sure which yet. Let's talk about this tomorrow.

(In reply to comment #4)

What was the outcome ?

(In reply to comment #5)

(In reply to comment #4)

What was the outcome ?

I don't remember, but I think we can close this one.