MediaWiki:Gadget-Welcome.js

/* * Adds a new link in the toolbox on user-talk-edit pages to automatically * welcome a new user or an anonymous user. Uses AJAX-based editing to post * a welcome message automatically. Requires Whiteknight's wknightcore.js * library to handle the AJAX editing functions. */

mw.hook('wikibooks.panels.tools').add(function(mw, $) {	if (mw.config.get('wgNamespaceNumber') === 3) {		if (mw.config.get('wgAction') === 'edit') {			var $text = $('#wpTextbox1'), tab;			if ($text.length && $text.val.length < 300) {				if (mw.config.get('wgTitle').match(/\d+\.\d+\.\d+\.\d+/)) {					tab = 'joinus';				} else {					tab = 'welcome';				}				add_toolbox_link(WelcomeUser, tab, 'ca-welcome');			}		}		add_toolbox_link(WarnUser, 'warn', 'ca-warn');	}	if (mw.config.get('wgCanonicalSpecialPageName') === "Contributions") {		add_toolbox_link(WarnUser, 'warn', 'ca-warn');	} });

function WelcomeUser { if (confirm("Welcome this new user?")) { if (mw.config.get('wgTitle').match(/\d+\.\d+\.\d+\.\d+/)) { wk.postEdit(mw.config.get('wgPageName'), "{"+"{subst:joinus|--"+"}}", "Join Us!", 				{section:"new"}); } else { wk.postEdit(mw.config.get('wgPageName'), "{"+"{subst:Bigwelcome|--"+"}}", "Welcome!",				{section:"new"}); }		$("#ca-welcome").html("welcomed"); var form = document.getElementById("editform"); if (form) { wk.toggleDisplay(form, "none"); } } }

function WarnUser { var username = mw.config.get('wgTitle'); if (mw.config.get('wgCanonicalSpecialPageName') === "Contributions") { username = $('input[name=target]').val; if (!username) { return; }	} else if (mw.config.get('wgNamespaceNumber') !== 3) { return; }	if (confirm("Warn this user? (" + username + ")")) { username = "User talk:" + username; wk.postEdit(username, "{"+"{subst:test|"+"}}", "Please use the [" + "[Wikibooks:Sandbox|sandbox]]",			{section:"new"}); $("#ca-warn").html('warned'); var form = document.getElementById("editform"); if (form) { wk.toggleDisplay(form, "none"); } } }