לדלג לתוכן

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

מתוך צפונות ויקי
now supports {{dont remove nsd or nld}} and {{please describe images}}
change code a bot; hopefully it is a bit easier to add support for more templates now...
שורה 24: שורה 24:
if(window.template_autosave == false){}else{ template_autosave = true; }
if(window.template_autosave == false){}else{ template_autosave = true; }


// String constants
// String constants
p_tag_text = "Please tag";
var uTemplate = new Array(10)
p_tag_tooltip = "Request user to please tag his images";
uTemplate[0] = 'Please describe images'
p_desc_text = "Please describe";
uTemplate[1] = 'Dont remove nsd or nld'
p_desc_tooltip = "Request user to please describe his images";
uTemplate[2] = 'End of copyvios'
p_name_text = "Please name";
uTemplate[3] = 'Please link images'
p_name_tooltip = "Request user to please name his images correctly";
uTemplate[4] = 'Please name images'
p_link_text = "Please link";
uTemplate[5] = 'Please tag images'
p_link_tooltip = "Request user to please link his images through categories or galleries";
uTemplate[6] = 'Test'
p_endcopyvio_text = "End copyvio";
uTemplate[7] = 'Test2'
p_endcopyvio_tooltip = "Give user a final warning because of previous copyright violations";
uTemplate[8] = 'Test3'
p_test1_text = "Sandboxing";
uTemplate[9] = 'Test4'
p_test1_tooltip = "Referral to sandbox for conducting experiments";
 
p_test2_text = "Vandalism";
var uText = new Array(10)
p_test2_tooltip = "Warning or vandalism and request to cease";
uText[0] = "Please describe"
p_test3_text = "Vandalism 2";
uText[1] = "Removed ns/ld"
p_test3_tooltip = "Second warning for vandalism and announcement of block if it continues";
uText[2] = "End copyvio"
p_test4_text = "Vandalism 3";
uText[3] = "Please link"
p_test4_tooltip = "Last warning for vandalism and annoument of block on next violation";
uText[4] = "Please name"
p_dontremovensd_text = "Removed ns/ld";
uText[5] = "Please tag"
p_dontremovensd_tooltip = "Reminder to not remove deletion templates unless all information is complete. Notifying user has reverted removal somewhere";
uText[6] = "Sandboxing"
uText[7] = "Vandalism"
uText[8] = "Vandalism 2"
uText[9] = "Vandalism 3"
 
var uHelp = new Array(10)
uHelp[0] = "Request user to please describe his images"
uHelp[1] = "Reminder to not remove deletion templates unless all information is complete. Notifying user has reverted removal somewhere"
uHelp[2] = "Give user a final warning because of previous copyright violations"
uHelp[3] = "Request user to please link his images through categories or galleries"
uHelp[4] = "Request user to please name his images correctly"
uHelp[5] = "Request user to please tag his images"
uHelp[6] = "Referral to sandbox for conducting experiments"
uHelp[7] = "Warning or vandalism and request to cease"
uHelp[8] = "Second warning for vandalism and announcement of block if it continues"
uHelp[9] = "Last warning for vandalism and annoument of block on next violation"


template_lang = "lang?";
template_lang = "lang?";
שורה 55: שורה 70:
prettyPath = "/wiki/";
prettyPath = "/wiki/";
wikiHostname = "commons.wikimedia.org";
wikiHostname = "commons.wikimedia.org";


// From [[en:Wikipedia:WikiProject User scripts/Scripts/addLink]]
// From [[en:Wikipedia:WikiProject User scripts/Scripts/addLink]]
שורה 68: שורה 82:
     //* name1 is what will appear as the name of the button.
     //* name1 is what will appear as the name of the button.
     //
     //
     //* id is the id of the button; it's best to define one.
     //* id is the id of the button; it's best to define one.
     //  Use a prefix to make sure its unique. Optional.
     //  Use a prefix to make sure its unique. Optional.
     //
     //
     //* title is the tooltip title that gives a longer description  
     //* title is the tooltip title that gives a longer description
     //  of the button; if you define a accesskey, mention it here. Optional.
     //  of the button; if you define a accesskey, mention it here. Optional.
     //
     //
