MediaWiki:Gadget-QuickDelete.js: differenze tra le versioni

Contenuto cancellato Contenuto aggiunto
akeytt non più valido
Nuovo gadget
Riga 1:
/**
//Installing this (as described on the talk page) will give you links in the toolbox for all pages in the Image: namespace, that say 'Nominate for deletion', 'mark as no source' and 'mark as no license'. The first one will give you a pop-up that asks for a reason. It inserts this reason on [[COM:DEL]], marks the image for deletion and notifies the uploader. The second and third one mark the image as missing source/license (NSD/NLD) and notify the uploader. Note: don't abuse this. If you mark 10 images from one user as no source, don't use this because they will get 10 separate warnings on their talk page!! (Or if you do, at least clean it up afterwards.)
* Gadget-QuickDelete.js
* Nel namespace File: aggiunge 5 portlet nella sezione Strumenti per inserire
* automaticamente il template unverdata all'immagine e un avviso all'utente.
* Riscritto da zero a partire da:
* http://it.wikipedia.org/w/index.php?title=MediaWiki:Gadget-QuickDelete.js&oldid=51134251
*
* @author [[Utente:Rotpunkt]]
*/
 
/* <nowiki> */
//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.
 
(function (mw, $) {
// Main code by [[:en:User:Jietse Niesen]], some adaption by [[user:pfctdayelise]], cleanup by [[User:Alphax]]
'use strict';
 
// se impostato a true la pagina viene salvata automaticamente
// Now available on en.wp! See [[w:User:Howcheng/quickimgdelete.js]].
var autosave = false;
 
var portlets = {
/* <source lang="javascript"><nowiki> */
licenza: {
// Configuration
name: 'Immagine senza licenza',
summary: 'Immagine senza licenza',
template: '{{subst:Avvisoimmagine|immagine=[[:$1]]}}'
},
fonte: {
name: 'Immagine senza fonte/autore',
summary: 'Informazioni mancanti',
template: '{{subst:Avvisoimmagine3|$1}}'
},
otrs: {
name: 'Immagine senza OTRS',
summary: 'Informazioni mancanti',
template: '{{subst:AvvisoOTRS|$1}}'
},
edp: {
name: 'Immagine EDP non accettabile',
summary: 'EDP non rispettata',
template: '{{subst:AvvisoEDP|$1}}'
},
altro: {
name: 'Immagine senza altre informazioni',
summary: 'Immagine senza informazioni',
template: '{{subst:Avvisoimmagine2|immagine=[[:$1]]}}'
}
}
 
function addPortlets() {
// Should the edits be saved automatically?
$.each(portlets, function (key, portlet) {
if(window.mnx_autosave == false){}else if(window.mnx_autosave){}else{ mnx_autosave = true; }
var portletLink = mw.util.addPortletLink('p-tb', '#', portlet.name);
$(portletLink).click(function (event) {
event.preventDefault();
var username = $('table[class="wikitable filehistory"] tr td:nth-child(6):first a').filter('[title]');
if (username.length) {
username = username.attr('title').split(':')[1];
window.open(wgScript +
'?action=edit&title=Discussioni_utente:' + username +
'&gqdaction=' + key +
'&gqdpage=' + encodeURIComponent(wgPageName), '_blank');
document.___location = wgScript + '?title=' + wgPageName +
'&action=edit&gqdaction=unverdata';
} else {
alert('[Gadget-QuickDelete] username non trovato');
}
});
});
}
 
// modifica la pagina dell'immagine
// String constants
function editFile() {
mnlicenza_text = "Immagine senza licenza";
if ($('#wpTextbox1').length && $('#wpSummary').length && $('#wpSave').length) {
mnlicenza_tooltip = "Segna questa immagine come mancante di informazioni sulla licenza";
$('#wpTextbox1').val(function (i, text) {
mnlicenza_template = "{{subst:Avvisoimmagine}}";
return '{{subst:unverdata}}\n' + text;
mnfonte_text = "Immagine senza fonte/autore";
});
mnfonte_tooltip = "Segna questa immagine come mancante di informazioni sulla fonte/autore";
$('#wpSummary').val('Segnalazione di immagine [[Wikipedia:Immagini da verificare|' +
mnfonte_template = "{{subst:Avvisoimmagine3}}";
'da verificare]] (unverified). Se non verificata questa immagine ' +
mnotrs_text = "Immagine senza OTRS";
'sarà cancellata tra 7 giorni.');
mnotrs_tooltip = "Segna questa immagine come mancante di informazioni sul ticket OTRS";
if (autosave)
mnotrs_template = "{{subst:AvvisoOTRS}}";
$('#wpSave').click();
mnedp_text = "Immagine EDP non accettabile";
}
mnedp_tooltip = "Segna questa immagine come non rispettante le norme EDP";
}
mnedp_template = "{{subst:AvvisoEDP}}";
mnaltro_text = "Immagine senza altre informazioni";
mnaltro_tooltip = "Segna questa immagine come mancante di informazioni";
mnaltro_template = "{{Avvisoimmagine2}}";
 
// modifica la pagina di discussione dell'utente
// From [[en:Wikipedia:WikiProject User scripts/Scripts/addLink]]
function editUserTalk(gqdaction, gqdpage) {
function addLink(where, url1, name1, id, title, key, after, url2, name2)
if ($('#wpTextbox1').length && $('#wpSummary').length && $('#wpSave').length) {
{
$('#wpTextbox1').val(function (i, text) {
//* where is the id of the toolbar where the button should be added;
return text + '\n==' + portlets[gqdaction].summary + '==\n' +
// i.e. one of "p-cactions", "p-personal", "p-navigation", or "p-tb".
portlets[gqdaction].template.replace('$1', decodeURIComponent(gqdpage)) +
//
//* url1 is the URL which will be called when the button is clicked. '~~~~\n';
});
// javascript: urls can be used to do more complex things.
$('#wpSummary').val(portlets[gqdaction].summary);
//
//* name1 is what will appear as the nameif of the button.(autosave)
$('#wpSave').click();
//
}
//* 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);
}
 
if ($.inArray(mw.config.get('wgAction'), ['edit', 'submit']) !== -1) {
var tabs = document.getElementById(where).getElementsByTagName('ul')[0];
// edit richiamato dallo script stesso per modificare la pagina dell'immagine o dell'utente
if(after) {
var gqdaction = mw.util.getParamValue('gqdaction');
tabs.insertBefore(li,document.getElementById(after));
var gqdpage = mw.util.getParamValue('gqdpage');
} else {
if (wgNamespaceNumber == 6 && gqdaction && gqdaction == 'unverdata')
tabs.appendChild(li);
editFile();
else if (wgNamespaceNumber == 3 && gqdaction && gqdpage)
editUserTalk(gqdaction, gqdpage);
} else if (wgNamespaceNumber == 6) {
addPortlets();
}
}(mediaWiki, jQuery));
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 el = document.getElementById('mw-imagepage-section-filehistory').firstChild;
if (!el) {
alert("getUploader: Non è possibile trovare la cronologia ... esco");
return null;
}
while (el.nextSibling) {
el = el.nextSibling;
if (el.tagName && el.tagName.toLowerCase() == 'table')
break;
}
if (!el) {
alert("getUploader: Non è possibile trovare la tabella ... esco");
return null;
}
 
var as = el.getElementsByTagName('a');
 
var re1 = new RegExp((wgServer + wgArticlePath.substr(0, wgArticlePath.length-2) ).replace(/\./g, '\\.') + 'Utente:(.*)$');
var re2 = new RegExp((wgServer + wgScript).replace(/\./g, '\\.') + '\\?title=Utente:([^&]*)');
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("getUploader: Non è possibile trovare l'utente che ha caricato l'immagine ... esco");
return null;
}
 
function mnx_mark(imagepage_fakeaction, usertalk_fakeaction) {
var answer = confirm ("Sicuro di voler inserire il template nella pagina?");
if (answer == false)
return;
var pagename = encodeURIComponent(wgPageName);
var uploader = getUploader();
if (!uploader) return;
// Open new window for the user page
openWindow(wgScript + '?title=Discussioni_utente:' + 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) {
// the edit summary for when you mark the image. You can change it if you want.
var txt = '{{subst:unverdata}}';
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.';
document.editform.wpSummary.value = 'Segnalazione di immagine [[Wikipedia:Immagini da verificare|da verificare]] (unverified). Se non verificata questa immagine sarà cancellata tra 7 giorni.';
if (mnx_autosave) document.editform.wpSave.click();
}
 
// Add warning template to uploader's talk page
function mnx_addUserWarningTemplate(imagetarget, template_type) {
if (template_type == 'mnlicenza')
{
// add in subst: if you want to subst these warnings
var txt = '{{subst:Avvisoimmagine' + '|immagine=[[:' + imagetarget + ']]}}';
document.editform.wpTextbox1.value += '\n==Immagine senza licenza==\n' + txt + '~~' + '~~\n';
document.editform.wpSummary.value = "Immagine senza licenza";
}
if (template_type == 'mnfonte')
{
// add in subst: if you want to subst these warnings
var txt = '{{subst:Avvisoimmagine3' + '|' + imagetarget + '}}';
document.editform.wpTextbox1.value += '\n==Informazioni mancanti==\n' + txt + '~~' + '~~\n';
document.editform.wpSummary.value = "Informazioni mancanti";
}
if (template_type == 'mnotrs')
{
// add in subst: if you want to subst these warnings
var txt = '{{subst:AvvisoOTRS' + '|' + imagetarget + '}}';
document.editform.wpTextbox1.value += '\n==Informazioni mancanti==\n' + txt + '~~' + '~~\n';
document.editform.wpSummary.value = "Informazioni mancanti";
}
if (template_type == 'mnedp')
{
// add in subst: if you want to subst these warnings
var txt = '{{subst:AvvisoEDP' + '|' + imagetarget + '}}';
document.editform.wpTextbox1.value += '\n==EDP non rispettata==\n' + txt + '~~' + '~~\n';
document.editform.wpSummary.value = "EDP non rispettata";
}
if (template_type == 'mnaltro')
{
// add in subst: if you want to subst these warnings
var txt = '{{Avvisoimmagine2' + '|immagine=[[:' + imagetarget + ']]}}';
document.editform.wpTextbox1.value += '\n==Immagine senza informazioni==\n' + txt + '~~' + '~~\n';
document.editform.wpSummary.value = "Immagine senza informazioni.";
}
// 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(\'mnlicenza\', \'mnx_warn\')', mnlicenza_text, 'mark-no-license', mnlicenza_tooltip, null, null);
addLink('p-tb', 'javascript:mnx_mark(\'mnfonte\', \'mnx_warn\')', mnfonte_text, 'mark-no-source', mnfonte_tooltip, null, null);
addLink('p-tb', 'javascript:mnx_mark(\'mnotrs\', \'mnx_warn\')', mnotrs_text, 'mark-no-otrs', mnotrs_tooltip, null, null);
addLink('p-tb', 'javascript:mnx_mark(\'mnedp\', \'mnx_warn\')', mnedp_text, 'mark-no-edp', mnedp_tooltip, null, null);
addLink('p-tb', 'javascript:mnx_mark(\'mnaltro\', \'mnx_warn\')', mnaltro_text, 'mark-no-altro', mnaltro_tooltip, null, null);
}
var fakeaction = getParamValue('fakeaction');
var template_type = getParamValue('template_type'); // Fetch what template to add
 
// In realta' tutti aggiungono il template {{unverdata}} alla pagina dell'immagine. Questo meta-switch e' stato lasciato
// per semplificare futuri improvements
if (fakeaction == 'mnlicenza'){
mnx_addTemplate('mnlicenza');
}
else if (fakeaction == 'mnfonte'){
mnx_addTemplate('mnfonte');
}
else if (fakeaction == 'mnotrs'){
mnx_addTemplate('mnfonte');
}
else if (fakeaction == 'mnedp'){
mnx_addTemplate('mnfonte');
}
else if (fakeaction == 'mnaltro'){
mnx_addTemplate('mnfonte');
}
if (fakeaction == 'mnx_warn') { // Add warning to uploader's talk page
mnx_addUserWarningTemplate(decodeURIComponent(getParamValue('target')), template_type);
}
}
 
addOnloadHook(mnx_onload); //No source, no permission, no license.
 
//* </nowiki>< */source>