מדיה ויקי:Gadget-UserMessages.js

גרסה מ־10:00, 12 ביוני 2007 מאת wikipedia:he>Siebrand (rename variables)

הערה: לאחר הפרסום, ייתכן שיהיה צורך לנקות את זיכרון המטמון (cache) של הדפדפן כדי להבחין בשינויים.

  • פיירפוקס / ספארי: להחזיק את המקש Shift בעת לחיצה על טעינה מחדש (Reload) או ללחוץ על צירוף המקשים Ctrl-F5 או Ctrl-R (במחשב מק: ⌘-R).
  • גוגל כרום: ללחוץ על צירוף המקשים Ctrl-Shift-R (במחשב מק: ⌘-Shift-R).
  • אדג': להחזיק את המקש Ctrl בעת לחיצה על רענן (Refresh) או ללחוץ על צירוף המקשים Ctrl-F5.
/*
==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|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 {{tl|test}}, {{tl|test2}}, {{tl|test3}}, and {{tl|test4}} buttons.
<pre>
*/
// Configuration

// Should the edits be saved automatically?
if(window.mnx_autosave == false){}else if(window.mnx_autosave){}else{ mnx_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";

mnx_lang = "lang?";
mnx_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;
}

function nfd_onload() {
  if (wgNamespaceNumber == 3) { //NS_USERTALK
    addLink('p-tb', 'javascript:nfd_nomForDel()', nfd_text, 'nom-for-del', nfd_tooltip);
  }
  var fakeaction = getParamValue('fakeaction');
  if (fakeaction == 'nfd_delete')
    nfd_addDeleteTemplate();
  else if (fakeaction == 'nfd_warn')
    nfd_addIdwTemplate(decodeURIComponent(getParamValue('target')));
  else if (fakeaction == 'nfd_add')
    nfd_updateDelReq(decodeURIComponent(getParamValue('target')), decodeURIComponent(getParamValue('reason')));
  else if (fakeaction == 'nfd_add2')
    nfd_updateDelReq2(decodeURIComponent(getParamValue('target')));
}

// ??
function mnx_mark(imagepage_fakeaction, usertalk_fakeaction, message_lang) {
  if (!message_lang) return; //User pressed cancel

  var pagename = encodeURIComponent(wgPageName);
  var uploader = getUploader();
  
  if (!uploader) return;
  // Open new window for the user page
  var editlk = document.getElementById('ca-edit').getElementsByTagName('a')[0].href;
  document.location = editlk + '&fakeaction=' + imagepage_fakeaction + '&mnx_lang=' + message_lang;
}

// Add template to user talk page
function mnx_addTemplate(template) {		
  if (template == 'nsd') template='no source since';
  if (template == 'nld') template='no license';
  if (template == 'npd') template='no permission since';
  if (getParamValue('mnx_lang')) {
          template = template + '/' + getParamValue('mnx_lang');
          template = template + '|' + 'month={{subst:CURRENTMONTHNAME}}|day={{subst:CURRENTDAY}}|year={{subst:CURRENTYEAR}}';
  }

  //  the edit summary for when you mark the image. You can change it if you want.  
  var txt = '{{' + template + '}}';
  document.editform.wpTextbox1.value = txt + '\n' + document.editform.wpTextbox1.value;
  document.editform.wpSummary.value = 'marking image as missing essential ' + sorl + ' information. If this is not fixed this image might be deleted after 7 days.';
  if (mnx_autosave) document.editform.wpSave.click();
}

function mnx_onload() {
  if (wgNamespaceNumber == 3) { //NS_USERTALK
    addLink('p-tb', 'javascript:mnx_mark(\'ptag_mns\', \'mnx_warn\', \'en\')', ptag_text, 'mark-no-source', ptag_tooltip, null, null, 'javascript:mnx_mark(\'ptag_mns\', \'mnx_warn\', prompt(\'' + mnx_langquery + '\', wgUserLanguage))', mnx_lang);
    addLink('p-tb', 'javascript:mnx_mark(\'plink_mnp\', \'mnx_warn\', \'en\')', plink_text, 'mark-no-permission', plink_tooltip, null, null, 'javascript:mnx_mark(\'plink_mnp\', \'mnx_warn\', prompt(\'' + mnx_langquery + '\', wgUserLanguage))', mnx_lang);
    addLink('p-tb', 'javascript:mnx_mark(\'pname_mnl\', \'mnx_warn\', \'en\')', pname_text, 'mark-no-license', pname_tooltip, null, null, 'javascript:mnx_mark(\'pname_mnl\', \'mnx_warn\', prompt(\'' + mnx_langquery + '\', wgUserLanguage))', mnx_lang);
  }
  var fakeaction = getParamValue('fakeaction');
  var template_type = getParamValue('template_type');	// Fetch what template to add

  if (fakeaction == 'ptag_mns'){
    mnx_addTemplate('please tag images');
	}  if (fakeaction == 'plink_mnp'){
    mnx_addTemplate('please name images');
	}  if (fakeaction == 'pname_mnl'){
    mnx_addTemplate('please link images');
	}  

 }

addOnloadHook(mnx_onload);
// </pre>