User:Mattflaschen/quickDelete.js

//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

// ==Automatic 'nominate for deletion' script== // // Configuration

// Should the edits be saved automatically? nfd_autosave = true;

nfd_text = "Nominate for deletion"; nfd_tooltip = "Nominate this image for deletion"; nfd_prompt = "Why do you want to nominate this image for deletion?";

// Site info

nfd_path = "/w/index.php"; nfd_prettypath = "/wiki/"; nfd_hostname = "commons.wikimedia.org"

nfd_delReq = "Template:Deletion_requests"; nfd_deleteTemplate = "delete"; nfd_idwTemplate = "idw";

// From en:Wikipedia:WikiProject User scripts/Scripts/Get Page Name function getPname { z=document.getElementById("content").childNodes; for (var n=0;n<z.length;n++) { if (z[n].className=="firstHeading") return z[n].textContent; }; }

// From en:Wikipedia:WikiProject User scripts/Scripts/addLink 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; }

// 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 nfd_openWindow(url) { var res = window.open(url, '_blank'); if (!res) alert("nfd_openWindow: window.open returned null"); }

function nfd_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("nfd_getUploader: Cannot find filehistory ... exiting"); return null; } while (el.nextSibling) { el = el.nextSibling; if (el.tagName && el.tagName.toLowerCase == 'ul') break; } if (!el) { alert("nfd_getUploader: Cannot find UL tag ... exiting"); return null; } var el = el.getElementsByTagName('li')[0]; if (!el) { alert("nfd_getUploader: Cannot find LI tag ... exiting"); return null; } var as = el.getElementsByTagName('a');

var re1 = new RegExp('http://' + (nfd_hostname + nfd_prettypath).replace(/\./g, '\\.') + 'User:(.*)$'); var re2 = new RegExp('http://' + (nfd_hostname + nfd_path).replace(/\./g, '\\.') + '\\?title=User:([^&]*)'); 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("nfd_getUploader: Cannot find uploader ... exiting"); return null; }

function nfd_nomForDel { var reason = prompt(nfd_prompt, ''); if (!reason) return; var pagename = encodeURIComponent(getPname); var uploader = nfd_getUploader; if (!uploader) return; nfd_openWindow(nfd_path + '?title=User_talk:' + uploader		 + '&action=edit&fakeaction=nfd_warn&target=' + pagename); nfd_openWindow(nfd_path + '?title=' + nfd_delReq + '&action=edit&fakeaction=nfd_add' 		 + '&target=' + pagename + '&reason=' + encodeURIComponent(reason)); var editlk = document.getElementById('ca-edit').getElementsByTagName('a')[0].href; document.location = editlk + '&fakeaction=nfd_delete'; }

function nfd_addDeleteTemplate { var txt = ''; document.editform.wpTextbox1.value = txt + '\n' + document.editform.wpTextbox1.value; document.editform.wpSummary.value = txt; if (nfd_autosave) document.editform.wpSave.click; }

function nfd_addIdwTemplate(target) { var txt = ''; document.editform.wpTextbox1.value += '\n' + '== ' + target + ' listed for deletion ==\n' + txt + '' + '\n'; document.editform.wpSummary.value = txt; if (nfd_autosave) document.editform.wpSave.click; }

function nfd_updateDelReq(target, reason) { document.editform.wpTextbox1.value += '\n' + '=== ' + target + ' ===\n' + reason + ' -- ' + ' \n'; document.editform.wpSummary.value = 'Nominating ' + target + ''; if (nfd_autosave) document.editform.wpSave.click; }

