User:Pkbwcgs/Twinkle warn.js

From Wiktionary, the free dictionary
Jump to navigation Jump to search

Note – after saving, you may have to bypass your browser’s cache to see the changes.

  • Mozilla / Firefox / Safari: hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (Command-R on a Macintosh);
  • Konqueror and Chrome: click Reload or press F5;
  • Opera: clear the cache in Tools → Preferences;
  • Internet Explorer: hold Ctrl while clicking Refresh, or press Ctrl-F5.

// If TwinkleConfig aint exist.
if( typeof( TwinkleConfig ) == 'undefined' ) {
	TwinkleConfig = {};
}
 
/**
 TwinkleConfig.defaultGroup (int)
 if true, watch the page which has been dispatched an warning or notice, if false, default applies
 */
if( typeof( TwinkleConfig.defaultWarningGroup ) == 'undefined' ) {
	TwinkleConfig.defaultWarningGroup = 1;
}
 
/**
 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 = false;
}
 
/**
 TwinkleConfig.watchWarnings (boolean)
 if true, watch the page which has been dispatched an warning or notice, if false, default applies
 */
if( typeof( TwinkleConfig.watchWarnings ) == 'undefined' ) {
	TwinkleConfig.watchWarnings = true;
}
 
/**
 TwinkleConfig.blankTalkpageOnIndefBlock (boolean)
 if true, blank the talk page when issuing an indef block notice
 */
if( typeof( TwinkleConfig.blankTalkpageOnIndefBlock ) == 'undefined' ) {
	TwinkleConfig.blankTalkpageOnIndefBlock = false;
}
 
/**
 TwinkleConfig.summaryAd (string)
 If ad should be added or not to summary, default [[COM:TWINKLE|Twinkle]]
 */
if( typeof( TwinkleConfig.summaryAd ) == 'undefined' ) {
	TwinkleConfig.summaryAd = " using [[COM:TWINKLE|Twinkle]]";
}
 
function twinklewarn() {
	if( wgNamespaceNumber == 3 ) {
		mw.util.addPortletLink( 'p-cactions', (twinkleConfigExists ? "javascript:twinklewarn.callback()" : 'javascript:alert("Your account is too new to use Twinkle.");'), "Warn", "tw-warn", "Warn/Notify user", "");
	}
}
$(twinklewarn);
 
twinklewarn.callback = function twinklewarnCallback() {
	var Window = new SimpleWindow( 600, 400 );
	Window.setTitle( "Warn/Notify user" ); 
	var form = new QuickForm( twinklewarn.callback.evaluate );
 
	var main_select = form.append( {
			type:'field',
			label:'Choose type of warning/notice to issue', 
			tooltip:'First choose a main warning group, then the specific warning to issue.'
		} );
 
	var main_group = main_select.append( {
			type:'select',
			name:'main_group',
			event:twinklewarn.callback.change_category 
		} );
 
	main_group.append( { type:'option', label:'General Note (1)', value:'level1', selected: ( TwinkleConfig.defaultWarningGroup == 1 || TwinkleConfig.defaultWarningGroup < 1 || ( userIsInGroup( 'sysop' ) ? TwinkleConfig.defaultWarningGroup > 5 : TwinkleConfig.defaultWarningGroup > 4 ) ) } );
	main_group.append( { type:'option', label:'Caution (2)', value:'level2', selected: ( TwinkleConfig.defaultWarningGroup == 2 ) } );
	main_group.append( { type:'option', label:'Warning (3)', value:'level3', selected: ( TwinkleConfig.defaultWarningGroup == 3 ) } );
	main_group.append( { type:'option', label:'Final warning (4)', value:'level4', selected: ( TwinkleConfig.defaultWarningGroup == 4 ) } );
	if( userIsInGroup( 'sysop' ) ) {
		main_group.append( { type:'option', label:'Blocking', value:'block', selected: ( TwinkleConfig.defaultWarningGroup == 5 ) } );
	}
 
	main_select.append( { type:'select', name:'sub_group', event:twinklewarn.callback.change_subcategory } ); //Will be empty to begin with.
 
	form.append( { 
			type:'input',
			name:'article',
			label:'Linked article',
			value:( QueryString.exists( 'vanarticle' ) ? QueryString.get( 'vanarticle' ) : '' ),
			tooltip:'An article might be linked to the notice, either it was a revert to said article that dispatched this notice. Leave empty for no article to be linked'
		} );
 
 
	var more = form.append( { type:'field', label:'Fill in an optional reason and hit \"Submit\"' } );
	more.append( { type:'textarea', label:'More:', name:'reason', tooltip:'Perhaps a reason, or that a more detailed notice must be appended' } );
	more.append( { type:'submit', label:'Submit' } );
	var result = form.render();
	Window.setContent( result );
	Window.display();
	result.main_group.root = result;
 
	// We must init the first choice (General Note);
	var evt = document.createEvent( "Event" );
	evt.initEvent( 'change', true, true );
	result.main_group.dispatchEvent( evt );
	
	// This is all the messages that might be dispatched by the code
twinklewarn.messages = {
	level1: {
		
		"Vandalism": {
			label:"Vandalism"
			summary:"General note: Bad edits"
},
		"Protologism": {
			label:"Protologism"
			summary:"General note: Protologism"
},
        "Spam": {
        	label:"Spam"
        	summary:"General note: Added spam"
},
        "Unsourced": {
        	label:"Unsourced"
        	summary:"General note: Unsourced"
},        	
        "Not Wikipedia": {
        	label:"Not Wikipedia"
        	summary:"General note: Not Wikipedia"
    },
    level2: {
    	"Vandalism level 2": {
    		label:"Vandalism"
    		summary:"Caution: Bad edits"
    },
    level3: {
    	"Vandalism level 3" {
    		label:"Vandalism"
    		summary:"Warning: Vandalism"
    	}
    }
};

	Status.init( e.target );
 
	var query = { 
		'title': wgPageName, 
		'action': 'submit'
	};
	Wiktionary.actionCompleted.redirect = wgPageName;
	Wiktionary.actionCompleted.notice = "Warning complete, reloading talk page in a few seconds";
	var wiktionary_wiki = new Wiktionary.wiki( 'User talk page modification', query, twinklewarn.callbacks.main );
	wiktionary_wiki.params = params;
	wiktionary_wiki.get();
}