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 |
1.1 | Edits by Konman72, see talk page | MonoBook | Konman72 |
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)