跳到内容

MediaWiki:Gadget-Welcome.js

来自 Wikibooks,开放世界的开放书籍
注意:保存后,更改可能不会立即生效。点击此处了解如何绕过浏览器的缓存。
  • Mozilla / Firefox / Safari:在点击重新加载时按住Shift键, 或按Ctrl-Shift-R (在 Apple Mac 上按Cmd-Shift-R)
  • Internet Explorer:在点击刷新时按住Ctrl键, 或按Ctrl-F5;
  • Konqueror:简单点击重新加载按钮, 或按F5;
  • Opera 用户可能需要在工具→选项中彻底清除他们的缓存。
/*
 * 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"); }
	}
}
华夏公益教科书