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

Contenuto cancellato Contenuto aggiunto
Nessun oggetto della modifica
m refuso
 
(26 versioni intermedie di 4 utenti non mostrate)
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 cinque link al portlet 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]]
*/
/*jshint unused: false */
/*global mediaWiki, jQuery */
/* <nowiki> */
 
( function ( mw, $ ) {
//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.
'use strict';
//Also it has no i18n. I will leave that for the experts.
 
// se impostato a true la pagina viene salvata automaticamente
// Main code by [[:en:User:Jietse Niesen]], some adaption by [[user:pfctdayelise]], cleanup by [[User:Alphax]]
var autosave = true,
// portlet links
portletLinks = {
licenza: {
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]]}}'
}
};
 
// modifica la pagina dell'immagine
// Now available on en.wp! See [[w:User:Howcheng/quickimgdelete.js]].
function editFile() {
if ( $( '#wpTextbox1' ).length && $( '#wpSummary' ).length && $( '#wpSave' ).length ) {
$( '#wpTextbox1' ).val( function ( i, text ) {
return '{{subst:unverdata}}\n' + text;
} );
$( '#wpSummary' ).val( 'Segnalazione di immagine [[Wikipedia:Immagini da verificare|' +
'da verificare]] ( unverified ). Se non verificata questa immagine ' +
'sarà cancellata tra 7 giorni.' );
if ( autosave ) {
$( '#wpSave' ).click();
}
}
}
 
// modifica la pagina di discussione dell'utente
/* <source lang="javascript"><nowiki> */
function editUserTalk( gqdaction, gqdpage ) {
// Configuration
if ( $( '#wpTextbox1' ).length && $( '#wpSummary' ).length && $( '#wpSave' ).length ) {
$( '#wpTextbox1' ).val( function ( i, text ) {
return text + '\n== ' + portletLinks[gqdaction].summary + ' ==\n' +
portletLinks[gqdaction].template.replace( '$1', decodeURIComponent( gqdpage ) ) +
' ~~~~\n';
} );
$( '#wpSummary' ).val( portletLinks[gqdaction].summary );
if ( autosave ) {
$( '#wpSave' ).click();
}
}
}
 
function addPortletLinks() {
// Should the edits be saved automatically?
$.each( portletLinks, function ( key, portletLink ) {
if(window.nfd_autosave == false){}else if(window.nfd_autosave){}else{ nfd_autosave = true; }
var link = mw.util.addPortletLink( 'p-tb', '#', portletLink.name );
if(window.mnx_autosave == false){}else if(window.mnx_autosave){}else{ mnx_autosave = true; }
$( link ).click( function ( event ) {
event.preventDefault();
var username = $( 'table[class="wikitable filehistory"] tr:eq( 1 ) td:eq( -2 ):first a' ).filter( '[title]' );
username = username.length ? username.attr( 'title' ).split( ':' ) : null;
if ( username && username[0] === 'Utente' ) {
username[1] = username[1].replace( '(la pagina non esiste)', '' );
window.open( mw.config.get( 'wgScript' ) +
'?action=edit&title=Discussioni_utente:' + username[1] + '&gqdaction=' + key +
'&gqdpage=' + encodeURIComponent( mw.config.get( 'wgPageName' ) ), '_blank' );
document.___location = mw.config.get( 'wgScript' ) +
'?title=' + mw.config.get( 'wgPageName' ) +
'&action=edit&gqdaction=unverdata';
} else {
alert( '[Gadget-QuickDelete] username non trovato' );
}
} );
} );
}
 
$( function () {
// String constants
var nsNum = mw.config.get( 'wgNamespaceNumber' ),
mnl_text = "Immagine senza licenza";
gqdaction = mw.util.getParamValue( 'gqdaction' ),
mnl_tooltip = "Segna questa immagine come mancante di informazioni sulla licenza";
gqdpage = mw.util.getParamValue( 'gqdpage' );
if ( $.inArray( mw.config.get( 'wgAction' ), ['edit', 'submit'] ) !== -1 ) {
// edit richiamato dallo script stesso per modificare la pagina dell'immagine o dell'utente
if ( nsNum === 6 && gqdaction && gqdaction === 'unverdata' ) {
editFile();
} else if ( nsNum === 3 && gqdaction && gqdpage ) {
editUserTalk( gqdaction, gqdpage );
}
} else if ( nsNum === 6 ) {
addPortletLinks();
}
} );
}( mediaWiki, jQuery ) );
 
/* </nowiki> */
// From [[en:Wikipedia:WikiProject User scripts/Scripts/addLink]]
function addLink(where, url1, name1, id, title, key, after, url2, name2)
{
//* 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".
//
//* url1 is the URL which will be called when the button is clicked.
// javascript: urls can be used to do more complex things.
//
//* name1 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.
//
//* 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);
}
 
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;
}
 
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('filehistory')
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 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() {
// 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 = 'Segno l\'immagine come unverified. Manca la licenza. Se non corretta entro 7 giorni verrà cancellata.';
if (mnx_autosave) document.editform.wpSave.click();
}
 
// Add warning template to uploader's talk page
function mnx_addUserWarningTemplate(imagetarget, template_type) {
var txt = '{{subst:Avvisoimmagine' + '|immagine=' + imagetarget + '}}';
 
// add in subst: if you want to subst these warnings
document.editform.wpTextbox1.value += '\n==Attenzione: caricata immagine senza licenza==\n' + txt + '~~' + '~~\n';
document.editform.wpSummary.value = "Attenzione: caricata immagine senza licenza.";
// 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(\'mnl_mnl\', \'mnx_warn\')', mnl_text, 'mark-no-license', mnl_tooltip, null, null);
}
var fakeaction = getParamValue('fakeaction');
var template_type = getParamValue('template_type'); // Fetch what template to add
 
if (fakeaction == 'mnl_mnl'){
mnx_addTemplate('nld','license');
}
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>