// Get the name of the "Page" namespace from mw.config
self.page_namespace = mw.config.get('wgNamespaceIds').page;
self.page_namespace = mw.config.get('wgFormattedNamespaces')[self.page_namespace];
// Until we can use dependencies to ensure load of Base.js first, we need this and window.ws_msg
// in this script.
if(!self.ws_messages) self.ws_messages = { };
window.ws_msg = function (name) {
var m = self.ws_messages[name];
if(m) return m; else return name;
};
function match_callback(data) {
var sp = document.getElementById("wpRobot");
if(sp) sp.innerHTML = "";
if (data.error) {
alert(data.text);
} else {
window.location.href=window.location.href;
}
}
function request_url(cmd) {
return "//phetools.toolforge.org/match_and_split.php?cmd=" + cmd +
"&title=" + mw.config.get('wgPageName') + "&lang=" +
mw.config.get('wgContentLanguage') + "&user=" + mw.config.get('wgUserName') + "&server=" + mw.config.get('wgServer');
}
function do_match(){
var sp = document.getElementById("wpRobot");
if(sp) sp.innerHTML = ws_msg('matching')+"…";
$.getJSON(request_url('match')).done(match_callback);
}
function add_match_button(){
$("span.mw-headline").each(function () {
if ($(this).attr('id').substring(0, 7) == "MATCH_:") {
var html = $(this).html();
html = html.replace('__MATCH__:','<span id="wpRobot"><a href="javascript:do_match();">'+ '__MATCH__:' + '</a></span>');
$(this).html(html);
}
});
}
function do_split() {
var sp = document.getElementById("wpRobot");
if(sp) sp.innerHTML = ws_msg('splitting')+"…";
$.getJSON(request_url('split')).done(match_callback);
}
function add_split_button() {
var prefix = self.page_namespace+":";
$("span.mw-headline").each(function () {
if ($(this).attr('id').substring(0, prefix.length) == prefix) {
var a;
if ( mw.config.get('skin')=="vector" )
a = document.getElementById("p-namespaces");
else
a = document.getElementById("p-cactions");
if (!a)
return false;
var b = a.getElementsByTagName("ul");
if (!b)
return false;
b[0].innerHTML = b[0].innerHTML + '<li id="ca-split">' + '<span id="wpRobot"><a href="javascript:do_split();"><span>split</span></a></span></li>';
return false;
}
});
}
if (mw.config.get("wgCanonicalNamespace") !== 'Page' ) {
$(add_match_button);
$(add_split_button);
if ({ edit:1, submit:1 }[mw.config.get('wgAction')]) {
mw.loader.using('mediawiki.toolbar', function () {
if (mw.toolbar) {
mw.toolbar.addButton(
'//upload.wikimedia.org/wikipedia/commons/9/97/Template_button.png',
'Match',
'==__MATCH__:[[',
']]==',
'',
'mw-editbutton-match'
);
}
});
}
}