לדלג לתוכן

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

מתוך צפונות ויקי
taking flexibility out. Not for me to code...
add support for 5 more templates
שורה 2: שורה 2:
==Automatic user messages ==
==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:
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|end of copyvios}}
*{{tl|please tag images}}
*{{tl|please tag images}}
*{{tl|please name images}}
*{{tl|please name images}}
שורה 11: שורה 13:


===TODO===
===TODO===
* Add {{tl|test}}, {{tl|test2}}, {{tl|test3}}, and {{tl|test4}} buttons (including local variants) and/or basically all templates from [[Commons:Message templates]].
* Add parameter support
* Add basically all templates from [[Commons:Message templates]].
<pre>
<pre>
*/
*/
שורה 26: שורה 29:
plink_text = "Please link";
plink_text = "Please link";
plink_tooltip = "Request user to please link his images through categories or galleries";
plink_tooltip = "Request user to please link his images through categories or galleries";
pendcopyvio_text = "End copyvio";
pendcopyvio_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";


template_lang = "lang?";
template_lang = "lang?";
שורה 117: שורה 130:
function template_onload() {
function template_onload() {
   if (wgNamespaceNumber == 3) { //NS_USERTALK
   if (wgNamespaceNumber == 3) { //NS_USERTALK
     addLink('p-tb', 'javascript:template_mark(\'ptag_mns\', \'en\')', ptag_text, 'mark-please-tag', ptag_tooltip, null, null, 'javascript:template_mark(\'ptag_mns\', prompt(\'' + template_langquery + '\', wgUserLanguage))', template_lang);
     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(\'pname_mnl\', \'en\')', pname_text, 'mark-please-name', pname_tooltip, null, null, 'javascript:template_mark(\'pname_mnl\', 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(\'plink_mnp\', \'en\')', plink_text, 'mark-please-link', plink_tooltip, null, null, 'javascript:template_mark(\'plink_mnp\', 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_endcopyvio\', \'en\')', pendcopyvio_text, 'mark-end-copyvios', pendcopyvio_tooltip, null, null, 'javascript:template_mark(\'p_endcopyvio\', prompt(\'' + template_langquery + '\', wgUserLanguage))', template_lang);
    addLink('p-tb', 'javascript:template_mark(\'p_tag\', \'en\')', ptag_text, 'mark-please-tag', ptag_tooltip, null, null, 'javascript:template_mark(\'p_tag\', prompt(\'' + template_langquery + '\', wgUserLanguage))', template_lang);
     addLink('p-tb', 'javascript:template_mark(\'p_name\', \'en\')', pname_text, 'mark-please-name', pname_tooltip, null, null, 'javascript:template_mark(\'p_name\', prompt(\'' + template_langquery + '\', wgUserLanguage))', template_lang);
     addLink('p-tb', 'javascript:template_mark(\'p_link\', \'en\')', plink_text, 'mark-please-link', plink_tooltip, null, null, 'javascript:template_mark(\'p_link\', prompt(\'' + template_langquery + '\', wgUserLanguage))', template_lang);
   }
   }
   var fakeaction = getParamValue('fakeaction');
   var fakeaction = getParamValue('fakeaction');
   var template_type = getParamValue('template_type'); // Fetch what template to add
   var template_type = getParamValue('template_type'); // Fetch what template to add


   if (fakeaction == 'ptag_mns'){
   if (fakeaction == 'p_test1'){ template_addTemplate('test'); }
    template_addTemplate('please tag images');
  if (fakeaction == 'p_test2'){ template_addTemplate('test2'); }
}  if (fakeaction == 'pname_mnl'){
  if (fakeaction == 'p_test3'){ template_addTemplate('test3'); }
    template_addTemplate('please name images');
  if (fakeaction == 'p_test4'){ template_addTemplate('test4'); }
}  if (fakeaction == 'plink_mnp'){
  if (fakeaction == 'p_endcopyvio'){ template_addTemplate('end of copyvios'); } 
    template_addTemplate('please link images');
  if (fakeaction == 'p_tag'){ template_addTemplate('please tag images'); }
}   
  if (fakeaction == 'p_name'){ template_addTemplate('please name images'); }
 
  if (fakeaction == 'p_link'){ template_addTemplate('please link images'); }   
  }
  }


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

גרסה מ־12:21, 12 ביוני 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|end of copyvios}}
*{{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
ptag_text = "Please tag";
ptag_tooltip = "Request user to please tag his images";
pname_text = "Please name";
pname_tooltip = "Request user to please name his images correctly";
plink_text = "Please link";
plink_tooltip = "Request user to please link his images through categories or galleries";
pendcopyvio_text = "End copyvio";
pendcopyvio_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";

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_endcopyvio\', \'en\')', pendcopyvio_text, 'mark-end-copyvios', pendcopyvio_tooltip, null, null, 'javascript:template_mark(\'p_endcopyvio\', prompt(\'' + template_langquery + '\', wgUserLanguage))', template_lang);
    addLink('p-tb', 'javascript:template_mark(\'p_tag\', \'en\')', ptag_text, 'mark-please-tag', ptag_tooltip, null, null, 'javascript:template_mark(\'p_tag\', prompt(\'' + template_langquery + '\', wgUserLanguage))', template_lang);
    addLink('p-tb', 'javascript:template_mark(\'p_name\', \'en\')', pname_text, 'mark-please-name', pname_tooltip, null, null, 'javascript:template_mark(\'p_name\', prompt(\'' + template_langquery + '\', wgUserLanguage))', template_lang);
    addLink('p-tb', 'javascript:template_mark(\'p_link\', \'en\')', plink_text, 'mark-please-link', plink_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_endcopyvio'){ template_addTemplate('end of copyvios'); }  
  if (fakeaction == 'p_tag'){ template_addTemplate('please tag images'); }
  if (fakeaction == 'p_name'){ template_addTemplate('please name images'); }
  if (fakeaction == 'p_link'){ template_addTemplate('please link images'); }  
 }

addOnloadHook(template_onload);
// </pre>