משתמש:ערן/quickdelete.js

מתוך ויקיפדיה, האנציקלופדיה החופשית

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

  • פיירפוקס / ספארי: להחזיק את המקש Shift בעת לחיצה על טעינה מחדש (Reload) או ללחוץ על צירוף המקשים Ctrl-F5 או Ctrl-R (במחשב מק: ⌘-R).
  • גוגל כרום: ללחוץ על צירוף המקשים Ctrl-Shift-R (במחשב מק: ⌘-Shift-R).
  • אינטרנט אקספלורר / אדג': להחזיק את המקש Ctrl בעת לחיצה על רענן (Refresh) או ללחוץ על צירוף המקשים Ctrl-F5.
  • אופרה: ללחוץ על Ctrl-F5.
 // 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;
 }

// Configuration

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

// String constants
nfd_text = "סומן למחיקה";
nfd_tooltip = "סמן תמונה זו למחיקה";
nfd_prompt = "מדוע ברצונך להציע תמונה זו למחיקה?";
nfd_delReq = "ויקיפדיה:בקשות_ממפעילים";
nfd_deleteTemplate = "מחק";
nfd_idwTemplate = "מקור תמונה";

mns_text = "חסר מקור";
mns_tooltip = "סמן תמונה זו כחסרה מקור";
mnl_text = "חסר רשיון";
mnl_tooltip = "סמן תמונה זו כחסרה פרטי רשיון";
mnp_text = "ספק שימוש הוגן";
mnp_tooltip = "סמן תמונה זו כחסרה מידע על האישור";

// Site info
scriptPath = "/w/index.php";
prettyPath = "/wiki/";
wikiHostname = "he.wikipedia.org";

var now = new Date();
nfd_datePage = nfd_delReq;
var monthsArray = ["ינואר", "פברואר", "מרץ", "אפריל", "מאי", "יוני", "יולי", "אוגוסט", "ספטמבר", "אוקטובר", "נובמבר", "דצמבר"];
var timestamp2 = monthsArray[now.getUTCMonth()] + " " + now.getUTCDate();

// 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 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 tables=document.getElementsByTagName('table');
  var uploaders;
  for(var i=0;i<tables.length;i++){
   if(tables[i].className=='filehistory'){
     uploaders=tables[i];
     break;
   }
  }
  if (uploaders==null) {
    alert("תקלה: לא נמצאה טבלת מעלים");
    return null;
  }
  var el = uploaders.getElementsByTagName('tr')[1];
  if (el==null) {
    alert("תקלה: לא נמצא מעלה ... משימה נכשלה");
    return null;
  }
  
  var as = el.getElementsByTagName('a');

  var re1 = new RegExp('http://' + (wikiHostname + prettyPath).replace(/\./g, '\\.') + '%D7%9E%D7%A9%D7%AA%D7%9E%D7%A9:(.*)$');
  var re2 = new RegExp('http://' + (wikiHostname + scriptPath).replace(/\./g, '\\.') + '\\?title=%D7%9E%D7%A9%D7%AA%D7%9E%D7%A9:([^&]*)');
  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("תקלה: לא נמצא מעלה ... משימה נכשלה");
  return null;
}

function nfd_nomForDel() {
  var reason = prompt(nfd_prompt, '');
  if (!reason) return;
  var pagename = encodeURIComponent(mw.config.get('wgPageName'));
  var uploader = getUploader();
  if (!uploader) return;
  openWindow(scriptPath + '?title=שיחת_משתמש:' + uploader
     + '&action=edit&fakeaction=nfd_warn&target=' + pagename);
  openWindow(scriptPath + '?title=' + nfd_delReq + '/' + pagename 
     + '&action=edit&fakeaction=nfd_add&target=' + pagename + '&reason='
     + encodeURIComponent(reason));
  openWindow(scriptPath + '?title=' + nfd_datePage +
     '&action=edit&fakeaction=nfd_add2&target=' + pagename);
  var editlk = document.getElementById('ca-edit').getElementsByTagName('a')[0].href;
  document.location = editlk + '&fakeaction=nfd_delete&reason=' + encodeURIComponent(reason);
}

function nfd_addDeleteTemplate() {
  var reason = decodeURIComponent(getParamValue('reason'));
  var txt = '{{' + nfd_deleteTemplate + '|סיבה=' + reason + '}}';
  document.editform.wpTextbox1.value = txt + '\n' + document.editform.wpTextbox1.value;
  document.editform.wpSummary.value = 'סימון תמונה למחיקה';
  if (nfd_autosave) document.editform.wpSave.click();
}

