לדלג לתוכן

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

מתוך צפונות ויקי
now supports {{dont remove nsd or nld}} and {{please describe images}}
מ 90 גרסאות של הדף wikipedia:he:מדיה_ויקי:Gadget-UserMessages.js יובאו
 
(71 גרסאות ביניים של 13 משתמשים אינן מוצגות)
שורה 1: שורה 1:
/*
/* adds to the toolbox a list of templates to add in talkpages. */
==Automatic user messages ==
$(function() {
Installing this script as described on the talk page will give you links in the toolbox for all pages in the User talk: namespace, that say 'Please tag', 'Please name', and 'Please link'. Clicking any of the buttons will add one of the following templates to the user's talk page, signed by you:
    var user = findUser(),
*{{tl|test}}, {{tl|test2}}, {{tl|test3}}, and {{tl|test4}}
userAnon = mw.util.isIPAddress( user ),
*{{tl|dont remove nsd or nld}}
tlist = userAnon
*{{tl|end of copyvios}}
? [
*{{tl|please describe images}}
{title: 'אזהרות', templates: ['אזהרה', 'לך', 'הבל', 'העתקה', 'נחסמת', 'תלונה', 'שגיאה']},
*{{tl|please tag images}}
{title: 'הודעות', templates: ['ניסויים', 'נמחק ניסויים', 'נמחק', 'בוטל', 'חזרה על עריכה', 'קישור מבוטל']},
*{{tl|please name images}}
{title: 'הסברים', templates: ['טעות', 'הסבר', 'לא כאן', 'נייטרליות', 'סגנון', 'שימוש בדף השיחה', 'כבר קיים', 'התנחלות', 'ויקיזציה', 'מילון']},
*{{tl|please link images}}
{title: 'תודות', templates: ['תודה', 'הזמנה']}
]
: [
{title: 'אזהרות', templates: ['אזהרה', 'הבל', 'העתקה', 'שם פוגעני', 'נחסמת', 'לך', 'שגיאה']},
{title: 'הודעות', templates: ['פרסומת', 'ניסויים', 'נמחק ניסויים', 'נמחק', 'בוטל', 'חזרה על עריכה', 'קישור מבוטל']},
{title: 'תמונות', templates: ['אזהרת תמונות2',  'תמונה מוגנת', 'מחיקת תמונה', 'מקור תמונה', 'הנחיות תמונה']},
{title: 'הסברים', templates: ['אוטוביוגרפיה', 'טעות', 'הסבר', 'נייטרליות', 'לא כאן', 'סגנון', 'שימוש בדף השיחה', 'כבר קיים', 'התנחלות', 'ויקיזציה', 'זכות הצבעה', 'מילון']},
{title: 'תודות', templates: ['תודה לרשום', 'בדוק עריכות אוטומטית']}
],
tooltips = {
'תמונה מוגנת': 'הסבר למשתמש שהעלה תמונה מוגנת',
'תלונה': 'הודעה למשתמש שהוגשה תלונה נגדו לספק האינטרנט שלו',
'תודה': 'תודה לאלמוני על תרומתו, והזמנה להרשם',
'תודה לרשום': 'תודה אישית למשתמש רשום - יש להוסיף לתבנית את הערך בגינו את מודה לו',
'שם פוגעני': 'הודעה למשתמש רשום שהשם שבחר פוגעני, ובקשה להרשם בשם אחר',
'שימוש בדף השיחה': 'הודעה למשתמש שכתב דברים שמתאימים לדף שיחה בערך עצמו',
'שגיאה': 'אזהרת משתמש שעריכתו הכילה מידע שגוי, מידע שאין מקומו בערך או לא אנציקלופדי',
'קישור מבוטל': 'הודעה למשתמש אחרי שהסרת קישור שהוסיף',
'פרסומת': 'הודעה למשתמש אחרי שהסרת פרסומת שהוסיף',
'סגנון': 'אחרי שמחקת עריכה בגלל סגנון או תוכן לא מתאים לערך',
'נמחק': 'הודעה למשתמש אחרי מחיקת ערך חדש שכתב',
'נמחק ניסויים': 'הודעה למשתמש אחרי מחיקת ערך הבל שכתב',
'ניסויים': 'הודעה למשתמש אחרי שחזור עריכת הבל קטנה',
'נייטרליות': 'הודעה למשתמש אחרי שחזור עריכה לא נייטרלית',
'נחסמת': 'אזהרת משתמש שנחסם בגלל השחתות, עם איום לפנות לספק האינטרנט ולרשויות',
'מקור תמונה': 'יש להכליל תבנית זו בדף שיחת המשתמש של משתמש שהעלה תמונה שלא ידוע מה מקורה. (פרמטרים)',
'מילון': 'הזמנה להרשם, והערה לגבי ערכים מילוניים, הפניה לויקימילון',
'מחיקת תמונה': 'הודעה למשתמש שתמונה שהעלה נמחקה',
'לך': 'אזהרה אחרונה לפני חסימה למשחית',
'לא כאן': 'תבנית פרמטרית למשתמש שכתב דברים בדף לא מתאים, והם נמחקו או הועברו',
'כבר קיים': 'תבנית פרמטרית למשתמש שיצר ערך חדש שכבר קיים (בשם אחר), אחרי שהדף שיצר שונה להפניה',
'טעות': '"אם לדעתך יש טעות בערך כלשהו, יש לציין זאת בדף השיחה של הערך"',
'חזרה על עריכה':'אזהרה: "חזרה על עריכות ששוחזרו ללא דיון בדף שיחה אינה מקובלת בוויקיפדיה"',
'זכות הצבעה': 'אחרי הסרת הצבעה בגלל ז"ה, פרמטר: דף ההצבעה',
'ויקיזציה': 'הפניה למדריכי עריכה שונים',
'התנחלות': 'הסבר על החלטה שהתקבלה בפרלמנט על קווים ירוקים ואחרים',
'העתקה': 'במקביל להחלפת תוכן הדף בתבנית הז"י',
'הסבר': 'בקשה להסבר על עריכה. כשמציבים תבנית זו יש לעקוב אחרי דף השיחה כדי לקבל את ההסבר',
'הנחיות תמונה': 'פרמטרים: תמונה=(התמונה או "הכל"), ועוד אחד עד שלושה פרמטרים מהרשימה הבאה: מקור,ערך,הוגן,חשבון,קישור,זרה,OTRS',
'הזמנה': 'הזמנת אלמוני להרשם',
'הבל': 'אזהרה עדינה',
'בוטל': 'הסבר לביטול עריכה. פרמטר ראשון:שם הערך, פרמטר שני (אופציונלי): סיבת הביטול',
'אזהרת תמונות2':'הסבר על העלאת תמונות',
'אזהרה': 'אזהרת אנונימיים וחדשים (עד 4 ימים) לפני החסימה',
'אוטוביוגרפיה': 'לאדם שהעלה ערך לא ראוי על עצמו',
'בדוק עריכות אוטומטית':'למשתמש שקיבל הרשאת בדוק עריכות'
},
templates_requiring_params = ['כבר קיים', 'בוטל', 'לא כאן', 'הסבר', 'מקור תמונה', 'זכות הצבעה', 'הנחיות תמונה'];


Alternatively you can place a template in a user's language. Click the link 'lang' and fill in a language code to have a localised version of the template put on the talk page.
function findUser() {
var diffName = $('#mw-diff-ntitle2 a:first').text();
if (diffName ) return diffName;
if ( mw.config.get('wgNamespaceNumber') !== 3 ) return;
return new mw.Title( mw.config.get('wgPageName') ).getMainText();
}
function openDialog() {
var dialog, template, selector, needParam, paramfield, paramrow;
selector = $('<select>')
.append($('<option>', {text: 'אנא בחרו תבנית מהרשימה', value: ''}))
.change(setValues);


Main code by [[User:Siebrand]], derived from [[MediaWiki:Quick-delete.js]] by [[:en:User:Jietse Niesen|Jietse Niesen]], [[User:pfctdayelise|pfctdayelise]] and [[User:Alphax|Alphax]]
for (var i in tlist) {
var t = tlist[i];
selector.append($('<option>', {text: '==== ' + t.title + ' ====' , value: '', disabled: 1}));
for (var j in t.templates) {
var templ = t.templates[j];
selector.append($('<option>', {text: '\t' + templ, label: '\t' + templ, value: templ, title:tooltips[templ]}));
}
}


===TODO===
mw.loader.using( 'jquery.ui' ).done( function() {
* Add parameter support
dialog = $('<div>').dialog({
* Add basically all templates from [[Commons:Message templates]].
title:  'הוספת תבנית אזהרה לדף השיחה של ' + user,
<pre>
width: 'auto',
*/
height: 'auto',
// Configuration
overflow: 'auto',
closeTest: '',
position: [$('body').width() * 0.4, $('body').height() * 0.4],
buttons: {
'ביטול': function() {dialog.dialog('close');},
'בצע': doIt
}});
dialog.append(selector);
paramfield = $('<input>').on('paste cut drop input change', setValues);
paramrow = $('<span>', {text: 'פרמטר לתבנית: '}).append(paramfield).toggle(false);
dialog.append($('<p>')).append(paramrow);
$(".ui-dialog-buttonpane button:contains('בצע')").button('disable');
$('.ui-dialog-buttonpane').children().css({float: 'right'});
} );


// Should the edits be saved automatically?
function doIt() {
if(window.template_autosave == false){}else{ template_autosave = true; }
var fromDiff = $('#mw-diff-ntitle2 a:first').length,
title = fromDiff
? '[[' + mw.config.get('wgPageName').replace(/_/g, ' ') + ']]'
: template,
summary = 'תבנית ' + template,
message = '\n== ' + title + ' ==\n' +
'{{ס:' + template + (needParam ? '|' + paramfield.val() : '') + "}} ~~" + "~~";
dialog.css({cursor: 'wait'});
$.ajax({
url: mw.util.wikiScript('api'),
aync: false,
type: 'post',
data: {action: 'edit', title: 'שיחת משתמש:' + user, summary: summary, token: mw.user.tokens.get('csrfToken'), appendtext: message, format:'json'},
success: function(data){
if (data && data.edit && data.edit.result === "Success") {
dialog.css({cursor: ''});
dialog.dialog('close');
if (fromDiff)  
mw.util.jsMessage('נוספה תבנית {{' + template + '}} לדף [[שיחת משתמש:' + user + ']]');
else
location.reload(true);
} else  
dialog.append($('<p>').css({color: 'red'}).text('כנראה אירעה תקלה. אנא בידקו ב"תרומות המשתמש" שלכם מה בדיוק קרה'));
},
error: function(data) {
dialog.append($('<p>').css({color: 'red'}).text('תקלה. התבנית לא נשמרה בדף השיחה של המשתמש'));
}
});
}
function setValues() {
template = selector.val();
needParam = $.inArray(template, templates_requiring_params) + 1;
paramrow.toggle(!!needParam);
var canOK = (template.length && (! needParam || $.trim(paramfield.val()).length)) ? 'enable' : 'disable';
$(".ui-dialog-buttonpane button:contains('בצע')").button(canOK);
}
}


// String constants
if (user)
p_tag_text = "Please tag";
mw.util.addPortletLink('p-tb', '#null', 'תבנית אזהרה בדף השיחה', 'warnUser', 'הוספת תבנית אזהרה לדף השיחה של ' + user)
p_tag_tooltip = "Request user to please tag his images";
.onclick = openDialog;
p_desc_text = "Please describe";
});
p_desc_tooltip = "Request user to please describe his images";
p_name_text = "Please name";
p_name_tooltip = "Request user to please name his images correctly";
p_link_text = "Please link";
p_link_tooltip = "Request user to please link his images through categories or galleries";
p_endcopyvio_text = "End copyvio";
p_endcopyvio_tooltip = "Give user a final warning because of previous copyright violations";
p_test1_text = "Sandboxing";
p_test1_tooltip = "Referral to sandbox for conducting experiments";
p_test2_text = "Vandalism";
p_test2_tooltip = "Warning or vandalism and request to cease";
p_test3_text = "Vandalism 2";
p_test3_tooltip = "Second warning for vandalism and announcement of block if it continues";
p_test4_text = "Vandalism 3";
p_test4_tooltip = "Last warning for vandalism and annoument of block on next violation";
p_dontremovensd_text = "Removed ns/ld";
p_dontremovensd_tooltip = "Reminder to not remove deletion templates unless all information is complete. Notifying user has reverted removal somewhere";
 
