User:Synoman Barris/Warn.js

/** * Script for warning users * Rip-off from Twinkle's Warn module(MediaWiki:Gadget-friendlywelcome.js) */

// $.when(	mw.loader.using('ext.gadget.morebits'), 	$.ready ).then(function {

if (!mw.config.get('wgRelevantUserName')) { return; }

var Warn = {}; window.Warn = Warn;

Warn.advert = ' (Syno warn)';

var li = mw.util.addPortletLink('p-cactions', '#', 'Syno warn', 'p-warn', 'Warn user'); li.addEventListener('click', function {	Warn.callback(mw.config.get('wgRelevantUserName')); });

Warn.callback = function (uid) { if (uid === mw.config.get('wgUserName') && !confirm('Are you really sure you want to warn yourself?...')) { return; }	Morebits.wiki.api.setApiUserAgent('wb:User:Synoman Barris/warn.js');

var Window = new Morebits.simpleWindow(600, 420); Window.setTitle('Warn user'); Window.addFooterLink('Syno Warner', 'WB:Warn');

var form = new Morebits.quickForm(Wish.callback.evaluate);

form.append({		type: 'select',		name: 'type',		label: 'Type of warning: ',		event: Warn.Syno warn,		list: [			{ type: 'option', value: 'Vandalism', label: 'Warning', selected: true },			{ type: 'option', value: 'Test edit ', label: 'Warning' },			{ type: 'option', value: 'Blanking', label: 'Warning' }		].concat( window.warn_CustomTemplates && window.warn_CustomTemplates.length ? [ { type: 'option', value: 'custom', label: 'Custom templates' } ] : [] )	});

form.append({		type: 'div',		id: 'warnWorkArea'	});

form.append({		type: 'input',		name: 'heading',		label: 'Section heading: ',		value: 'Warning'	});

var previewlink = document.createElement('a'); $(previewlink).click(function {		Wish.callbacks.preview(result); // |result| is defined below	}); previewlink.style.cursor = 'pointer'; previewlink.textContent = 'Preview'; form.append({ type: 'div', id: 'wishpreview', label: [ previewlink ] }); form.append({ type: 'div', id: 'wish-previewbox', style: 'display: none' });

form.append({ type: 'submit' });

var result = form.render; Window.setContent(result); Window.display; result.previewer = new Morebits.wiki.preview($('#wish-previewbox').last[0]);

// initialize the wish list var evt = document.createEvent('Event'); evt.initEvent('change', true, true); result.type.dispatchEvent(evt); };

Warn.populateWishList = function(e) { var type = e.target.value; var form = e.target.form; var container = new Morebits.quickForm.element({ type: 'fragment' });

var appendTemplates = function(list) { container.append({			type: 'radio',			name: 'template',			list: list.map(function(obj) { return { value: obj, label: '' }			})		});	};

switch (type) { case 'birthday': form.heading.value = 'Happy Birthday!'; appendTemplates([				'Happy Birthday',				'Happy Birthday 2',				'Happy Birthday 3',				'Happy Birthday 4',				'Happy Birthday 5',				'Happy Birthday 6',				'Happy Birthday 7',				'Happy Birthday 8',				'Happy Birthday 9',				'Happy Birthday 10',				'Happy Birthday 11',				'Happy Birthday 12',				'Happy Birthday 13'			]); break;

case 'firsteditday': form.heading.value = 'Happy First Edit Day!'; appendTemplates([				'First Edit Day',				'First Edit Day 2',				'First Edit Day 3',				'First Edit Day 4',			]); break;

case 'anniv': form.heading.value = 'Happy Adminship Anniversary!'; appendTemplates([				'Happy Adminship',				'Happy Adminship 2',				'Happy Adminship 3',				'Happy Adminship 4',				'Happy Adminship 5',				'Happy Adminship 6',				'Happy Adminship 7',				'Happy Bureaucratship',				'Happy Bureaucratship 2',				'Happy Bureaucratship 3',			]); break;

case 'custom': form.heading.value = ''; appendTemplates(window.BDCS_CustomTemplates); break;

default: container.append({ type: 'div', label: 'Wish.populateWishList: something went wrong' }); break; }

var rendered = container.render; $('#wishWorkArea').empty.append(rendered);

var firstRadio = form.template[0] || form.template; firstRadio.checked = true; };

Wish.getTemplateWikitext = function(template, heading) { return '==' + heading + '==\n'; };

Wish.callbacks = { preview: function(form) { form.previewer.beginRender(Wish.getTemplateWikitext(form.getChecked('template'), form.heading.value), 'User talk:' + mw.config.get('wgRelevantUserName')); },	main: function(pageobj) { var params = pageobj.getCallbackParameters; var text = pageobj.getPageText;

var wishText = Wish.getTemplateWikitext(params.value, params.heading);

text += '\n' + wishText;

summaryText = (params.heading ? ('/* ' + params.heading + ' */ ') : '') + 'new section'; pageobj.setPageText(text); pageobj.setEditSummary(summaryText + Wish.advert); pageobj.setCreateOption('nocreate'); pageobj.save; } };

Wish.callback.evaluate = function wishEvaluate(e) { var form = e.target;

var params = { value: form.getChecked('template'), heading: form.heading.value };

Morebits.simpleWindow.setButtonsEnabled(false); Morebits.status.init(form);

var userTalkPage = mw.config.get('wgFormattedNamespaces')[3] + ':' + mw.config.get('wgRelevantUserName'); Morebits.wiki.actionCompleted.redirect = userTalkPage; Morebits.wiki.actionCompleted.notice = 'Wishing complete, reloading talk page in a few seconds';

var wikipedia_page = new Morebits.wiki.page(userTalkPage, 'User talk page modification'); wikipedia_page.setFollowRedirect(true); wikipedia_page.setCallbackParameters(params); wikipedia_page.load(Wish.callbacks.main); };

}); //