Utente:Superpes15/MassDelete.js

Da Wikipedia, l'enciclopedia libera.
Vai alla navigazione Vai alla ricerca

Questa pagina definisce alcuni parametri di aspetto e comportamento generale di tutte le pagine. Per personalizzarli vedi Aiuto:Stile utente.


Nota: dopo aver salvato è necessario pulire la cache del proprio browser per vedere i cambiamenti (per le pagine globali è comunque necessario attendere qualche minuto). 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 Chrome: premere Ctrl-Shift-R (Command-Shift-R su un Mac); per Konqueror: premere il pulsante Ricarica o il tasto F5; per Opera può essere necessario svuotare completamente la cache dal menù Strumenti → Preferenze; per Internet Explorer: mantenere premuto il tasto Ctrl mentre si preme il pulsante Aggiorna o premere Ctrl-F5.

mw.util.addPortletLink(
	'p-tb',
	'/wiki/Special:Massdelete',
	'Massdelete',
	't-massd',
	'Cancella le pagine massivamente',
	'm',
	'#t-massd'
);

	var config = mw.config.get(['wgNamespaceNumber', 'wgTitle', 'wgUserGroups', 'skin']);
	var userGroups = mw.config.get( 'wgUserGroups' );
	function removeBlanks(arr) {
		var ret = [];
		var i, len;
		for (i = 0, len = arr.length; i < len; i++) {
			var s = arr[i];
			s = s.trim();
			if (s) {
				ret.push(s);
			}
		}
		return ret;
	}

	function doMassDelete() {
		document.getElementById("wpMassDeleteSubmit").disabled = true;
		var articles = document.getElementById("wpMassDeletePages").value.split("\n");
		articles = removeBlanks(articles);
		if (!articles.length) {
			return;
		}
		var
			api = new mw.Api(),
			wpMassDeleteReasons = document.getElementById("wpMassDeleteReasons").value,
			wpMassDeleteReason = document.getElementById("wpMassDeleteReason").value,
			deleted = 0,
			failed = [],
			error = [],
			deferreds = [],
			reason = wpMassDeleteReasons == "altra" ?
				wpMassDeleteReason :
				wpMassDeleteReasons + (wpMassDeleteReason ? ": " + wpMassDeleteReason + "" : ""),
			onSuccess = function () {
				deleted++;
				document.getElementById("wpMassDeleteSubmit").value = "(" + deleted + ")";
			};

		function makeDeleteFunc(article) {
			return function () {
				return $.Deferred(function (deferred) {
					var promise = api.postWithToken('delete', {
						format: 'json',
						action: 'delete',
						title: article,
						reason: reason
					});
					promise.done(onSuccess);
					promise.fail(function (code, obj) {
						failed.push(article);
						error.push(obj.error.info);
					});
					promise.always(function () {
						deferred.resolve();
					});
				});
			};
		}

		// Make a chain of deferred objects. We chain them rather than execute them in
		// parallel so that we don't make 1000 simultaneous delete requests and bring the
		// site down. We use deferred objects rather than the promise objects returned
		// from the API request so that the chain continues even if some articles gave
		// errors.
		var deferred = makeDeleteFunc(articles[0])();
		for (var i = 1, len = articles.length; i < len; i++) {
			deferred = deferred.then(makeDeleteFunc(articles[i]));
		}

		// Show the output and do cleanup once all the requests are done.
		$.when(deferred).then(function () {
			document.getElementById("wpMassDeleteSubmit").value = "Complimenti! Hai distrutto Wiki! (" + deleted + ")";
			if (failed.length) {
				var $failedList = $('<ul>');
				for(var x = 0; x < failed.length; x++) {
					// Link the titles in the "failed" array
					var failedTitle = mw.Title.newFromText(failed[x]);
					var $failedItem = $('<li>');
					if (failedTitle) {
						$failedItem.append( $('<a>')
							.attr('href', failedTitle.getUrl())
							.text(failed[x])
						);
					} else {
						$failedItem.text(failed[x]);
					}
					$failedItem.append(document.createTextNode(': ' + error[x]));
					$failedList.append($failedItem);
				}
				$('#wpMassDeleteFailedContainer')
					.append($('<br />'))
					.append($('<b>')
						.text('Cancellazioni fallite:')
					)
					.append($failedList);
			}
		});
	}
        		
	function massdeleteform() {
		var bodyContent = (config.skin == "cologneblue" ? "article" : "bodyContent");
		var siteSub = $('#siteSub').text();
		document.getElementsByTagName("h1")[0].textContent = "Cancellazione massiva di pagine (e attento alle trote in faccia)";
		document.title = "Cancellazione in massa delle pagine - "+mw.config.get( 'wgServerName' );+"";
		document.getElementById(bodyContent).innerHTML = '<h3 id="siteSub">'+siteSub+'</h3><br /><br />' +
			'<form id="wpMassDelete" name="wpMassDelete">' +
			'Benvenuto nel modulo per la cancellazione massiva delle pagine e per andare a pesca di trote o di castori (è risaputo che i castori si possano trovare insieme alle trote nell\'universo Wiki). Se intendi cancellare pagine create da un solo utente, per favore usa <a href="/wiki/Speciale:Nuke">Speciale:Nuke</a>! Se stai per cancellare <b>tantissime pagine</b> (circa 15-20 pagine), <a href="/wiki/Special:UserRights/'+mw.config.get( 'wgUserName' )+'">flaggati</a> prima brevemente come flood editor, in modo che le tue modifiche siano nascoste e quindi non intasino i <a href="/wiki/Special:Log">registri</a>, grazie!<br />Per iniziare aggiungi i titoli delle pagine che vuoi cancellare nello spazio qui sotto avendo cura di metterle in colonna (una pagina per riga), senza parentesi quadre.<br />Esempio: Per cancellare la pagina <a href="/wiki/Vercingetorige_(personaggio)">Vercingetorige (Personaggio)</a> scrivi semplicemente: Vergingetorige (personaggio).<br /><b>Nota: Usando questo strumento ti avvicini a una zona ricca di trote! La responsabilità sull\'uso dello strumento è solo tua! Se abusi di questo tool, che potrebbe comunque contenere errori, potresti incorrere nel deflag!</b>'+
			'<div id="wpIsFlood"></div>'+
			'<br />'+
			'<div id="wpMassDeleteFailedContainer"></div>' +
			'<br /><br />' +
				'Pagine da cancellare (una per ogni riga):<br />' +
					'<textarea tabindex="1" accesskey="," name="wpMassDeletePages" id="wpMassDeletePages" rows="10" cols="80"></textarea>' +
				'<br /><br /><table style="background-color:transparent">' +
					'<tr><td>Ragioni più comuni:</td>' +
						'<td><select id="wpMassDeleteReasons">' +
							'<optgroup label="Criteri per la cancellazione immediata">' +
                            '<optgroup label="Ragioni più comuni per la cancellazione" id="RagioniComuni">' +

                                '</optgroup>' +
                                '<optgroup label="Altre ragioni" id="AltreRagioni">' +
								'<option value="Altra">Altre ragioni</option>' +
							'</optgroup>' +
                             '<optgroup label="Personali" id="Personali">' +
                               
                            '</optgroup>' +
                        '</optgroup>' +
						'</select></td></tr>' +
				'<tr><td>Altre/ragioni addizionali:</td>' +
					'<td><input type="text" id="wpMassDeleteReason" name="wpMassDeleteReason" maxlength="255" size="70"/></td></tr>' +
					'<tr><td><input type="button" id="wpMassDeleteSubmit" name="wpMassDeleteSubmit" value="Castoro in arrivo" /></td>' +
			'</form>';
			
			if ( userGroups.indexOf( 'flood' ) !== -1 ) {
				$('#wpIsFlood').html('<br/><img src="https://upload.wikimedia.org/wikipedia/commons/b/bb/Echo_curation_alt.svg" alt="ATTENZIONE" width="25" /> <u> sei correttamente flaggato come <b>Flood editor</b>!</u>');
				
			} else {
				$('#wpIsFlood').html('<br/><img src="https://upload.wikimedia.org/wikipedia/commons/e/e5/OOjs_UI_icon_alert_destructive_black-darkred.svg" alt="ATTENZIONE" width="20" /> <b>ATTENZIONE!</b> <u>Ricorda di flaggarti come <b>Flood editor</b> se le cancellazioni sono davvero massive!</u>');
				
			}


		document.getElementById("wpMassDeleteReasons").onchange = function() {
			var maxlength = (document.getElementById("wpMassDeleteReasons").value == "altre" ? 255 : 252-document.getElementById("wpMassDeleteReasons").value.length); //It's 252 because of the three characters (" ()") in addition to the selected summary.
			document.getElementById("wpMassDeleteReason").setAttribute("maxlength", maxlength);
		};
		document.getElementById("wpMassDeleteSubmit").addEventListener("click", function (e) {
			doMassDelete();
		});
	}
	 
	if (config.wgNamespaceNumber == -1 &&
		config.wgTitle.toLowerCase() == "massdelete"
	) {
		massdeleteform();
		
		function optionInitialize ()
{
	window.Criteri = function Criteri(numero,spiegazione) {
        		$("#RagioniComuni").last().append('<option value="([[:WP:'+numero+'|'+numero+']]) '+spiegazione+'">'+numero+' - '+spiegazione+'</option>')
        		}
   		
	window.AltreMotivazioniSemplici = function AltreMotivazioniSemplici(ID,spiegazione) {
        		$("#"+ID+"").last().append('<option value="'+spiegazione+'">'+spiegazione+'</option>')
        		}
        		        		
	window.AltreMotivazioni = function AltreMotivazioni(ID,testo,spiegazione) {
        		$("#"+ID+"").last().append('<option value="'+testo+'">'+spiegazione+'</option>')
        		}
        		
}
		optionInitialize();
		
function criteriInitialize ()
{
AddMotivazioniPersonali (Criteri,AltreMotivazioniSemplici,AltreMotivazioni);
AddMotivazioniComuni (Criteri,AltreMotivazioniSemplici,AltreMotivazioni);
}
// AGGIUNGO MOTIVAZIONI PERSONALIZZATE
		addOnloadHook (criteriInitialize);
		
		
		mw.util.addPortletLink(
		'p-tb',
		'/wiki/Special:Log/delete?user=' + encodeURIComponent(mw.config.get('wgUserName')),
		'Log di cancellazione',
		't-massdLog',
		'My delete log',
		'',
		'#t-massdLog'
		);
	}