Jump to content

User:Werdan7/twinklewarn.js

From Simple English Wikipedia, the free encyclopedia

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.
// If TwinkleConfig aint exist.
if( typeof( TwinkleConfig ) == 'undefined' ) {
	TwinkleConfig = {};
}

/**
 TwinkleConfig.showSharedIPNotice may take arguments:
  true: to show shared ip notice if an IP address
  false: to not print the notice
*/
if( typeof( TwinkleConfig.showSharedIPNotice ) == 'undefined' ) {
	TwinkleConfig.showSharedIPNotice = true;
}

/**
 TwinkleConfig.markWarningsAsMinor (boolean)
 Defines if a warning should be marked as minor, if false, default is applied as per preference.
*/
if( typeof( TwinkleConfig.markWarningsAsMinor ) == 'undefined' ) {
	TwinkleConfig.markWarningsAsMinor = true;
}

/**
TwinkleConfig.summaryAd (string)
If ad should be added or not to summary, default [[WP:TWINKLE|TWINKLE]]
*/
if( typeof( TwinkleConfig.summaryAd ) == 'undefined' ) {
	TwinkleConfig.summaryAd = "";
}

function blockTagAdd( tag, summary ) {
	var reason = null;
	var notice = null;
	var duration = null;

	if( [ 'block' ].indexOf( tag ) != -1 ) {
		duration = prompt( 'What is the duration of the block? (Put "indef" for an indefinite block, leave blank to not specify)' );
		if( /indef/.exec( duration ) ) {
		reason = prompt( 'Reason for block? (leave blank for none' );
			if( reason !='' ) {
			notice = '[[Image:Octagon-warning.svg|35px|left]]'''You have been [[Wikipedia:Bans_and blocks|blocked]]''' as it says in [[Wikipedia:Bans and blocks|Wikipedia's blocking policy]]{{#if:{{{2|}}}| for {{{2}}}}}{{#if:{{{1|}}}| for breaking the policy against {{{1}}}}}{{#if:' + reason '| for ' + reason '}}.  If you do not agree with this block, please reply here on your talk page by adding the text {{tlp|unblock|''reason''}}, replacing ''reason'' with why you think the block is wrong, or send an e-mail to an active administrator in [[Wikipedia:Administrators and bureaucrats#List of administrators|this list]].~~' + '~~';
			} else {
			notice = '[[Image:Octagon-warning.svg|35px|left]]'''You have been [[Wikipedia:Bans_and blocks|blocked]]''' as it says in [[Wikipedia:Bans and blocks|Wikipedia's blocking policy]]{{#if:{{{2|}}}| for {{{2}}}}}{{#if:{{{1|}}}| for breaking the policy against {{{1}}}}}{{#if:{{{3|}}}| for {{{3}}}}}.  If you do not agree with this block, please reply here on your talk page by adding the text {{tlp|unblock|''reason''}}, replacing ''reason'' with why you think the block is wrong, or send an e-mail to an active administrator in [[Wikipedia:Administrators and bureaucrats#List of administrators|this list]].~~' + '~~';			

		} else if( duration != '' ) {
			notice = '[[Image:Octagon-warning.svg|35px|left]]'''You have been [[Wikipedia:Bans_and blocks|blocked]]''' as it says in [[Wikipedia:Bans and blocks|Wikipedia's blocking policy]]{{#if:' + duration + '| for ' + duration + '}}{{#if:{{{1|}}}| for breaking the policy against {{{1}}}}}{{#if:{{{3|}}}| for {{{3}}}}}.  If you do not agree with this block, please reply here on your talk page by adding the text {{tlp|unblock|''reason''}}, replacing ''reason'' with why you think the block is wrong, or send an e-mail to an active administrator in [[Wikipedia:Administrators and bureaucrats#List of administrators|this list]]. ~~' + '~~';
		} else {
			notice = '[[Image:Octagon-warning.svg|35px|left]]'''You have been [[Wikipedia:Bans_and blocks|blocked]]''' as it says in [[Wikipedia:Bans and blocks|Wikipedia's blocking policy]]{{#if:{{{2|}}}| for {{{2}}}}}{{#if:{{{1|}}}| for breaking the policy against {{{1}}}}}{{#if:{{{3|}}}| for {{{3}}}}}.  If you do not agree with this block, please reply here on your talk page by adding the text {{tlp|unblock|''reason''}}, replacing ''reason'' with why you think the block is wrong, or send an e-mail to an active administrator in [[Wikipedia:Administrators and bureaucrats#List of administrators|this list]]. ~~' + '~~';
		}
	} 

	// BEGIN WikiEd -> wpTextbox1
	if (typeof(wikEdUseWikEd) != 'undefined') {
		if (wikEdUseWikEd == true) {
			WikEdUpdateTextarea();
		}
	}
	// END
	var textbox = document.getElementById( 'wpTextbox1' );
	textbox.value += "\n" + notice;
	// BEGIN wpTextbox1 -> WikiEd
	if (typeof(wikEdUseWikEd) != 'undefined') {
		if (wikEdUseWikEd == true) {
			WikEdUpdateFrame();
		}
	}
	// END

	if( TwinkleConfig.markWarningsAsMinor ) {
		document.getElementById( 'wpMinoredit' ).checked = true;
	}
	document.getElementById( 'wpSummary' ).value = summary + '.' + TwinkleConfig.summaryAd;
}

function tagadd( tag , summary) {
	var article;

	if( QueryString.exists( 'vanarticle' ) ) {
		article = decodeURI(QueryString.get( 'vanarticle' )).replace( /^(Image|Category):/i, ':$1:' );
	} else {
		article = prompt('Which article?').replace( /^(Image|Category):/i, ':$1:' );
	}

	var date = new Date();
	var notice = "";
	var header = "";

	var headerRe = new RegExp( "^===\\s*" + date.getUTCMonthName() + "\\s+" + date.getUTCFullYear() + "\\s*===", 'm' );
	var textbox = document.getElementById( 'wpTextbox1' );

	if ( textbox.value.length > 0 ) {
		textbox.value += '\n';
	}
	if( !headerRe.exec( textbox.value ) ) {
		header += "=== " + date.getUTCMonthName() + " " + date.getUTCFullYear() + " ===\n";
	}

	notice += header;
	notice += "{{subst:" + tag + ( article ? '|' + article + '|subst=subst:' : '' ) + "}} ~~" + "~~"; // subst=subst: hack only on article given as per MW bug :(
	if ( TwinkleConfig.showSharedIPNotice && isIPAddress( wgTitle ) ) {
		switch( QueryString.get( 'type' ) ) {
			case 'vand':
			notice +=  "\n:''If this is a shared [[IP address]], and you didn't make any [[Wikipedia:vandalism|bad]] edits, consider <span style="plainlinks">http://simple.wikipedia.org/w/index.php?title=Special:Userlogin&type=signup creating an account] </span> for yourself so you can avoid further warnings for other people.'' ";
			break;
			default:
			notice +=  "\n:''If this is a shared [[IP address]], and you didn't make the edit, consider <span style="plainlinks">http://simple.wikipedia.org/w/index.php?title=Special:Userlogin&type=signup creating an account] </span> for yourself so you can avoid further notices for other people.'' ";
			break;
		}
	}

	// BEGIN WikiEd -> wpTextbox1
	if (typeof(wikEdUseWikEd) != 'undefined') {
		if (wikEdUseWikEd == true) {
			WikEdUpdateTextarea();
		}
	}
	// END


	textbox.value += "\n" + notice;
	// BEGIN wpTextbox1 -> WikiEd
	if (typeof(wikEdUseWikEd) != 'undefined') {
		if (wikEdUseWikEd == true) {
			WikEdUpdateFrame();
		}
	}
	// END	

	document.getElementById( 'wpSummary' ).value = summary + ( article ? ' on [[' + article + ']]'  : '' ) + '.' + TwinkleConfig.summaryAd;
	if( TwinkleConfig.markWarningsAsMinor ) {
		document.getElementById( 'wpMinoredit' ).checked = true;
	}
}

//Quick warning tabs
function add_warn_tabs() 
{ 
	var tabs = document.getElementById('p-cactions').getElementsByTagName('ul')[0];

	if ( wgNamespaceNumber == 3 && ( QueryString.equals( 'action', 'edit' ) || QueryString.equals( 'action', 'submit' ) ) ) {

		addlimenu(tabs, '[1]', 'warningfunc');
				mw.util.addPortletLink('warningfunc', 'javascript:tagadd("test", "UW: test1")', 'T1', '');
		mw.util.addPortletLink('warningfunc', 'javascript:tagadd("test2", "UW: test2")', 'T2', '');
		mw.util.addPortletLink('warningfunc', 'javascript:tagadd("test3", "UW: test3")', 'T3', '');
		mw.util.addPortletLink('warningfunc', 'javascript:tagadd("test4", "UW: test4")', 'T4', '');
		mw.util.addPortletLink('warningfunc', 'javascript:tagadd("test4im", "UW: test4im")', 'BV', '');

		
		if( userIsInGroup( 'sysop' ) ) {
			addlimenu(tabs, '[B]', 'blockfunc');
			a		mw.util.addPortletLink('warningfunc', 'javascript:tagadd("block", "blocked")', 'block', '');'');
		}
	}
}
$(add_warn_tabs);