Gebruiker:Zanaq/Zeusmode/revert.js
< Gebruiker:Zanaq | Zeusmode
Opmerking: nadat u de wijzigingen hebt gepubliceerd is het wellicht nodig uw browsercache te legen.
- Firefox / Safari: houd Shift ingedrukt terwijl u op Vernieuwen klikt of druk op Ctrl-F5 of Ctrl-R (⌘-Shift-R op een Mac)
- Google Chrome: druk op Ctrl-Shift-R (⌘-Shift-R op een Mac)
- Internet Explorer / Edge: houd Ctrl ingedrukt terwijl u op Vernieuwen klikt of druk op Ctrl-F5
- Opera: druk op Ctrl-F5.
//<pre><nowiki>
//-------------------------------------------------------------
// Provide revert capability from history view, diffs and user-contributions
// From [[user:Zanaq/Zeusmode]]
// (c) Zanaq & Sam Hocevar, released under GPL
//-------------------------------------------------------------
function placeOldVersion(oldid, timestamp, editor)
{
pov_oldid=oldid; pov_timestamp=timestamp; pov_editor=editor;
xmlhttp = HTTPClient();
if (!xmlhttp)
return;
var thetitle=document.title.slice(0, String(document.title).indexOf(" - "));
document.getElementById('bodyContent').innerHTML=txtPlaceOld + '<br>';
wpComment = prompt(txtComment, '');
if (wpComment == null) return;
wpComment = (wpComment == '') ? '' : (' - ' + wpComment);
wpComment = txtPlace.replace(/\$1/g, oldid).replace(/\$2/g, timestamp).replace(/\$3/g, editor) + wpComment;
SavePage(thetitle + '&oldid='+oldid, '$1', wpComment, 1, mw.config.get('wgCurRevisionId'));
}
function addPlaceLinksHist()
{
var links, versionLink;
var bc = document.getElementById('bodyContent');
if(!bc) return;
versions=document.getElementById('bodyContent').getElementsByTagName('li');
//alert('ok');
startFrom = (versions[0].getElementsByTagName('a')[0].textContent == txtDiffPrevious) ? 1 : 0;
for (i=startFrom;i<versions.length;i++)
{
links = versions[i].getElementsByTagName('a');
versionLink=links[2];
if(versionLink) {
oldid=versionLink.href.substring(versionLink.href.indexOf('&oldid=')+7);
timestamp=versionLink.textContent;
editor=links[3] ? links[3].textContent : null;
} else {
editor = null;
}
if(editor) {
var placeLink = document.createElement('span');
placeLink.innerHTML = ' [<a href=\'JavaScript:placeOldVersion("' + oldid + '","'+ timestamp + '","' + editor + '");\'>' + txtPlaceLink + '</a>]';
versions[i].appendChild(placeLink);
}
}
}
function addPlaceLinksDiff()
{
td = document.getElementById('mw-diff-otitle4');
if(!td) return;
var pl=document.createElement("div");
pl.style.float='left';
var tdLinks = td.getElementsByTagName('a');
var tdLinkHref = tdLinks && tdLinks[0] && tdLinks[0].href;
oldid = tdLinkHref ? tdLinkHref.substring(
tdLinkHref.indexOf('&oldid=')+7
) : null;
if(oldid) return;
editor=document.getElementById('mw-diff-otitle2').getElementsByTagName('a')[0].textContent;
timestamp=document.getElementById('mw-diff-otitle1').getElementsByTagName('a')[0].textContent.substring(lenRevisionOf);
pl.innerHTML = innerHTML = '<div style=float:left>[<a href=\'JavaScript:placeOldVersion("' + oldid + '","'+ timestamp + '","' + editor + '");\'><b>' + txtPlaceLink + '</b></a>]</div>';
td.insertBefore(pl, td.firstChild);
var pl=document.createElement("div");
pl.style.float='right';
td = document.getElementById('mw-diff-ntitle4');
oldid=td.getElementsByTagName('a')[0].href.substring(td.getElementsByTagName('a')[0].href.indexOf('&oldid=')+7);
editor=document.getElementById('mw-diff-ntitle2').getElementsByTagName('a')[0].textContent;
timestamp=document.getElementById('mw-diff-ntitle1').getElementsByTagName('a')[0].textContent.substring(lenRevisionOf);
pl.innerHTML = '<div style=float:right>[<a href=\'JavaScript:placeOldVersion("' + oldid + '","'+ timestamp + '","' + editor + '");\'><b>' + txtPlaceLink + '</b></a>]</div>';
td.insertBefore(pl, td.firstChild);
}
if(zmUsePlace)
{
if (document.location.href.indexOf('&action=history') != -1)
addPlaceLinksHist();
if (document.location.href.indexOf('&diff=') != -1 || document.location.href.indexOf('?diff=') != -1)
addPlaceLinksDiff();
}
// -----------------------------------------------------------------------------
// Sam Hocevar's nice Revert functions
// taken from
// -----------------------------------------------------------------------------
// God-like Monobook skin
// (c) 2005 Sam Hocevar <sam@zoy.org>
// $Id: godmode-light.js 980 2005-11-12 01:51:51Z sam $
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
var gml_vandal, gml_editor, gml_url, gml_curid;
function PerformRevert(url, vandal, curid) {
gml_url= url;
gml_vandal=vandal;
gml_curid = curid;
document.getElementById('bodyContent').innerHTML = txtPleaseWait + gml_vandal + '...';
xmlhttp = HTTPClient();
if (!xmlhttp)
return;
document.getElementById('bodyContent').innerHTML += '<br />' + txtGetHist + ' (' + gml_url + '&action=history&limit=50):';
xmlhttp.open("GET", "/w/index.php?title="+gml_url + '&action=history&limit=50', true);
xmlhttp.onreadystatechange = RevertStepTwo;
xmlhttp.send(null);
//alert(gml_url + '&action=history&limit=50');
}
function RevertStepTwo() {
if (xmlhttp.readyState != 4)
return
document.getElementById('bodyContent').innerHTML+=txtOk + '<br>';
if (gml_curid == 0)
{
gml_curid=xmlhttp.responseText.indexOf('var wgCurRevisionId = "');
gml_curid=xmlhttp.responseText.substring(gml_curid + 23);
gml_curid=gml_curid.substring(0, gml_curid.indexOf('";'));
}
var l;
var oldid;
document.getElementById('bodyContent').innerHTML+= txtParseHist ;
// Get the vandal and new editor names
gml_vandal = gml_vandal.replace(/_/g, ' ');
gml_editor = '';
doc = XMLParse(xmlhttp.responseText);
l = doc.getElementById('pagehistory').getElementsByTagName('li');
//l = doc.selectSingleNode('//*[@id="pagehistory"]').getElementsByTagName('li');
for (i = 0; i < l.length; i++) {
var name = l[i].getElementsByTagName('a')[2 +(i>0)].getElementsByTagName('bdi')[0].innerHTML.replace(/_/g, ' ');
if (i == 0 && name != gml_vandal) {
console.log('Zeusmode: name last editor error. gml_editor: "' + encodeURI(gml_editor) + '", gml_vandal: "' + encodeURI(gml_vandal) + '", name: "' + encodeURI(name) + '"');
document.getElementById('bodyContent').innerHTML += '<br />' + txtLastErr.replace(/\$1/g, name).replace(/\$2/g, gml_vandal);
return;
} else if (i > 0 && name != gml_vandal) {
oldid = l[i].getElementsByTagName('input')[0].value;
gml_editor = name;
break;
}
}
if (gml_editor == '') {
document.getElementById('bodyContent').innerHTML += '<br />' + txtOnlyErr.replace(/\$1/g, gml_vandal);
return;
}
document.getElementById('bodyContent').innerHTML+=txtOk + '<br>';
wpComment = prompt(txtComment, '');
if (wpComment == null) return;
wpComment = (wpComment == '') ? '' : (' - ' + wpComment);
wpComment = revertpage.replace(/\$1/g, gml_editor).replace(/\$2/g, gml_vandal) + wpComment;
SavePage(gml_url + '&oldid='+oldid, '$1', wpComment, 1, gml_curid );
/* xmlhttp = HTTPClient();
if (!xmlhttp)
return;
document.getElementById('bodyContent').innerHTML += '<br />Getting article edit form (GET' + gml_url + '&action=edit&oldid=' + oldid + ')...';
xmlhttp.open('GET', gml_url + '&action=edit&oldid=' + oldid, true);
xmlhttp.onreadystatechange = RevertStepThree;
xmlhttp.send(null);
*/
}
// -----------------------------------------------------------------------------
// Add revert buttons to the page
// -----------------------------------------------------------------------------
function AddRevertButtons() {
var l, article = '', vandal;
// Add 'revert' links to a diff page
if (document.location.href.indexOf('&diff')!=-1 || document.location.href.indexOf('?diff')!=-1)
{
//alert(document.getElementById("differences-nextlink"));
if (document.getElementById("differences-nextlink")) return(0);
//alert(document.getElementById("differences-nextlink"));
var diffntitle = document.getElementById("mw-diff-ntitle2");
if(diffntitle)a=diffntitle.getElementsByTagName('a');
vandal = a[0].textContent.replace(/ /, '_');
wgCurRevisionId=0;
document.getElementById("mw-diff-ntitle1").innerHTML += ' <strong>[<a href=Javascript:PerformRevert("' + mw.config.get('wgPageName') + '","' + vandal + '","' + mw.config.get('wgCurRevisionId') + '")>' + rollbacklink + '</a>]</strong> ';
}
/*
l = document.getElementById('bodyContent').getElementsByTagName('td');
for (i = 0; i < l.length; i++) {
if (l[i].className == 'diff-otitle') {
*/
//article = l[i].getElementsByTagName('a')[0].href.split('&')[0].replace(/[^\/]*\/\/[^\/]*/, '');
/*} else if (l[i].className == 'diff-ntitle') {
var toplink = l[i].getElementsByTagName('a')[0].href;
vandal = l[i].getElementsByTagName('a')[3].textContent.replace(/ /g, '_');
var t = l[i].innerHTML
n = t.indexOf('</a>) <br') + t.indexOf('</A>) <BR') + 1; // XXX: WOW HACK!!!!
if (n >= 0 && article != '' && toplink.indexOf('oldid=') == -1) {
a=document.location.href.indexOf('?title=')+7;
b=document.location.href.indexOf('&diff=') || document.location.href.indexOf('?diff=');
articlename=document.location.href.substring(a,b);
//alert(articlename);
l[i].innerHTML = t.substring(0, n + 5) + ' <strong>[<a href=Javascript:PerformRevert("' + articlename + '","' + vandal + '","' + mw.config.get('wgCurRevisionId') + '")>' + rollbacklink + '</a>]</strong> ' + t.substring(n + 5, t.length);
}
}
}
*/
// Add 'revert' links to a contributions page
if (
(mw.config.get('wgCanonicalSpecialPageName') == "Contributions")
)
{
var c = document.getElementById('contentSub');
var a = c.getElementsByTagName('a');
if (a.length == 4) {
vandal=c.getElementsByTagName('a')[0].href.substring(c.getElementsByTagName('a')[0].href.indexOf(':',6)+1);
} else {
vandal=c.getElementsByTagName('a')[0].innerHTML;
}
var bc = document.getElementById('bodyContent');
l = bc ? bc.getElementsByTagName('li') : [];
//alert(vandal + " - " + l.length);
for (i = 0; i < l.length; i++) {
var t = l[i].innerHTML
/* // If we are already a sysop on this wiki, abort
if (t.indexOf('>' + rollbacklink + '</a>]') != -1)
break;
*/
//if (t.indexOf('&diff=0') != -1) {
if (t.indexOf('<span class="mw-uctop">') != -1) {
article = l[i].getElementsByTagName('a')[0].href.split('&')[0].replace(/[^\/]*\/\/[^\/]*/, '');
article=article.substring(19);
l[i].innerHTML += ' [<a href=Javascript:PerformRevert("' + article + '","' + vandal.replace(/ /, '_') + '","' + mw.config.get('wgCurRevisionId') + '")>' + rollbacklink + '</a>]';
}
}
}
}
// -----------------------------------------------------------------------------
// Modify the page once it is loaded
// -----------------------------------------------------------------------------
if (zmUseRollback == true)
{
AddRevertButtons();
}
/*----------------------------------
//Function to use the undo function a little faster
-----------------------------------*/
function fastUndo()
{
a=document.getElementById('wpSummary');
if (a.value=='') return(0);
summaryLength=a.value.length;
if (a.value.substring(summaryLength-1) != '.') return(0);
a.value=a.value.substring(0, summaryLength-1) + ' ';
prompted=prompt(txtComment, '');
if (prompted == null) return(0);
a.value+=(prompted == '') ? prompted : '- ' + prompted;
document.editform.submit();
}
if (zmUseUndo)
{
if (document.location.href.indexOf('&undo=') != -1)
fastUndo();
}
// -----------------------------------------------------------------------------
// Savepage
// -----------------------------------------------------------------------------
var glbSavePageText = '';
var glbSummaryText = '';
var glbMinorEdit = '';
var glbCurrentRevision = '';
function SavePage(pageTitle, saveText, summary, minor, currentRevision)
{
//alert(pageTitle);
xmlhttp = HTTPClient();
if (!xmlhttp)
return;
var thetitle="/w/index.php?title="+pageTitle;
glbSavePageText = saveText;
glbSummaryText = summary;
glbMinorEdit = minor;
glbCurrentRevision = currentRevision;
document.getElementById('bodyContent').innerHTML+=txtLoadEditform.replace(/\$1/g, pageTitle + '&action=edit');
//alert(thetitle + '&action=edit');
xmlhttp.open("GET", thetitle + '&action=edit', true);
xmlhttp.onreadystatechange = SavePageSubmit;
xmlhttp.send(null);
}
function SavePageSubmit() {
if (xmlhttp.readyState != 4)
return;
document.getElementById('bodyContent').innerHTML+=txtOk;
if (glbCurrentRevision > 0)
{
if ( !(xmlhttp.responseText.indexOf('"wgCurRevisionId":' + glbCurrentRevision + ',') > 0))
{
document.getElementById('bodyContent').innerHTML += '<br />' + txtEditconflict;
return(0);
}
}
document.getElementById('bodyContent').innerHTML += '<div style="display:none">' + xmlhttp.responseText + '</div>';
document.getElementById('wpSummary').value=glbSummaryText;
document.editform.submit();
}
//</nowiki></pre>