Wikipedia talk:WikiProject User scripts/Scripts/Revert tools

message: 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§ion=new&warn=1">Test</a> / <a href="http://en.wikipedia.org/w/index.php?title=User_talk:'+user2+'&action=edit§ion=new&warn=2">Blatant</a> / <a href="http://en.wikipedia.org/w/index.php?title=User_talk:'+user2+'&action=edit§ion=new&warn=3">Nonsense</a> / <a href="http://en.wikipedia.org/w/index.php?title=User_talk:'+user2+'&action=edit§ion=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 = ' ~~'+'~~';
    document.getElementById('editform').submit();
  } else if (location.href.match(/warn=2/)) {
    document.getElementById('wpSummary').value = 'Vandalism warning';
    document.getElementById('wpTextbox1').value = ' ~~'+'~~';
    document.getElementById('editform').submit();
  } else if (location.href.match(/warn=3/)) {
    document.getElementById('wpSummary').value = 'Vandalism warning';
    document.getElementById('wpTextbox1').value = ' ~~'+'~~';
    document.getElementById('editform').submit();
  } else if (location.href.match(/warn=4/)) {
    document.getElementById('wpSummary').value = 'Vandalism warning';
    document.getElementById('wpTextbox1').value = ' ~~'+'~~';
    document.getElementById('editform').submit();
  }
});
Konman72 09:56, 5 August 2006 (UTC)
replies: text: Thanks for your contribution. :) --LorianTC 10:14, 5 August 2006 (UTC)
replies: text: Glad I could help, thanks for writing this thing in the first place ;) Konman72 10:15, 5 August 2006 (UTC)
thread_title: Alterations

message: 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)
replies: text: 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)
replies: text: 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)
thread_title:  bug 

message: 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)
thread_title:  Bug 

message: Is it possible to use the uw warnings instead? - BANG! 02:43, 9 May 2007 (UTC)
replies: text: Concur! - BillCJ (talk) 01:55, 29 March 2008 (UTC)
thread_title:  Vandalism warnings 

message: 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)
thread_title:  Bug 

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

message: 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)
thread_title: UW functionality

message: 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)
thread_title:  Cross-skin support