Jump to content

User:Beetstra/Gadget-Spam-whitelist-Handler.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Beetstra (talk | contribs) at 05:21, 5 June 2016 (intermediate save). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
		/**
		 * Support for quick handling of the [[MediaWiki talk:Spam-whitelist]] at en.wikipedia.
		 * See [[:m:User:Erwin/SBHandler]] for more information.
		 * Tested only in Firefox.
		 *
		 * Author: [[:m:User:Erwin]], October 2008 - February 2009
		 * License: Quadruple licensed GFDL, GPL, LGPL and Creative Commons Attribution 3.0 (CC-BY-3.0)
		 *
		 * Version history:
		 *
		 * - This tool uses code from DelReqHandler at Commons.
		 *   [[:Commons:MediaWiki:Gadget-DelReqHandler.js]] (oldid=15093612)
		 *   Author: [[:Commons:User:Lupo]], October 2007 - January 2008
		 *   License: Quadruple licensed GFDL, GPL, LGPL and Creative Commons Attribution 3.0 (CC-BY-3.0)
		 *
		 * - Script adapted to account for change in section edit links -- [[m:user:billinghurst]] 2013-05
		 *
		 * - User sDrewth reported the script is broken. -- 2013-11-27
		 *
		 * - Cleaned up to pass JSHint, and migrated use of (now deprecated) legacy wikibits tof
		 *   jQuery and newer MediaWiki core built-in javascript libraries. --Krinkle 2013-11-28
		 * 
		 * - ported to en.wikipedia, adapted which pages to handle  --Beetstra 2015-04-25
		 * - copied from [[User:Beetstra/Gadget-Spam-whitelist-Handler.js]] -- Beetstra 2016-06-05
		 */
		/*jshint unused:true, eqnull:true, browser:true, white:true, indent:4 */
		/*global mw, $ */
		/*global WLHandlerAddComment, WLHandlerRemComment, WLHandlerCloseComment, WLHandlerRevComment, WLHandlerDecComment */
		// <nowiki>
		(function () {
		    // Guard against double inclusions
		    if (typeof window.WLHandler !== 'undefined') {
		        return;
		    }
		
		    var conf = mw.config.get([
		        'wgUserGroups',
		        'wgPageName',
		        'wgServer',
		        'wgScriptPath',
		        'wgUserName'
		    ]);
		
		    if ((conf.wgPageName.substr(0, 33) !== 'MediaWiki_talk:Spam-whitelist')) {
		        return;
		   }
		
		    var action, fakesource, urls, params, logtitle, tprevid, log_text, summary;
		
		    var WLrequest;
		    var BLdebug;
		
		    var BLlist;
		    var BLlog;
		
		    var BLUtils = {
		        // userIsInGroup (from Commons:MediaWiki:Utilities.js)
		        UserIsInGroup: function (group) {
		            if (conf.wgUserGroups) {
		                if (!group || group.length === 0) {
		                    group = '*';
		                }
		                for (var i = 0; i < conf.wgUserGroups.length; i++) {
		                    if (conf.wgUserGroups[i] === group) {
		                        return true;
		                    }
		                }
		            }
		            return false;
		        },
		
		        // setEditSummary (from Commons:MediaWiki:Utilities.js)
		        setEditSummary: function (text) {
		            if (document.editform == null || document.editform.wpSummary == null) {
		                return;
		            }
		            var summary = document.editform.wpSummary.value;
		            if (summary == null || summary.length === 0) {
		                document.editform.wpSummary.value = text;
		            } else if (summary.substr(-3) === '*/ ' || summary.substr(-2) === '*/') {
		                document.editform.wpSummary.value += text;
		            } else {
		                document.editform.wpSummary.value += '; ' + text;
		            }
		        },
		
		        // makeRawLink (from Commons:MediaWiki:Utilities.js)
		        makeRawLink: function (name, url, target) {
		            var link = document.createElement('a');
		            link.setAttribute('href', url);
		            if (target) {
		                link.setAttribute('target', target);
		            }
		            link.appendChild(document.createTextNode(name));
		            return link;
		        },
		
		        // The following function is defined in several places, and unfortunately, it is defined
		        // wrongly in some places. (For instance, in [[:en:User:Lupin/popups.js]]: it should use
		        // decodeURIComponent, not decodeURI!!!) Make sure we've got the right version here:
		        getParamValue: function (paramName) {
		            var cmdRe = new RegExp('[&?]' + paramName + '=([^&]*)');
		            var m = cmdRe.exec(document.location.href);
		            if (m) {
		                try {
		                    return decodeURIComponent(m[1]);
		                } catch (someError) {}
		            }
		            return null;
		        }
		    };
		
		    /**** Enable the whole shebang only for sysops and stewards. */
		    var WLHandler;
		    if (BLUtils.UserIsInGroup('sysop') || BLUtils.UserIsInGroup('steward')) {
		
		        WLHandler = {
		
		            /*------------------------------------------------------------------------------------------
		            User:XLinkBot/RevertList requests closing: add "[add]", "[remove]", "[reverted]" and "[decline]" links to
		            the left of the section edit links of a request.
		            ------------------------------------------------------------------------------------------*/
		
		            wl_close_add: 'wl_close_add',
		            wl_close_rem: 'wl_close_rem',
		            wl_close_na: 'wl_close_na',
		            wl_close_rev: 'wl_close_rev',
		            wl_close_dec: 'wl_close_dec',
		            wl_add: 'addRL',
		            wl_rem: 'remRL',

		            BLcloseRequestLinks: function () {
		                function addRequestLinks(name, href, before, parent) {
		                    parent.insertBefore(document.createTextNode('['), before);
		                    parent.insertBefore(BLUtils.makeRawLink(name, href), before);
		                    parent.insertBefore(document.createTextNode(']'), before);
		                }
		
		                var param = BLUtils.getParamValue('fakeaction');
						fakesource = BLUtils.getParamValue('fakesource');
		                var wpAction = BLUtils.getParamValue('action');
		                var edit_lks, anchors, ignore;
		                var anchor, href, orig_bracket, title, lk_name1, lk_name2, lk_action1, lk_action2;
		                if (param == null) {
		                    if (conf.wgPageName === 'MediaWiki_talk:Spam-whitelist') {
		                        // We're on [[MediaWiki_talk:Spam-whitelist]]
		                        edit_lks = $('span.mw-editsection').toArray();
		                        if (edit_lks.length === 0) {
		                            return;
		                        }
		                        for (i = 0; i < edit_lks.length; i++) {
		                            // Set to true if the addition or removal section is found
		                            ignore = false;
		                            // Find the A within:
		                            anchors = edit_lks[i].getElementsByTagName('a');
		                            if (anchors != null && anchors.length > 0) {
		                                anchor = anchors[0];
		                                href = anchor.getAttribute('href');
		                                title = anchor.getAttribute('title');
		                                if (title.indexOf('additions') > 0 ) {
		                                    ignore = true;
		                                    lk_name2 = 'add WL';
		                                    lk_action2 = WLHandler.wl_close_add;
		                                } else if (title.indexOf('removals') > 0) {
		                                    ignore = true;
		                                    lk_name1 = 'remove WL';
		                                    lk_action1 = WLHandler.wl_close_rem;
		                                    lk_name2 = null;
		                                } else if (title.indexOf('problems') > 0) {
		                                    lk_name1 = null;
		                                    lk_action1 = null;
		                                }
		                                if (href.indexOf('MediaWiki_talk:Spam-whitelist') > 0 && href.indexOf('&section=') > 0 && lk_name1 != null && !ignore) {
		                                    orig_bracket = edit_lks[i].firstChild;
		                                    addRequestLinks(lk_name1, href + '&fakesource=whitelist&fakeaction=' + lk_action1, orig_bracket, edit_lks[i]);
		                                    if (lk_name2 !== null) {
												addRequestLinks(lk_name2, href + '&fakesource=whitelist&fakeaction=' + lk_action2, orig_bracket, edit_lks[i]);
											}
		                                    addRequestLinks('decline', href + '&fakesource=whitelist&fakeaction=' + WLHandler.bl_close_dec, orig_bracket, edit_lks[i]);
		                                }
		                            }
		                        }
		                    } 
		
		                } else if (param != null) {
		                    // We're on a request page
		                    var summary = null;
		                    action = null;
		                    var text = document.editform.wpTextbox1;
		                    urls = [];
		                    var i, m, url;
		                    var append;
		
		                    //Only do anything if we're editing a section.
		                    if (document.getElementsByName('wpSection') == null) {
		                        return;
		                    }
		
		                    // Get URLs
		                    if (conf.wgPageName == 'MediaWiki_talk:Spam-whitelist') {
		                        var reurl = /\{\{requestlink|(.*?)\}\}/g;
		                        m = text.value.match(reurl);
		                        if (m != null) {	
		                            for (i = 0; i < m.length; i++) {
		                                url = m[i].substr(m[i].indexOf('|') + 1, m[i].length - m[i].indexOf('|') - 3); // Can't simply refer to the group
		                                urls.push('\\b' + url.replace(/\./g, '\\.') + '\\b');
		                            }
		                        }
		                        WLrequest = text.value.match(/^\=.*?\=$/m);
		                        if (WLrequest && WLrequest.length > 0) {
		                            WLrequest = WLrequest[0].substr(2, WLrequest[0].length - 4); // MediaWiki_talk:Spam-whitelist uses level 2 ('== sectionname ==')
		                            if (WLrequest.substr(0,1) == ' ') {
		                            	WLrequest = WLrequest.substr(1, 256); // try to strip initial space
		                            }
		                            if (WLrequest.substr(0,1) == ' ') {
		                            	WLrequest = WLrequest.substr(1, 256); // try to strip initial space
		                            }
		                            if (WLrequest.substr(0,1) == ' ') {
		                            	WLrequest = WLrequest.substr(1, 256); // try to strip initial space
		                            }
		                        } else {
		                            WLrequest = '';
		                        }
		
		                        if (urls === '' && WLrequest !== '') {
		                            m = WLrequest.match(/(?:www\.|)[^\s]*?\.[a-zA-Z]{2,3}/g);
		                            for (i = 0; i < m.length; i++) {
		                                if (m[i].substr(0, 4) === 'www.') {
		                                    urls.push('\\b' + m[i].substr(4).replace(/\./g, '\\.') + '\\b');
		                                } else {
		                                    urls.push('\\b' + m[i].replace(/\./g, '\\.') + '\\b');
		                                }
		                            }
		                        }
		                    } 
		
		                    var copyWarn = document.getElementById('editpage-copywarn');
		                    copyWarn.innerHTML = copyWarn.innerHTML + '<div style=\"border: 1px solid; margin: 5px; padding: 5px;\"><h3>WLHandler</h3>\n<div id=\"BLdebug\"></div>';
		                    BLdebug = document.getElementById('BLdebug');
		                    if (param == WLHandler.wl_close_add) {
		                        summary = "Added to WhiteList";
		                        append = (typeof WLHandlerAddComment !== 'undefined' ? WLHandlerAddComment : ':{{Added}} to [[User:XLinkBot/RevertList]]. --~~~~');
		                        action = WLHandler.wl_add;
		                    } else if (param == WLHandler.wl_close_rem) {
		                        summary = "Removed from WhiteList";
		                        append = (typeof WLHandlerRemComment !== 'undefined' ? WLHandlerRemComment : ':{{Removed}} from [[User:XLinkBot/RevertList]]. --~~~~');
		                        action = WLHandler.wl_rem;
		                    } else if (param == WLHandler.wl_close_na) {
		                        summary = "Closed";
		                        append = (typeof WLHandlerCloseComment !== 'undefined' ? WLHandlerCloseComment : ':{{Close}}. --~~~~');
		                    } else if (param == WLHandler.wl_close_dec) {
		                        summary = "Declined";
		                        append = (typeof WLHandlerDecComment !== 'undefined' ? WLHandlerDecComment : ':{{Declined}}. --~~~~');
		                    } else if (param == WLHandler.wl_close_CR) {
		                    	summary = "did you read [[/Common requests]]?"
		                    	append = (typeof WLHandlerDecComment !== 'undefined' ? WLHandlerDecComment : ':Did you read [[/Common requests]]?  --~~~~')
		                    }
		                    if (summary != null) {
		                        if (wpAction == 'edit') {
		                            BLUtils.setEditSummary(summary);
		                            text.value += '\n' + append;
		                        }
		                        if (action != null && urls !== '') {
		                            BLdebug.innerHTML += '<span style=\"font-weight:bold;\">Action: </span>' + action + ';<br />';
		                            BLdebug.innerHTML += '<span style=\"font-weight:bold;\">Domains: </span>' + urls.join(', ') + ';<br />';
		                            var editform = document.getElementById('editform');
		                            editform.action += '&fakeaction=' + param + '&fakesource=' + fakesource;
		
		                            // Remove save button
		                            var wpSave = document.getElementById('wpSave');
		                            wpSave.parentNode.removeChild(wpSave);
		
		                            //Add save link:
		                            wpSave = document.createElement('span');
		                            wpSave.setAttribute('id', 'wpSave');
									} else if (action == WLHandler.wl_rem) {
										wpSave.innerHTML = '<a href=\"javascript:WLHandler.HandlerSaveRequest()\">Save and remove domains from whitelist</a> ';
									} else if (action == WLHandler.wl_add) {
										wpSave.innerHTML = '<a href=\"javascript:WLHandler.HandlerSaveRequest()\">Save and add domains to whitelist</a> ';
									}
		
		                            var wpPreview = document.getElementById('wpPreview');
		                            wpPreview.parentNode.insertBefore(wpSave, wpPreview);
		                        }
		                        // Don't close the window to allow adding a comment.
		                        if (text.scrollHeight > text.clientHeight) {
		                            text.scrollTop = text.scrollHeight - text.clientHeight;
		                        }
		                        text.focus();
		                    }
		                }
		            },
		
		            HandlerSaveRequest: function () {
		                BLdebug.innerHTML += '<span style=\"font-weight:bold;\">Saving request…</span><br />';
		                var summary = document.getElementById('wpSummary').value;
		                var text = document.getElementById('wpTextbox1').value;
		                var section = document.getElementsByName('wpSection')[0].value;
		                var minor = document.getElementById('wpMinoredit');
		                if (minor.checked) {
		                    minor = '&minor=1';
		                } else {
		                    minor = '&notminor=1';
		                }
		                var watch = document.getElementById('wpWatchthis');
		                if (watch.checked) {
		                    watch = '&watchlist=watch';
		                } else {
		                    watch = '&watchlist=unwatch';
		                }
		                if (section !== '') {
		                    section = '&section=' + encodeURIComponent(section);
		                }
		                var token = document.getElementsByName('wpEditToken')[0].value;
		                var query = 'format=xml';
		                var params = 'action=edit&title=' + encodeURIComponent(conf.wgPageName) + '&summary=' + encodeURIComponent(summary) + '&text=' + encodeURIComponent(text) + section + minor + watch + '&token=' + encodeURIComponent(token);
		                WLHandler.BLpostRequest(query, WLHandler.BLsetLocation, params, true);
		            },
		
		            BLsetLocation: function (request) {
		                var xml = request.responseXML;
		                var location = conf.wgServer + conf.wgScriptPath + '/index.php' +
		                    '?title=Special:Spamwhitelist' +
		                    '&action=' + action +
							'&fakesource=' + fakesource + 
		                    '&urls=' + urls.join('|') +
		                    '&request=' + WLrequest;
		                if (xml != null) {
		                    var edits = xml.getElementsByTagName('edit');
		                    if (edits.length === 0) {
		                        BLdebug.innerHTML = '<div style=\"font-weight:bold;\">Saving might have failed. Please close the request yourself. ' +
		                            'Use <a href="' + location +
		                            '" title="Special:Spamwhitelist">Special:Spamwhitelist</a>' +
		//                            ' to add/remove the domains to/from the revertlist.<br />Params:<br /><pre>' + params + '</pre><br />Response:<pre>' + request.responseText + '</pre></div>';
		                            ' to add/remove the domains to/from the Spam-whitelist.<br />Params:<br /><pre>' + params + '</pre><br />Response:<pre>' + request.responseText + '</pre></div>';
		                        return;
		                    }
		                    var result = edits[0].getAttribute('result');
		                    WLHandler.oldid = edits[0].getAttribute('newrevid');
		                    if (result != 'Success') {
		                        BLdebug.innerHTML = '<div style=\"font-weight:bold;\">Saving failed. Please close the request yourself. ' +
		                            'Use <a href="' + location +
		                            '" title="Special:Spamwhitelist">Special:Spamwhitelist</a>' +
		//                            ' to add/remove the domains to/from the revertlist.<br />Params:<br /><pre>' + params + '</pre><br />Response:<pre>' + request.responseText + '</pre></div>';
		                            ' to add/remove the domains to/from the Spam-whitelist.<br />Params:<br /><pre>' + params + '</pre><br />Response:<pre>' + request.responseText + '</pre></div>';
		                        return;
		                    } else {
		                        window.location = location;
		                    }
		                } else {
		                    BLdebug.innerHTML += '<div style=\"font-weight:bold;\">ERROR: ' + request.status + '<br /> Please close the request yourself. ' +
		                        'Use <a href="' + location +
		                        '" title="Special:Spamwhitelist">Special:Spamwhitelist</a>' +
		//                        ' to add/remove the domains to/from the revertlist.<br />Params:<br /><pre>' + params + '</pre><br />Response:<pre>' + request.responseText + '</pre></div>';
		                        ' to add/remove the domains to/from the Spam-whitelist.<br />Params:<br /><pre>' + params + '</pre><br />Response:<pre>' + request.responseText + '</pre></div>';
		                    return;
		                }
		            },
		
		            /*------------------------------------------------------------------------------------------
		            Add to revertlist or whitelist.
		            ------------------------------------------------------------------------------------------*/
		            edittoken: '',
		            text: '',
		            request: '',
		            urls: '',
		            action: '',
		            timestamp: '',
		            oldid: '',
		            custom: false,
		
		            BLWrapper: function () {
		                WLHandler.action = BLUtils.getParamValue('action');
		                WLHandler.fakesource = BLUtils.getParamValue('fakesource');
		                WLHandler.urls = BLUtils.getParamValue('urls');
		                WLHandler.request = BLUtils.getParamValue('request');
						if (WLHandler.request.substr(0,1) == ' ') {
							WLHandler.request = WLHandler.request.substr(1, 256); // try to strip initial space
						}
						if (WLHandler.request.substr(0,1) == ' ') {
							WLHandler.request = WLHandler.request.substr(1, 256); // try to strip initial space
						}
						if (WLHandler.request.substr(0,1) == ' ') {
							WLHandler.request = WLHandler.request.substr(1, 256); // try to strip initial space
						}
						
		                var header = document.getElementsByTagName('h1')[0];
		                var content = document.getElementById('bodyContent');
		
						if (WLHandler.action == WLHandler.wl_add || WLHandler.action == WLHandler.wl_rem) {
							document.title = 'User:XLinkBot/RevertList';
							header.innerHTML = 'User:XLinkBot/RevertList';
							content.innerHTML = '<h3 id=\"siteSub\">en.wikipedia whitelist tool.</h3>' +
								'<p>Use this tool to add domains to the <a href=\"//en.wikipedia.org/wiki/User:XLinkBot/RevertList\" title=\"User:XLinkBot/RevertList\">User:XLinkBot/RevertList</a>, or remove them, and log the change. Note that it does not escape paths. <span style=\"font-weight:bold;\">Do not use this tool unless you have a basic understanding of regex.</span> You still need to confirm the changes. Do not assume that the proposed edit is correct.</p>';
						} else if (WLHandler.action == WLHandler.bl_add || WLHandler.action == WLHandler.bl_rem) {
							document.title = 'MediaWiki:Spam-whitelist';
							header.innerHTML = 'MediaWiki:Spam-whitelist';
							content.innerHTML = '<h3 id=\"siteSub\">en.wikipedia whitelist tool.</h3>' +
								'<p>Use this tool to add domains to the <a href=\"//en.wikipedia.org/wiki/MediaWiki:Spam-whitelist\" title=\"MediaWiki:Spam-whitelist\">MediaWiki:Spam-whitelist</a>, or remove them, and log the change. Note that it does not escape paths. <span style=\"font-weight:bold;\">Do not use this tool unless you have a basic understanding of regex.</span> You still need to confirm the changes. Do not assume that the proposed edit is correct.</p>';
						}
						
		
		                if ((WLHandler.action == WLHandler.bl_add || WLHandler.action == WLHandler.bl_rem) && WLHandler.urls != null && WLHandler.urls !== '' && WLHandler.request != null) {
		                    content.innerHTML += '<div id=\"RLstatus\" style=\"font-style: italic; border: 1px solid; padding: 5px; float:right;\">' +
		                                        '<span id=\"Sthrobber\" style=\"text-align:center; font-weight:bold; float:right;\">' +
		                                        '<img src=\"/media/wikipedia/commons/d/d2/Spinning_wheel_throbber.gif\" alt=\"Loading\">' +
		                                        'Loading…</span>' +
		                                        '<br clear=\"all\" />' +
		                                        '<table><tr style=\"vertical-align:top;\"><td>' +
		                                        '<h5>whitelist</h5>' +
		                                        '<ul><li id=\"SgetRL\" style=\"color:grey;\">Get whitelist text</li>' +
		                                        '<li id=\"SaddRL\" style=\"color:grey;\">Add/remove domains</li>' +
		                                        '<li id=\"SgetC\" style=\"color:grey;\">Get changes from server</li>' +
		                                        '<li id=\"SparseRL\" style=\"color:grey;\">Parse and show changes</li>' +
		                                        '<li id=\"SconfirmRL\" style=\"color:grey;\">Confirm changes</li>' +
		                                        '<li id=\"SsaveRL\" style=\"color:grey;\">Save changes</li></ul></td><td>' +
		                                        '<h5>Log</h5>' +
		                                        '<ul><li id=\"SgetL\" style=\"color:grey;\">Get log text</li>' +
		                                        '<li id=\"SaddL\" style=\"color:grey;\">Add/remove domains</li>' +
		                                        '<li id=\"SsaveL\" style=\"color:grey;\">Save changes</li>' +
		                                        '</ul></tr></table></div><br clear=\"all\" />' +
		                                        '<h3>RevertList</h3><div id=\"RLlist\"></div>' +
		                                        '<h3>Log</h3><div id=\"RLlog\"></div>';
		                    BLlist = document.getElementById("RLlist");
		                    BLlog = document.getElementById("RLlog");
		                    WLHandler.BLgetRequest('action=query&prop=info&intoken=edit&titles=MediaWiki:Spam-whitelist', WLHandler.BLgetRL, true);
		                } else if ((WLHandler.action == WLHandler.wl_add || WLHandler.action == WLHandler.wl_rem) && WLHandler.urls != null && WLHandler.urls !== '' && WLHandler.request != null) {
		                    content.innerHTML += '<div id=\"RLstatus\" style=\"font-style: italic; border: 1px solid; padding: 5px; float:right;\">' +
		                                        '<span id=\"Sthrobber\" style=\"text-align:center; font-weight:bold; float:right;\">' +
		                                        '<img src=\"/media/wikipedia/commons/d/d2/Spinning_wheel_throbber.gif\" alt=\"Loading\">' +
		                                        'Loading…</span>' +
		                                        '<br clear=\"all\" />' +
		                                        '<table><tr style=\"vertical-align:top;\"><td>' +
		                                        '<h5>RevertList</h5>' +
		                                        '<ul><li id=\"SgetRL\" style=\"color:grey;\">Get RevertList text</li>' +
		                                        '<li id=\"SaddRL\" style=\"color:grey;\">Add/remove domains</li>' +
		                                        '<li id=\"SgetC\" style=\"color:grey;\">Get changes from server</li>' +
		                                        '<li id=\"SparseRL\" style=\"color:grey;\">Parse and show changes</li>' +
		                                        '<li id=\"SconfirmRL\" style=\"color:grey;\">Confirm changes</li>' +
		                                        '<li id=\"SsaveRL\" style=\"color:grey;\">Save changes</li></ul></td><td>' +
		                                        '<h5>Log</h5>' +
		                                        '<ul><li id=\"SgetL\" style=\"color:grey;\">Get log text</li>' +
		                                        '<li id=\"SaddL\" style=\"color:grey;\">Add/remove domains</li>' +
		                                        '<li id=\"SsaveL\" style=\"color:grey;\">Save changes</li>' +
		                                        '</ul></tr></table></div><br clear=\"all\" />' +
		                                        '<h3>RevertList</h3><div id=\"RLlist\"></div>' +
		                                        '<h3>Log</h3><div id=\"RLlog\"></div>';
		                    BLlist = document.getElementById("RLlist");
		                    BLlog = document.getElementById("RLlog");
		                    WLHandler.BLgetRequest('action=query&prop=info&intoken=edit&titles=User:XLinkBot/RevertList', WLHandler.BLgetRL, true);
		                } else {
		                    content.innerHTML += '<p style=\"font-style:italic\">This tool can only be used in conjunction with <a href=\"//en.wikipedia.org/wiki/Wikipedia:WikiProject_Spam/Local/\" title=\"Wikipedia:WikiProject_Spam/Local/\">COIBot\'s spam reports</a> to add or remove domains.</p>';
		                }
		            },
		
		            // Get the current text and oldid of [[User:XLinkBot/RevertList]] or of [[MediaWiki:Spam-whitelist]]
		            BLgetRL: function (request) {
		                var xml = request.responseXML;
		                if (xml != null) {
		                    var pages = xml.getElementsByTagName('page');
		                    WLHandler.edittoken = pages[0].getAttribute('edittoken');
							if (WLHandler.action == WLHandler.wl_add || WLHandler.action == WLHandler.wl_rem) {
								WLHandler.BLgetRequest('action=query&prop=revisions&titles=User:XLinkBot/RevertList&rvprop=ids|timestamp|user|comment|content', WLHandler.BLparseRL, true);
							} else if (WLHandler.action == WLHandler.bl_add || WLHandler.action == WLHandler.bl_rem) {
								WLHandler.BLgetRequest('action=query&prop=revisions&titles=MediaWiki:Spam-whitelist&rvprop=ids|timestamp|user|comment|content', WLHandler.BLparseRL, true);
							}
		                }
		            },
		
		            // Add/remove domains from the text
		            BLparseRL: function (request) {
		                var xml = request.responseXML;
		                if (xml == null) {
		                    BLlist.innerHTML += '<div style=\"font-weight:bold;\">ERROR: ' + request.status + '<br />Aborting.</div>';
		                    return;
		                }
		                var revs = xml.getElementsByTagName('rev');
		                WLHandler.timestamp = revs[0].getAttribute('timestamp');
		                WLHandler.text = revs[0].textContent;
		                var oldlength = WLHandler.text.length;
		                document.getElementById('SgetRL').style.color = 'black';
		
		                if ((WLHandler.action == WLHandler.wl_add) || (WLHandler.action == WLHandler.bl_add)) {
		                    urls = WLHandler.urls.replace(/\|/g, '\n');
		                    if (WLHandler.text.length > 1000) {
		                        var lastchars = WLHandler.text.substr(-1000);
		                        WLHandler.text = WLHandler.text.substr(0, WLHandler.text.length - 1000);
		                        if (lastchars.indexOf('## WLHandler_end') > 0) {
		                            lastchars = lastchars.replace('## WLHandler_end', urls + '\n## WLHandler_end');
		                        } else {
		                            BLlist.innerHTML += '<div style=\"font-weight:bold;\">ERROR: Could not find marker. Aborting.</div>';
		                            return;
		                        }
		                        WLHandler.text += lastchars;
		                    } else {
		                        if (WLHandler.text.indexOf('## WLHandler_end') > 0) {
		                            WLHandler.text = WLHandler.text.replace('## WLHandler_end', urls + '\n## WLHandler_end');
		                        } else {
		                            BLlist.innerHTML += '<div style=\"font-weight:bold;\">ERROR: Could not find marker. Please add \"## WLHandler_end\" on a single line below the whitelist\'s entry\'s and try again.</div>';
		                            return;
		                        }
		                    }
		                } else if ((WLHandler.action == WLHandler.wl_rem) || (WLHandler.action == WLHandler.bl_rem)) {
		                    urls = WLHandler.urls.split('|');
		                    for (var i = 0; i < urls.length; i++) {
		                        WLHandler.text = WLHandler.text.replace(urls[i] + '\n', '');
		                    }
		                }
		                //Check if the length changed, if not assume nothing changed.
		                if (oldlength == WLHandler.text.length) {
		                    BLlist.innerHTML += '<div style=\"font-weight:bold;\">ERROR: The length of the old and new text are the same. This shouldn\'t happen. Aborting.</div>';
		                    return;
		                }
		                document.getElementById('SaddRL').style.color = 'black';
						
						if (WLHandler.action === WLHandler.wl_add || WLHandler.action === WLHandler.wl_rem) {
						    params = 'action=query&prop=revisions&titles=User:XLinkBot/RevertList&rvdifftotext=' + encodeURIComponent(WLHandler.text);
						} else if (WLHandler.action === WLHandler.bl_add || WLHandler.action === WLHandler.bl_rem) {
							params = 'action=query&prop=revisions&titles=MediaWiki:Spam-whitelist&rvdifftotext=' + encodeURIComponent(WLHandler.text);
						}
		                WLHandler.BLpostRequest('format=xml', WLHandler.HandlerParseDiff, params, true);
		            },
		
		            // Parse and show the proposed edit
		            HandlerParseDiff: function (request) {
		                var xml = request.responseXML;
		                if (xml != null) {
		                    document.getElementById('SgetC').style.color = 'black';
		                    var diffSource = xml.getElementsByTagName('diff');
		                    var summary;
		                    if (diffSource[0].childNodes[0].nodeValue) {
		                        urls = WLHandler.urls.split('|');
		
		                        if ((WLHandler.action == WLHandler.wl_add) || (WLHandler.action == WLHandler.bl_add)) {
		                            summary = 'Adding ';
		                        } else {
		                            summary = 'Removing ';
		                        }
		
		                        if (urls.length > 1) {
		                            summary += urls.length + ' domains ';
		                        } else {
		                            summary += urls[0] + ' ';
		                        }
		
								if (WLHandler.fakesource === 'localreport') {
									summary += 'per [[' + WLHandler.request + ']].';
								} else if (WLHandler.fakesource === 'revertlist') {
									summary += 'per [[User talk:XLinkBot/RevertList#' + WLHandler.request + ']].';
								} else if (WLHandler.fakesource === 'whitelist') {
									summary += 'per [[MediaWiki talk:Spam-whitelist#' + WLHandler.request + ']].';
								} else if (WLHandler.fakesource === 'wpspam') {
									summary += 'per [[Wikipedia talk:WikiProject Spam#' + WLHandler.request + ']].';
								}
		                        BLlist.innerHTML += '<div id="wikiDiff"><table class="diff"><col class="diff-marker" /><col class="diff-content" /><col class="diff-marker" /><col class="diff-content" /><tr valign="top"><td colspan="2" class="diff-otitle">Current revision</td><td colspan="2" class="diff-ntitle">Your text</td></tr>' +
		                          diffSource[0].childNodes[0].nodeValue + '</table></div>' +
		                          '<br /><div id=\"BLform\">' +
		                          '<input type=\"text\" value=\"' + summary + '\" id=\"summary\" maxlength=\"200\" size=\"60\" >&nbsp;&nbsp;&nbsp;<button onclick=\"WLHandler.HandlerSubmitEdit()\">Confirm changes</button><button onclick=\"WLHandler.HandlerEditList()\">Edit changes</button></div>';
		
		                        document.getElementById('SparseRL').style.color = 'black';
		                    } else {
		                        BLlist.innerHTML += '<div style=\"font-weight:bold;\">ERROR: Could not show diff.<br />Aborting.</div>';
		                        return;
		                    }
		                } else {
		                    BLlist.innerHTML += '<div style=\"font-weight:bold;\">ERROR: ' + request.status + '<br />Aborting.</div>';
		                    return;
		                }
		            },
		
		            // Add a text area to change the revertlist or the whitelist yourself
		
		            HandlerEditList: function () {
		                var BLform = document.getElementById('BLform');
		                BLform.innerHTML = '<textarea name=\"wpTextbox1\" id=\"wpTextbox1\" cols=\"80\" rows=\"25\" accesskey=\",\">' +
		                  WLHandler.text +
		                  '</textarea>' +
		                  BLform.innerHTML;
		            },
		
		            // Submit the edit to [[User:XLinkBot/RevertList]] or [[MediaWiki:Spam-whitelist]]
		            HandlerSubmitEdit: function () {
		                var wpTextbox = document.getElementById('wpTextbox1');
		                if (wpTextbox != null) {
		                    WLHandler.text = wpTextbox.value;
		                    WLHandler.custom = true; //We can't simply log the change. User needs to do that.
		                }
		                document.getElementById('SconfirmRL').style.color = 'black';
		                summary = document.getElementById('summary').value;
		                summary += ' Using [[User:Beetstra/SBH|whitelist/ReverList Handler]].';
		                var query = 'format=xml';
		
						if (WLHandler.action == WLHandler.wl_add || WLHandler.action == WLHandler.wl_rem) {
							params = 'action=edit&title=User:XLinkBot/RevertList&summary=' + encodeURIComponent(summary) + '&text=' + encodeURIComponent(WLHandler.text) + '&basetimestamp=' + WLHandler.timestamp  +  '&token=' + encodeURIComponent(WLHandler.edittoken);
						} else if (WLHandler.action == WLHandler.bl_add || WLHandler.action == WLHandler.bl_rem) {
							params = 'action=edit&title=MediaWiki:Spam-whitelist&summary=' + encodeURIComponent(summary) + '&text=' + encodeURIComponent(WLHandler.text) + '&basetimestamp=' + WLHandler.timestamp  +  '&token=' + encodeURIComponent(WLHandler.edittoken);
						}
		
		
						
		                WLHandler.BLpostRequest(query, WLHandler.BLLWrapper, params, true);
		            },
		
		            // Start logging procedure
		            BLLWrapper: function (request) {
		                var xml = request.responseXML;
		                if (xml != null) {
		                    var edits = xml.getElementsByTagName('edit');
		                    if (edits.length === 0) {
		                        BLlist.innerHTML = '<div style=\"font-weight:bold;\">Saving might have failed. Please check if it succeeded and log the edit yourself if necessary.</div>';
		                        return;
		                    }
		                    var result = edits[0].getAttribute('result');
		                    WLHandler.oldid = edits[0].getAttribute('newrevid');
		                    if (result !== 'Success') {
								if (WLHandler.action == WLHandler.wl_add || WLHandler.action == WLHandler.wl_rem) {
									BLlist.innerHTML = '<div style=\"font-weight:bold;\">Saving failed. Please revertlist the domains yourself.</div>';
								} else if (WLHandler.action == WLHandler.bl_add || WLHandler.action == WLHandler.bl_rem) {
									BLlist.innerHTML = '<div style=\"font-weight:bold;\">Saving failed. Please whitelist the domains yourself.</div>';
								}
		                        return;
		                    } else {
		                        document.getElementById('SsaveRL').style.color = 'black';
								if (WLHandler.action == WLHandler.wl_add || WLHandler.action == WLHandler.wl_rem) {
									BLlist.innerHTML = '<div>RevertList has been updated, <a href=\"' + conf.wgServer + conf.wgScriptPath + '/index.php?oldid=' + WLHandler.oldid + '&diff=prev\" title=\"diff\">diff</a>.</div>';
								} else if (WLHandler.action == WLHandler.bl_add || WLHandler.action == WLHandler.bl_rem) {
									BLlist.innerHTML = '<div>whitelist has been updated, <a href=\"' + conf.wgServer + conf.wgScriptPath + '/index.php?oldid=' + WLHandler.oldid + '&diff=prev\" title=\"diff\">diff</a>.</div>';
								}
		                    }
		
		                } else {
		                    BLlist.innerHTML += '<div style=\"font-weight:bold;\">ERROR: ' + request.status + '<br />Aborting.</div>';
		                    return;
		                }
		
		                var d = new Date();
		                var m = d.getMonth() + 1;
		                if (m < 10) {
		                    m = '0' + m;
		                }
		                var y = d.getFullYear();		
						if (WLHandler.action == WLHandler.wl_add || WLHandler.action == WLHandler.wl_rem) {
							logtitle = 'User:XLinkBot/RevertList_requests/log' ;
						} else if (WLHandler.action == WLHandler.bl_add || WLHandler.action == WLHandler.bl_rem) {
							logtitle = 'MediaWiki_talk:Spam-whitelist/log/'+ y;
						}
		
						if (WLHandler.fakesource === 'localreport') {
		                    WLHandler.BLgetRequest('action=query&prop=revisions&titles=' + logtitle + '&rvprop=ids|timestamp|user|comment|content', WLHandler.BLparseL, true);
						} else if (WLHandler.fakesource === 'revertlist') {
		                    WLHandler.BLgetRequest('action=query&prop=revisions&titles=User_talk:XLinkBot/RevertList&rvprop=ids|timestamp|user|comment|content', WLHandler.BLparseTRL, true);
						} else if (WLHandler.fakesource === 'whitelist') {
		                    WLHandler.BLgetRequest('action=query&prop=revisions&titles=MediaWiki_talk:Spam-whitelist&rvprop=ids|timestamp|user|comment|content', WLHandler.BLparseTRL, true);
						} else if (WLHandler.fakesource === 'wpspam') {
		                    WLHandler.BLgetRequest('action=query&prop=revisions&titles=Wikipedia_talk:WikiProject_Spam&rvprop=ids|timestamp|user|comment|content', WLHandler.BLparseTRL, true);
						}
						
						
		            },
		
		            // Get current oldid of [[User_talk:XLinkBot/RevertList]], because that's the location of the request.
		            BLparseTRL: function (request) {
		                var xml = request.responseXML;
		                if (xml != null) {
		                    var revs = xml.getElementsByTagName('rev');
		                    tprevid = revs[0].getAttribute('revid');
		                } else {
		                    BLlog.innerHTML += '<div style=\"font-weight:bold;\">ERROR: ' + request.status + '<br />. Please log the edit yourself.</div>';
		                    return;
		                }
		
		                WLHandler.BLgetRequest('action=query&prop=revisions&titles=' + logtitle + '&rvprop=ids|timestamp|user|comment|content', WLHandler.BLparseL, true);
		            },
		
		            // Add/remove domains to/from log
		            BLparseL: function (request) {
		                var xml = request.responseXML;
		                if (xml != null) {
		                    document.getElementById('SgetL').style.color = 'black';
		                    var revs = xml.getElementsByTagName('rev');
		                    if (revs.length === 0) {
		                        BLlog.innerHTML += '<div style=\"font-weight:bold;\">ERROR: Could not get log.<br /> It probably does not exist yet. Please create <a href="/wiki/' + logtitle + '" title="' + logtitle + '">' + logtitle + '</a> and log the edit yourself.</div>';
		                        return;
		                    }
		                    WLHandler.timestamp = revs[0].getAttribute('timestamp');
		                    WLHandler.text = revs[0].textContent;
		                } else {
		                    BLlog.innerHTML += '<div style=\"font-weight:bold;\">ERROR: ' + request.status + '<br /> Please log the edit yourself.</div>';
		                    return;
		                }
		
		                var rldiff;
		                if ((WLHandler.action == WLHandler.wl_add) || (WLHandler.action == WLHandler.bl_add)) {
		                    rldiff = '{{bl-diff|' + WLHandler.oldid + '}}';
		                } else {
		                    rldiff = '{{bl-diff|' + WLHandler.oldid + '|removal}}';
		                }
		
		                urls = WLHandler.urls.split('|');
		                var r = WLHandler.request;
						if (WLHandler.fakesource === 'localreport') {
		                    r = '[[' + r + ']]';
						} else if (WLHandler.fakesource === 'revertlist') {
		                    r = '{{XLinkBot-log|' + tprevid + '#{{subst:anchorencode:' + r + '}}}}';
						} else if (WLHandler.fakesource === 'whitelist') {
		                    r = '{{bl-log|' + tprevid + '#{{subst:anchorencode:' + r + '}}}}';
						} else if (WLHandler.fakesource === 'wpspam') {
		                    r = '{{wpspam-log|' + tprevid + '#{{subst:anchorencode:' + r + '}}}}';
						}
		
		                var spaces = '                                        ';
		
		                if (urls.length == 1) {
		                    log_text = ' ' + urls[0] + spaces.substr(0, 39 - urls[0].length) + '# ' +
		                      conf.wgUserName + ' # ' + rldiff + '; see ' + r;
		                } else {
		                    log_text = ' #:                                     ' +
		                      conf.wgUserName + ' # ' + rldiff + '; see ' + r;
		                    for (var i = 0; i < urls.length; i++) {
		                        log_text += '\n   ' + urls[i];
		                    }
		                }
		
		                // User needs to confirm log edit
		                if (WLHandler.custom) {
		                    BLlog.innerHTML += '<p>The following text will be added to the log. You need to update this to reflect the changes you made to the proposed edit.</p>' +
		                      '<textarea name=\"wpTextbox1\" id=\"wpTextbox1\" cols=\"80\" rows=\"10\" accesskey=\",\">' +
		                      log_text +
		                      '</textarea>' +
		                      '<button onclick=\"WLHandler.BLsubmitL()\">Confirm changes</button>';
		                } else {
		                    WLHandler.BLsubmitL();
		                }
		            },
		
		            BLsubmitL: function () {
		                var wpTextbox = document.getElementById('wpTextbox1');
		                if (wpTextbox != null) {
		                    WLHandler.text += '\n' + wpTextbox.value;
		                } else {
		                    WLHandler.text += '\n' + log_text;
		                }
		                document.getElementById('SaddL').style.color = 'black';
		                var query = 'format=xml';
		                var params = 'action=edit&title=' + encodeURIComponent(logtitle) + '&summary=' + encodeURIComponent(summary) + '&text=' + encodeURIComponent(WLHandler.text) + '&token=' + encodeURIComponent(WLHandler.edittoken);
		                WLHandler.BLpostRequest(query, WLHandler.BLLEnd, params, true);
		            },
		
		            // Confirm results
		            BLLEnd: function (request) {
		                var xml = request.responseXML;
		
		                if (xml != null) {
		                    var edits = xml.getElementsByTagName('edit');
		                    if (edits.length === 0) {
		                        BLlist.innerHTML = '<div style=\"font-weight:bold;\">Saving might have failed. Please check if it succeeded and log the edit yourself if necessary.</div>';
		                        return;
		                    }
		                    var result = edits[0].getAttribute('result');
		                    var oldid = edits[0].getAttribute('newrevid');
		                    if (result !== 'Success') {
		                        BLlog.innerHTML = '<div>Saving failed. Please log the edit yourself.</div>';
		                        return;
		                    } else {
		                        document.getElementById('SsaveL').style.color = 'black';
		                        document.getElementById('Sthrobber').innerHTML = '';
								if ((WLHandler.action == WLHandler.wl_add) || (WLHandler.action == WLHandler.wl_add)) {
			                        BLlog.innerHTML = '<div>Log has been updated, <a href=\"' + conf.wgServer + conf.wgScriptPath + '/index.php?oldid=' + oldid + '&diff=prev\" title=\"diff\">diff</a>.<p style=\"font-style:italic\">Thanks for helping with the Spam revertlist!</p></div>';
								} else {
									BLlog.innerHTML = '<div>Log has been updated, <a href=\"' + conf.wgServer + conf.wgScriptPath + '/index.php?oldid=' + oldid + '&diff=prev\" title=\"diff\">diff</a>.<p style=\"font-style:italic\">Thanks for helping with the Spam whitelist!.</p></div>';
								}
		                    }
		                }	
		            },
		
		            BLgetRequest: function (query, callback, api) {
		                var url;
		                if (api) {
		                    url = conf.wgServer + conf.wgScriptPath + '/api.php?format=xml&' + query;
		                } else {
		                    url = conf.wgServer + conf.wgScriptPath + '/index.php?' + query;
		                }
		
		                $.ajax({
		                    url: url,
		                    type: 'GET',
		                    headers: {
		                        'Pragma': 'cache=yes',
		                        'Cache-Control': 'no-transform'
		                    }
		                }).done(function (data, textStatus, jqXHR) {
		                    callback(jqXHR);
		                });
		            },
		
		            BLpostRequest: function (query, callback, params, api) {
		                var url;
		                if (api) {
		                    url = conf.wgServer + conf.wgScriptPath + '/api.php?' + query;
		                } else {
		                    url = conf.wgServer + conf.wgScriptPath + '/index.php?' + query;
		                }
		
		                $.ajax({
		                    url: url,
		                    type: 'POST',
		                    headers: {
		                        'Content-type': 'application/x-www-form-urlencoded',
		                        'Content-length': params.length,
		                        'Pragma': 'cache=yes',
		                        'Cache-Control': 'no-transform'
		                    },
		                    data: params
		                }).done(function (data, textStatus, jqXHR) {
		                    callback(jqXHR);
		                });
		            },
		
		            BLsetupHandler: function () {
		                if (conf.wgPageName == 'Special:Spamwhitelist') {
		                    WLHandler.BLWrapper();
		                } else {
		                    WLHandler.BLcloseRequestLinks();
		                }
		            }
		
		        };
		        // End of WLHandler object
		
		        $(WLHandler.BLsetupHandler);
		
		    }
		    // End of if-sysop check
		
		    // Export global variables
		    window.WLHandler = WLHandler;
		    window.WLrequest = WLrequest;
		
		}());
		// </nowiki>
		// [[Category:Gadgets|WLHandler.js]]
		// [[Category:Wikipedia scripts]]