template_lang = "lang?";
template_langquery = "In which language should the message be given? "+
"Example: en for English, de for German, es for Spanish, etc. " +
"If the language does not exist for the template, a red link will be inserted. ";
 
// Site info
scriptPath = "/w/index.php";
prettyPath = "/wiki/";
wikiHostname = "commons.wikimedia.org";
 
 
// From [[en:Wikipedia:WikiProject User scripts/Scripts/addLink]]
function addLink(where, url1, name1, id, title, key, after, url2, name2)
{
    //* where is the id of the toolbar where the button should be added;
    //  i.e. one of "p-cactions", "p-personal", "p-navigation", or "p-tb".
    //
    //* url1 is the URL which will be called when the button is clicked.
    //  javascript: urls can be used to do more complex things.
    //
    //* name1 is what will appear as the name of the button.
    //
    //* id is the id of the button; it's best to define one. 
    //  Use a prefix to make sure its unique. Optional.
    //
    //* title is the tooltip title that gives a longer description
    //  of the button; if you define a accesskey, mention it here. Optional.
    //
    //* key is the char you want for the accesskey. Optional.
    //
    //* after is the id of the button you want to follow this one. Optional.
    //
    //* url2 is a second url to add. Optional
    //
    //*name2 is the name of the second url; defaults to name1. Optional
    var na = document.createElement('a');
    na.href = url1;
    na.appendChild(document.createTextNode(name1));
    var li = document.createElement('li');
    if(id) li.id = id;
    li.appendChild(na);
 
    if (url2) { //Another link, brother of the previous.
      var na = document.createElement('a');
      na.href = url2;     
      na.appendChild(document.createTextNode(name2 ? name2 : name1));
      li.appendChild(document.createTextNode(" · ")); //separate them a bit
      li.appendChild(na);
    }
 
    var tabs = document.getElementById(where).getElementsByTagName('ul')[0];
    if(after) {
        tabs.insertBefore(li,document.getElementById(after));
    } else {
        tabs.appendChild(li);
    }
    if(id) {
        if(key && title) { ta[id] = [key, title]; }
        else if(key) { ta[id] = [key, '']; }
        else if(title) { ta[id] = ['', title];}
    }
    // re-render the title and accesskeys from existing code in wikibits.js
    akeytt();
    return li;
}
 
