Utilisateur:Stef48/quickdelete.js

Un article de Wikipédia, l'encyclopédie libre.

Note : Après avoir publié la page, vous devrez forcer son rechargement pour voir les changements : Mozilla / Konqueror / Firefox : Shift-Ctrl-R, Internet Explorer / Opera : Ctrl-F5, Safari : Cmd-R.

/* <pre><nowiki> */
/* quickimgdelete.js
 * Current version: 1.2.1
 * =======================================
 * Created by [[User:Howcheng|Howard Cheng]]
 * Released under the [[GNU Public License]] (GPL)
 * Full documentation at [[User talk:Howcheng/quickimgdelete.js]]
 * =======================================
 */
// ==Helper functions== 
// from [[User:Jnothman/automod.js]]
function GuessUTCDate() {
    var monthnames = new Array( "janvier", "février", "mars", "avril", "mai", "juin", "juillet", "août", "septembre", "octobre", "novembre", "décembre");
    var today = new Date();
    return today.getUTCFullYear() + ' ' + monthnames[today.getUTCMonth()] + ' ' + today.getUTCDate();
}
 
function addLink(where, url, name, id, title, key, after){
    //* 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".
    //
    //* url is the URL which will be called when the button is clicked.
    //   javascript: urls can be used to do more complex things.
    //
    //* name 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.
    //
    var na = document.createElement('a');
    na.href = url;
    na.appendChild(document.createTextNode(name));
    var li = document.createElement('li');
    if(id) li.id = id;
    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;
}
 
/*Returns the name of the page. For example, if you were browsing the "[[foo]]" WP page, getPname() would return "foo".*/
function getPname() {
  return wgPageName.replace(/_/g, ' ');
}
 
 
// From [[en:User:Lupin/autoedit.js]]
function getParamValue(paramName) {
  var cmdRe=RegExp('[&?]'+paramName+'=([^&]*)');
  var h=document.location;
  var m=cmdRe.exec(h);
  if (m) {
    try {
      return decodeURIComponent(m[1]);
    } catch (someError) {}
  }
  return null;
}
 
function qid_openWindow(url, windowName) {
  if (!windowName) windowName = 'qid_window';
  var res = window.open(url, windowName);
  if (!res) alert("qid_openWindow: window.open() returned null");
}
 
function qid_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('filehistory')
  if (!el) {
    alert("qid_getUploader: ne peut pas trouver l'historique... fin");
    return null;
  }
  while (el.nextSibling) {
    el = el.nextSibling;
    if (el.tagName && el.tagName.toLowerCase() == 'ul') 
      break;
  }
  if (!el) {
    alert("qid_getUploader: Cannot find UL tag ... exiting");
    return null;
  }
 
  var els = el.getElementsByTagName('li');
  if (!els) {
    alert("qid_getUploader: Cannot find LI tag ... exiting");
    return null;
  }
  var uploaders = new Array();
  var re1 = new RegExp('http://' + (qid_hostname + qid_prettypath).replace(/\./g, '\\.') + 'Utilisateur:(.*)$');
  var re2 = new RegExp('http://' + (qid_hostname + qid_path).replace(/\./g, '\\.') + '\\?title=Utilisateur:([^&]*)');
  var re3 = /(Discussion )?Utilisateur:(.*)$/; // this is for IE and handling Unicode characters
 
  var m;
  var uploader;
  var uploaderList = "";
  var count = 0;
  el = els[0];
  do {
    var as = el.childNodes;
    for (var k=0; k<as.length; k++) {
       if (as[k].tagName != 'A') continue;
       m = re3.exec(as[k].title);
       if (m) uploader = encodeURIComponent(m[2]);
       m = re1.exec(as[k].href);
       if (m) uploader = m[1];
       m = re2.exec(as[k].href);
       if (m) uploader = m[1];
    }
 
    if (uploaderList.indexOf(uploader) == -1) {
      if (count > 0) uploaderList += "; ";
      uploaderList += count + " - " + uploader;
      uploaders[uploaders.length] = uploader;
      count += 1;
    }
    el = el.nextSibling;
  } while (el);
 
  if (!uploaders || uploaders.length == 0) {
    alert("qid_getUploader: Cannot find uploader ... exiting");
    return null;
  }
  if (uploaders.length == 1)
    return uploaders[0];
 
  var which = parseInt(window.prompt("Choose which uploader to notify: " + uploaderList));
  if (isNaN(which) || which < 0 || which > uploaders.length) {
    alert("qid_getUploader: Invalid selection ... exiting");
    return null;
  }
  return uploaders[which];
}
 
