Wikipedia talk:WikiProject User scripts/Scripts/Revert tools

Page contents not supported in other languages.
From Wikipedia, the free encyclopedia

Instructions[edit]

Installation[edit]

To install the script:

  • Edit your monobook.js page.
  • Copy/Paste the following script into the edit box, and save. Follow the displayed instruction to bypass your browser cache.
importScript('Wikipedia:WikiProject User scripts/Scripts/Revert tools');

Usage[edit]

Go to any diff page and these links will be placed at the top under "From Wikipedia, the free encyclopedia".

(Revert / Message) (Vandalism / Message) (Warn: Test / Blatant / Nonsense / Blanking)
  • Revert: Will revert the edit and put this in the edit summary: Reverted edits by [user] to version [version] by [user].
  • Message: Displays a dialogue box for you to enter a message (Ie. Why you reverted it) and will put it in backets after the "Reverted edits..." bit.
  • Vandalism/Message: Does the same as above but displays "Reverted vandalism" instead of "Reverted edits".
  • Warnings: Will subst the relevant warnings on the editors talk page.

History[edit]

Name Version Description Skins Author
Revert tools 1.0 Displays links to revert an edit when viewing a diff page MonoBook Lorian
Revert tools 1.1 Edits by Konman72, see talk page MonoBook Konman72
Revert tools 1.1.1 Update due to addition of the "undo" link MonoBook rotemliss

Comments[edit]

Alterations[edit]

Hey, I made some slight alterations to the code that I thought made it better. First of all there was a typo in the message text. Secondly I changed it so that the links in the edit summary lead to contributions rather than the user page. I find this useful since most vandals are IP addresses without an actual user page. I don't know the etiquette for these sorts of things so I didn't want to edit the code here, but if it is alright I thought this might help.

// Revert tools by Lorian
function getElementsByClass(searchClass,node,tag) {
  // Function from http://www.dustindiaz.com/getelementsbyclass/
  var classElements = new Array();
  if ( node == null )
    node = document;
  if ( tag == null )
    tag = '*';
  var els = node.getElementsByTagName(tag);
  var elsLen = els.length;
  var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
  for (i = 0, j = 0; i < elsLen; i++) {
    if ( pattern.test(els[i].className) ) {
      classElements[j] = els[i];
      j++;
    }
  }
  return classElements;
}

// _GET code from NoGray JS Library http://www.nogray.com/new_site/
var _GET = new Array();
var _uri = location.href;

var _temp_get_arr = _uri.substring(_uri.indexOf('?')+1, _uri.length).split("&");

var _temp_get_arr_1 = new Array();

for(_get_arr_i=0; _get_arr_i<_temp_get_arr.length; _get_arr_i++){
  _temp_get_arr_1 = _temp_get_arr[_get_arr_i].split("=");
  _GET[decodeURI(_temp_get_arr_1[0])] = decodeURI(_temp_get_arr_1[1]);
}

delete _uri; delete _temp_get_arr; delete _temp_get_arr_1;

function getMessage (where, user1, user2) {
  var message = prompt ('What message would you like to leave?', '');
  window.location = 'http://en.wikipedia.org/w/index.php?title=' + _GET['title'] + '&action=edit&oldid=' + _GET['oldid'] + '&'+where+'=2&user1='+user1+'&user2='+user2+'&message='+message;
}