// Add the template
function template_mark(talkpage_fakeaction, message_lang) {
  if (!message_lang) return; //User pressed cancel
 
  var pagename = encodeURIComponent(wgPageName);
  var editlk = document.getElementById('ca-edit').getElementsByTagName('a')[0].href;
  document.location = editlk + '&fakeaction=' + talkpage_fakeaction + '&template_lang=' + message_lang;
}
 
// Add template to user talk page
function template_addTemplate(template) {
  if (getParamValue('template_lang')) {
          template = template + '/' + getParamValue('template_lang');
  }
 
  var txt = '{{subst:' + template + '}}';
  document.editform.wpTextbox1.value = document.editform.wpTextbox1.value + '\n' + txt + ' ~~~~';
  //  the edit summary for when you mark the image. You can change it if you want. 
  document.editform.wpSummary.value = 'Placing user message ' + template + '. Please take notice.';
  if (template_autosave) document.editform.wpSave.click();
}
 
function template_onload() {
  if (wgNamespaceNumber == 3) { //NS_USERTALK
    addLink('p-tb', 'javascript:template_mark(\'p_test1\',        \'en\')', p_test1_text, 'mark-test1',                p_test1_tooltip, null, null,        'javascript:template_mark(\'p_test1\', prompt(\'' + template_langquery + '\', wgUserLanguage))', template_lang);
    addLink('p-tb', 'javascript:template_mark(\'p_test2\',        \'en\')', p_test2_text, 'mark-test2',               p_test2_tooltip, null, null,        'javascript:template_mark(\'p_test2\', prompt(\'' + template_langquery + '\', wgUserLanguage))', template_lang);
    addLink('p-tb', 'javascript:template_mark(\'p_test3\',        \'en\')', p_test3_text, 'mark-test3',                p_test3_tooltip, null, null,        'javascript:template_mark(\'p_test3\', prompt(\'' + template_langquery + '\', wgUserLanguage))', template_lang);
    addLink('p-tb', 'javascript:template_mark(\'p_test4\',        \'en\')', p_test4_text, 'mark-test4',                p_test4_tooltip, null, null,        'javascript:template_mark(\'p_test4\', prompt(\'' + template_langquery + '\', wgUserLanguage))', template_lang);
    addLink('p-tb', 'javascript:template_mark(\'p_dontremovensd\', \'en\')', p_dontremovensd_text, 'mark-end-copyvios', p_dontremovensd_tooltip, null, null, 'javascript:template_mark(\'p_dontremovensd\', prompt(\'' + template_langquery + '\', wgUserLanguage))', template_lang);
    addLink('p-tb', 'javascript:template_mark(\'p_endcopyvio\',    \'en\')', p_endcopyvio_text, 'mark-end-copyvios',    p_endcopyvio_tooltip, null, null,    'javascript:template_mark(\'p_endcopyvio\', prompt(\'' + template_langquery + '\', wgUserLanguage))', template_lang);
    addLink('p-tb', 'javascript:template_mark(\'p_desc\',          \'en\')', p_desc_text, 'mark-describe-tag',          p_desc_tooltip, null, null,          'javascript:template_mark(\'p_desc\', prompt(\'' + template_langquery + '\', wgUserLanguage))', template_lang);
    addLink('p-tb', 'javascript:template_mark(\'p_tag\',          \'en\')', p_tag_text, 'mark-please-tag',            p_tag_tooltip, null, null,          'javascript:template_mark(\'p_tag\', prompt(\'' + template_langquery + '\', wgUserLanguage))', template_lang);
    addLink('p-tb', 'javascript:template_mark(\'p_name\',          \'en\')', p_name_text, 'mark-please-name',          p_name_tooltip, null, null,          'javascript:template_mark(\'p_name\', prompt(\'' + template_langquery + '\', wgUserLanguage))', template_lang);
    addLink('p-tb', 'javascript:template_mark(\'p_link\',          \'en\')', p_link_text, 'mark-please-link',          p_link_tooltip, null, null,          'javascript:template_mark(\'p_link\', prompt(\'' + template_langquery + '\', wgUserLanguage))', template_lang);
  }
 
  var fakeaction = getParamValue('fakeaction');
  var template_type = getParamValue('template_type'); // Fetch what template to add
 
  if (fakeaction == 'p_test1')        { template_addTemplate('test'); }
  if (fakeaction == 'p_test2')        { template_addTemplate('test2'); }
  if (fakeaction == 'p_test3')        { template_addTemplate('test3'); }
  if (fakeaction == 'p_test4')        { template_addTemplate('test4'); }
  if (fakeaction == 'p_dontremovensd'){ template_addTemplate('dont remove nsd or nld'); } 
  if (fakeaction == 'p_endcopyvio')  { template_addTemplate('end of copyvios'); } 
  if (fakeaction == 'p_tag')          { template_addTemplate('please tag images'); }
  if (fakeaction == 'p_desc')        { template_addTemplate('please describe images'); }
  if (fakeaction == 'p_name')        { template_addTemplate('please name images'); }
  if (fakeaction == 'p_link')        { template_addTemplate('please link images'); } 
}
 
