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.
//<pre><nowiki>
//IMPORTS
importScript('User:Voice_of_All/Addtabs/monobook.js');
importScript('User:Voice_of_All/UTCclock.js');
//importScript('User:Voice_of_All/Revert.js');
importScript('User:Voice_of_All/History/monobook.js');

importScript('User:Lightdarkness/aiv.js');
//</nowiki></pre>

//<pre><nowiki>
// [[User:Lupin/popupsdev.js]] - please include this line 
document.write('<script type="text/javascript" src="' 
             + 'http://en.wikipedia.org/w/index.php?title=User:Lupin/popupsdev.js' 
             + '&action=raw&ctype=text/javascript&dontcountme=s"></script>');
popupStructure='shortmenus';
popupSubpopups=false;
// [[User:Lupin/recent2.js]] - please include this line
mw.loader.load(
             'https://en.wikipedia.org/w/index.php?title=User:Lupin/recent2.js'
             + '&action=raw&ctype=text/javascript&dontcountme=s');
//</nowiki></pre>

// Revert functions
//<pre>

//////AOL RANGES////////
var AOL_RANGES = /^(64\.12\.|149\.174|152\.163\.|195\.93\.[0-9]\d{0,1}\.|195\.93\.1[0-1][0-9]\.|195\.93\.12[0-7]\.|198\.81\.[0-9]\.|198\.81\.[1-2][0-9]\.|198\.81\.3[01]\.|202\.67\.6[4-9]\.|202\.67\.[7-9][0-9]\.|202\.67\.1[01]|202\.67\.12[0-7]|205\.188\.|207\.200\.6[4-9]\.|207\.200\.[7-9][0-9]\.|207\.200\.1[01]|207\.200\.12[0-7])/;
//all ranges
var AOL_RANGES_ALL = /^(64\.12\.|149\.174|152\.163\.|195\.93\.[0-9]\d{0,1}\.|195\.93\.1[0-1][0-9]\.|195\.93\.12[0-7]\.|198\.81\.[0-9]\.|198\.81\.[1-2][0-9]\.|198\.81\.3[01]\.|202\.67\.6[4-9]\.|202\.67\.[7-9][0-9]\.|202\.67\.1[01]|202\.67\.12[0-7]|205\.188\.|207\.200\.6[4-9]\.|207\.200\.[7-9][0-9]\.|207\.200\.1[01]|207\.200\.12[0-7]|172\.12[0-8]|172\.1[3-9][0-9]|172\.20[0-9]|172\.21[0-6])/;

TwinkleConfig = {
 	userTalkPageMode		:	'window',
 	showSharedIPNotice		:	true,
 	openTalkPage			:	[ 'agf', 'vand' ],
 	openTalkPageOnAutoRevert	:	false,
 	openAOLAnonTalkPage		:	false,
 	addAdToSummary			:	true,
 	addAdToDeletionSummary		:	true,
 	watchSpeedyPages		:	[ 'g3', 'g5', 'g10', 'g11', 'g12' ],
 	watchRevertedPages		:	[ 'agf', 'torev' ],
 	overrideWatchRevertedPages	:	[ 'agf', 'norm', 'vand', 'torev' ],
 	markRevertedPagesAsMinor	:	[ 'agf', 'norm', 'vand', 'torev' ],
 	overrideMarkRevertedPagesAsMinor:	[ 'agf', 'norm', 'vand', 'torev' ],
 	deleteTalkPageOnDelete		:	false
 };

//User:AzaToth
document.write('<script type="text/javascript" src="' 
             + 'http://en.wikipedia.org/w/index.php?title=User:AzaToth/morebits.js' 
             + '&action=raw&ctype=text/javascript&dontcountme=s"></script>');
//

//////
/**
Twinklefluff revert and antivandalism utillity
By AzaToth, modified a bit (Voice of All), added by request
*/
var VERSION = '1.1';
var MAXREV = 8; // maximum number of revision to lookup

// If TwinkleConfig aint exist.
if( typeof( TwinkleConfig ) == 'undefined' ) {
	TwinkleConfig = function() {};
}
/**
TwinkleConfig.userTalkPageMode may take arguments:
'window': open a new window, remmenber the opened window
'tab': opens in a new tab, if possible.
'blank': force open in a new window, even if a such window exist
*/
if( typeof( TwinkleConfig.userTalkPageMode ) == 'undefined' ) {
	TwinkleConfig.userTalkPageMode = 'window';
}

/**
TwinkleConfig.openTalkPage (array)
What types of actions that should result in opening of talk page
*/
if( typeof( TwinkleConfig.openTalkPage ) == 'undefined' ) {
	TwinkleConfig.openTalkPage = [ 'agf', 'norm', 'vand' ];
}

/**
TwinkleConfig.openTalkPageOnAutoRevert (bool)
Defines if talk page should be opened when canling revert from contrib page, this because from there, actions may be multiple, and opening talk page not suitable. If set to true, openTalkPage defines then if talk page will be opened.
*/
if( typeof( TwinkleConfig.openTalkPageOnAutoRevert ) == 'undefined' ) {
	TwinkleConfig.openTalkPageOnAutoRevert = false;
}

/**
TwinkleConfig.openAOLAnonTalkPage may take arguments:
true: to open Anon AOL talk pages on revert
false: to not open them
*/
if( typeof( TwinkleConfig.openAOLAnonTalkPage ) == 'undefined' ) {
	TwinkleConfig.openAOLAnonTalkPage = false;
}

