MediaWiki:Gadget-QuickDelete.js

Da Cathopedia, l'enciclopedia cattolica.
Vai alla navigazione Vai alla ricerca

Nota: Dopo aver salvato le preferenze, perché i cambi abbiano effetto, devi bypassare la cache del tuo browser. Mozilla / Firefox / Safari: tieni premuto Shift mentre clicchi Reload, o premi Ctrl-Shift-R (Cmd-Shift-R per Apple Mac); Google Chrome: premi Ctrl o Shift mentre clicchi F5; IE: premi Ctrl mentre clicchi Refresh, o premi Ctrl-F5; Konqueror:: clicca semplicemente il pulsante di Reload, o premi F5; se usi Opera devi cancellare completamente la chache nel menu Tools→Preferences.

//Installing this (as described on the talk page) will give you links in the toolbox for all pages in the Image: namespace, that say 'Nominate for deletion', 'mark as no source' and 'mark as no license'. The first one will give you a pop-up that asks for a reason. It inserts this reason on [[COM:DEL]], marks the image for deletion and notifies the uploader. The second and third one mark the image as missing source/license (NSD/NLD) and notify the uploader. Note: don't abuse this. If you mark 10 images from one user as no source, don't use this because they will get 10 separate warnings on their talk page!! (Or if you do, at least clean it up afterwards.)

//Yes, this needs super cleaning-up and there's duplicate code and it doesn't work for Konqueror. Nonetheless it works at least for Firefox. If there's one central copy it's much easier to keep up to date than everyone having their own copy.
//Also it has no i18n. I will leave that for the experts.

// Main code by [[:en:User:Jietse Niesen]], some adaption by [[user:pfctdayelise]], cleanup by [[User:Alphax]]

// Now available on en.wp! See [[w:User:Howcheng/quickimgdelete.js]].

/* <source lang="javascript"><nowiki> */
// Configuration

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

// String constants
mnlicenza_text = "Immagine senza licenza";
mnlicenza_tooltip = "Segna questa immagine come mancante di informazioni sulla licenza";
mnlicenza_template = "{{subst:Avvisoimmagine}}";
mnfonte_text = "Immagine senza fonte/autore";
mnfonte_tooltip = "Segna questa immagine come mancante di informazioni sulla fonte/autore";
mnfonte_template = "{{subst:Avvisoimmagine3}}";
mnotrs_text = "Immagine senza OTRS";
mnotrs_tooltip = "Segna questa immagine come mancante di informazioni sul ticket OTRS";
mnotrs_template = "{{subst:AvvisoOTRS}}";
mnedp_text = "Immagine EDP non accettabile";
mnedp_tooltip = "Segna questa immagine come non rispettante le norme EDP";
mnedp_template = "{{subst:AvvisoEDP}}";
mnaltro_text = "Immagine senza altre informazioni";
mnaltro_tooltip = "Segna questa immagine come mancante di informazioni";
mnaltro_template = "{{Avvisoimmagine2}}";

// 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);
    }
    return li;
}

function openWindow(url) {
  var res = window.open(url, '_blank');
  if (!res) alert("openWindow: window.open() returned null");
}

function getUploader() {
  // Get uploader from first point in the list under "File history"
  // Uploader is stored in second A tag in UL tag under "File history"
  // Returns title of user page (without name space) in URL form
  var el = document.getElementById('mw-imagepage-section-filehistory').firstChild;
  if (!el) {
    alert("getUploader: Non è possibile trovare la cronologia ... esco");
    return null;
  }
  while (el.nextSibling) {
    el = el.nextSibling;
    if (el.tagName && el.tagName.toLowerCase() == 'table') 
      break;
  }
  if (!el) {
    alert("getUploader: Non è possibile trovare la tabella ... esco");
    return null;
  }

  var as = el.getElementsByTagName('a');

  var re1 = new RegExp((wgServer + wgArticlePath.substr(0, wgArticlePath.length-2) ).replace(/\./g, '\\.') + 'Utente:(.*)$');
  var re2 = new RegExp((wgServer  + wgScript).replace(/\./g, '\\.') + '\\?title=Utente:([^&]*)');
  var m;
  for (var k=0; k<as.length; k++) {
     m = re1.exec(as[k].href);
     if (m) return m[1];
     m = re2.exec(as[k].href);
     if (m) return m[1];
  }
  alert("getUploader: Non è possibile trovare l'utente che ha caricato l'immagine ... esco");
  return null;
}

function mnx_mark(imagepage_fakeaction, usertalk_fakeaction) {
  var answer = confirm ("Sicuro di voler inserire il template nella pagina?");
  
  if (answer == false)
    return;
  
  var pagename = encodeURIComponent(wgPageName);
  var uploader = getUploader();
  
  if (!uploader) return;
  // Open new window for the user page
  openWindow(wgScript + '?title=Discussioni_utente:' + uploader
     + '&action=edit&fakeaction=' + usertalk_fakeaction + '&target=' + pagename + '&template_type=' + imagepage_fakeaction);
  var editlk = document.getElementById('ca-edit').getElementsByTagName('a')[0].href;
  document.location = editlk + '&fakeaction=' + imagepage_fakeaction;
}

