Wikipedia talk:WikiProject User scripts/Scripts/Revert tools
From Wikipedia, the free encyclopedia
Contents |
[edit] Instructions
[edit] Installation
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');
[edit] 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.
[edit] 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 |
[edit] Comments
[edit] 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)
[edit] 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)
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)
[edit] bug
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)
- 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)
[edit] Bug
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)
[edit] Vandalism warnings
Is it possible to use the uw warnings instead? - BANG! 02:43, 9 May 2007 (UTC)
[edit] Bug
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)
[edit] firefox
i think it is compatible with firefox it does't work ! but in IE it works--mardetanha(/\/\ ()[-]$[- /\/) (talk) 21:19, 8 March 2008 (UTC)
[edit] UW functionality
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)
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)