/**
TwinkleConfig.addAdToSummary
If [[WP:TWINKLE|TWINKLE]] should be added or not to summary
*/
if( typeof( TwinkleConfig.addAdToSummary ) == 'undefined' ) {
	TwinkleConfig.addAdToSummary = true;
}

/**
TwinkleConfig.markRevertedPagesAsMinor (array)
What types of actions that should result in marking edit as minor
*/
if( typeof( TwinkleConfig.markRevertedPagesAsMinor ) == 'undefined' ) {
	TwinkleConfig.markRevertedPagesAsMinor = [ 'agf', 'norm', 'vand', 'torev' ];
}

/**
TwinkleConfig.overrideMarkRevertedPagesAsMinor (array)
What types of actions that should override predefined minor markings of edits
*/
if( typeof( TwinkleConfig.overrideMarkRevertedPagesAsMinor ) == 'undefined' ) {
	TwinkleConfig.overrideMarkRevertedPagesAsMinor = [ 'agf', 'norm', 'vand', 'torev' ];
}


/**
TwinkleConfig.watchRevertedPages (array)
What types of actions that should result in forced addition to watchlist
*/
if( typeof( TwinkleConfig.watchRevertedPages ) == 'undefined' ) {
	TwinkleConfig.watchRevertedPages = [ 'agf', 'norm', 'vand', 'torev' ];
}

/**
TwinkleConfig.overrideWatchRevertedPages (array)
What types of actions should override predefined whatching of pages
*/
if( typeof( TwinkleConfig.overrideWatchRevertedPages ) == 'undefined' ) {
	TwinkleConfig.overrideWatchRevertedPages = [ 'agf', 'norm', 'vand', 'torev' ];
}

// a list of usernames, usually only bots, that vandalism revert is jumped over, that is
// if vandalism revert is choosen on such username, then it's target in on the revision before.
// This is for handeling quick bots that makes edits seconds after the original edit is made.
// This only affect vandalism rollback, for good faith rollback, it will stop, indicating a bot 
// has no faith, and for normal rollback, it will rollback that edit.
var WHITELIST = [
	'HagermanBot',
	'HBC AIV helperbot',
	'HBC AIV helperbot2',
	'HBC AIV helperbot3',
]

var revertXML;
var contentXML;
var contentDoc;
var editXML;
var vandal;
var type;
var goodRev;
var nbrOfRevisions;
var curStatus;
var curVersion = true;

addOnloadHook(twinklestart);

function twinklestart() {
	if( QueryString.exists( 'twinklerevert' ) ) {
		twinkleAutoRevert();
	} else {
		addRevertButtons();
	}
}

function twinkleAutoRevert() {
	if( QueryString.get( 'oldid' ) != wgCurRevisionId ) {
		// not latest revision
		return;
	}

	var ntitle = getElementsByClassName( document.getElementById('bodyContent'), 'td' , 'diff-ntitle' )[0];
	if( ntitle.getElementsByTagName('a')[0].firstChild.nodeValue != 'Current revision' ) {
		// not latest revision
		return;
	}

	vandal = ntitle.getElementsByTagName('a')[3].firstChild.nodeValue.replace("'", "\\'");

	if( !TwinkleConfig.openTalkPageOnAutoRevert ) {
		TwinkleConfig.openTalkPage = [];
	}

	return revertPage( QueryString.get( 'twinklerevert' ), vandal );
}

