User:Magister Scienta/default edit summary.js

if (typeof(unsafeWindow) != 'undefined') {	var console = unsafeWindow.console; mw = unsafeWindow.mw; } $(defaultEditSummary);

function defaultEditSummary {	if (!$('#wpSummary').length || ($('#wpSummary').attr('value') != '' && $('#wpSummary').attr('value').indexOf('/*') == -1) || !$('#wpTextbox1').length) return false; //If the edit summary exists, or if its a special page, the program ends here

var myValue; var defaultValue = 'cleanup of page'; //Edit summary if none of the criteria below are met

//Start of core situations if ($('#wpTextbox1').attr('value').length == 0 && mw.config.get('wgCanonicalNamespace') != 'User_talk' ) myValue = 'created page'; // If a non user-talk page is created if ($('#wpTextbox1').attr('value').length == 0 && mw.config.get('wgCanonicalNamespace') == 'User_talk' ) myValue = 'Welcomed new user using Template:Welcome-to-Wikipedia'; // If a user talk page is created else if (mw.config.get('wgCanonicalNamespace') == 'User_talk' && mw.config.get('wgPageName').indexOf('Archive') != -1) myValue = 'archiving page'; // If a user talk page is archived else if ($('#wpTextbox1').attr('value').length != 0 && mw.config.get('wgCanonicalNamespace') == 'Project' || mw.config.get('wgCanonicalNamespace') == 'Talk' ||		mw.config.get('wgCanonicalNamespace').indexOf('_talk') != -1) myValue = 'commenting'; // If a Wikipedia (aka Project) page or a talk page is edited (not created) else myValue = defaultValue; // If none of the criteria are met

//End of core situations

if ($('#wpSummary').attr('value').indexOf('/*') != -1 && ($('#wpSummary').attr('value').indexOf('*/') + 3) == $('#wpSummary').attr('value').length) {		var addedValue = ''; if (myValue != defaultValue) addedValue = myValue; $('#wpSummary').attr('value', document.getElementById('wpSummary').value + addedValue); }	else if ($('#wpSummary').attr('value').indexOf('/*') == -1) $('#wpSummary').attr('value', myValue); $('#wpSummary').focus(function	{		var summary = $(this);		var index = summary.attr('value').indexOf(myValue);		if (index == -1) return false;		summary[0].selectionStart = index;		summary[0].selectionEnd = index + myValue.length;	}); }