addOnloadHook(template_onload);
// </pre>

גרסה אחרונה מ־13:11, 5 בדצמבר 2022

/* adds to the toolbox a list of templates to add in talkpages. */
$(function() {
    var user = findUser(),
		userAnon = mw.util.isIPAddress( user ),
		tlist = userAnon
		? [
			{title: 'אזהרות', templates: ['אזהרה', 'לך', 'הבל', 'העתקה', 'נחסמת', 'תלונה', 'שגיאה']},
			{title: 'הודעות', templates: ['ניסויים', 'נמחק ניסויים', 'נמחק', 'בוטל', 'חזרה על עריכה', 'קישור מבוטל']},
			{title: 'הסברים', templates: ['טעות', 'הסבר', 'לא כאן', 'נייטרליות', 'סגנון', 'שימוש בדף השיחה', 'כבר קיים', 'התנחלות', 'ויקיזציה', 'מילון']},
			{title: 'תודות', templates: ['תודה', 'הזמנה']}
		]
		: [
			{title: 'אזהרות', templates: ['אזהרה', 'הבל', 'העתקה', 'שם פוגעני', 'נחסמת', 'לך', 'שגיאה']},
			{title: 'הודעות', templates: ['פרסומת', 'ניסויים', 'נמחק ניסויים', 'נמחק', 'בוטל', 'חזרה על עריכה', 'קישור מבוטל']},
			{title: 'תמונות', templates: ['אזהרת תמונות2',  'תמונה מוגנת', 'מחיקת תמונה', 'מקור תמונה', 'הנחיות תמונה']},
			{title: 'הסברים', templates: ['אוטוביוגרפיה', 'טעות', 'הסבר', 'נייטרליות', 'לא כאן', 'סגנון', 'שימוש בדף השיחה', 'כבר קיים', 'התנחלות', 'ויקיזציה', 'זכות הצבעה', 'מילון']},
			{title: 'תודות', templates: ['תודה לרשום', 'בדוק עריכות אוטומטית']}
		],
		tooltips = {
			'תמונה מוגנת': 'הסבר למשתמש שהעלה תמונה מוגנת',
			'תלונה': 'הודעה למשתמש שהוגשה תלונה נגדו לספק האינטרנט שלו',
			'תודה': 'תודה לאלמוני על תרומתו, והזמנה להרשם',
			'תודה לרשום': 'תודה אישית למשתמש רשום - יש להוסיף לתבנית את הערך בגינו את מודה לו',
			'שם פוגעני': 'הודעה למשתמש רשום שהשם שבחר פוגעני, ובקשה להרשם בשם אחר',
			'שימוש בדף השיחה': 'הודעה למשתמש שכתב דברים שמתאימים לדף שיחה בערך עצמו',
			'שגיאה': 'אזהרת משתמש שעריכתו הכילה מידע שגוי, מידע שאין מקומו בערך או לא אנציקלופדי',
			'קישור מבוטל': 'הודעה למשתמש אחרי שהסרת קישור שהוסיף',
			'פרסומת': 'הודעה למשתמש אחרי שהסרת פרסומת שהוסיף',
			'סגנון': 'אחרי שמחקת עריכה בגלל סגנון או תוכן לא מתאים לערך',
			'נמחק': 'הודעה למשתמש אחרי מחיקת ערך חדש שכתב',
			'נמחק ניסויים': 'הודעה למשתמש אחרי מחיקת ערך הבל שכתב',
			'ניסויים': 'הודעה למשתמש אחרי שחזור עריכת הבל קטנה',
			'נייטרליות': 'הודעה למשתמש אחרי שחזור עריכה לא נייטרלית',
			'נחסמת': 'אזהרת משתמש שנחסם בגלל השחתות, עם איום לפנות לספק האינטרנט ולרשויות',
			'מקור תמונה': 'יש להכליל תבנית זו בדף שיחת המשתמש של משתמש שהעלה תמונה שלא ידוע מה מקורה. (פרמטרים)',
			'מילון': 'הזמנה להרשם, והערה לגבי ערכים מילוניים, הפניה לויקימילון',
			'מחיקת תמונה': 'הודעה למשתמש שתמונה שהעלה נמחקה',
			'לך': 'אזהרה אחרונה לפני חסימה למשחית',
			'לא כאן': 'תבנית פרמטרית למשתמש שכתב דברים בדף לא מתאים, והם נמחקו או הועברו',
			'כבר קיים': 'תבנית פרמטרית למשתמש שיצר ערך חדש שכבר קיים (בשם אחר), אחרי שהדף שיצר שונה להפניה',
			'טעות': '"אם לדעתך יש טעות בערך כלשהו, יש לציין זאת בדף השיחה של הערך"',
			'חזרה על עריכה':'אזהרה: "חזרה על עריכות ששוחזרו ללא דיון בדף שיחה אינה מקובלת בוויקיפדיה"',
			'זכות הצבעה': 'אחרי הסרת הצבעה בגלל ז"ה, פרמטר: דף ההצבעה',
			'ויקיזציה': 'הפניה למדריכי עריכה שונים',
			'התנחלות': 'הסבר על החלטה שהתקבלה בפרלמנט על קווים ירוקים ואחרים',
			'העתקה': 'במקביל להחלפת תוכן הדף בתבנית הז"י',
			'הסבר': 'בקשה להסבר על עריכה. כשמציבים תבנית זו יש לעקוב אחרי דף השיחה כדי לקבל את ההסבר',
			'הנחיות תמונה': 'פרמטרים: תמונה=(התמונה או "הכל"), ועוד אחד עד שלושה פרמטרים מהרשימה הבאה: מקור,ערך,הוגן,חשבון,קישור,זרה,OTRS',
			'הזמנה': 'הזמנת אלמוני להרשם',
			'הבל': 'אזהרה עדינה',
			'בוטל': 'הסבר לביטול עריכה. פרמטר ראשון:שם הערך, פרמטר שני (אופציונלי): סיבת הביטול',
			'אזהרת תמונות2':'הסבר על העלאת תמונות',
			'אזהרה': 'אזהרת אנונימיים וחדשים (עד 4 ימים) לפני החסימה',
			'אוטוביוגרפיה': 'לאדם שהעלה ערך לא ראוי על עצמו',
				'בדוק עריכות אוטומטית':'למשתמש שקיבל הרשאת בדוק עריכות'
		},
	templates_requiring_params = ['כבר קיים', 'בוטל', 'לא כאן', 'הסבר', 'מקור תמונה', 'זכות הצבעה', 'הנחיות תמונה'];

	function findUser() {
		var diffName = $('#mw-diff-ntitle2 a:first').text();
		if (diffName ) return diffName;
		if ( mw.config.get('wgNamespaceNumber') !== 3 ) return;
		return new mw.Title( mw.config.get('wgPageName') ).getMainText();
	}
	
	function openDialog() {
		var dialog, template, selector, needParam, paramfield, paramrow;
		
		selector = $('<select>')
			.append($('<option>', {text: 'אנא בחרו תבנית מהרשימה', value: ''}))
			.change(setValues);

		for (var i in tlist) {
			var t = tlist[i];
			selector.append($('<option>', {text: '==== ' + t.title + ' ====' , value: '', disabled: 1}));
			for (var j in t.templates) {
				var templ = t.templates[j];
				selector.append($('<option>', {text: '\t' + templ, label: '\t' + templ, value: templ, title:tooltips[templ]}));
			}
		}

		mw.loader.using( 'jquery.ui' ).done( function() {
			dialog = $('<div>').dialog({
				title:  'הוספת תבנית אזהרה לדף השיחה של ' + user,
				width: 'auto',
				height: 'auto',
				overflow: 'auto',
				closeTest: '',
				position: [$('body').width() * 0.4, $('body').height() * 0.4],
				buttons: {
				'ביטול': function() {dialog.dialog('close');},
				'בצע': doIt
			}});
			dialog.append(selector);
			paramfield = $('<input>').on('paste cut drop input change', setValues);
			paramrow = $('<span>', {text: 'פרמטר לתבנית: '}).append(paramfield).toggle(false);
			dialog.append($('<p>')).append(paramrow);
			$(".ui-dialog-buttonpane button:contains('בצע')").button('disable');
			$('.ui-dialog-buttonpane').children().css({float: 'right'});
		} );

		function doIt() {
			var fromDiff = $('#mw-diff-ntitle2 a:first').length,
				title = fromDiff 
					? '[[' + mw.config.get('wgPageName').replace(/_/g, ' ') + ']]'
					: template,
				summary = 'תבנית ' + template,
				message = '\n== ' + title + ' ==\n' +
						'{{ס:' + template + (needParam ? '|' + paramfield.val() : '') + "}} ~~" + "~~";
			dialog.css({cursor: 'wait'});
			$.ajax({
				url: mw.util.wikiScript('api'),
				aync: false,
				type: 'post',
				data: {action: 'edit', title: 'שיחת משתמש:' + user, summary: summary, token: mw.user.tokens.get('csrfToken'), appendtext: message, format:'json'},
				success: function(data){
					if (data && data.edit && data.edit.result === "Success") {
						dialog.css({cursor: ''});
						dialog.dialog('close');
						if (fromDiff) 
							mw.util.jsMessage('נוספה תבנית {{' + template + '}} לדף [[שיחת משתמש:' + user + ']]');
						else 
							location.reload(true);
					} else 
						dialog.append($('<p>').css({color: 'red'}).text('כנראה אירעה תקלה. אנא בידקו ב"תרומות המשתמש" שלכם מה בדיוק קרה'));
				},
				error: function(data) {
					dialog.append($('<p>').css({color: 'red'}).text('תקלה. התבנית לא נשמרה בדף השיחה של המשתמש'));
				}
			});
		}
		
		function setValues() {
			template = selector.val();
			needParam = $.inArray(template, templates_requiring_params) + 1;
			paramrow.toggle(!!needParam);
			var canOK = (template.length && (! needParam || $.trim(paramfield.val()).length)) ? 'enable' : 'disable';
			$(".ui-dialog-buttonpane button:contains('בצע')").button(canOK);
		}
	}

	if (user)
		mw.util.addPortletLink('p-tb', '#null', 'תבנית אזהרה בדף השיחה', 'warnUser', 'הוספת תבנית אזהרה לדף השיחה של ' + user)
		.onclick = openDialog;
});