Page MenuHomePhabricator

Provide an OutputPage::addScript() function
Closed, ResolvedPublic

Description

Author: misspell

Description:
The ability to add javascripts in the <head> tags.
When creating a extension, enabling this feature would be very helpfull to dev's.


Version: unspecified
Severity: enhancement

Details

Reference
bz4474

Event Timeline

bzimport raised the priority of this task from to Medium.Nov 21 2014, 9:01 PM
bzimport set Reference to bz4474.
bzimport added a subscriber: Unknown Object (MLST).

robchur wrote:

Would this be accepting JavaScript as a parameter (to be slapped between
<script> tags), the path to a .js file, or both?

misspell wrote:

I would say both so it can please a wider range of people (two different calls).
Personaly, the path to a script file would be fine.

I've noticed $wgOut->addScript() but it seams to do nothing when a page is rendered.
You can hold info with it and check that info $wgOut->getScript() but it
out-puts nothing.

robchur wrote:

I'll look into it and either tweak how the existing functions work, or add
something else.

misspell wrote:

Sounds good.
Right now its not a big deal being the extention is in the begining stages, i
just edited the MonoBook.php file, but in the past while making forum mods &
add-ons i always tried to do the least amount of editing to the orginal files as
possable.

Thanks for the responce.

avarab wrote:

This should be done via hooks, not by adding a custom function that duplicates
what we have in the codebase already for cases like these.

robchur wrote:

(In reply to comment #5)

This should be done via hooks, not by adding a custom function that duplicates
what we have in the codebase already for cases like these.

I hadn't even gotten round to doing it yet. If you want to, go ahead and
implement it with hooks.

misspell wrote:

Forgotten about ?

james.robinson wrote:

I ran into this, and Google landed me here. In short, none of the default
templates use SkinTemplate::html to get the 'headscripts' data element that is
populated from OutputPage::getScript(). To get the data you shoved into
OutputPage::addScript(), add the following to a template in the 'right' place:

<?php $this->html('headscripts') ?>

Perhaps that should be another bug entry...

robchur wrote:

MediaWiki 1.6+ contains OutputPage::addScript() and it works. Closing FIXED.