问题
MediaWiki Version and LocalSettings.php
MediaWiki 1.22.4
$wgAllowUserJs = true;
$wgUseSiteJs = true;
Browser Version
FireFox 28.0
JavaScript Code
$ gvim common.js
function myFunction() {
alert("Hello World!");
}
var onClickAttribute = document.createAttribute("onclick");
onClickAttribute.value="myFunction()";
var button = document.createElement("button");
button.setAttributeNode(onClickAttribute);
button.innerHTML = "Say hello";
if (document.URL === 'http://mywiki.com/w/index.php/User:Pjc/common.js') {
var wikiaArticle = document.getElementById("WikiaArticle");
wikiaArticle.insertBefore(button, wikiaArticle.firstChild);
}
:wq!
Browse to
http://mywiki.com/w/index.php/Special:MyPage/common.js
click "edit this page"
copy/paste common.js into page
click "Save" button
clear the cache in your browser
THE BUTTON DID NOT DISPLAY!
It just displays the code that was entered.
回答1:
Users javascript should be in MediaWiki:Common.js or under User:YourUserName/common.js. Scripts under Special:Mypage does not work. Please refer https://www.mediawiki.org/wiki/Manual:Interface/JavaScript for details
来源:https://stackoverflow.com/questions/23047188/mediawiki-specialmypage-common-js-not-working