function nfd_addIdwTemplate(target) {
  var txt = '==' + target.substring(6,target.length) + '==\n{{subst:' + nfd_idwTemplate + '|שם התמונה=' + target.substring(6,target.length) + '}}';
  document.editform.wpTextbox1.value += 
    (document.editform.wpTextbox1.value.length > 0 ? '\n' : '') +
    txt + ' ~~' + '~~\n';
  document.editform.wpSummary.value = 'אזהרת מחיקת תמונה: ' + target;
  if (nfd_autosave) document.editform.wpSave.click();
}

function nfd_updateDelReq(target, reason) {
  document.editform.wpTextbox1.value += 
    (document.editform.wpTextbox1.value.length > 0 ? '\n' : '') +
    '{{subst:delete2|image=' + target + '|reason=' + reason + ' -- ~~' + '~~}}';
  document.editform.wpSummary.value = 'Nominating [[' + target + ']]';
  if (nfd_autosave) document.editform.wpSave.click();
}

function nfd_updateDelReq2(target) {
  document.editform.wpTextbox1.value += 
    (document.editform.wpTextbox1.value.length > 0 ? '\n' : '==' + timestamp2 + '==\n') +
    '{{subst:delete3|pg=' + target + '}}';
  document.editform.wpSummary.value = 'Nominating [[' + target + ']]';
  if (nfd_autosave) document.editform.wpSave.click();
}

function nfd_onload() {
  if (wgNamespaceNumber == 6) { //NS_IMAGE
    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) {

  var pagename = encodeURIComponent(mw.config.get('wgPageName'));
  var uploader = getUploader();
  
  if (!uploader) return;
  // Open new window for the user page
  openWindow(scriptPath + '?title=User_talk:' + 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, sorl) {
  if (template == 'nsd') template='ס:תמונה חשודה|חסר מקור'; //no source since
  if (template == 'nld') template='ס:תמונה חשודה|חסר רישיון'; //no license
  if (template == 'npd') template='ס:תמונה חשודה|ספק שימוש הוגן'; //no permission since
  //  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 = 'סימון תמונה כחסרה מידע הכרחי על ' + sorl + '. אם זה לא יתוקן התמונה עלולה להימחק תוך שבוע.';
  if (mnx_autosave) document.editform.wpSave.click();
}

// Add warning template to uploader's talk page
function mnx_addUserWarningTemplate(imagetarget, template_type) {
  // If template to add is a not permission template, add {{image permission}}
  if (template_type == 'mnp_mnp')                       
     var txt = '=='+imagetarget+'==\nשלום, נראה כי התמונה ' + '[[:' + imagetarget + ']] שהעלית אינה בשימוש הוגן ולכן צפויה להימחק בקרוב. אנא עיין ב[[ויקיפדיה:רישוי/שימוש הוגן]] וב[[ויקיפדיה:שאלות ותשובות/זכויות יוצרים]]. אם יש לך השגות על כך אנא ציין אותן ב[[שיחת '+imagetarget+'|דף השיחה]]. בברכה, ';
  // else, add the {{image source}} template
  else
     var txt = '==' + imagetarget.substring(6,imagetarget.length) + '==\n{{subst:מקור תמונה' + '|שם התמונה=' + imagetarget.substring(6,imagetarget.length) + '}}';

  // add in subst: if you want to subst these warnings
  document.editform.wpTextbox1.value += '\n' + txt + ' ~~' + '~~\n';
  document.editform.wpSummary.value = "אזהרה: תמונה חסרה מידע הכרחי על מקור או רישיון.";
  // 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(\'mns_mns\', \'mnx_warn\')', mns_text, 'mark-no-source', mns_tooltip, null, null);
    addLink('p-tb', 'javascript:mnx_mark(\'mnp_mnp\', \'mnx_warn\')', mnp_text, 'mark-no-permission', mnp_tooltip, null, null);
    addLink('p-tb', 'javascript:mnx_mark(\'mnl_mnl\', \'mnx_warn\')', mnl_text, 'mark-no-license', mnl_tooltip, null, null);
  }
  var fakeaction = getParamValue('fakeaction');
  var template_type = getParamValue('template_type');   // Fetch what template to add

  if (fakeaction == 'mns_mns'){
    mnx_addTemplate('nsd','מקור');
        }  if (fakeaction == 'mnp_mnp'){
    mnx_addTemplate('npd','אישור שימוש בתמונה');
        }  if (fakeaction == 'mnl_mnl'){
    mnx_addTemplate('nld','רישיון');
        }  
        if (fakeaction == 'mnx_warn') {                                 // Add warning to uploader's talk page
                        mnx_addUserWarningTemplate(decodeURIComponent(getParamValue('target')), template_type); }

 }

$(mnx_onload);
//