function addRevertButtons() {

	var spanTag = function( color, content ) {
		var span = document.createElement( 'span' );
		span.style.color = color;
		span.appendChild( document.createTextNode( content ) );
		return span;
	}

	if( wgNamespaceNumber == -1 && wgCanonicalSpecialPageName == "Contributions" ) {
		var list = document.getElementById('bodyContent').getElementsByTagName( 'ul' )[0].getElementsByTagName( 'li' );
		var vandal = document.getElementById('contentSub').getElementsByTagName( 'a' )[0].getAttribute( 'title' ).replace(/^User( talk)?:/ , '').replace("'", "\\'");

		var revNode = document.createElement('strong');
		var revLink = document.createElement('a');
		revLink.appendChild( spanTag( 'Black', ' [' ) );
		revLink.appendChild( spanTag( 'SteelBlue', 'rollback' ) );
		revLink.appendChild( spanTag( 'Black', ']' ) );
		revNode.appendChild(revLink);

		var revVandNode = document.createElement('strong');
		var revVandLink = document.createElement('a');
		revVandLink.appendChild( spanTag( 'Black', ' [' ) );
		revVandLink.appendChild( spanTag( 'Red', 'vandalism' ) );
		revVandLink.appendChild( spanTag( 'Black', ']' ) );
		revVandNode.appendChild(revVandLink);

		for(var i in list ) {
			var item = list[i].lastChild;
			if ( !item ) {
				continue;
			}
			if( userIsInGroup( 'sysop' ) ) {
				item = item.previousSibling;
			}
			if( item.nodeName != 'STRONG' ) {
				continue
			}

			var href = list[i].getElementsByTagName( 'a' )[1].getAttribute( 'href' );
//			var oldid = list[i].getElementsByTagName( 'a' )[1].getAttribute( 'href' ).split( 'oldid=' )[1];
//			var page = list[i].getElementsByTagName( 'a' )[2].getAttribute( 'title' ).replace("'", "\\'");
			var tmpNode = revNode.cloneNode( true );
			tmpNode.firstChild.setAttribute( 'href', href + '&' + QueryString.create( { 'twinklerevert': 'norm' } ) );
//			tmpNode.firstChild.setAttribute( 'href', "javascript:revertPage('norm' , '" + vandal + "', " + oldid + ", '" + page + "')" );
			list[i].appendChild( tmpNode );
			var tmpNode = revVandNode.cloneNode( true );
			tmpNode.firstChild.setAttribute( 'href', href + '&' + QueryString.create( { 'twinklerevert': 'vand' } ) );
//			tmpNode.firstChild.setAttribute( 'href', "javascript:revertPage('vand' , '" + vandal + "', " + oldid + ", '" + page + "')" );
			list[i].appendChild( tmpNode );
		}


	} else {

		var otitle = getElementsByClassName( document.getElementById('bodyContent'), 'td' , 'diff-otitle' )[0];
		var ntitle = getElementsByClassName( document.getElementById('bodyContent'), 'td' , 'diff-ntitle' )[0];

		if( !ntitle ) {
			// Nothing to see here, move along...
			return;
		}

		if( !otitle.getElementsByTagName('a')[0] ) {
			// no previous revision available
			return;
		}

		// Lets first add a [edit this revision] link

		var oldrev = QueryString.get( 'oldid', decodeURI( otitle.getElementsByTagName( 'a' )[0].getAttribute( 'href' ).split( '&', 2 )[1] ) );

		var oldEditNode = document.createElement('strong');

		var oldEditLink = document.createElement('a');
		oldEditLink.href = "javascript:revertToRevision('" + oldrev + "')";
		oldEditLink.appendChild( spanTag( 'Black', '[' ) );
		oldEditLink.appendChild( spanTag( 'SaddleBrown', 'restore this version' ) );
		oldEditLink.appendChild( spanTag( 'Black', ']' ) );
		oldEditNode.appendChild(oldEditLink);

		var cur = otitle.insertBefore(oldEditNode, otitle.firstChild);
		otitle.insertBefore(document.createElement('br'), cur.nextSibling);

		if( ntitle.getElementsByTagName('a')[0].firstChild.nodeValue != 'Current revision' ) {
			// not latest revision
			curVersion = false;
			return;
		}

		vandal = ntitle.getElementsByTagName('a')[3].firstChild.nodeValue.replace("'", "\\'");

		var agfNode = document.createElement('strong');
		var vandNode = document.createElement('strong');
		var normNode = document.createElement('strong');

		var agfLink = document.createElement('a');
		var vandLink = document.createElement('a');
		var normLink = document.createElement('a');

		agfLink.href = "javascript:revertPage('agf' , '" + vandal + "')"; 
		vandLink.href = "javascript:revertPage('vand' , '" + vandal + "')"; 
		normLink.href = "javascript:revertPage('norm' , '" + vandal + "')"; 

		agfLink.appendChild( spanTag( 'Black', '[' ) );
		agfLink.appendChild( spanTag( 'DarkOliveGreen', 'rollback (AGF)' ) );
		agfLink.appendChild( spanTag( 'Black', ']' ) );

		vandLink.appendChild( spanTag( 'Black', '[' ) );
		vandLink.appendChild( spanTag( 'Red', 'rollback (VANDAL)' ) );
		vandLink.appendChild( spanTag( 'Black', ']' ) );

		normLink.appendChild( spanTag( 'Black', '[' ) );
		normLink.appendChild( spanTag( 'SteelBlue', 'rollback' ) );
		normLink.appendChild( spanTag( 'Black', ']' ) );

		agfNode.appendChild(agfLink);
		vandNode.appendChild(vandLink);
		normNode.appendChild(normLink);

		var cur = ntitle.insertBefore(agfNode, ntitle.firstChild);
		cur = ntitle.insertBefore(document.createTextNode(' || '), cur.nextSibling);
		cur = ntitle.insertBefore(normNode, cur.nextSibling);
		cur = ntitle.insertBefore(document.createTextNode(' || '), cur.nextSibling);
		cur = ntitle.insertBefore(vandNode, cur.nextSibling);
		cur = ntitle.insertBefore(document.createElement('br'), cur.nextSibling);
	}

}

