User:Zppix/cvtToolbox.js

///CVT Toolbox by Zppix

if($('input[name="disablecookiewarning"')[0]) $('input[name="disablecookiewarning"')[0].click // Disable if you want the cookie warnings by placing "//" in front of "if($...".

///CVTReasons // /* * Script designed to add CVT specific deletion and block reasons on wikis. * Based heavily off https://meta.wikimedia.org/w/index.php?title=User:Snowolf/GS_delete.js */ $( document ).ready( function {	'use strict';

if ( mw.config.get( 'wgAction' ) !== 'protect' && mw.config.get( 'wgAction' ) !== 'delete' && mw.config.get( 'wgCanonicalSpecialPageName' ) !== 'Block' && mw.config.get( 'wgCanonicalSpecialPageName' ) !== 'GlobalBlock' ) { return; }

// Creates the html for a containing the given reasons function constructOptgroup( reasons ) { var html = '';

for ( var i = 0; i<reasons.length; i++ ) { html += mw.html.element( 'option', { 'value' : reasons[i] }, reasons[i] ); }		html += ' ';

return html; }

// Reasons for both delete and block var additionalReasons = [ "Spam (CVT action)", "Vandalism (CVT action)", ];	// Reasons for protect only var additionalProtect = additionalReasons;/*.concat( [			Not sure we have any of these.		] );*/ // Reasons for delete only var additionalDelete = additionalReasons;/*.concat( [			Not sure we have any of these.		] );*/ // Reasons for global blocks only var additionalGlobalBlock = additionalReasons;/*.concat( [			Not sure we have any of these.		] );*/ // Reasons for blocks only var additionalBlock = additionalReasons.concat( [			"Intimidating behaviour/harassment (CVT action)",			"Cross-wiki issues (CVT action)",		] );

if ( mw.config.get( 'wgAction' ) === 'delete' ) { // Append reasons to action=delete $( '#wpDeleteReasonList' ).append( constructOptgroup( additionalDelete ) ); }	else if ( mw.config.get( 'wgAction' ) === 'protect' ) { // Append reasons to action=protect $( '#wpProtectReasonSelection' ).append( constructOptgroup( additionalProtect ) ); }	else if ( mw.config.get( 'wgAction' ) === 'globalblock' ) { // Append reasons to action=globalblock $( '#mw-globalblock-reason' ).append( constructOptgroup( additionalGlobalBlock ) ); }	else { // Special:Block $( '#mw-input-wpReason' ).append( constructOptgroup( additionalBlock ) ); // Unselect the block reason and put it into the "Other:" field $( 'form input[type=submit]' ).click( function {			var blockReason = '',				$reasonSelect = $( '#mw-input-wpReason' ),				$reasonOther = $( '#mw-input-wpReason-other' );

if ( $reasonSelect.val === 'other' ) { return; }

blockReason = $reasonSelect.val; if ( blockReason && $reasonOther.val ) { blockReason += ': '; }			blockReason += $reasonOther.val;

$reasonOther.val( blockReason ); $reasonSelect.val( 'other' ); } );	} } ); ///end CVTReasons // mw.util.addPortletLink(   'p-personal',    mw.util.getUrl("Special:AbuseLog"),    'AbuseLog',    'pt-abuseloglink',    'View the Abuse Log',    null,    '#pt-watchlist' ); var user = mw.config.get( 'wgRelevantUserName' ); if (mw.util.isIPAddress(user) === true) { mw.util.addPortletLink(   'p-personal',	mw.util.getUrl( ( mw.config.get('wgDBname') === 'metawiki' ? '' : 'meta:' ) + 'Special:GlobalBlock/' + user ),    'Add Global Block',    'pt-globalblock',    'Block currently viewed user globally.',    null,    '#pt-watchlist' ); }

// //This tool adds two different ways to quickly block and lock a user account mw.util.addPortletLink(	'p-personal',	'#',	'QuickLock',	'p-quicklock',	'Quickly lock an account',	null,	'#pt-preferences' );

$("#p-quicklock").click(function{	var user = prompt("Enter a username:");	if( user !== mw.config.get("wgUserName") ) {		var summary = '';		do {summary = prompt("Enter a reason for locking the account:", "LTA");}		while (summary.trim.length === 0);		lock(user, summary);	} });

if( mw.config.get("wgRelevantUserName") && mw.config.get("wgRelevantUserName") !== mw.config.get("wgUserName") ) { mw.util.addPortletLink(		'p-cactions',		'#',		'QuickLock',		'p-lockacc',		'Quickly lock ' + mw.config.get("wgRelevantUserName")	); $("#p-lockacc").click(function{		var user = mw.config.get("wgRelevantUserName");		if(confirm("Lock account " + user + "?")) {			var summary = '';			do {summary = prompt("Enter a reason for locking the account:", "LTA");}			while (summary.trim.length === 0);			lock(user, summary);		}	}); }

function lock( username, summary ) { $.ajax( {       url: mw.util.wikiScript( 'api' ),        type: 'POST',        dataType: 'json',        data: {            format: 'json',            action: 'block',            user: username,            expiry: "infinite",            nocreate: 1,            autoblock: 1,            noemail: 1,            reblock: 1,            reason: summary,            token: mw.user.tokens.get( 'csrfToken' ),        }    } ).done( function {    	console.log( "Blocked user: " + username );    }    ).fail( function ( e, data ) {    	console.log( e.message );    	console.log( JSON.stringify( data ) );    }); $.getJSON(	//Get setglobalaccountstatus token   mw.util.wikiScript('api'),    {        format: 'json',        action: 'query',        meta: 'tokens',        type: 'setglobalaccountstatus'    }).done( function ( data ) {    	try {    		var Token = data.query.tokens.setglobalaccountstatustoken;    		//Lock account    		$.ajax( { url: mw.util.wikiScript( 'api' ), type: 'POST', dataType: 'json', data: { format: 'json', action: 'setglobalaccountstatus', user: username, locked: 'lock', reason: summary, token: Token, }	   	} ).done( function { $.getJSON(	   			mw.util.wikiScript( 'api' ),	    			{	    				format: 'json',	    				action: 'query',	    				list: 'globalallusers',	    				agufrom: username,	    				agulimit: 1,	    				aguprop: 'lockinfo'	    			}	    		).done(function (data) {	    			if(data.query.globalallusers[0].locked !== undefined)	    				console.log( "Locked account: " + username );	    			else {	    				alert( 'Could not lock account ' + username + '\nYou will now be sent to CentralAuth to do so manually' );	    				window.location = mw.util.getUrl( 'Special:CentralAuth/' + username );	    			}	    		}); }		   ).fail( function ( e, data ){ console.log( e.message ); console.log( JSON.stringify( data ) ); });   	}    	catch ( e ) {        	console.log( "Content request error: " + e.message );        	console.log( "Content request response: " + JSON.stringify( data ) );    	}	} ).fail( function  {	    console.log( "While getting the token, there was an AJAX error." );	} ); }

//