Wikipedia talk:WikiProject User scripts/Scripts/Revert tools
Instructions
Installation
To install the script:
- Go to Special:Mypage/monobook.js and click on edit.
- Copy/Paste the following script into the edit box, and save. Follow the displayed instruction to bypass your browser cache.
document.write('<script type="text/javascript" src="http://en.wikipedia.org/w/index.php?title=Wikipedia:WikiProject User scripts/Scripts/Revert tools&action=raw&ctype=text/javascript&dontcountme=s"></script>');
Usage
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
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
Alterations
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 = '{{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)
- Thanks for your contribution. :) --LorianTC 10:14, 5 August 2006 (UTC)
- Glad I could help, thanks for writing this thing in the first place ;) Konman72 10:15, 5 August 2006 (UTC)
Fix for undo
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)
- 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)
- 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)
additional info: I was here went I clicked revert ▪◦▪≡Ѕirex98≡ 17:57, 8 December 2006 (UTC)
- 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)
- 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)
- 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)
- 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)
- 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)
- 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)
- 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)
I fixed the problem. The "if" is now not necessary, as I think every diff has "undo" link now. – rotemliss – Talk 11:38, 20 December 2006 (UTC)
- thanks. will try it out. ∴ here…♠ 01:47, 22 December 2006 (UTC)