User:Zppix/cvtToolbox.js

///CVT Toolbox by Zppix ///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' ); 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' );