function nfd_onload { if (getPname.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(getParamValue('target')); else if (fakeaction == 'nfd_add') nfd_updateDelReq(getParamValue('target'), getParamValue('reason')); }

$(nfd_onload); //

//================================================================================

// ==Automatic 'mark no source' (mns) and 'mark no license' (mnl) script== // mnx = applies to both // // Configuration

// Should the edits be saved automatically? mnx_autosave = true;

mns_text = "Mark as no source"; mns_tooltip = "Mark this image as missing required source information";

mnl_text = "Mark as no license"; mnl_tooltip = "Mark this image as missing required licensing information";

// Site info

mnx_path = "/w/index.php"; mnx_prettypath = "/wiki/"; mnx_hostname = "commons.wikimedia.org"

// From en:Wikipedia:WikiProject User scripts/Scripts/Get Page Name function getPname { z=document.getElementById("content").childNodes; for (var n=0;n<z.length;n++) { if (z[n].className=="firstHeading") return z[n].textContent; }; }

// From en:Wikipedia:WikiProject User scripts/Scripts/addLink function addLink(where, url, name, id, title, key, after){ 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; }

// 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 mnx_openWindow(url) { var res = window.open(url, '_blank'); if (!res) alert("mnx_openWindow: window.open returned null"); }

function mnx_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("mnx_getUploader: Cannot find filehistory ... exiting"); return null; } while (el.nextSibling) { el = el.nextSibling; if (el.tagName && el.tagName.toLowerCase == 'ul') break; } if (!el) { alert("mnx_getUploader: Cannot find UL tag ... exiting"); return null; } var el = el.getElementsByTagName('li')[0]; if (!el) { alert("mnx_getUploader: Cannot find LI tag ... exiting"); return null; } var as = el.getElementsByTagName('a');

var re1 = new RegExp('http://' + (mnx_hostname + mnx_prettypath).replace(/\./g, '\\.') + 'User:(.*)$'); var re2 = new RegExp('http://' + (mnx_hostname + mnx_path).replace(/\./g, '\\.') + '\\?title=User:([^&]*)'); 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("mnx_getUploader: Cannot find uploader ... exiting"); return null; }

// these next 2 only differ in the names and the fakeactions. please merge, somehow function mns_markNoSource { var pagename = encodeURIComponent(getPname); var uploader = mnx_getUploader; if (!uploader) return; mnx_openWindow(mnx_path + '?title=User_talk:' + uploader		 + '&action=edit&fakeaction=mnx_warn&target=' + pagename); var editlk = document.getElementById('ca-edit').getElementsByTagName('a')[0].href; document.location = editlk + '&fakeaction=mns_mns'; }

function mnl_markNoLicense { var pagename = encodeURIComponent(getPname); var uploader = mnx_getUploader; if (!uploader) return; mnx_openWindow(mnx_path + '?title=User_talk:' + uploader		 + '&action=edit&fakeaction=mnx_warn&target=' + pagename); var editlk = document.getElementById('ca-edit').getElementsByTagName('a')[0].href; document.location = editlk + '&fakeaction=mnl_mnl'; }

function mnx_addTemplate(template, sorl) { var txt = ''; // this MUST be subst since templates are NSD, NLD 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.'; // this is the edit summary for when you mark the image. you can change it if you want. // sorl = "source" or "license" if (mnx_autosave) document.editform.wpSave.click; }

function mnx_addUserWarningTemplate(imagetarget) { var txt = ''; // add in subst: if you want to subst these warnings document.editform.wpTextbox1.value += '\n' + txt + '' + '\n'; document.editform.wpSummary.value = "Warning: image missing source or licensing information."; // 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; }

function mnx_onload { if (getPname.indexOf('Image:') == 0) { addLink('p-tb', 'javascript:mns_markNoSource', mns_text, 'mark-no-source', mns_tooltip); addLink('p-tb', 'javascript:mnl_markNoLicense', mnl_text, 'mark-no-license', mnl_tooltip); } var fakeaction = getParamValue('fakeaction');

if (fakeaction == 'mns_mns'){ mnx_addTemplate('nsd','source'); } if (fakeaction == 'mnl_mnl'){ mnx_addTemplate('nld','license'); } if (fakeaction == 'mnx_warn'){ mnx_addUserWarningTemplate(getParamValue('target')); } }

$(mnx_onload); //