function qid_removeUntaggedTemplate(editformval) {
  var untaggedpos = editformval.indexOf('{{untagged');
  if (untaggedpos > -1) {
    var lastbracepos = editformval.indexOf('}}', untaggedpos) + 1;
    editformval = editformval.substr(0, untaggedpos) + editformval.substr(lastbracepos + 2);
  }
  return editformval;
}
 
// ==General configuration==
qid_autosave = true; // Should the edits be saved automatically?
// Site info
qid_path = "/w/index.php";
qid_prettypath = "/wiki/";
qid_hostname = "fr.wikipedia.org";
 
 
/* Je mets en commentaire cette partie, réservée aux propositions de suppression... qui ne marcherait pas sur fr: pour l'instant.
 
 
// ==Automatic 'nominate for deletion' script==
// Configuration
nfd_text = "Image à supprimer";
nfd_tooltip = "Proposer cette image à la suppression";
nfd_prompt = "Pourquoi voulez-vous proposer cette image à la suppression ?";
nfd_delReq = "Wikipédia:Images_à_supprimer";
nfd_deleteTemplate = "ias";
nfd_idwTemplate = "asi";
nfd_ifdTemplate = "ifd2";
 
 
function nfd_nomForDel() {
  var reason = prompt(nfd_prompt, '');
  if (!reason) return;
  var pagename = encodeURIComponent(getPname());
  var uploader = qid_getUploader();
  if (!uploader) return;
  qid_openWindow(qid_path + '?title=Discussion_Utilisateur:' + uploader
                 + '&action=edit&fakeaction=nfd_warn&target=' + pagename);
  qid_openWindow(qid_path + '?title=' + nfd_delReq + '&action=edit&fakeaction=nfd_add' 
                 + '&target=' + pagename + '&reason=' + encodeURIComponent(reason)
                 + '&uploader=' + uploader, 'qid_ifd_window');
  var editlk = document.getElementById('ca-edit').getElementsByTagName('a')[0].href;
  window.location = editlk + '&fakeaction=nfd_delete';
}
 
function nfd_addDeleteTemplate() {
  var txt = '{{' + nfd_deleteTemplate + '}}';
  var editformval = qid_removeUntaggedTemplate(document.editform.wpTextbox1.value);
  document.editform.wpTextbox1.value = txt + '\n' + editformval;
  document.editform.wpSummary.value = 'Proposition à la [[WP:IAS|suppression]]';
  if (qid_autosave) document.editform.wpSave.click();
}
 
function nfd_addIdwTemplate(target) {
  var txt = '{{subst:' + nfd_idwTemplate + '|' + target + '}}';
  document.editform.wpTextbox1.value += '\n' + txt + '\n';
  document.editform.wpSummary.value = txt;
  if (qid_autosave) document.editform.wpSave.click();
}
 
function nfd_updateDelReq(target, reason, uploader) {
  var colonPos = target.indexOf(':');
  var imageName = target.substring(colonPos + 1);
  var txt = '{{subst:' + nfd_ifdTemplate + '|' + imageName +
    '|Uploader=' + uploader + '|Reason=' + reason + '}}';
  document.editform.wpTextbox1.value += '\n' + txt + ' ~~' + '~~ \n';
  document.editform.wpSummary.value = 'Nominating [[:' + target + ']]';
  if (qid_autosave) document.editform.wpSave.click();
}
 
function nfd_onload() {
  var pname = getPname();
  if (pname.indexOf('Image:') == 0) {
    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(unescape(getParamValue('target')));
  else if (fakeaction == 'nfd_add')
    nfd_updateDelReq(decodeURIComponent(getParamValue('target')), decodeURIComponent(getParamValue('reason')), 
      decodeURIComponent(getParamValue('uploader')));
}
 
addLoadEvent(nfd_onload);
 
*/
 
 
//================================================================================
// ==Automatic 'mark no source' (mns) and 'mark no license' (mnl) script== // mnx = applies to both
//
// Configuration
mns_text = "Sans source";
mns_tooltip = "Marquer cette image comme manquant de source";
 
