User:Ostrichyearning3/challenge-submit.js

/* jshint maxerr: 999 */ /* */ $.when(	mw.loader.using(['mediawiki.Title', 'ext.gadget.morebits']),	$.ready ).then(function {

// hide on special pages and talk pages if (mw.config.get('wgNamespaceNumber') < 0 || mw.config.get('wgNamespaceNumber') % 2 === 1 || !mw.config.get('wgRevisionId')) { return; }

var advert = ' (challenge-submit)';

var menu = mw.util.addPortletLink('p-cactions', '#', 'challenge-submit', 'p-challenge-submit', 'Redirect to another article and add merge templates to talk pages'); menu.addEventListener('click', callback);

function callback(e) { if (e) e.preventDefault; var Window = new Morebits.simpleWindow(600, 500); Window.setScriptName('challenge-submit'); Window.setTitle("Submit articles to challenges"); Window.addFooterLink('10000 Challenge', 'Wikipedia:The 10,000 Challenge');

var form = new Morebits.quickForm(evaluate);

form.append({		type: 'input',		label: 'Location (used for undefined', name: 'location', value: '' });

// form.append({	// 	type: 'input', // changed to 'date' after render	// 	name: 'date',	// 	label: 'Date of merger: ',	// 	value: new Date.toISOString.slice(0, 10),	// 	tooltip: 'This date is used in the and  templates'	// });

form.append({		type: 'checkbox',		name: 'challenges',		list: [			{				label: 'Submit to the 10000 challenge',				name: 'chall_10_submit',				checked: true			},			{				label: 'Submit to the 50000 challenge',				name: 'chall_50_submit',				checked: true			}			// {		]	});

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

var result = form.render;

Window.setContent(result); Window.display;

}

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

var params = {}; params.target = form.target.value; if (!params.target.trim) { alert('Please enter a flag'); return; }	params.current = Morebits.pageNameNorm;

// params.redirect = form.redirect.checked; // params.summary = form['redirect.summary'] && form['redirect.summary'].value.replace('###', params.target); // params.removemerge = form.removemerge.checked; // params.addmergedfrom = form.addmergedfrom.checked; // params.addmergedto = form.addmergedto.checked; // params.adjusttalktemplates = form.adjusttalktemplates.checked; params.chall_10_submit = form.chall_10_submit.checked; params.chall_50_submit = form.chall_50_submit.checked; params.location = form.location.value;

// var dateobj = new Date(form.date.value); // if (isNaN(dateobj.getTime)) { // 	alert('Invalid date. Please enter in YYYY-MM-DD format'); // should arise only for browsers w/o datepicker // 	return; // }	// params.date = dateobj.getUTCDate + ' ' + dateobj.getUTCMonthName + ' ' + dateobj.getUTCFullYear;

Morebits.simpleWindow.setButtonsEnabled(false); Morebits.status.init(form); Morebits.wiki.api.setApiUserAgent('w:User:Ostrichyearning3/challenge-submit.js');

if (params.chall_10_submit) { // var page = new Morebits.wiki.page(params.current, 'Submitting'); var challenge_page = new Morebits.wiki.page(63582974, 'Submitting');

page.load(function(page) {			var pageText = page.getPageText + "append"

page.setPageText(pageText); page.setEditSummary(params.summary + advert); page.setCreateOption('nocreate'); page.save; });	}

}

}); /* */