שורה 90: שורה 104:
     if (url2) { //Another link, brother of the previous.
     if (url2) { //Another link, brother of the previous.
       var na = document.createElement('a');
       var na = document.createElement('a');
       na.href = url2;      
       na.href = url2;
       na.appendChild(document.createTextNode(name2 ? name2 : name1));
       na.appendChild(document.createTextNode(name2 ? name2 : name1));
       li.appendChild(document.createTextNode(" · ")); //separate them a bit
       li.appendChild(document.createTextNode(" · ")); //separate them a bit
שורה 105: שורה 119:
         if(key && title) { ta[id] = [key, title]; }
         if(key && title) { ta[id] = [key, title]; }
         else if(key) { ta[id] = [key, '']; }
         else if(key) { ta[id] = [key, '']; }
         else if(title) { ta[id] = ['', title];}  
         else if(title) { ta[id] = ['', title];}
     }
     }
     // re-render the title and accesskeys from existing code in wikibits.js
     // re-render the title and accesskeys from existing code in wikibits.js
שורה 129: שורה 143:
   var txt = '{{subst:' + template + '}}';
   var txt = '{{subst:' + template + '}}';
   document.editform.wpTextbox1.value = document.editform.wpTextbox1.value + '\n' + txt + ' ~~~~';
   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.
   //  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.';
   document.editform.wpSummary.value = 'Adding template \"' + template + '\" to inform user.';
   if (template_autosave) document.editform.wpSave.click();
   if (template_autosave) document.editform.wpSave.click();
}
}
שורה 136: שורה 150:
function template_onload() {
function template_onload() {
   if (wgNamespaceNumber == 3) { //NS_USERTALK
   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(\'0\', \'en\')', uText[0], 'mark-please', uHelp[0], null, null, 'javascript:template_mark(\'0\', 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(\'3\', \'en\')', uText[3], 'mark-please', uHelp[3], null, null, 'javascript:template_mark(\'3\', 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(\'4\', \'en\')', uText[4], 'mark-please', uHelp[4], null, null, 'javascript:template_mark(\'4\', 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(\'5\', \'en\')', uText[5], 'mark-please', uHelp[5], null, null, 'javascript:template_mark(\'5\', 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(\'1\', \'en\')', uText[1], 'mark-warn',   uHelp[1], null, null, 'javascript:template_mark(\'1\', 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(\'2\', \'en\')', uText[2], 'mark-warn',   uHelp[2], null, null, 'javascript:template_mark(\'2\', 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(\'6\', \'en\')', uText[6], 'mark-warn',   uHelp[6], null, null, 'javascript:template_mark(\'6\', 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(\'7\', \'en\')', uText[7], 'mark-warn',   uHelp[7], null, null, 'javascript:template_mark(\'7\', 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(\'8\', \'en\')', uText[8], 'mark-warn',   uHelp[8], null, null, 'javascript:template_mark(\'8\', 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);
     addLink('p-tb', 'javascript:template_mark(\'9\', \'en\')', uText[9], 'mark-warn',   uHelp[9], null, null, 'javascript:template_mark(\'9\', prompt(\'' + template_langquery + '\', wgUserLanguage))', template_lang);
   }
   }


שורה 151: שורה 165:
   var template_type = getParamValue('template_type'); // Fetch what template to add
   var template_type = getParamValue('template_type'); // Fetch what template to add


   if (fakeaction == 'p_test1')       { template_addTemplate('test'); }
   if (fakeaction == '0'){ template_addTemplate( uTemplate[0] ); }
   if (fakeaction == 'p_test2')       { template_addTemplate('test2'); }
   if (fakeaction == '1'){ template_addTemplate( uTemplate[1] ); }
   if (fakeaction == 'p_test3')       { template_addTemplate('test3'); }
   if (fakeaction == '2'){ template_addTemplate( uTemplate[2] ); }
   if (fakeaction == 'p_test4')       { template_addTemplate('test4'); }
   if (fakeaction == '3'){ template_addTemplate( uTemplate[3] ); }
   if (fakeaction == 'p_dontremovensd'){ template_addTemplate('dont remove nsd or nld'); }
   if (fakeaction == '4'){ template_addTemplate( uTemplate[4] ); }
   if (fakeaction == 'p_endcopyvio')   { template_addTemplate('end of copyvios'); }
   if (fakeaction == '5'){ template_addTemplate( uTemplate[5] ); }
   if (fakeaction == 'p_tag')         { template_addTemplate('please tag images'); }
   if (fakeaction == '6'){ template_addTemplate( uTemplate[6] ); }
   if (fakeaction == 'p_desc')         { template_addTemplate('please describe images'); }
   if (fakeaction == '7'){ template_addTemplate( uTemplate[7] ); }
   if (fakeaction == 'p_name')         { template_addTemplate('please name images'); }
   if (fakeaction == '8'){ template_addTemplate( uTemplate[8] ); }
   if (fakeaction == 'p_link')         { template_addTemplate('please link images'); }
   if (fakeaction == '9'){ template_addTemplate( uTemplate[9] ); }
  }
  }


