mediawiki 1.16.5:为特定命名空间加载 javascript

发布于 2024-12-17 12:57:34 字数 342 浏览 2 评论 0 原文

我正在为 Mediawiki 开发一个扩展,该扩展基于另一个扩展(内部开发),该扩展无法与具有高级版本 1.16.5 的 Mediawiki 安装一起使用。我需要在属于特定命名空间的页面中包含 javascript,但无法使用 ResourceLoader http://www.mediawiki.org/wiki/ResourceLoader

有人知道是否有一个简单的方法可以做到这一点?我需要包含 JQuery 和 Datatables 来自定义呈现属于命名空间的页面。

I am developing an extension for Mediawiki which is based on another extension (developed in-house) that will not work above with a Mediawiki installation with a version superior 1.16.5 . I need to include javascript in pages belonging to a specific namespace and I cannot use the ResourceLoader http://www.mediawiki.org/wiki/ResourceLoader .

Does someone know if there's a simple to do this? I need to include JQuery and Datatables for a custom rendering of the pages belonging to the namespace.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

乖乖 2024-12-24 12:57:34

至少有三种方法可以解决这个问题。

第一种方法是编辑魔术页面 MediaWiki:Common.js 并添加如下内容:

if(wgNamespaceNumber == 0) { // NS_MAIN
  importScript('MediaWiki:MyScript.js');
}

您可以在块中放置任意 javascript,其中的 importScript 位用于执行JavaScript 存储在 Wiki 页面中,但也有其他方法可以动态包含 JS(参见例如 Manual:Interface/JavaScript

第二种方法是破解生成 MediaWiki 页面的 PHP,根据当前命名空间注入

第三种方法是简单地编辑皮肤并为 wiki 中的每个页面加载 JS——您是否有理由不想为每个页面都执行此操作?无论如何,它们都会被缓存,所以这只是一次性的点击。

There are at least three ways to go about this.

The 1st approach is to edit the magic page MediaWiki:Common.js and add something like this:

if(wgNamespaceNumber == 0) { // NS_MAIN
  importScript('MediaWiki:MyScript.js');
}

You can place arbitrary javascript in the block, the importScript bit there is for executing JavaScript stored in a Wiki page but there are other ways to include JS on the fly as well (see eg. this question). See Manual:Interface/JavaScript for details of the MediaWiki side of things.

The 2nd approach would be to hack the PHP that produces the MediaWiki page to inject <script> tags depending on the current namespace, but that's a bit more involved: you'd need to build a custom extension and hook it in at some appropriate point. The ParserAfterTidy hook looks suitable, see Hooks.

The 3rd approach would be to simply edit the skin and load the JS for every page in the wiki -- is there a reason you don't want to do this for every page? They're cached anyway, so it's only a one-time hit.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文