mediawiki 1.16.5:为特定命名空间加载 javascript
我正在为 Mediawiki 开发一个扩展,该扩展基于另一个扩展(内部开发),该扩展无法与具有高级版本 1.16.5 的 Mediawiki 安装一起使用。我需要在属于特定命名空间的页面中包含 javascript,但无法使用 ResourceLoader
http://www.mediawiki.org/wiki/ResourceLoader。
有人知道是否有一个简单的方法可以做到这一点?我需要包含 JQuery 和 Datatables 来自定义呈现属于命名空间的页面。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
至少有三种方法可以解决这个问题。
第一种方法是编辑魔术页面
MediaWiki:Common.js
并添加如下内容:您可以在块中放置任意 javascript,其中的
importScript
位用于执行JavaScript 存储在 Wiki 页面中,但也有其他方法可以动态包含 JS(参见例如 Manual:Interface/JavaScript。第二种方法是破解生成 MediaWiki 页面的 PHP,根据当前命名空间注入
标签,但这会涉及更多一些:您需要构建一个自定义扩展并将其挂在某个适当的位置。 ParserAfterTidy 钩子看起来很合适,请参阅钩子。
第三种方法是简单地编辑皮肤并为 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: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.