addOnloadHook(function (){
  if (location.href.match(/diff=/)) {
    // Get username of submitter
    var user1 = getElementsByClass('diff-otitle',null,'td'); user1 = user1[0].getElementsByTagName('a')[2].innerHTML;
    var user2 = getElementsByClass('diff-ntitle',null,'td'); user2 = user2[0].getElementsByTagName('a')[2].innerHTML;
    document.getElementById('contentSub').innerHTML = '(<a href="http://en.wikipedia.org/w/index.php?title=' + _GET['title'] + '&action=edit&oldid=' + _GET['oldid'] + '&revert=1&user1='+user1+'&user2='+user2+'">Revert</a> / <a href="javascript:var message = getMessage(\'revert\', \''+user1+'\', \''+user2+'\');">Message</a>) (<a href="http://en.wikipedia.org/w/index.php?title=' + _GET['title'] + '&action=edit&oldid=' + _GET['oldid'] + '&vandalism=1&user1='+user1+'&user2='+user2+'">Vandalism</a> / <a href="javascript:var message = getMessage(\'vandalism\', \''+user1+'\', \''+user2+'\');">Message</a>) (Warn: <a href="http://en.wikipedia.org/w/index.php?title=User_talk:'+user2+'&action=edit&section=new&warn=1">Test</a> / <a href="http://en.wikipedia.org/w/index.php?title=User_talk:'+user2+'&action=edit&section=new&warn=2">Blatant</a> / <a href="http://en.wikipedia.org/w/index.php?title=User_talk:'+user2+'&action=edit&section=new&warn=3">Nonsense</a> / <a href="http://en.wikipedia.org/w/index.php?title=User_talk:'+user2+'&action=edit&section=new&warn=4">Blanking</a>)';
  } else if (location.href.match(/revert=1/)) {
    document.getElementById('wpSummary').value = 'Reverted edits by [[Special:Contributions/'+_GET['user2']+'|'+_GET['user2']+']] to version ' + _GET['oldid']+' by [[Special:Contributions/'+_GET['user1']+'|'+_GET['user1']+']]';
    document.getElementById('editform').submit();
  } else if (location.href.match(/revert=2/)) {
    document.getElementById('wpSummary').value = 'Reverted edits by [[Special:Contributions/'+_GET['user2']+'|'+_GET['user2']+']] to version ' + _GET['oldid']+' by [[Special:Contributions/'+_GET['user1']+'|'+_GET['user1']+']] ('+_GET['message']+')';
    document.getElementById('editform').submit();
  } else if (location.href.match(/vandalism=1/)) {
    document.getElementById('wpSummary').value = 'Reverted vandalism by [[Special:Contributions/'+_GET['user2']+'|'+_GET['user2']+']] to version ' + _GET['oldid']+' by [[Special:Contributions/'+_GET['user1']+'|'+_GET['user1']+']]';
    document.getElementById('editform').submit();
  } else if (location.href.match(/vandalism=2/)) {
    document.getElementById('wpSummary').value = 'Reverted vandalism by [[Special:Contributions/'+_GET['user2']+'|'+_GET['user2']+']] to version ' + _GET['oldid']+' by [[Special:Contributions/'+_GET['user1']+'|'+_GET['user1']+']] ('+_GET['message']+')';
    document.getElementById('editform').submit();
  } else if (location.href.match(/warn=1/)) {
    document.getElementById('wpSummary').value = 'Vandalism warning';
    document.getElementById('wpTextbox1').value = '{{sub'+'st:test}} ~~'+'~~';
    document.getElementById('editform').submit();
  } else if (location.href.match(/warn=2/)) {
    document.getElementById('wpSummary').value = 'Vandalism warning';
    document.getElementById('wpTextbox1').value = '{{sub'+'st:blatantvandal}} ~~'+'~~';
    document.getElementById('editform').submit();
  } else if (location.href.match(/warn=3/)) {
    document.getElementById('wpSummary').value = 'Vandalism warning';
    document.getElementById('wpTextbox1').value = '{{sub'+'st:test2}} ~~'+'~~';
    document.getElementById('editform').submit();
  } else if (location.href.match(/warn=4/)) {
    document.getElementById('wpSummary').value = 'Vandalism warning';
    document.getElementById('wpTextbox1').value = '{{sub'+'st:test2a}} ~~'+'~~';
    document.getElementById('editform').submit();
  }
});

Konman72 09:56, 5 August 2006 (UTC)[reply]

Thanks for your contribution. :) --LorianTC 10:14, 5 August 2006 (UTC)[reply]
Glad I could help, thanks for writing this thing in the first place ;) Konman72 10:15, 5 August 2006 (UTC)[reply]

Fix for undo[edit]

When reverting beyond the newest revision, the new undo option messes up the reported username. To fix, replace this line:

    var user2 = getElementsByClass('diff-ntitle',null,'td'); user2 = user2[0].getElementsByTagName('a')[2].innerHTML;

with:

   var user2 = getElementsByClass('diff-ntitle',null,'td');
   if (user2[0].getElementsByTagName('a')[2].innerHTML == 'undo')
       user2 = user2[0].getElementsByTagName('a')[3].innerHTML;
   else
       user2 = user2[0].getElementsByTagName('a')[2].innerHTML;

I will leave it to someone to double check this and/or improve it before modifying the code on the project page. Seems to work for me. Thanks for the script, working nicely -- will add my own auto-messages shortly ;). here 05:31, 8 December 2006 (UTC)[reply]

Three words of thanks, thank you to Lorian for the script v1.0, to Konman72 for the modification v1.1 and here for the undo fix! (umm (v1.1.1) I guess), looks good! :-) ▪◦▪≡Ѕirex98≡ 15:20, 8 December 2006 (UTC)[reply]
a bug, on a revert here it says (Reverted edits by Antandrus to version 92946117 by 66.121.167.14) it should had said (Reverted edits by Itis51890 to version 92946117 by Antandrus) I wasn't reverting Antandrus. ▪◦▪≡Ѕirex98≡ 17:52, 8 December 2006 (UTC)[reply]

additional info: I was here went I clicked revert ▪◦▪≡Ѕirex98≡ 17:57, 8 December 2006 (UTC)[reply]