addOnloadHook(template_onload);
addOnloadHook(template_onload);
// </pre>
// </pre>

גרסה מ־23:23, 13 ביוני 2007

/*
==Automatic user messages ==
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:
*{{tl|test}}, {{tl|test2}}, {{tl|test3}}, and {{tl|test4}}
*{{tl|dont remove nsd or nld}}
*{{tl|end of copyvios}}
*{{tl|please describe images}}
*{{tl|please tag images}}
*{{tl|please name images}}
*{{tl|please link images}}

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.

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]]

===TODO===
* Add parameter support
* Add basically all templates from [[Commons:Message templates]].
<pre>
*/
// Configuration

// Should the edits be saved automatically?
if(window.template_autosave == false){}else{ template_autosave = true; }

// String constants
var uTemplate = new Array(10)
uTemplate[0] = 'Please describe images'
uTemplate[1] = 'Dont remove nsd or nld'
uTemplate[2] = 'End of copyvios'
uTemplate[3] = 'Please link images'
uTemplate[4] = 'Please name images'
uTemplate[5] = 'Please tag images'
uTemplate[6] = 'Test'
uTemplate[7] = 'Test2'
uTemplate[8] = 'Test3'
uTemplate[9] = 'Test4'

var uText = new Array(10)
uText[0] = "Please describe"
uText[1] = "Removed ns/ld"
uText[2] = "End copyvio"
uText[3] = "Please link"
uText[4] = "Please name"
uText[5] = "Please tag"
uText[6] = "Sandboxing"
uText[7] = "Vandalism"
uText[8] = "Vandalism 2"
uText[9] = "Vandalism 3"

var uHelp = new Array(10)
uHelp[0] = "Request user to please describe his images"
uHelp[1] = "Reminder to not remove deletion templates unless all information is complete. Notifying user has reverted removal somewhere"
uHelp[2] = "Give user a final warning because of previous copyright violations"
uHelp[3] = "Request user to please link his images through categories or galleries"
uHelp[4] = "Request user to please name his images correctly"
uHelp[5] = "Request user to please tag his images"
uHelp[6] = "Referral to sandbox for conducting experiments"
uHelp[7] = "Warning or vandalism and request to cease"
uHelp[8] = "Second warning for vandalism and announcement of block if it continues"
uHelp[9] = "Last warning for vandalism and annoument of block on next violation"

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 = 'Adding template \"' + template + '\" to inform user.';
  if (template_autosave) document.editform.wpSave.click();
}