mnl_text = "Sans licence";
mnl_tooltip = "Marquer cette image comme manquant de licence";
 
function mnx_markNo(action) {
  var pagename = encodeURIComponent(getPname());
  var uploader = qid_getUploader();
  if (!uploader) return;
  qid_openWindow(qid_path + '?title=User_talk:' + uploader
                 + '&action=edit&fakeaction=mnx_warn&target=' + pagename
                 + '&type=' + action);
  var editlk = document.getElementById('ca-edit').getElementsByTagName('a')[0].href;
  window.location = editlk + '&fakeaction=' + action ;
}
 
function mnx_addTemplate(template) {
  var txt = '{{subst:' + template + '}}';
// this MUST be subst since templates are NSD, NLD
  var editformval = qid_removeUntaggedTemplate(document.editform.wpTextbox1.value);
  document.editform.wpTextbox1.value = txt + '\n' + editformval;
  var summary;
  switch (template) {
    case "nsd":
      summary = "L’image ne possède pas de source précise et sera supprimée si la source n’est pas précisée.";
      break;
    case "nld":
      summary = "L’image ne possède pas de licence vérifiable et sera supprimée si une licence n’est pas ajoutée.";
      break;
  }
  document.editform.wpSummary.value = summary
 
  if (qid_autosave) document.editform.wpSave.click();
}
 
function mnx_addUserWarningTemplate(type, imagetarget) {
  var template;
  var editSummary;
  switch (type) {
    case "mnx_mns":
      template = "Avertissement source inconnue";
      editSummary = "Attention : image manquant d'information sur sa source.";
      break;
    case "mnx_mnl":
      template = "Avertissement licence inconnue";
      editSummary = "Attention : image manquant d'information sur sa licence.";
      break;
  }
  var txt = '{{subst:' + template + '|' + imagetarget + '}}';
// add in subst: if you want to subst these warnings
  document.editform.wpTextbox1.value += '\n' + txt + ' ~~' + '~~\n';
  document.editform.wpSummary.value = editSummary;
// this is the edit summary for when you leave the user warning on the talk page.
// you can change it if you want.
  if (qid_autosave) document.editform.wpSave.click();
}
 
function mnx_onload() {
  if (getPname().indexOf('Image:') == 0) {
    addLink('p-tb', 'javascript:mnx_markNo(\'mnx_mns\')', mns_text, 'mark-no-source', mns_tooltip);
    addLink('p-tb', 'javascript:mnx_markNo(\'mnx_mnl\')', mnl_text, 'mark-no-license', mnl_tooltip);
  }
  var fakeaction = getParamValue('fakeaction');
 
  switch (fakeaction) {
    case 'mnx_mns':
      mnx_addTemplate('nsd');
      break;
    case 'mnx_mnl':
      mnx_addTemplate('nld');
      break;
    case 'mnx_warn':
      mnx_addUserWarningTemplate(getParamValue('type'), decodeURIComponent(getParamValue('target')));
      break;
  }
}
 
addLoadEvent(mnx_onload);
/* </nowiki></pre> */