function revertPage( pType, pVandal, rev, page ) {

	wgPageName = page || wgPageName;
	wgCurRevisionId = rev || wgCurRevisionId;


	try {
		vandal = pVandal;
		type = pType;
		Status.init( document.getElementById('bodyContent') );

		revertXML = sajax_init_object();
		Status.debug( 'revertXML' + revertXML );
		revertXML.overrideMimeType('text/xml');

		var query = {
			'action': 'query',
			'prop': 'revisions',
			'titles': wgPageName,
			'rvlimit': TwinkleConfig.revertMaxRevisions,
			'rvprop': [ 'ids', 'timestamp', 'user', 'comment' ],
			'format': 'xml'
		}

		Status.status( 'Querying revisions' );
		revertXML.onreadystatechange = revertPageCallback;
		revertXML.open( 'GET' , mw.config.get('wgServer') + mw.config.get('wgScriptPath') + '/api.php?' + QueryString.create( query ), true );
		revertXML.send( null );
	} catch(e) {
		if( e instanceof Exception ) {
			Status.error( 'Error: ' + e.what() );
		} else {
			Status.error( 'Error: ' + e );
		}
	}

}
function revertPageCallback() {

	if ( revertXML.readyState != 4 ){
		Status.progress('.');
		return;
	} 

	if( revertXML.status != 200 ){
		Status.error('Bad status , bailing out');
		return;
	}

	var doc = revertXML.responseXML.documentElement;

	if( !doc ) {
		Status.error( 'Possible failure in recieving document, will abort.' );
		return;
	}
	var revisions = doc.getElementsByTagName('rev');
	var top = revisions[0];
	Status.debug( 'revisions[0]: ' + top );

	if( top.getAttribute( 'revid' ) < wgCurRevisionId ) {
		Status.error( [ 'The recieved top revision id ', htmlNode( 'strong', top.getAttribute('revid') ), ' is less than our current revision id, this could indicate that the current revision has been deleted, the server is lagging, or that bad data has been recieved. Will stop proceeding at this point.' ] );
		return;
	}
	if( !top ) {
		Status.error( 'No top revision found,  this could indicate that the page has been deleted, or that a problem in the transmittion has occoured, will abort reversion ');
		return;
	}


	Status.status( [ 'Evaluating revisions to see if ', htmlNode( 'strong', vandal), ' is the last contributor...' ] );
	Status.debug( 'wgCurRevisionId: ' + wgCurRevisionId + ', top.getAttribute(revid): ' + top.getAttribute('revid') );

	if( wgCurRevisionId != top.getAttribute('revid') ) {
		Status.warn( [ 'Latest revision ', htmlNode( 'strong', top.getAttribute('revid') ), ' doesn\'t equals our revision ', htmlNode( 'strong', wgCurRevisionId) ] );
		Status.debug( 'top.getAttribute(user): ' + top.getAttribute( 'user' ) );

		if( top.getAttribute( 'user' ) == vandal ) {
			switch( type ) {
				case 'vand':
				Status.info( [ 'Latest revision is made by ', htmlNode( 'strong', vandal ) , ', as we assume vandalism, we continue to revert' ]);
				break;
				case 'afg':
				Status.warn( [ 'Latest revision is made by ', htmlNode( 'strong', vandal ) , ', as we assume good faith, we stop reverting, as the problem might have been fixed.' ]);
				return;
				default:
				Status.warn( [ 'Latest revision is made by ', htmlNode( 'strong', vandal ) , ', but we will stop reverting anyway.' ] );
				return;
			}
		} else if( 
			type == 'vand' && 
			WHITELIST.indexOf( top.getAttribute( 'user' ) ) != -1 && 
			top.nextSibling.getAttribute( 'pageId' ) == wgCurRevisionId 
		) {
			Status.info( [ 'Latest revision is made by ', htmlNode( 'strong', top.getAttribute( 'user' ) ), ', a trusted bot, and the revision before was made by our vandal, so we proceed with the revert.' ] );
			top = top.nextSibling;
		} else {
			Status.error( [ 'Latest revision is made by ', htmlNode( 'strong', top.getAttribute( 'user' ) ), ', so it might already been reverted, stopping  reverting.'] );
			return;
		}
	} 

	if( type == 'vand' && WHITELIST.indexOf( vandal ) != -1 ) {
		Status.info( [ 'Vandalism revert is choosen on ', htmlNode( 'strong', vandal ), ', as this is a whitelisted bot, we assume you wanted to revert vandalism made by the previous user instead.' ] );
		top = top.nextSibling;
		vandal = top.getAttribute( 'user' );
	} else if( type == 'agf'  && WHITELIST.indexOf( vandal ) != -1 ) {
		Status.warn( [ 'Good faith revert is choosen on ', htmlNode( 'strong', vandal ), ', as this is a whitelisted bot, it makes no sense at all to revert it as a good faith edit, will stop reverting.' ] );
		return;
	}

	Status.status( 'Finding last good revision...' );

	goodRev = top;
	nbrOfRevisions = 0;

	while( goodRev.getAttribute('user') == vandal ) {

		goodRev = goodRev.nextSibling;

		nbrOfRevisions++;

		if( goodRev == null ) {
			Status.error( [ 'No previous revision found, perhaps ', htmlNode( 'strong', vandal ), ' is the only contributor, or that the user has made more than ' + MAXREV + ' edits in a row.' ] );
			return;
		}
	}

	if( nbrOfRevisions == 0 ) {
		Status.error( "We where to revert zero revisions. As that makes no sense, we'll stop reverting this time. It could be that the edit already have been reverted, but the revision id was still the same." );
		return;
	}

	if( 
		type != 'vand' && 
		nbrOfRevisions > 1  && 
		!confirm( vandal + ' has done ' + nbrOfRevisions + ' edits in a row. Are you sure you want to revert them all?' ) 
	) {
		Status.info( 'Stopping reverting per user input' );
		return;
	}

	Status.progress( [ ' revision ', htmlNode( 'strong', goodRev.getAttribute( 'revid' ) ), ' that was made ', htmlNode( 'strong', nbrOfRevisions ), ' revisions ago by ', htmlNode( 'strong', goodRev.getAttribute( 'user' ) ) ] );

	Status.status( [ 'Getting content for revision ', htmlNode( 'strong', goodRev.getAttribute( 'revid' ) ) ] );
	var query = {
		'action': 'query',
		'prop': 'revisions',
		'titles': wgPageName,
		'rvlimit': 1,
		'rvprop': 'content',
		'rvstartid': goodRev.getAttribute( 'revid' ),
		'format': 'xml'
	}

	Status.debug( 'query:' + query.toSource() );

	// getting the content for the last good revision
	revertXML = sajax_init_object();
	revertXML.overrideMimeType('text/xml');
	revertXML.onreadystatechange = revertCallback2;
	revertXML.open( 'GET' , mw.config.get('wgServer') + mw.config.get('wgScriptPath') + '/api.php?' + QueryString.create( query ), true );
	revertXML.send( null );

}