function template_onload() {
  if (wgNamespaceNumber == 3) { //NS_USERTALK
    addLink('p-tb', 'javascript:template_mark(\'0\', \'en\')', uText[0], 'mark-please', uHelp[0], null, null, 'javascript:template_mark(\'0\', prompt(\'' + template_langquery + '\', wgUserLanguage))', template_lang);
    addLink('p-tb', 'javascript:template_mark(\'3\', \'en\')', uText[3], 'mark-please', uHelp[3], null, null, 'javascript:template_mark(\'3\', prompt(\'' + template_langquery + '\', wgUserLanguage))', template_lang);
    addLink('p-tb', 'javascript:template_mark(\'4\', \'en\')', uText[4], 'mark-please', uHelp[4], null, null, 'javascript:template_mark(\'4\', prompt(\'' + template_langquery + '\', wgUserLanguage))', template_lang);
    addLink('p-tb', 'javascript:template_mark(\'5\', \'en\')', uText[5], 'mark-please', uHelp[5], null, null, 'javascript:template_mark(\'5\', prompt(\'' + template_langquery + '\', wgUserLanguage))', template_lang);
    addLink('p-tb', 'javascript:template_mark(\'1\', \'en\')', uText[1], 'mark-warn',   uHelp[1], null, null, 'javascript:template_mark(\'1\', prompt(\'' + template_langquery + '\', wgUserLanguage))', template_lang);
    addLink('p-tb', 'javascript:template_mark(\'2\', \'en\')', uText[2], 'mark-warn',   uHelp[2], null, null, 'javascript:template_mark(\'2\', prompt(\'' + template_langquery + '\', wgUserLanguage))', template_lang);
    addLink('p-tb', 'javascript:template_mark(\'6\', \'en\')', uText[6], 'mark-warn',   uHelp[6], null, null, 'javascript:template_mark(\'6\', prompt(\'' + template_langquery + '\', wgUserLanguage))', template_lang);
    addLink('p-tb', 'javascript:template_mark(\'7\', \'en\')', uText[7], 'mark-warn',   uHelp[7], null, null, 'javascript:template_mark(\'7\', prompt(\'' + template_langquery + '\', wgUserLanguage))', template_lang);
    addLink('p-tb', 'javascript:template_mark(\'8\', \'en\')', uText[8], 'mark-warn',   uHelp[8], null, null, 'javascript:template_mark(\'8\', prompt(\'' + template_langquery + '\', wgUserLanguage))', template_lang);
    addLink('p-tb', 'javascript:template_mark(\'9\', \'en\')', uText[9], 'mark-warn',   uHelp[9], null, null, 'javascript:template_mark(\'9\', prompt(\'' + template_langquery + '\', wgUserLanguage))', template_lang);
  }

  var fakeaction = getParamValue('fakeaction');
  var template_type = getParamValue('template_type');	// Fetch what template to add

  if (fakeaction == '0'){ template_addTemplate( uTemplate[0] ); }
  if (fakeaction == '1'){ template_addTemplate( uTemplate[1] ); }
  if (fakeaction == '2'){ template_addTemplate( uTemplate[2] ); }
  if (fakeaction == '3'){ template_addTemplate( uTemplate[3] ); }
  if (fakeaction == '4'){ template_addTemplate( uTemplate[4] ); }
  if (fakeaction == '5'){ template_addTemplate( uTemplate[5] ); }
  if (fakeaction == '6'){ template_addTemplate( uTemplate[6] ); }
  if (fakeaction == '7'){ template_addTemplate( uTemplate[7] ); }
  if (fakeaction == '8'){ template_addTemplate( uTemplate[8] ); }
  if (fakeaction == '9'){ template_addTemplate( uTemplate[9] ); }
 }

addOnloadHook(template_onload);
// </pre>