Utente:Wim b/monobook.js/quickimgdelete.js
Da Wikiversità, l'università aperta.
Nota: dopo aver salvato è necessario pulire la cache del proprio browser per vedere i cambiamenti. Per Mozilla / Firefox / Safari: fare clic su Ricarica tenendo premuto il tasto delle maiuscole, oppure premere Ctrl-F5 o Ctrl-R (Command-R su Mac); per Konqueror: premere il pulsante Ricarica o il tasto F5; per Opera può essere necessario svuotare completamente la cache dal menu Strumenti → Preferenze; per Internet Explorer: mantenere premuto il tasto Ctrl mentre si preme il pulsante Aggiorna o premere Ctrl-F5.
/* <pre><nowiki> */ /* quickimgdelete.js * Current version: 1.9.2 * ======================================= * Created by [[User:Howcheng|Howard Cheng]] * Released under the [[GNU Public License]] (GPL) * Full documentation at [[User talk:Howcheng/quickimgdelete.js]] * ======================================= */ // ==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; // ==Helper functions== // from [[User:Jnothman/automod.js]] function GuessUTCDate() { var monthnames = new Array( "Gennaio", "Febbraio", "Marzo", "Aprile", "Maggio", "Giugno", "Luglio", "Agosto", "Settembre", "Ottobre", "Novembre", "Dicembre"); 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: Impossibile trovare la cronologia ... rimuovere"); 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: Impossibile trovare l'uploader ... Rimuovere"); 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: Selezione non valida ... Rimuovere"); return null; } return uploaders[which]; } function qid_removeTemplate(editformval, template) { var templatepos = editformval.indexOf('{{' + template); if (templatepos > -1) { var lastbracepos = editformval.indexOf('}}', templatepos) + 1; editformval = editformval.substr(0, templatepos) + editformval.substr(lastbracepos + 2); } return editformval; } function qid_doesTemplateExist(editformval, template) { var templatepos = editformval.indexOf('{{' + template); return (templatepos > -1); } 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); } function qid_saveEditForm(txt, summary) { document.editform.wpTextbox1.value = txt; document.editform.wpSummary.value = summary; if (qid_autosave) document.editform.wpSave.click(); } function qid_userBeenWarned(txt, template) { var re = eval("/\<!-- ?Template:" + template + " ?--\>/;"); return re.test(txt); } /** ================================================================================ * ==Automatic 'nominate for deletion/pui/imagevio' script== * The actions in this section do three things: * 1. Add a tag to the image page. * 2. List the image on a log page. * 3. Add a warning template to the uploader's talk page. */ // Configuration nfd_text = "Proposta per la cancellazione"; nfd_tooltip = "Proponi questa immagine per la cancellazione"; nfd_prompt = "Perché intendi proporre questa immagine per la cancellazione?"; nfd_delReq = "Wikipedia:Images_and_media_for_deletion/" + GuessUTCDate().replace(' ', '_'); nfd_deleteTemplate = "ifd"; nfd_idwTemplate = "idw"; nfd_ifdTemplate = "ifd2"; nfd_glossary = new Array( new Array("AB", "Uploader assente"), new Array("AU", "Uploader assente "), new Array("CV", "Violazione di Copyright"), new Array("OB", "Obsoleta"), new Array("OR", "Orfana"), new Array("LQ", "Bassa qualità"), new Array("UE", "Non wikiversitaria") ); pui_text = "Possibile immagine non libera"; pui_tooltip = "Segna questa immagine come non libera"; pui_prompt = "Perché pensi che questa immagine non sia libera?"; pui_delReq = "Wikipedia:Possibly_unfree_images"; pui_deleteTemplate = "PUIdisputed"; pui_idwTemplate = "idw-pui"; vio_text = "Copyviol"; vio_tooltip = "MSegna questa immagine come Copyviol"; vio_prompt = "Inserisci l'URL da cui è stata presa questa immagine."; vio_delReq = "Wikipedia:Copyright_problems/" + GuessUTCDate().replace(' ', '_') + "/Images"; vio_deleteTemplate = "imagevio"; vio_idwTemplate = "idw-cp"; function nfd_tagImage(which) { var promptTxt; var targetUrl; var editlk = document.getElementById('ca-edit').getElementsByTagName('a')[0].href; editlk += '&fakeaction=' + which + '_delete' switch (which) { case 'nfd': promptTxt = nfd_prompt; targetUrl = nfd_delReq; break; case 'pui': promptTxt = pui_prompt; targetUrl = pui_delReq; break; case 'vio': promptTxt = vio_prompt; targetUrl = vio_delReq; editlk += '&url=' + reason; break; } var reason = prompt(promptTxt, ''); 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=' + which + '_warn&target=' + pagename); qid_openWindow(qid_path + '?title=' + targetUrl + '&action=edit&fakeaction=' + which + '_add' + '&target=' + pagename + '&reason=' + encodeURIComponent(reason) + '&uploader=' + uploader, 'qid_ifd_window'); window.location = editlk; } function nfd_addDeleteTemplate(template, otherparam) { var txt = '{{' + template; var summary; switch (template) { case nfd_deleteTemplate: summary = 'nomination for [[WP:IFD|deletion]]'; break; case pui_deleteTemplate: summary = 'this is a [[WP:PUI|possibly unfree image]]'; break; case vio_deleteTemplate: summary = 'this image is suspected to be a [[WP:CP|copyright violation]]'; txt += '|1=' + otherparam; break; } txt += '}}'; var editformval = qid_removeTemplate(document.editform.wpTextbox1.value, 'untagged'); qid_saveEditForm(txt + '\n' + editformval, summary); } function nfd_addIdwTemplate(template, target) { var editformval = document.editform.wpTextbox1.value; qid_checkForRedirect(editformval); var txt = '{{subst:' + template + '|1=' + target + '}}'; editformval += '\n' + txt + '\n'; qid_saveEditForm(editformval, txt); } function nfd_updateDelReq(target, reason, uploader) { var colonPos = target.indexOf(':'); var imageName = target.substring(colonPos + 1); var abbrevCount = 0; for (var i = 0; i < nfd_glossary.length; i++) { var abbrev = nfd_glossary[i][0]; var meaning = nfd_glossary[i][1]; var re = eval("/\\b" + abbrev + "\\b/"); if (re.test(reason)) reason = reason.replace(re, meaning); } var txt = '{{subst:' + nfd_ifdTemplate + '|' + imageName + '|Uploader=' + uploader + '|Reason=' + reason + '}}'; var editformval = document.editform.wpTextbox1.value + '\n' + txt + ' ~~' + '~~ \n'; var summary = 'Nominating [[:' + target + ']]'; qid_saveEditForm(editformval, summary); } function pui_updateDelReq(target, reason) { var txt = '* [[:' + target + ']] - ' + reason; var editformval = document.editform.wpTextbox1.value + txt + ' ~~' + '~~ \n'; var summary = document.editform.wpSummary.value + 'Adding [[:' + target + ']]'; qid_saveEditForm(editformval, summary); } function vio_updateDelReq(target, url) { var txt = '* {{subst:Image-cv|' + target + '}} from [' + url + '].'; var editformval = document.editform.wpTextbox1.value + txt + ' ~~' + '~~ \n'; var summary = document.editform.wpSummary.value + 'Adding [[:' + target + ']]'; qid_saveEditForm(editformval, summary); } function nfd_onload() { if (document.getElementById('ca-edit') == null) // not editable by non-admin return; if (wgAction == "view" && wgCanonicalNamespace == "Image") { addPortletLink('p-tb', 'javascript:nfd_tagImage(\'nfd\')', nfd_text, 'nom-for-del', nfd_tooltip); addPortletLink('p-tb', 'javascript:nfd_tagImage(\'pui\')', pui_text, 'pui', pui_tooltip); addPortletLink('p-tb', 'javascript:nfd_tagImage(\'vio\')', vio_text, 'imagevio', 'vio_tooltip'); } var fakeaction = getParamValue('fakeaction'); switch (fakeaction) { case 'nfd_delete': nfd_addDeleteTemplate(nfd_deleteTemplate); break; case 'pui_delete': nfd_addDeleteTemplate(pui_deleteTemplate); break; case 'vio_delete': nfd_addDeleteTemplate(vio_deleteTemplate, decodeURIComponent(getParamValue('url'))); break; case 'nfd_warn': nfd_addIdwTemplate(nfd_idwTemplate, decodeURIComponent(getParamValue('target'))); break; case 'pui_warn': nfd_addIdwTemplate(pui_idwTemplate, decodeURIComponent(getParamValue('target'))); break; case 'vio_warn': nfd_addIdwTemplate(vio_idwTemplate, decodeURIComponent(getParamValue('target'))); break; case 'nfd_add': nfd_updateDelReq(decodeURIComponent(getParamValue('target')), decodeURIComponent(getParamValue('reason')), decodeURIComponent(getParamValue('uploader'))); break; case 'pui_add': pui_updateDelReq(decodeURIComponent(getParamValue('target')), decodeURIComponent(getParamValue('reason'))); break; case 'vio_add': vio_updateDelReq(decodeURIComponent(getParamValue('target')), decodeURIComponent(getParamValue('reason'))); break; } } addOnloadHook(nfd_onload); /** ================================================================================ * ==Automatic 'mark no source' (mns) and 'mark no license' (mnl) script== // mnx = applies to all * The actions in this section do two things: * 1. Add a tag to the image page. * 2. Add a warning to the uploader's talk page. */ // Configuration mns_text = "Senza fonte"; mns_tooltip = "Segna questa immagine come senza fonte"; mnl_text = "Senza licenza"; mnl_tooltip = "Segna questa immagine come senza licenza"; mnsl_text = "Senza fonte/licenza"; mnsl_tooltip = "Segna questa immagine come senza fonte ne licenza"; mnr_text = "Non razionale"; mnr_tooltip = "Segna questa immagine come priva di spiegazione razionale"; mor_text = "Fair use orfanizzato"; mor_tooltip = "Segna questa immagine come fair use orfanizzato"; mrfu_text = "Fair use sostituibile"; mrfu_tooltip = "Segna questa immagine come fair use sostituibile"; mfud_text = "Fair use disputato "; mfud_tooltip = "Segna questa immagine come fair use disputato "; mbsr_text = "Base URL"; mbsr_tooltip = "Questa immagine si collega direttamente all'immagine o è un URL generico"; function mnx_markNo(action) { var pagename = encodeURIComponent(wgPageName); var txt; var warnaction = action; switch (action) { case "mnx_mns": case "mnx_mnsl": case "mnx_mnl": // if image is marked as GFDL-presumed, then user a different user warning template if (document.getElementById("GFDL-presumed")) warnaction = "mnx_gfdl"; break; case 'mnx_mfud': txt = window.prompt('Prego inserire le informazione per cui ritieni che l\'uso sia :', ''); if (!txt) { alert('mnx_markNo: Action canceled.'); return; } break; } var uploader = qid_getUploader(); if (!uploader) return; qid_openWindow(qid_path + '?title=User_talk:' + uploader + '&action=edit&fakeaction=mnx_warn&target=' + pagename + '&type=' + warnaction); var editlk = document.getElementById('ca-edit').getElementsByTagName('a')[0].href; var targetUrl = editlk + '&fakeaction=' + action if (txt) targetUrl += '&txt=' + txt; window.location = targetUrl; } function mnx_addTemplate(template) { var txt = '{{subst:' + template + '}}'; // this is subst for most cases var editformval = qid_removeTemplate(document.editform.wpTextbox1.value, 'untagged'); var summary; switch (template) { case "nsl": txt = '{{subst:nsd}}\n{{subst:nld}}'; case "nsd": summary = "L'immagine priva delle informazioni sulla fonte e sarà cancellata in sette giorni se non aggiunte ."; break; case "nld": summary = "L'immagine è priva dell'autorizzazione e sarà cancellata in sette giorni se non aggiunte ."; break; case "nrd": summary = "L'immagine è priva di spiegazione razionale e sarà cancellata in sette giorni se non è aggiunta ."; break; case "orfud": summary = "Questa immagine fair use non è usata nessun articolo e sarà cancellata in sette giorni se rimane tale."; break; case "rfu": summary = "Questo fair use sembra illustrare un oggetto per cui un'immagine libera potrebbe ragionevolmente essere trovata o generata e sarà cancellato in sette giorni."; break; case "dfu": txt = '{{subst:' + template + '|1=' + getParamValue('txt') + '}}'; summary = "L'uso di questa immagine è controverso."; break; case "bsr": txt = '{{' + template + '}}'; summary = "La fonte URL è inadeguata."; break; } qid_saveEditForm(txt + '\n' + editformval, summary); } function mnx_addUserWarningTemplate(type, imagetarget) { qid_checkForRedirect(document.editform.wpTextbox1.value, type); var template; var editSummary; var hasShortNotice = false; var shortimagetarget; if (imagetarget) shortimagetarget = imagetarget.substring(6); // remove Image: namespace switch (type) { case "mnx_mns": case "mnx_mnsl": template = "image source"; editSummary = "Attenzione: mancano le informazioni necessari per l'immagine."; break; case "mnx_mnl": template = "image copyright"; editSummary = "Attenzione: le informazioni dell'immagine sono prive dell'autorizzazione ."; break; case "mnx_mnr": template = "Missing rationale"; editSummary = "Attenzione: Immagine fair use priva di spiegazione rezionale."; hasShortNotice = true; break; case "mnx_mor": template = "Orphaned"; editSummary = "L'immagine fair use caricata è ora orfana."; hasShortNotice = true; break; case "mnx_mrfu": template = "Replaceable"; editSummary = "L'immagine fair use caricata è sostituibile da una libera ."; imagetarget = shortimagetarget; // {{replaceable|example.png}} hasShortNotice = true; break; case "mnx_mfud": template = "No fair"; editSummary = "L'uso di un'immagine caricata non-libera è disputato ."; hasShortNotice = true; break; case "mnx_mbsr": template = "bsr-user"; editSummary = "Fornire prego un URL della fonte migliore per la vostra immagine."; break; case "mnx_gfdl": template = "GFDL presumed warning"; editSummary = "Attenzione: Informazione di licenza perse."; imagetarget = shortimagetarget; // {{GFDL presumed warning|example.png}} break; } var editformval = document.editform.wpTextbox1.value; var useShortNotice = false; if (hasShortNotice) useShortNotice = qid_userBeenWarned(editformval, template); var txt = '{{subst:' + template; if (useShortNotice) txt += ' short'; txt += '|1=' + imagetarget + '}}'; editformval += '\n' + txt + ' ~~' + '~~\n'; qid_saveEditForm(editformval, editSummary); } function mnx_onload() { if (document.getElementById('ca-edit') == null) // not editable by non-admin return; if (wgAction == "view" && wgCanonicalNamespace == "Image") { addPortletLink('p-tb', 'javascript:mnx_markNo(\'mnx_mns\')', mns_text, 'marca-senza-fonte', mns_tooltip); addPortletLink('p-tb', 'javascript:mnx_markNo(\'mnx_mnl\')', mnl_text, 'marca-senza-licenza', mnl_tooltip); addPortletLink('p-tb', 'javascript:mnx_markNo(\'mnx_mnsl\')', mnsl_text, 'marca-senza-licenza-ne-fonte', mnsl_tooltip); addPortletLink('p-tb', 'javascript:mnx_markNo(\'mnx_mnr\')', mnr_text, 'marca-non-razionale', mnr_tooltip); addPortletLink('p-tb', 'javascript:mnx_markNo(\'mnx_mor\')', mor_text, 'marca-orfana', mor_tooltip); addPortletLink('p-tb', 'javascript:mnx_markNo(\'mnx_mrfu\')', mrfu_text, 'mark-replaceable', mrfu_tooltip); addPortletLink('p-tb', 'javascript:mnx_markNo(\'mnx_mfud\')', mfud_text, 'mark-disputed', mfud_tooltip); addPortletLink('p-tb', 'javascript:mnx_markNo(\'mnx_mbsr\')', mbsr_text, 'mark-base-url', mbsr_tooltip); } var fakeaction = getParamValue('fakeaction'); switch (fakeaction) { case 'mnx_mns': mnx_addTemplate('nsd'); break; case 'mnx_mnl': mnx_addTemplate('nld'); break; case 'mnx_mnsl': mnx_addTemplate('nsl'); break; case 'mnx_mnr': mnx_addTemplate('nrd'); break; case 'mnx_mor': mnx_addTemplate('orfud'); break; case 'mnx_mrfu': mnx_addTemplate('rfu'); break; case 'mnx_mfud': mnx_addTemplate('dfu'); break; case 'mnx_mbsr': mnx_addTemplate('bsr'); break; case 'mnx_warn': mnx_addUserWarningTemplate(getParamValue('type'), decodeURIComponent(getParamValue('target'))); break; } } addOnloadHook(mnx_onload); /** ================================================================================ * ==Automatic speedy tagging== * The actions in this section do one thing: * 1. Add a tag to the image page. */ mred_text = "Immagine doppia"; mred_tooltip = "Segna questa immagine come doppia (template per la cancellazione immediata)"; mmi_text = "Immagine mancante"; mmi_tooltip = "Segna questa immagine come mancante (template per la cancellazione immediata)"; mmtc_text = "trasferibile su commons"; mmtc_tooltip = "Segna questa immagine come trasferibile su Commons"; mncd_text = "Duplicata su Commons"; mncd_tooltip = "Segna come già presente in commons"; function speedyi_addTemplate(template, imagetarget) { var summary; var usesubst = false; switch (template) { case 'isd': summary = 'Segnata per la [[Categoria:Da cancellare subito |Cancellazione immadiata]]: Immagine già presente in [[:Immagine:' + imagetarget + ']].'; break; case 'Immagine mancante': summary = 'Segnata per la [[WP:CSD#I2|speedy deletion]]: Immagine mancante o corrotta.'; break; case 'trasferisci su commons': summary = 'Imageine candidata a essere trasferita in [[Commons:Main Page|Wikimedia Commons]].'; break; case 'ncd': var commonsimgname = (!imagetarget) ? wgPageName : imagetarget; summary = 'Immagine già pubblicata in [[Commons:Main Page|Commons]] ( [[Commons:' + commonsimgname + '|]] ).'; usesubst = true; break; } var txt = '{{' + (usesubst ? 'subst:' : '') + template; if (template == 'isd' || (template == 'ncd' && imagetarget)) { txt += '|1=' + imagetarget; } txt += '}}'; var editformval = qid_removeTemplate(document.editform.wpTextbox1.value, 'untagged'); if (template == 'ncd') { // for ncd, remove "Move to Commons" (and variations thereof) template var mtctemplates = new Array('Copia su Wikimedia Commons', 'Trasferisci in Commons', 'trasferisci in commons'); for (var i = 0; i < mtctemplates.length; i++) { editformval = qid_removeTemplate(editformval, mtctemplates[i]); } } qid_saveEditForm(txt + '\n' + editformval, summary); } 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('Introdurre prego il nome dell\'immagine ridondante.', ''); if (!dupe) { alert('speedyi_mark: Nessuno nome immagine inserito.'); return; } if (dupe.indexOf('Imagine:') == 0) { dupe = dupe.substring(6); } xtra = '&target=' + dupe; break; case "speedyi_mncd": var commonsimg = window.prompt('Introdurre prego il nome dell\'immagine corrispondente su Commons (è possibile lasciarlo vuoto se ha lo stesso nome) .', ''); if (commonsimg == null) { alert('speedyi_mark: Action canceled.'); return; } if (commonsimg != '') { xtra = '&target=' + commonsimg; } break; } window.location = editlk + '&fakeaction=' + action + xtra; } function speedyi_onload() { if (document.getElementById('ca-edit') == null) // not editable by non-admin return; if (wgAction == "view" && 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); addPortletLink('p-tb', 'javascript:speedyi_mark(\'speedyi_mmtc\')', mmtc_text, 'mark-movecommons', mmtc_tooltip); addPortletLink('p-tb', 'javascript:speedyi_mark(\'speedyi_mncd\')', mncd_text, 'mark-commons', mncd_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; case 'speedyi_mmtc': speedyi_addTemplate('Move to Commons'); break; case 'speedyi_mncd': var target = getParamValue('target'); if (target) target = decodeURIComponent(target); speedyi_addTemplate('ncd', target); break; } } addOnloadHook(speedyi_onload); /* </nowiki></pre> */