Javascript 如何添加外部<;脚本>;至<;头>;所有mediawiki页面的节?

Javascript 如何添加外部<;脚本>;至<;头>;所有mediawiki页面的节?,javascript,php,mediawiki,Javascript,Php,Mediawiki,我想将外部脚本添加到mediawiki中所有页面的标题部分 函数onBeforePageDisplay从挂钩回调: 在这个函数中,我想添加 <script type="text/javascript" src="http://static.wowhead.com/widgets/power.js"></script> <script>var wowhead_tooltips = { "colorlinks": true, "iconizelinks": tru

我想将外部脚本添加到mediawiki中所有页面的标题部分

函数
onBeforePageDisplay
从挂钩回调:

在这个函数中,我想添加

<script type="text/javascript" src="http://static.wowhead.com/widgets/power.js"></script>
<script>var wowhead_tooltips = { "colorlinks": true, "iconizelinks": true, "renamelinks": true }</script>
但是现在

对于MediaWiki 1.17及更高版本,请使用ResourceLoader模块

$out->addModules(数组(/modules/)

我无法让它工作,也找不到任何这样的例子

也许我必须使用
mw.loader.load
模块,但我不知道如何做。请帮帮我,对不起我的英语

p.s.解决方案可行,但不正确。需要使用ResourceLoader解决方案。(c) IMHO

解决方案很简单(看起来像解决方案):

//LocalSettings.php
...
#将我的函数分配给hook
$wgHooks['BeforePageDisplay'][]='onBeforePageDisplay';
函数onBeforePageDisplay(OutputPage和$out、Skin和$Skin)
{
$script='var wowhead_tooltips={“colorlinks”:true,“iconizelinks”:true,“renamelinks”:true}';
$out->addHeadItem(“wowhead脚本”,“$script”);
返回true;
};

这样看起来更好,因为它可以直接(在解析之后)处理OutputPage。

您无法通过ResourceLoader加载外部脚本。我写了自己的扩展来实现这一点。最好使用我的答案中的解决方案。И у тебя в коде яваскрипт вставлен в пхп. :)这导致性能不佳。你应该使用。
<script type="text/javascript" src="http://static.wowhead.com/widgets/power.js"></script>
<script>var wowhead_tooltips = { "colorlinks": true, "iconizelinks": true, "renamelinks": true }</script>
$out->addScript( $html )
// Add a JS file. $html is a full script tag: '<script type="text/javascript" src="..."></script>'
//LocalSettings.php
...
# Assign my functions to hook

$wgHooks['BeforePageDisplay'][] ='onBeforePageDisplay';

function onBeforePageDisplay( OutputPage &$out, Skin &$skin )
{
    $script = '<script type="text/javascript" src="http://static.wowhead.com/widgets/power.js"></script><script>var wowhead_tooltips = { "colorlinks": true, "iconizelinks": true, "renamelinks": true }</script>';
    $out->addHeadItem("wowhead script", $script);
    return true;
};