Gebruiker:Tomgreep/Zeusmode/revert.js

Opmerking: na het publiceren is het wellicht nodig uw browsercache te legen om de veranderingen te zien.

  • Firefox / Safari: houd Shift ingedrukt terwijl u:je 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)
  • Edge: houd Ctrl ingedrukt terwijl u:je op Vernieuwen klikt of 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, wgCurRevisionId);

}


function addPlaceLinksHist()
{
   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++)
   {
        versionLink=versions[i].getElementsByTagName('a')[2];

        oldid=versionLink.href.substring(versionLink.href.indexOf('&oldid=')+7);
        timestamp=versionLink.textContent;
        editor=versions[i].getElementsByTagName('a')[3].textContent;

        var placeLink = document.createElement('span');
  	placeLink.innerHTML = ' [<a href=\'JavaScript:placeOldVersion("' + oldid + '","'+ timestamp + '","' + editor + '");\'>' + txtPlaceLink + '</a>]';
  	versions[i].appendChild(placeLink);
   }
    

}

function addPlaceLinksDiff()
{
    

  l = document.getElementById('bodyContent').getElementsByTagName('tr');

  for (i = 0;i<2;i++)
  {
    a = l[0].getElementsByTagName('td')[i].getElementsByTagName('a');
    //alert(a[0].href);
    if (a[0].href.indexOf('&oldid=') > 0)
    {
    timestamp=a[0].textContent.substring(lenRevisionOf);
    editor=a[2+i].textContent;
    oldid=a[0].href.substring(a[0].href.indexOf('&oldid=')+7);

    l[0].getElementsByTagName('td')[i].innerHTML += ' [<a href=\'JavaScript:placeOldVersion("' + oldid + '","'+ timestamp + '","' + editor + '");\'><b>' + txtPlaceLink + '</b></a>]';
    }
   }

}


if(zmUsePlace)
{
 if (document.location.href.indexOf('&action=history') != -1)
      window.addEventListener ('DOMContentLoaded',addPlaceLinksHist,false);

 if (document.location.href.indexOf('&diff=') != -1)
      window.addEventListener ('DOMContentLoaded',addPlaceLinksDiff,false);
}

// -----------------------------------------------------------------------------
// 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)].innerHTML.replace(/_/g, ' ');
    if (i == 0 && name != gml_vandal) {
      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)
{
//alert(document.getElementById("differences-nextlink"));
if (document.getElementById("differences-nextlink")) return(0);
//alert(document.getElementById("differences-nextlink"));
a=document.getElementById("mw-diff-ntitle2").getElementsByTagName('a');
vandal = a[0].textContent.replace(/ /, '_');
wgCurRevisionId=0;
document.getElementById("mw-diff-ntitle1").innerHTML += ' &nbsp;&nbsp;&nbsp;<strong>[<a href=Javascript:PerformRevert("' + wgPageName + '","' + vandal + '","' + 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=');

articlename=document.location.href.substring(a,b);
//alert(articlename);

        l[i].innerHTML = t.substring(0, n + 5) + ' &nbsp;&nbsp;&nbsp;<strong>[<a href=Javascript:PerformRevert("' + articlename + '","' + vandal + '","' + wgCurRevisionId + '")>' + rollbacklink + '</a>]</strong> ' + t.substring(n + 5, t.length);
      }
    }
  }

*/
  // Add 'revert' links to a contributions page
  if (
            (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;
  
    }

    l = document.getElementById('bodyContent').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('&amp;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(/ /, '_') + '","' + wgCurRevisionId + '")>' + rollbacklink + '</a>]';
      }
    }
  }
}

// -----------------------------------------------------------------------------
// Modify the page once it is loaded
// -----------------------------------------------------------------------------

if (zmUseRollback == true)
{
   window.addEventListener("DOMContentLoaded", AddRevertButtons, false);
}

/*----------------------------------
//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)
   window.addEventListener ('DOMContentLoaded',fastUndo,false);
}



// -----------------------------------------------------------------------------
// 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>';
akeytt();
document.getElementById('wpSummary').value=glbSummaryText;
document.editform.submit();
 
}



//</nowiki></pre>