function revertCallback2() {
	if ( revertXML.readyState != 4 ){
		Status.progress( '.' );
		return;
	} 

	if( revertXML.status != 200 ){
		Status.error( 'Bad status , bailing out' );
		return;
	}

	contentDoc = revertXML.responseXML.documentElement;
	if( !contentDoc ) {
		Status.error( 'Failed to recieve revision to revert to, will abort.');
		return;
	}

	Status.status( 'Grabbing edit form' );

	revertXML = sajax_init_object();
	revertXML.overrideMimeType('text/xml');
	revertXML.onreadystatechange = revertCallback3;

	var query = {
		'title': wgPageName,
		'action': 'submit'
	};

	Status.debug( 'query:' + query.toSource() );

	revertXML.open( 'GET' , mw.config.get('wgServer') + mw.config.get('wgScriptPath') + '/index.php?' + QueryString.create( query ), true );
	revertXML.send( null );
}

function revertCallback3() {
	if ( revertXML.readyState != 4 ){
		Status.progress( '.' );
		return;
	} 

	if( revertXML.status != 200 ){
		Status.error( 'Bad status , bailing out' );
		return;
	}

	Status.status( 'Updating the textbox...' );

	var doc = revertXML.responseXML;

	var form = doc.getElementById( 'editform' );
	Status.debug( 'editform: ' + form );
	if( !form ) {
		Status.error( 'couldn\'t grab element "editform", aborting, this could indicate failed respons from the server' );
		return;
	}
	form.style.display = 'none';


	var content = contentDoc.getElementsByTagName('rev')[0];
	if( !content ) {
		Status.error( 'we recieved no revision, something is wrong, bailing out!' );
		return;
	}

	var textbox = doc.getElementById( 'wpTextbox1' );

	textbox.value = "";

	var cn =  content.childNodes;

	for( var i in cn ) {
		textbox.value += cn[i].nodeValue ? cn[i].nodeValue : '';
	}

	Status.status( 'Updating the summary...' );
	var summary;



	switch( type ) {
		case 'agf':
		summary = "Reverted [[WP:AGF|good faith]] edits by [[Special:Contributions/" + vandal + "|" + vandal + "]] per policy concerns. Please read up on [[WP:POL#Key_policies|policies and guidelines]]. Thanks!" + ( TwinkleConfig.addAdToSummary ? ' ([[WP:TWINKLE|TW]])' : '');
		break;
		case 'vand':
		summary = "Reverted " + nbrOfRevisions + " edit" + ( nbrOfRevisions > 1 ? "s" : '' ) + " by [[Special:Contributions/" + vandal + "|" + vandal + "]] identified as [[WP:VAND|vandalism]] to last revision by [[User:" + goodRev.getAttribute( 'user' ) + "|" + goodRev.getAttribute( 'user' ) + "]]." + ( TwinkleConfig.addAdToSummary ? ' ([[WP:TWINKLE|TW]])' : '');
		break;
		case 'norm':
		summary = "Reverted " + nbrOfRevisions + " edit" + ( nbrOfRevisions > 1 ? "s" : '' ) + " by [[Special:Contributions/" + vandal + "|" + vandal + "]]  to last revision by  [[User:" + goodRev.getAttribute( 'user' ) + "|" + goodRev.getAttribute( 'user' ) + "]]." + ( TwinkleConfig.addAdToSummary ? ' ([[WP:TWINKLE|TW]])' : '');
	}
	doc.getElementById( 'wpSummary' ).value = summary;

	if( TwinkleConfig.overrideMarkRevertedPagesAsMinor.indexOf( type ) != -1 ) {
		doc.getElementById( 'wpMinoredit' ).checked = true;
	}

	if( TwinkleConfig. overrideWatchRevertedPages.indexOf( type ) != -1 ) {
		doc.getElementById( 'wpWatchthis' ).checked = true;
	}

	Status.status( [ 'Open user talk page edit form for user ', htmlNode( 'strong', vandal ) ]);

	var opentalk = true;

	if( TwinkleConfig.openTalkPage.indexOf( type ) != -1 ) {

		if( isIPAddress( vandal ) ) {
			Status.info( [ htmlNode( 'strong', vandal ), ' is an ip-address, checking if it\'s inside the AOL range' ] );

			if( AOLNetworks.some( function( net ) { return isInNetwork( vandal, net ) } )) {
				if( TwinkleConfig.openAOLAnonTalkPage ) {
					Status.info( [ htmlNode( 'strong', vandal ), ' is an AOL address. Per configuration, we will open talk page anyway' ] );
				} else {
					Status.warn( [ htmlNode( 'strong', vandal ), ' is an AOL address. will not open a edit form for the user talk page because AOL addresses are randomly assigned' ] );
					opentalk = false;
				}
			} else {
				Status.info( [ htmlNode( 'strong', vandal ), ' is an normal ip-address, opening user talk page' ] );
			}

		}

		if( opentalk ) {
			var query = {
				'title': 'User talk:' + vandal,
				'action': 'edit',
				'vanarticle': wgPageName.replace(/_/g, ' '),
				'vanarticlerevid': wgCurRevisionId,
				'vanarticlegoodrevid': goodRev.getAttribute( 'revid' ),
				'type': type,
				'count': nbrOfRevisions
			}

			Status.debug( 'query:' + query.toSource() );

			switch( TwinkleConfig.userTalkPageMode ) {
				case 'tab':
				window.open( mw.config.get('wgServer') + mw.config.get('wgScriptPath') + '/index.php?' + QueryString.create( query ), '_tab' );
				break;
				case 'blank':
				window.open( mw.config.get('wgServer') + mw.config.get('wgScriptPath') + '/index.php?' + QueryString.create( query ), '_blank', 'location=no,toolbar=no,status=no,directories=no,scrollbars=yes,width=1200,height=800' );
				break;
				case 'window':
				default :
				window.open( mw.config.get('wgServer') + mw.config.get('wgScriptPath') + '/index.php?' + QueryString.create( query ), 'twinklewarnwindow', 'location=no,toolbar=no,status=no,directories=no,scrollbars=yes,width=1200,height=800' );
				break;
			}
		}
	}

	document.getElementById('globalWrapper').appendChild( form );

	Status.status( 'Submitting the form...' );
	form.submit();
}

