// ==Automatic 'nominate for deletion' script==
// <pre>
// 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 = '{{' + nfd_deleteTemplate + '}}';
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 = '{{' + nfd_idwTemplate + '|' + target + '}}';
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);
// </pre>