/*
This script is derived from the script at ], with some
slight enhancements.
*/
var RollbackBits = {
Type: '', // Defined by an onload function, below
// @private: Technically, one should always use RollbackBits.GetType()
CheckType: function () {
if(document.getElementById('pagehistory')) { return 'hist'; }
if(document.getElementById('mw-diff-ntitle2')) { return 'diff'; }
if(wgCanonicalSpecialPageName && wgCanonicalSpecialPageName == 'Contributions') { return 'trib'; }
else { return false; }
},
GetType: function () {
if(this.Type == '') { this.Type = this.CheckType(); return this.Type; }
else return this.Type;
},
PromptForSummary: function () { // Designed to be called by the onclick of a rollback link
var summary = prompt('Enter a summary for your rollback. Replacement strings: $rv, $u', '');
var user = this.href.match(/from=(*)/);
var user = decodeURIComponent(user.replace("+", " "));
if (summary) {
while (summary.match(/\$u(ser)?|\$re?v(ert|v)? */i)) {
summary = summary.replace(/\$u(ser)?/i, user);
summary = summary.replace(/\$re?v(ert|v)? */i, 'Reverted edits by \\] (\\]). ');
}
this.href += '&summary=' + escape(summary).replace(/\+/,'%2B');
return true;
} else {
return false;
}
}
};
function rollbackSummaryOnload() {
var links = false;
switch(RollbackBits.GetType()) {
case 'hist': links = document.getElementById('pagehistory').getElementsByTagName('a'); break;
case 'diff': links = document.getElementById('mw-diff-ntitle2').getElementsByTagName('a'); break;
case 'trib': links = document.getElementById('bodyContent').getElementsByTagName('a'); break;
}
for(var linkid = links.length - 1; linkid >= 0; linkid--) { //append prompt links after rollback links
if (links.href.match(/action=rollback/)) {
var rbsumm = links.cloneNode(false);
rbsumm.onclick = RollbackBits.PromptForSummary;
rbsumm.innerHTML = 'revert';
switch(RollbackBits.GetType()) {
case 'hist':
links.parentNode.appendChild(document.createTextNode(' | '));
links.parentNode.appendChild(rbsumm); break;
case 'diff': case 'trib':
links.parentNode.appendChild(document.createTextNode(' ['));
links.parentNode.appendChild(rbsumm);
links.parentNode.appendChild(document.createTextNode('] '));
}
}
}
}
$(rollbackSummaryOnload);