function revertToRevision( oldrev ) {

	try {
		Status.init( document.getElementById('bodyContent') );

		revertXML = sajax_init_object();
		revertXML.overrideMimeType('text/xml');

		var query = {
			'action': 'query',
			'prop': 'revisions',
			'titles': wgPageName,
			'rvlimit': 1,
			'rvstartid': oldrev,
			'rvprop': [ 'timestamp', 'user', 'comment', 'content' ],
			'format': 'xml'
		}

		Status.status( 'Querying revision' );
		revertXML.onreadystatechange = revertToRevisionCallback;
		revertXML.open( 'GET' , mw.config.get('wgServer') + mw.config.get('wgScriptPath') + '/api.php?' + QueryString.create( query ), true );
		revertXML.send( null );
	} catch(e) {
		if( e instanceof Exception ) {
			Status.error( 'Error: ' + e.what() );
		} else {
			Status.error( 'Error: ' + e );
		}
	}

}

function revertToRevisionCallback() {
	if ( revertXML.readyState != 4 ){
		Status.progress( '.' );
		return;
	} 

	if( revertXML.status != 200 ){
		Status.error( 'Bad status , bailing out' );
		return;
	}

	contentDoc = revertXML.responseXML.documentElement;

	Status.status( 'Grabbing edit form' );

	revertXML = sajax_init_object();
	revertXML.overrideMimeType('text/xml');
	revertXML.onreadystatechange = revertToRevisionCallback2;
	revertXML.open( 'GET' , mw.config.get('wgServer') + mw.config.get('wgScriptPath') + '/index.php?' + QueryString.create( { 'title': wgPageName, 'action': 'submit' } ), true );
	revertXML.send( null );
}

function revertToRevisionCallback2() {
	if ( revertXML.readyState != 4 ){
		Status.progress( '.' );
		return;
	} 

	if( revertXML.status != 200 ){
		Status.error( 'Bad status , bailing out' );
		return;
	}

	Status.status( 'Updating the textbox...' );

	var doc = revertXML.responseXML;

	var form = doc.getElementById( 'editform' );
	Status.debug( 'editform: ' + form );
	if( !form ) {
		Status.error( 'couldn\'t grab element "editform", aborting, this could indicate failed respons from the server' );
		return;
	}
	form.style.display = 'none';


	var content = contentDoc.getElementsByTagName('rev')[0];

	var textbox = doc.getElementById( 'wpTextbox1' );

	textbox.value = "";

	var cn =  content.childNodes;

	for( var i in cn ) {
		textbox.value += cn[i].nodeValue ? cn[i].nodeValue : '';
	}

	Status.status( 'Updating the summary...' );
	var summary = 'Reverted to revision ' + content.getAttribute( 'revid' ) + ' by [[User:' + content.getAttribute( 'user' ) + '|' + content.getAttribute( 'user' ) + ']].' + ( TwinkleConfig.addAdToSummary ? ' [[WP:TWINKLE|TWINKLE]]' : '');

	doc.getElementById( 'wpSummary' ).value = summary;

	if( TwinkleConfig.overrideMarkRevertedPagesAsMinor.indexOf( 'torev' ) != -1 ) {
		doc.getElementById( 'wpMinoredit' ).checked = true;
	}

	if( TwinkleConfig. overrideWatchRevertedPages.indexOf( 'torev' ) != -1 ) {
		doc.getElementById( 'wpWatchthis' ).checked = true;
	}

	document.getElementById('globalWrapper').appendChild( form );

	Status.status( 'Submitting the form...' );
	form.submit();
}
//</pre>
//End of revert functions

//<pre><nowiki>
// ============= test-n.js ==============
function tnaddlilink(url, name)
{
  var na = document.createElement('a');
  na.setAttribute('href', url);

  var txt = document.createTextNode(name);
  na.appendChild(txt);

  var li = document.createElement('li');
  li.appendChild(na);
  return li;
}

function testn(number)
{
  var IPnote = '';
  if (document.title.split(' - ')[0].split('.').length == 4)
  {IPnote = "''If this is an [[IP address]], and it is shared by multiple users, ignore this warning if you did not make any [[Wikipedia:vandalism|unconstructive]] edits.'' ";}
  var varticle = '';
  if (location.href.indexOf('&vanarticle=') != -1)
  {varticle = ' to [[' + unescape(location.href.split('&vanarticle=')[1].split('&')[0].replace(/(Image|Category):/i,':$1:')) + ']]';}
  var f = document.editform, t = f.wpTextbox1;
  if (t.value.length > 0)
    t.value += '\n';
  t.value +="====" + "Regarding edits made during [[{{subst:CURRENTMONTHNAME}} {{subst:CURRENTDAY}}]] [[{{subst:CURRENTYEAR}}]] ([[UTC]])" + varticle + "====" + "\n" + "{{subst:" + "test" + number + "}} " + IPnote + "~" + "~" + "~" + "~";
  f.wpSummary.value = "User notice:" + " test" + number;
}