I dunno, worked fine for me from the same place, diff. That said, my fix is somewhat uneducated... so please do report more problems if you run into them. here 23:14, 8 December 2006 (UTC)[reply]
Your test accidentally added the vandalism back, the text would had been right (Reverted edits by Itis51890 to version 92946247 by Antandrus) but the revert isn't, as it added back the text "Ivan Cho"..."thus being one of the greatest human figures of all times", which shouldn't be there. [1].. Look at Antandrus earlier good revert that removed the vandalism [2].
When I made a revert earlier the opposite happen [3] the text is wrong (Reverted edits by Antandrus to version 92946117 by 66.121.167.14) but the revert was correct as it removed Itis51890 vandalism ▪◦▪≡Ѕirex98≡ 02:32, 9 December 2006 (UTC)[reply]
Wow, you're right. I think this has something to do with the oldid. Check these diff pages, same diff, different oldid listed in the url: prev,93033256 , next,92961503. Since the script is basing it's revert on the oldid, this variation will mess up what version it reverts to. I don't believe my code changes are influencing this behavior. I haven't been able to replicate the misreported names.
I'm not sure it has ever worked perfectly when scrolling through diffs in this manner? Unfortunately, I don't have time to get to the bottom of this right now! Anyone? here 06:19, 9 December 2006 (UTC)[reply]
That's cool, I'll wait to see if anyone else can make a fix, or if you know of another good one, I liked the script a lil better then pop-up's, then again It just may be a matter of me getting used to it, thanks for looking into it. ps I was getting sick of my sig after looking this page, too big! :-) ▪◦▪≡ЅiREX≡Talk 07:00, 9 December 2006 (UTC)[reply]
I've always used godmode-lite for rollback... currently maintained at User:Olliminatore/godmode-light.js... but I love the message feature on these revert tools, an essential addition. I also hope to see a solution here shortly! here 09:16, 9 December 2006 (UTC)[reply]

I fixed the problem. The "if" is now not necessary, as I think every diff has "undo" link now. – rotemlissTalk 11:38, 20 December 2006 (UTC)[reply]

thanks. will try it out. here 01:47, 22 December 2006 (UTC)[reply]

bug[edit]

There seams to be a problem with the script, instead of setting the value of user2 to a user name its setting it to "Talk" (see User talk:Talk) as if its getting the content of the fifth 'a' element (Talk) and not the forth.— miketm - Queen WikiProject - 15:10, 28 January 2007 (UTC)[reply]

Additional info - see here where the "vandalism" button worked, but the summary says "(Reverted vandalism by Talk to version 97221758 by SatyrTN)". -- SatyrTN (talk | contribs) 17:59, 29 January 2007 (UTC)[reply]
Yep - a change in the "user2" statement to refer to item #3 instead of item #4 fixed it. I'm going to make the change here, but note you'll have to refresh your cache for it to work. -- SatyrTN (talk | contribs) 18:11, 29 January 2007 (UTC)[reply]

Bug[edit]

When using the "Nonsense" option, instead of sending the warning to the offending editor's user talk page, the warning was sent to a newly created talk page for a nonexistent user named "Current revision." See the history for User talk: Current revision.

I don't know java script, so I don't know how to fix this bug. But I'm rather leery of using the script now for fear some other unanticipated event will result. --Yksin 18:50, 30 March 2007 (UTC)[reply]

Vandalism warnings[edit]

Is it possible to use the uw warnings instead? - BANG! 02:43, 9 May 2007 (UTC)[reply]

Concur! - BillCJ (talk) 01:55, 29 March 2008 (UTC)[reply]

Bug[edit]

When I access the diff from the user contributions list, it reverts to the current (vandalized) version instead of the previous one. - BANG! 00:38, 13 May 2007 (UTC)[reply]

firefox[edit]

i think it is compatible with firefox it does't work ! but in IE it works--mardetanha(/\/\ ()[-]$[- /\/) (talk) 21:19, 8 March 2008 (UTC)[reply]

UW functionality[edit]

I've been experimenting with adding the UW warning templates to the script at User:BillCJ/Scripts/Revert tools-uw. I'd also like to expand the warnings to include the "uw-vandal" range of 1 through 4, but I've had difficulty getting it to work. In addition, it would be nice to add the pagename function to the script, so that the warning include the page on which the vandalism occured. Unfourtunately, I know absolutely nothing about these scripts, so any advice/help would be appreciated. This script appears to be the only one available that actually works with IE, and it would be nice to get it updated to the new UW codes, with a few more additional functions added to it. Thanks. - BillCJ (talk) 21:53, 9 April 2008 (UTC)[reply]

I've been able to get my additions working on my test page, so the UW-functionality is in place. I have 9 different Warn tabs now, instead of the original 4, and all use the UW templates. Anyone is welcome to try out my script now though, and if there's support for it, we can add it here, or set up a new script page. Now the final thing I'd like to add is the PAGENAME function, but again, I have no idea how to do it! - BillCJ (talk) 03:49, 14 April 2008 (UTC)[reply]

Cross-skin support[edit]

I just found this tool and it looks like exactly what I've been wanting.

I notice that as-is right now, not all skins are supported. I did some tinkering and found a small change that could be implemented to allow this script to work in any skin. If someone could check the change and implement it if there are no problems, I'd appreciate it. In the meantime, I've just pasted the code (with the change) to my personal javascript page for my chosen skin.

Here's the change:

    WAS: document.getElementById('contentSub').innerHTML
     IS: document.getElementById('difference').innerHTML

...as it appears all skins have a 'difference' id, but not all have a 'contentSub' id.

-- BullWikiWinkle 05:30, 7 October 2008 (UTC)[reply]