לדלג לתוכן

מדיה ויקי:Gadget-RestoreWarnings.js: הבדלים בין גרסאות בדף

מתוך צפונות ויקי
מ תקלדה
מ סתם בשביל העיצוב
שורה 1: שורה 1:
//<source lang="javascript">
/* סקריפט להוספת קישורים להוספת תבניות אזהרה שונות למשתמשים, התורמים: Yonidebest, Ofekalef, קיפודנחש, חיים 7 */
/* סקריפט להוספת קישורים להוספת תבניות אזהרה שונות למשתמשים, התורמים: Yonidebest, Ofekalef, קיפודנחש, חיים 7 */


$(document).ready(function() {
$(document).ready(function() {
שורה 81: שורה 81:
link.after(tn(') ')).after(span).after(tn(' ('));
link.after(tn(') ')).after(span).after(tn(' ('));
});
});
//</source>

גרסה מ־20:59, 3 בינואר 2012

//

/* סקריפט להוספת קישורים להוספת תבניות אזהרה שונות למשתמשים, התורמים: Yonidebest, Ofekalef, קיפודנחש, חיים 7 */

$(document).ready(function() {

	function save_topage(title, summary, content, unwatch, next) {
		var param = {action: 'edit', title: title, summary: summary, token: mw.user.tokens.get('editToken'), appendtext: content, format: 'json'};
		if (unwatch) 
			param.watchlist = 'unwatch';
		$.post(mw.util.wikiScript('api'), param, function (data) {
			if (data && data.error) 
				alert('error saving: ' + data.error['info']);
			else if (data && data.edit && data.edit.result == 'Success' && typeof next == 'function')
				next();
		});
	}
	 
	function activate() {
		var $this = $(this),
			user = $this.attr('user'),
			templ = $this.data('templ'),
			warning = templ.m,
			tw = warning,
			refPage = $this.attr('refPage').replace(/_/g, ' ');
			
		if (!warning || !user) 
			return;

		if (refPage)
			tw += '|' + refPage;
			
		if (templ.askExtra) {
			if (templ.askExtra.prompt) {
				var extra = $.trim(prompt(templ.askExtra.prompt));
				if (extra)
					tw += templ.askExtra.param + extra;
			}
			else if (templ.askExtra.confirm && confirm(templ.askExtra.confirm))
				tw += templ.askExtra.param;
		}

		text = "{{" + tw + "}} ~~" + "~~\n";
		if (refPage)
			text = "\n==[[" + refPage + "]]==\n" + text; 
		save_topage("שיחת משתמש:" + user, warning, text, templ.unwatch, function() {alert(' תבנית "' + warning + '" נרשמה בשיחת משתמש:' + user);});
	} 

	function tn(t) {return $('<span>').text(t);} 

	// main body of function
	var link = $('#mw-diff-ntitle2').find('a:eq(0)'),
		user = link.text(),
		span = $("<span>"),
		anon = /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/.test(user),
		all = [
			{t:"אזהרה", m: "אזהרה", tl: "הוספת תבנית אזהרה", unwatch: true},
			{t:"ניסוי", m: "ניסויים", tl:"הוספת תבנית ניסויים", unwatch: true},
			{t:"בוטל",  m: "בוטל", tl:"הוספת תבנית בוטל", askExtra: {prompt: 'סיבת הביטול', param: '|סיבה='}, unwatch: true},
			{t:"חזרה", m: "חזרה על עריכה", tl:"הוספת תבנית חזרה על עריכה"},
			{t:"פרסום", m: "פרסומת", tl:"הוספת תבנית פרסומת"},
			{t:"הסבר", m: "הסבר", tl:"הוספת תבנית הסבר", askExtra: {confirm: 'בוטל ? (ביטול=לא)', param: '|בוטל=כן'}},
			anon ? {t:"תודה", m: "תודה", tl:"הוספת תבנית תודה"} : {t:"בה", m: "בה", tl:"הוספת תבנית ברוך בואך", noPage: true}
		];
			
	if (! user)
		return;
	if ($.inArray('sysop', wgUserGroups)+1)
		all.push({t:"נחסמת", m: "הודעה על חסימה", tl:"הודעה למשתמש שנחסם"});

	for (var i in all) {
		var templ = all[i];
		var page = (templ.noPage)
			? ''
			: (($.inArray(mw.config.get('wgNamespaceNumber'), [6, 14]) + 1) ? ':' : '') + mw.config.get('wgPageName').replace(/_/g, " ");
		var a = $("<a>", {href: '#', user: user, refPage: page, title: templ.tl})
			.text(templ.t)
			.click(activate)
			.data({templ: templ});
		span.append(tn(i==0? '':' | ')).append(a);
	}	
	link.after(tn(') ')).after(span).after(tn(' ('));
});
//