User:Holly Cheng/quickimgdelete.js: Difference between revisions
Content deleted Content added
m addLink() -> addPortletLink(); doing this for all scripts listed on WP:JS |
m also replace getPname() with wgPageName and wgCanonicalNamespace |
||
Line 151: | Line 151: | ||
var reason = prompt(nfd_prompt, ''); |
var reason = prompt(nfd_prompt, ''); |
||
if (!reason) return; |
if (!reason) return; |
||
var pagename = encodeURIComponent( |
var pagename = encodeURIComponent(wgPageName); |
||
var uploader = qid_getUploader(); |
var uploader = qid_getUploader(); |
||
if (!uploader) return; |
if (!uploader) return; |
||
Line 192: | Line 192: | ||
if (document.getElementById('ca-edit') == null) // not editable by non-admin |
if (document.getElementById('ca-edit') == null) // not editable by non-admin |
||
return; |
return; |
||
if (wgCanonicalNamespace == "Image") { |
|||
var pname = getPname(); |
|||
if (pname.indexOf('Image:') == 0) { |
|||
addPortletLink('p-tb', 'javascript:nfd_nomForDel()', nfd_text, 'nom-for-del', nfd_tooltip); |
addPortletLink('p-tb', 'javascript:nfd_nomForDel()', nfd_text, 'nom-for-del', nfd_tooltip); |
||
} |
} |
||
Line 228: | Line 227: | ||
function mnx_markNo(action) { |
function mnx_markNo(action) { |
||
var pagename = encodeURIComponent( |
var pagename = encodeURIComponent(wgPageName); |
||
var uploader = qid_getUploader(); |
var uploader = qid_getUploader(); |
||
if (!uploader) return; |
if (!uploader) return; |
||
Line 305: | Line 304: | ||
if (document.getElementById('ca-edit') == null) // not editable by non-admin |
if (document.getElementById('ca-edit') == null) // not editable by non-admin |
||
return; |
return; |
||
if ( |
if (wgCanonicalNamespace == "Image") { |
||
addPortletLink('p-tb', 'javascript:mnx_markNo(\'mnx_mns\')', mns_text, 'mark-no-source', mns_tooltip); |
addPortletLink('p-tb', 'javascript:mnx_markNo(\'mnx_mns\')', mns_text, 'mark-no-source', mns_tooltip); |
||
addPortletLink('p-tb', 'javascript:mnx_markNo(\'mnx_mnl\')', mnl_text, 'mark-no-license', mnl_tooltip); |
addPortletLink('p-tb', 'javascript:mnx_markNo(\'mnx_mnl\')', mnl_text, 'mark-no-license', mnl_tooltip); |
||
Line 387: | Line 386: | ||
if (document.getElementById('ca-edit') == null) // not editable by non-admin |
if (document.getElementById('ca-edit') == null) // not editable by non-admin |
||
return; |
return; |
||
if ( |
if (wgCanonicalNamespace == "Image") { |
||
addPortletLink('p-tb', 'javascript:speedyi_mark(\'speedyi_mred\')', mred_text, 'mark-redundant', mred_tooltip); |
addPortletLink('p-tb', 'javascript:speedyi_mark(\'speedyi_mred\')', mred_text, 'mark-redundant', mred_tooltip); |
||
addPortletLink('p-tb', 'javascript:speedyi_mark(\'speedyi_mmi\')', mmi_text, 'mark-missing', mmi_tooltip); |
addPortletLink('p-tb', 'javascript:speedyi_mark(\'speedyi_mmi\')', mmi_text, 'mark-missing', mmi_tooltip); |
Revision as of 17:15, 14 January 2007
/* <pre><nowiki> */
/* quickimgdelete.js
* Current version: 1.4.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( "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
var today = new Date();
return today.getUTCFullYear() + ' ' + monthnames[today.getUTCMonth()] + ' ' + today.getUTCDate();
}
// 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: Cannot find filehistory ... exiting");
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, '\\.') + 'User:(.*)$');
var re2 = new RegExp('http://' + (qid_hostname + qid_path).replace(/\./g, '\\.') + '\\?title=User:([^&]*)');
var re3 = /User( talk)?:(.*)$/; // 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;
}
function qid_checkForRedirect(editformval, type) {
if (editformval.toLowerCase().indexOf("#redirect") == -1)
return;
var re = /\[\[([^\]]+)\]\]/;
var m = re.exec(editformval);
var redirtarget = m[1];
var fakeaction = getParamValue("fakeaction");
var pagename = getParamValue("target");
var redirurl = qid_path + '?title=' + redirtarget
+ '&action=edit&fakeaction=' + fakeaction + '&target=' + pagename;
if (type)
redirurl += '&type=' + type;
window.location.replace(redirurl);
}
// ==General configuration==
qid_autosave = true; // Should the edits be saved automatically?
// Site info
qid_path = "/w/index.php";
qid_prettypath = "/wiki/";
qid_hostname = window.location.hostname;
// ==Automatic 'nominate for deletion' script==
// Configuration
nfd_text = "Nominate for deletion";
nfd_tooltip = "Nominate this image for deletion";
nfd_prompt = "Why do you want to nominate this image for deletion?";
nfd_delReq = "Wikipedia:Images_and_media_for_deletion/" + GuessUTCDate();
nfd_deleteTemplate = "ifd";
nfd_idwTemplate = "idw";
nfd_ifdTemplate = "ifd2";
function nfd_nomForDel() {
var reason = prompt(nfd_prompt, '');
if (!reason) return;
var pagename = encodeURIComponent(wgPageName);
var uploader = qid_getUploader();
if (!uploader) return;
qid_openWindow(qid_path + '?title=User_talk:' + 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 = 'nomination for [[WP:IFD|deletion]]';
if (qid_autosave) document.editform.wpSave.click();
}
function nfd_addIdwTemplate(target) {
qid_checkForRedirect(document.editform.wpTextbox1.value);
var txt = '{{subst:' + nfd_idwTemplate + '|1=' + 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() {
if (document.getElementById('ca-edit') == null) // not editable by non-admin
return;
if (wgCanonicalNamespace == "Image") {
addPortletLink('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')));
}
addOnloadHook(nfd_onload);
//================================================================================
// ==Automatic 'mark no source' (mns) and 'mark no license' (mnl) script== // mnx = applies to both
//
// Configuration
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";
mnr_text = "Mark as no rationale";
mnr_tooltip = "Mark this image as missing fair use rationale";
mor_text = "Mark as orphaned fairuse";
mor_tooltip = "Mark this image as an orphaned fair use image";
mrfu_text = "Mark as replaceable fairuse";
mrfu_tooltip = "Mark this image as a replaceable fair use image";
function mnx_markNo(action) {
var pagename = encodeURIComponent(wgPageName);
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 = "Image is missing source information and will be deleted in seven days if it is not added.";
break;
case "nld":
summary = "Image is missing license information and will be deleted in seven days if it is not added.";
break;
case "nrd":
summary = "Image is missing fair use rationale and will be deleted in seven days if it is not added.";
break;
case "orfud":
summary = "This fair use image is not used in any articles and will be deleted in seven days if it remains so.";
break;
case "rfu":
summary = "This fair use appears to illustrate a subject for which a free image could reasonably be found or created and will be deleted in seven days.";
break;
}
document.editform.wpSummary.value = summary
if (qid_autosave) document.editform.wpSave.click();
}
function mnx_addUserWarningTemplate(type, imagetarget) {
qid_checkForRedirect(document.editform.wpTextbox1.value, type);
var template;
var editSummary;
switch (type) {
case "mnx_mns":
template = "image source";
editSummary = "Warning: image missing source information.";
break;
case "mnx_mnl":
template = "image copyright";
editSummary = "Warning: image missing license information.";
break;
case "mnx_mnr":
template = "missing rationale";
editSummary = "Warning: image missing fair use rationale.";
break;
case "mnx_mor":
template = "orphaned";
editSummary = "The fair use image you uploaded is now orphaned.";
break;
case "mnx_mrfu":
template = "replaceable";
editSummary = "The fair use image you uploaded is replaceable by a free one.";
imagetarget = imagetarget.substring(6); // {{replaceable|example.png}}
break;
}
var txt = '{{subst:' + template + '|1=' + 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 (document.getElementById('ca-edit') == null) // not editable by non-admin
return;
if (wgCanonicalNamespace == "Image") {
addPortletLink('p-tb', 'javascript:mnx_markNo(\'mnx_mns\')', mns_text, 'mark-no-source', mns_tooltip);
addPortletLink('p-tb', 'javascript:mnx_markNo(\'mnx_mnl\')', mnl_text, 'mark-no-license', mnl_tooltip);
addPortletLink('p-tb', 'javascript:mnx_markNo(\'mnx_mnr\')', mnr_text, 'mark-no-rationale', mnr_tooltip);
addPortletLink('p-tb', 'javascript:mnx_markNo(\'mnx_mor\')', mor_text, 'mark-orphaned', mor_tooltip);
addPortletLink('p-tb', 'javascript:mnx_markNo(\'mnx_mrfu\')', mrfu_text, 'mark-replaceable', mrfu_tooltip);
}
var fakeaction = getParamValue('fakeaction');
switch (fakeaction) {
case 'mnx_mns':
mnx_addTemplate('nsd');
break;
case 'mnx_mnl':
mnx_addTemplate('nld');
break;
case 'mnx_mnr':
mnx_addTemplate('nrd');
break;
case 'mnx_mor':
mnx_addTemplate('orfud');
break;
case 'mnx_mrfu':
mnx_addTemplate('rfu');
break;
case 'mnx_warn':
mnx_addUserWarningTemplate(getParamValue('type'), decodeURIComponent(getParamValue('target')));
break;
}
}
addOnloadHook(mnx_onload);
mred_text = "Mark as redundant image";
mred_tooltip = "Mark this image as redundant (tag for speedy deletion)";
mmi_text = "Mark as missing image";
mmi_tooltip = "Mark as missing image (tag for speedy deletion)";
function speedyi_addTemplate(template, imagetarget) {
var txt = '{{' + template;
if (template == 'isd')
txt += '|1=' + imagetarget;
txt += '}}';
var editformval = qid_removeUntaggedTemplate(document.editform.wpTextbox1.value);
document.editform.wpTextbox1.value = txt + '\n' + editformval;
var summary;
switch (template) {
case 'isd':
summary = 'Tagging for [[WP:CSD#I1|speedy deletion]]: Image is redundant to [[:Image:' + imagetarget + ']].';
break;
case 'missing image':
summary = 'Tagging for [[WP:CSD#I2|speedy deletion]]: Image is missing or corrupt.';
break;
}
document.editform.wpSummary.value = summary
if (qid_autosave) document.editform.wpSave.click();
}
function speedyi_mark(action) {
var editlk = document.getElementById('ca-edit').getElementsByTagName('a')[0].href;
var xtra = '';
switch (action) {
case "speedyi_mred":
var dupe = window.prompt("Please enter the name of the image this one is redundant to.");
if (!dupe) {
alert("speedyi_mark: No image name entered.");
return;
}
if (dupe.indexOf('Image:') == 0) {
dupe = dupe.substring(6);
}
xtra = '&target=' + dupe;
break;
}
window.location = editlk + '&fakeaction=' + action + xtra;
}
function speedyi_onload() {
if (document.getElementById('ca-edit') == null) // not editable by non-admin
return;
if (wgCanonicalNamespace == "Image") {
addPortletLink('p-tb', 'javascript:speedyi_mark(\'speedyi_mred\')', mred_text, 'mark-redundant', mred_tooltip);
addPortletLink('p-tb', 'javascript:speedyi_mark(\'speedyi_mmi\')', mmi_text, 'mark-missing', mmi_tooltip);
}
var fakeaction = getParamValue('fakeaction');
switch (fakeaction) {
case 'speedyi_mred':
speedyi_addTemplate('isd', decodeURIComponent(getParamValue('target')));
break;
case 'speedyi_mmi':
speedyi_addTemplate('missing image');
break;
}
}
addOnloadHook(speedyi_onload);
/* </nowiki></pre> */