function warningn()
{
  var IPnote = '';
  if (document.title.split(' - ')[0].split('.').length == 4)
  {IPnote = "''If this is an [[IP address]], and it is shared by multiple users, ignore this warning if you did not make any [[Wikipedia:vandalism|unconstructive]] edits.'' ";}
  var varticle = '';
  if (location.href.indexOf('&vanarticle=') != -1)
  {varticle = ' to [[' + unescape(location.href.split('&vanarticle=')[1].split('&')[0].replace(/(Image|Category):/i,':$1:')) + ']]';}
  var f = document.editform, t = f.wpTextbox1;
  if (t.value.length > 0)
    t.value += '\n';
  t.value +="====" + "Regarding edits made during [[{{subst:CURRENTMONTHNAME}} {{subst:CURRENTDAY}}]] [[{{subst:CURRENTYEAR}}]] ([[UTC]])" + varticle + "====" + "\n" + "{{subst:" + "bv" + "}} " + IPnote + "~" + "~" + "~" + "~";
  f.wpSummary.value = "User notice:" + " bv";
}

function testbl(number)
{
  var IPnote = '';
  if (document.title.split(' - ')[0].split('.').length == 4)
  {IPnote = "''If this is an [[IP address]], and it is shared by multiple users, ignore this warning if you did not make any [[Wikipedia:vandalism|unconstructive]] edits.'' ";}
  var varticle = '';
  if (location.href.indexOf('&vanarticle=') != -1)
  {varticle = ' to [[' + unescape(location.href.split('&vanarticle=')[1].split('&')[0].replace(/(Image|Category):/i,':$1:')) + ']]';}
  var f = document.editform, t = f.wpTextbox1;
  if (t.value.length > 0)
    t.value += '\n';
  t.value +="====" + "Regarding edits made during [[{{subst:CURRENTMONTHNAME}} {{subst:CURRENTDAY}}]] [[{{subst:CURRENTYEAR}}]] ([[UTC]])" + varticle + "====" + "\n" + "{{subst:" + "Blank" + number + "}} " + IPnote + "~" + "~" + "~" + "~";
  f.wpSummary.value = "User notice:" + " Blank" + number;
}

function spam()
{
  var IPnote = '';
  if (document.title.split(' - ')[0].split('.').length == 4)
  {IPnote = "''If this is an [[IP address]], and it is shared by multiple users, ignore this warning if you did not make any [[Wikipedia:vandalism|unconstructive]] edits.'' ";}
  var varticle = '';
  if (location.href.indexOf('&vanarticle=') != -1)
  {varticle = ' to [[' + unescape(location.href.split('&vanarticle=')[1].split('&')[0].replace(/(Image|Category):/i,':$1:')) + ']]';}
  var f = document.editform, t = f.wpTextbox1;
  if (t.value.length > 0)
    t.value += '\n';
  t.value +="====" + "Regarding edits made during [[{{subst:CURRENTMONTHNAME}} {{subst:CURRENTDAY}}]] [[{{subst:CURRENTYEAR}}]] ([[UTC]])" + varticle + "====" + "\n" + "{{subst:" + "spam}} " + IPnote + "~" + "~" + "~" + "~";
  f.wpSummary.value = "User notice:" + " spam";
}

function spamn(number)
{
  var IPnote = '';
  if (document.title.split(' - ')[0].split('.').length == 4)
  {IPnote = "''If this is an [[IP address]], and it is shared by multiple users, ignore this warning if you did not make any [[Wikipedia:vandalism|unconstructive]] edits.'' ";}
  var varticle = '';
  if (location.href.indexOf('&vanarticle=') != -1)
  {varticle = ' to [[' + unescape(location.href.split('&vanarticle=')[1].split('&')[0].replace(/(Image|Category):/i,':$1:')) + ']]';}
  var f = document.editform, t = f.wpTextbox1;
  if (t.value.length > 0)
    t.value += '\n';
  t.value +="====" + "Regarding edits made during [[{{subst:CURRENTMONTHNAME}} {{subst:CURRENTDAY}}]] [[{{subst:CURRENTYEAR}}]] ([[UTC]])" + varticle + "====" + "\n" + "{{subst:" + "spam" + number + "}} " + IPnote + "~" + "~" + "~" + "~";
  f.wpSummary.value = "User notice:" + " spam" + number;
}

//LAST DIFF TAB
function lastdiff() 
    {
    if (document.title.indexOf("Editing ") != -1)
    {return;}
    z=document.getElementById("content").childNodes;
    for (var n=0;n<z.length;n++) { 
      if (z[n].className=="firstHeading") 
      {
  var pname = URLEncoding(z[n].innerHTML);
      }
    }
    var l=addTab("http://en.wikipedia.org/w/index.php?title=" + pname + "&diff=cur&oldid=prev", 'last', '');
    l.lastChild.title="Show most recent diff";
}

