MediaWiki:Gadget-Botify.js

// // Will Bot the user just before the Replace Text starts //

function botOnReplaceText { $('#choose_pages').on('submit', function(e){		var api = new mw.Api,		   botExpiry = '1 minute', //Broken: It doesn't expire...		    userName = mw.config.get("wgUserName"),		    rightsToken;		console.log( (mw.config.get("wgUserGroups").indexOf("bot") !== -1) ? userName+" is botted." : userName+" is not botted.");		api.get( { action: 'query', meta: 'tokens', type: 'userrights' }, {			async: false } ).done( function ( data ) { rightsToken=data.query.tokens.userrightstoken; console.log( "Token retrieved: "+rightsToken ); api.post( {				action: 'userrights',				user: userName,				add: 'bot',				expiry: botExpiry,				token: rightsToken			}, {				async: false			} ).done( function ( data ) {				api.get( { action: 'query', meta: 'userinfo', uiprop: 'groups' } ).done( function ( data ) { console.log(data.query.userinfo.groups); } );				console.log( data );				console.log( "Submitting Replace Text..." );			} );		} );	}); } $( botOnReplaceText );

mediaWiki.util.addPortletLink(		"p-tb",		window.location,		"Unbot",		"ca-unbot",		"Click to unbot"	); console.log("|Unbot link added"); $("#ca-unbot").on("click", function(e) {		e.preventDefault;		var api = new mw.Api,		   userName = mw.config.get("wgUserName"),		    rightsToken;		console.log( (mw.config.get("wgUserGroups").indexOf("bot") !== -1) ? userName+" is botted." : userName+" is not botted.");		api.get( { action: 'query', meta: 'tokens', type: 'userrights' } ).done( function ( data ) { console.log( data ); rightsToken=data.query.tokens.userrightstoken; console.log( "Token retrieved: "+rightsToken ); api.post( {				action: 'userrights',				user: userName,				remove: 'bot',				token: rightsToken			} ).done( function ( data ) {				console.log( data );				alert( mw.config.get("wgUserGroups") + " \n" + ( (mw.config.get("wgUserGroups").indexOf("bot") !== -1) ? userName+" is currently botted." : userName+" is currently not botted." ) );				api.get( { action: 'query', meta: 'userinfo', uiprop: 'groups' } ).done( function ( data ) { alert(						data.query.userinfo.groups + " \n"						+ ( (data.query.userinfo.groups.indexOf("bot") !== -1) ? userName+" is now botted." : userName+" is now not botted." )					);				} );			} );		} );	}); console.log("|Unbot event added");