// Add template to image description page
// sorl = "source", "permission" or "license"
function mnx_addTemplate(template) {		
  //  the edit summary for when you mark the image. You can change it if you want.  
  var txt = '{{subst:unverdata}}';
  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.';
  document.editform.wpSummary.value = 'Segnalazione di immagine [[Wikipedia:Immagini da verificare|da verificare]] (unverified). Se non verificata questa immagine sarà cancellata tra 7 giorni.';
  if (mnx_autosave) document.editform.wpSave.click();
}

// Add warning template to uploader's talk page
function mnx_addUserWarningTemplate(imagetarget, template_type) {
  if (template_type == 'mnlicenza')
  {  
    // add in subst: if you want to subst these warnings
    var txt = '{{subst:Avvisoimmagine' + '|immagine=[[:' + imagetarget + ']]}}';
    document.editform.wpTextbox1.value += '\n==Immagine senza licenza==\n' + txt + '~~' + '~~\n';
    document.editform.wpSummary.value = "Immagine senza licenza";
  }
  if (template_type == 'mnfonte')
  {  
    // add in subst: if you want to subst these warnings
    var txt = '{{subst:Avvisoimmagine3' + '|' + imagetarget + '}}';
    document.editform.wpTextbox1.value += '\n==Informazioni mancanti==\n' + txt + '~~' + '~~\n';
    document.editform.wpSummary.value = "Informazioni mancanti";
  }
  if (template_type == 'mnotrs')
  {  
    // add in subst: if you want to subst these warnings
    var txt = '{{subst:AvvisoOTRS' + '|' + imagetarget + '}}';
    document.editform.wpTextbox1.value += '\n==Informazioni mancanti==\n' + txt + '~~' + '~~\n';
    document.editform.wpSummary.value = "Informazioni mancanti";
  }
  if (template_type == 'mnedp')
  {  
    // add in subst: if you want to subst these warnings
    var txt = '{{subst:AvvisoEDP' + '|' + imagetarget + '}}';
    document.editform.wpTextbox1.value += '\n==EDP non rispettata==\n' + txt + '~~' + '~~\n';
    document.editform.wpSummary.value = "EDP non rispettata";
  }
  if (template_type == 'mnaltro')
  {  
    // add in subst: if you want to subst these warnings
    var txt = '{{Avvisoimmagine2' + '|immagine=[[:' + imagetarget + ']]}}';
    document.editform.wpTextbox1.value += '\n==Immagine senza informazioni==\n' + txt + '~~' + '~~\n';
    document.editform.wpSummary.value = "Immagine senza informazioni.";
  }
	
  // this is the edit summary for when you leave the user warning on the talk page.
  // you can change it if you want.
  if (mnx_autosave) document.editform.wpSave.click();		// save page
}

function mnx_onload() {
  if (wgNamespaceNumber == 6) { //NS_IMAGE
    addLink('p-tb', 'javascript:mnx_mark(\'mnlicenza\', \'mnx_warn\')', mnlicenza_text, 'mark-no-license', mnlicenza_tooltip, null, null);
    addLink('p-tb', 'javascript:mnx_mark(\'mnfonte\', \'mnx_warn\')', mnfonte_text, 'mark-no-source', mnfonte_tooltip, null, null);
    addLink('p-tb', 'javascript:mnx_mark(\'mnotrs\', \'mnx_warn\')', mnotrs_text, 'mark-no-otrs', mnotrs_tooltip, null, null);
    addLink('p-tb', 'javascript:mnx_mark(\'mnedp\', \'mnx_warn\')', mnedp_text, 'mark-no-edp', mnedp_tooltip, null, null);
    addLink('p-tb', 'javascript:mnx_mark(\'mnaltro\', \'mnx_warn\')', mnaltro_text, 'mark-no-altro', mnaltro_tooltip, null, null);
  }
  var fakeaction = getParamValue('fakeaction');
  var template_type = getParamValue('template_type');	// Fetch what template to add

  // In realta' tutti aggiungono il template {{unverdata}} alla pagina dell'immagine. Questo meta-switch e' stato lasciato
  // per semplificare futuri improvements
  if (fakeaction == 'mnlicenza'){
    mnx_addTemplate('mnlicenza');
  }
  else if (fakeaction == 'mnfonte'){
    mnx_addTemplate('mnfonte');
  }
  else if (fakeaction == 'mnotrs'){
    mnx_addTemplate('mnfonte');
  }
  else if (fakeaction == 'mnedp'){
    mnx_addTemplate('mnfonte');
  }
  else if (fakeaction == 'mnaltro'){
    mnx_addTemplate('mnfonte');
  }
  
  if (fakeaction == 'mnx_warn') {  // Add warning to uploader's talk page
    mnx_addUserWarningTemplate(decodeURIComponent(getParamValue('target')), template_type);
  }
}

addOnloadHook(mnx_onload); //No source, no permission, no license.

// </nowiki></source>