//Quick warning tabs
addOnloadHook(add_testn_tabs);
function add_testn_tabs() 
{ 
var c1 = document.getElementById('column-one'); 
var tabs = c1.getElementsByTagName('div')[0].getElementsByTagName('ul')[0];
if(document.getElementById('ca-history'))
{lastdiff();}
if (document.title.indexOf("Editing User talk:") != -1)
    {
      tabs.appendChild(tnaddlilink('javascript:testn(1)',"t"));
      tabs.appendChild(tnaddlilink('javascript:testn(2)',"t2"));
      tabs.appendChild(tnaddlilink('javascript:testn(3)',"v"));
      tabs.appendChild(tnaddlilink('javascript:warningn()',"w"));
      tabs.appendChild(tnaddlilink('javascript:testbl(2)',"b"));
      tabs.appendChild(tnaddlilink('javascript:testbl(3)',"b2"));
      tabs.appendChild(tnaddlilink('javascript:spam()',"s"));
      tabs.appendChild(tnaddlilink('javascript:spamn(2)',"s2"));
      if(document.getElementById('ca-delete'))
      {
        document.getElementById('ca-delete').firstChild.innerHTML = '[d]';
      }  
      if(document.getElementById('ca-move'))
      {
      document.getElementById('ca-move').firstChild.innerHTML = '[m]';
      }  
      if(document.getElementById('ca-watch'))
      {
      document.getElementById('ca-watch').firstChild.innerHTML = '[w]';
       }  
      if(document.getElementById('ca-unwatch'))
      {
      document.getElementById('ca-unwatch').firstChild.innerHTML = '[uw]';
      }
      if(document.getElementById('ca-edit'))
      {
        document.getElementById('ca-edit').firstChild.innerHTML = 'Edit';
      }
      if(document.getElementById('ca-talk'))
      {
        document.getElementById('ca-talk').firstChild.innerHTML = 'Talk';
      }
      if(document.getElementById('ca-protect'))
      {
        document.getElementById('ca-protect').firstChild.innerHTML = 'P (off)';
      }
      if(document.getElementById('ca-unprotect'))
      {
        document.getElementById('ca-unprotect').firstChild.innerHTML = 'P (on)';
      }
    }
}
//</nowiki></pre>

//<pre><nowiki>
//Please leave the following line
//[[user:Where/easy db]]
//Start db script
//modded by VoA
addOnloadHook(function()
{
  //check if called from deletion request
  if (document.title.indexOf("Editing ") != -1 && wgNamespaceNumber !=-1)
  {
    if (document.URL.lastIndexOf("&fakeaction=huff") == -1)
      return;
    if (document.URL.lastIndexOf("&reason=off") != -1)
    {
      var type = prompt("Enter criteria for speedy deletion, e.g. A1, G3");
      var f = document.editform, t = f.wpTextbox1;
      t.value = "{{db-" + type.toLowerCase() + "}}\n" + t.value;
      f.wpSummary.value = "JS: Requesting speedy deletion ([[WP:CSD#" + type + "|CSD " + type + "]])";
      f.wpSave.click();
      return;
    }
    else if (document.URL.lastIndexOf("&reason=on") != -1)
    {
      var type = prompt("Enter reason for speedy deletion");
      var f = document.editform, t = f.wpTextbox1;
      t.value = "{{db|" + type + "}}\n" + t.value;
      f.wpSummary.value = "JS: Requesting speedy deletion";
      f.wpSave.click();
      return;
    }
  }
  if (window.location.href.search(/Special:|&action=/) != -1)
    return;

  addTab("javascript:easyDb(0)", "db (csd)", "ca-db0", "Request speedy deletion according to WP:CSD", "");
  addTab("javascript:easyDb(1)", "db (reason)", "ca-db0", "Request speedy deletion with reason", "");
});
 
function easyDb(n)
{
  if (n == 0)
  {
    //edit page
    var title = document.title.substr(0, document.title.lastIndexOf(' - Wikipedia, the free'));
    location.assign("/w/index.php?title=" + title + "&action=edit&fakeaction=huff&reason=off");
  }  
   
  if (n == 1)
  {
    //edit page
    var title = document.title.substr(0, document.title.lastIndexOf(' - Wikipedia, the free'));
    location.assign("/w/index.php?title=" + title + "&action=edit&fakeaction=huff&reason=on");
  }
}
//</nowiki></pre>



//Interiot's javascript edit counter
if (document.title.indexOf('User:Interiot/Tool2/code.js') != -1) {
  mw.loader.load('https://en.wikipedia.org/w/index.php?title=User:Interiot/Tool2/code.js&action=raw&ctype=text/javascript'); }

 //<nowiki> Helper tools
mw.loader.load(
             'https://en.wikipedia.org/w/index.php?title=User:Voice_of_All/Addtabs/monobook.js'
             + '&action=raw&ctype=text/javascript&dontcountme=s');
//</nowiki>

 //<nowiki> Helper tools
document.write('<script type="text/javascript" src="' 
             + 'http://en.wikipedia.org/w/index.php?title=User:Voice_of_All/Dropdown/monobook.css' 
             + '&action=raw&ctype=text/javascript&dontcountme=s"></script>');
//</nowiki>

 //<nowiki> AfD/PfD/Copyvio and tagging tabs
document.write('<script type="text/javascript" src="' 
             + 'http://en.wikipedia.org/w/index.php?title=User:Voice_of_All/Deletion/monobook.js' 
             + '&action=raw&ctype=text/javascript&dontcountme=s"></script>');
//</nowiki>[[Category:Wikipedians who use VoA script |{{PAGENAME}}]]


// This script adds an "[[DNSBL|RBL]] check" link to the toolbox on IP user/talk/contribs pages.  <pre><nowiki>

addOnloadHook(function () {
    var href = document.getElementById('t-contributions');
    if (href) href = href.getElementsByTagName('a');
    if (href) href = href[0];
    if (href) href = href.href;
    else href = window.location.href;

    var addr = /(\/wiki\/|[?&]title=)Special:Contributions(\/([^\/?&#]*)|[?&#]|$)/.exec(href);
    if (!addr) return;
    addr = addr[3];
    if (!addr) {
        addr = /^[^?#]*\?([^&#]*&)*target=([^&#]*)/.exec(href);
        if (!addr) return;
        addr = addr[2];
    }
    if (!/^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$/.test(addr)) return;

    addLink('p-tb', 'http://www.robtex.com/rbls/'+addr+'.html', 'RBL check', 't-rblcheck', 'Multi-RBL check', null, 't-contributions');
});

// </nowiki></pre>