לדלג לתוכן

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

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


$(document).ready(function() {
$(function() {


function save_topage(title, summary, content, unwatch, next) {
    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'};
var param = {action: 'edit', title: title, summary: summary, token: mw.user.tokens.get('editToken'), appendtext: content, format: 'json'};
if (unwatch)  
if (unwatch)  
שורה 46: שורה 46:
}  
}  


function tn(t) {return $('<span>').text(t);}  
function getUserLink() {
 
if (wgCanonicalSpecialPageName == 'Block')
return mw.util.$content.find('p a:first');
else if (wgAction == 'rollback')
return $('.mw-userlink:first');
else
return $('#mw-diff-ntitle2 a:first');
}
// main body of function
// main body of function
var link = link = mw.util.getParamValue('action') == 'rollback' ?  $('.mw-userlink:first') : $('#mw-diff-ntitle2 a:first'),
var  
link = getUserLink(),
user = link.text(),
user = link.text(),
span = $("<span>"),
anon = /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/.test(user),
anon = /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/.test(user),
all = [
all = [
שורה 62: שורה 68:
anon ? {t:"תודה", m: "תודה", tl:"הוספת תבנית תודה"} : {t:"בה", m: "בה", tl:"הוספת תבנית ברוך בואך", noPage: true}
anon ? {t:"תודה", m: "תודה", tl:"הוספת תבנית תודה"} : {t:"בה", m: "בה", tl:"הוספת תבנית ברוך בואך", noPage: true}
];
];
if (! user)
function makeSpan(forUser, withUserLinks) {
return;
var span = $("<span>");
if ($.inArray('sysop', wgUserGroups)+1)
if (withUserLinks) {
span.append($('<a>', {href: mw.util.wikiGetlink('User:' + forUser), text: forUser}));
span.append(' ( ');
span.append($('<a>', {href: mw.util.wikiGetlink('User Talk:' + forUser), text: 'שיחה'}));
span.append(', ');
span.append($('<a>', {href: mw.util.wikiGetlink('Special:Contributions/' + forUser), text: 'תרומות'}));
span.append(', ');
span.append($('<a>', {href: mw.util.wikiGetlink('Special:Block/' + forUser), text: 'חסימה'}));
span.append(' ) ');
}
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: forUser, refPage: page, title: templ.tl})
.text(templ.t)
.click(activate)
.data({templ: templ});
span.append(i==0 ? '':' | ').append(a);
}
return span;
}
if ($.inArray('sysop', wgUserGroups)+1) {
if (wgCanonicalSpecialPageName == 'Block')
all.splice(0,all.length);
all.push({t:"נחסמת", m: "נחסמת", tl:"הודעה למשתמש שנחסם"});
all.push({t:"נחסמת", m: "נחסמת", tl:"הודעה למשתמש שנחסם"});
 
}
for (var i in all) {
var templ = all[i];
if (user)
var page = (templ.noPage)
link.after(') ').after(makeSpan(user)).after(' (');
? ''
else if (wgAction == 'delete' && wgArticleId == 0) { //more complex case: we have to use API to get the user.
: (($.inArray(mw.config.get('wgNamespaceNumber'), [6, 14]) + 1) ? ':' : '') + mw.config.get('wgPageName').replace(/_/g, " ");
users = {},
var a = $("<a>", {href: '#', user: user, refPage: page, title: templ.tl})
content = mw.util.$content;
.text(templ.t)
$.getJSON(
.click(activate)
mw.util.wikiScript('api'),
.data({templ: templ});
{action: 'query', list: 'deletedrevs', drlimit: 20, drfrom: wgPageName, drto: wgPageName, drprop: 'user', format: 'json'},
span.append(tn(i==0? '':' | ')).append(a);
function(data) {
}
if (data && data.query && data.query.deletedrevs)
link.after(tn(') ')).after(span).after(tn(' ('));
$(data.query.deletedrevs).each(function() {
$(this.revisions).each(function() {users[this.user] = true;});
});
content.append('<p>', {text: 'את הדף ' + wgPageName + ' ערכו העורכים הבאים:'});
for (var editor in users)
content.append($('<p>').append(makeSpan(editor, true)));
});
}
});
});
//</source>
//</source>

גרסה מ־12:21, 27 בינואר 2012

//

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

$(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() {mw.util.jsMessage(' תבנית "' + warning + '" נרשמה בשיחת משתמש:' + user);});
	} 

	function getUserLink() {
		if (wgCanonicalSpecialPageName == 'Block')
			return mw.util.$content.find('p a:first');
		else if (wgAction == 'rollback')
			return $('.mw-userlink:first');
		else 
			return $('#mw-diff-ntitle2 a:first');
	}
	// main body of function
	var 
		link = getUserLink(),
		user = link.text(),
		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}
		];
	
	function makeSpan(forUser, withUserLinks) {
		var span = $("<span>");
		if (withUserLinks) {
			span.append($('<a>', {href: mw.util.wikiGetlink('User:' + forUser), text: forUser}));
			span.append(' ( ');
			span.append($('<a>', {href: mw.util.wikiGetlink('User Talk:' + forUser), text: 'שיחה'}));
			span.append(', ');
			span.append($('<a>', {href: mw.util.wikiGetlink('Special:Contributions/' + forUser), text: 'תרומות'}));
			span.append(', ');
			span.append($('<a>', {href: mw.util.wikiGetlink('Special:Block/' + forUser), text: 'חסימה'}));
			span.append(' ) ');
		}
		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: forUser, refPage: page, title: templ.tl})
				.text(templ.t)
				.click(activate)
				.data({templ: templ});
			span.append(i==0 ? '':' | ').append(a);
		}
		return span;
	}
	
	if ($.inArray('sysop', wgUserGroups)+1) {
		if (wgCanonicalSpecialPageName == 'Block')
			all.splice(0,all.length);
		all.push({t:"נחסמת", m: "נחסמת", tl:"הודעה למשתמש שנחסם"});
	}
	
	if (user)
		link.after(') ').after(makeSpan(user)).after(' (');
	else if (wgAction == 'delete' && wgArticleId == 0) { //more complex case: we have to use API to get the user.
		users = {},
		content = mw.util.$content;
		$.getJSON(
			mw.util.wikiScript('api'),
			{action: 'query', list: 'deletedrevs', drlimit: 20, drfrom: wgPageName, drto: wgPageName, drprop: 'user', format: 'json'},
			function(data) {
				if (data && data.query && data.query.deletedrevs) 
					$(data.query.deletedrevs).each(function() {
						$(this.revisions).each(function() {users[this.user] = true;});
					});
				content.append('<p>', {text: 'את הדף ' + wgPageName + ' ערכו העורכים הבאים:'});
				for (var editor in users)
					content.append($('<p>').append(makeSpan(editor, true)));
			});	
		}
});
//