Jump to content

User:Mike.lifeguard/blockOptions.js

From Meta, a Wikimedia project coordination wiki

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5.
function QuickBlock (blockOther,blockReason,anonOnly,createAccount,enableAutoblock,emailBan,hideName,watchUser,allowUsertalk) {
	blockForm = document.getElementById('blockip');
	inputs = blockForm.getElementsByTagName('input');
	for (i=0; i<inputs.length; i++) {
		if (inputs[i].name == 'wpBlockOther') {
			inputs[i].value = blockOther;
			continue;
		}
		if (inputs[i].name == 'wpBlockReason') {
			inputs[i].value = blockReason;
			continue;
		}
		if (inputs[i].name == 'wpAnonOnly') {
			if (anonOnly==1) {
				inputs[i].checked = true;
			}
			else {
				inputs[i].checked = false;
			}
			continue;
		}
		if (inputs[i].name == 'wpCreateAccount') {
			if (createAccount==1) {
				inputs[i].checked = true;
			}
			else {
				inputs[i].checked = false;
			}
			continue;
		}
		if (inputs[i].name == 'wpEnableAutoblock') {
			if (enableAutoblock==1) {
				inputs[i].checked = true;
			}
			else {
				inputs[i].checked = false;
			}
			continue;
		}
		if (inputs[i].name == 'wpEmailBan') {
			if (emailBan==1) {
				inputs[i].checked = true;
			}
			else {
				inputs[i].checked = false;
			}
			continue;
		}
		if (inputs[i].name == 'wpHideName') {
			if (hideName==1) {
				inputs[i].checked = true;
			}
			else {
				inputs[i].checked = false;
			}
			continue;
		}
		if (inputs[i].name == 'wpWatchUser') {
			if (watchUser==1) {
				inputs[i].checked = true;
			}
			else {
				inputs[i].checked = false;
			}
			continue;
		}
		if (inputs[i].name == 'wpAllowUsertalk') {
			if (allowUsertalk==1) {
				inputs[i].checked = true;
			}
			else {
				inputs[i].checked = false;
			}
			continue;
		}
	}
	blockForm.submit();
}

function userIsInGroup (group) {
//are they in a given local group?
	if (wgUserGroups) {
		if (!group || group.length == 0) group = '*';
		if (wgUserGroups.join (' ').indexOf (group) != -1){
			return true;
		}
		else{
			return false;
		}
	}
	return false;
}
function userIsInGlobalGroup (group) {
//are they in a given global group?
	if (wgGlobalGroups) {
		if (!group || group.length == 0) group = '*';
		if (wgGlobalGroups.join (' ').indexOf (group) != -1){
			return true;
		}
		else{
			return false;
		}
	}
	return false;
}

function addblockoptions() {//blockOther,blockReason,anonOnly,createAccount,enableAutoblock,emailBan,hideName,watchUser,allowUsertalk
	mw.util.addPortletLink('p-cactions',
		'javascript:('+QuickBlock+')("31 hours","recent vandalism",1,1,0,0,0,0,1)',
		'vandal: 31h',
		'p-block-31h');
	mw.util.addPortletLink('p-cactions',
		'javascript:('+QuickBlock+')("1 week","repeat vandalism",1,1,1,0,0,0,1)',
		'vandal: 1w',
		'p-block-week');
	mw.util.addPortletLink('p-cactions',
		'javascript:('+QuickBlock+')("1 month","chronic vandalism",1,1,1,0,0,0,1)',
		'vandal: 1m',
		'p-block-month');
	mw.util.addPortletLink('p-cactions',
		'javascript:('+QuickBlock+')("infinite","vandalism-only account",0,1,0,0,0,0,1)',
		'vandal: indef',
		'p-block-vandalism');
	mw.util.addPortletLink('p-cactions',
		'javascript:('+QuickBlock+')("3 months","cross-wiki issues",0,1,1,0,0,0,0)',
		'xwiki: 3mo',
		'p-block-xwiki');
	mw.util.addPortletLink('p-cactions',
		'javascript:('+QuickBlock+')("1 year","[[w:Open proxy|Open proxy]] or [[w:Zombie computer|zombie]] ([[m:WM:NOP|info]])",1,1,0,0,0,0,1)',
		'op',
		'p-block-proxy');
	if(userIsInGroup('checkuser')||userIsInGlobalGroup('steward')) mw.util.addPortletLink('p-cactions',
		'javascript:('+QuickBlock+')("infinite","checkuserblock",0,1,0,1,0,0,0)',
		'checkuserblock-user',
		'p-block-cu-user');
	if(userIsInGroup('checkuser')||userIsInGlobalGroup('steward')) mw.util.addPortletLink('p-cactions',
		'javascript:('+QuickBlock+')("1 year","checkuserblock",0,1,0,0,0,0,1)',
		'checkuserblock-IP',
		'p-block-cu-ip');
	if(userIsInGroup('oversight')||userIsInGlobalGroup('steward')) mw.util.addPortletLink('p-cactions',
		'javascript:('+QuickBlock+')("infinite","checkuserblock",0,1,1,1,1,0,0)',
		'invisible',
		'p-block-invisible');
	//blockOther,blockReason,anonOnly,createAccount,enableAutoblock,emailBan,hideName,watchUser,allowUsertalk
}
if ( mw.config.get('wgCanonicalSpecialPageName') == 'Blockip' ) {
  $(addblockoptions);
}