Utente:Ruthven/adminscript.js

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.

//<nowiki>
$(function(){
    var btoken;
    if (mw.config.get( 'wgCanonicalSpecialPageName' ) === "Block") {
    	$('#mw-upload-form .mw-htmlform-submit').change({
            click: function() {
                if ($('#msgscriptcktalk').is(':checked') && $('#msgScripttalkcontent').val() !== ''){
			    	$.post(mw.util.wikiScript('api'),
				   	{
				       format: 'json',
			           action: 'edit',
				       title: 'User talk:' + $('#mw-bi-target').val(),
				       appendtext: $('#msgScripttalkcontent').val(),                                              
			           token: btoken,
			           summary:'notifica di blocco',
			           recreate:''                                	                   
				   	});
				   	//getBlockcsfr
				   	//action = 'block'
				   	//$('.mw-htmlform-submit').click();
        		}
            }
    	});
	   	mw.util.addCSS(
        '#msgScriptForm {margin-top: 15px; background-color: #eeffaa; border: 1px solid grey;}' +
		'.msgscript-link {margin-left:0px;}' +
		'#msgScriptdivtalk {margin-top: 5px;}' +
		'#msgScripttalkcontent {margin-left:5px;}' +
		'msgScripttdcontent {margin-left:5px;}' +
		'#msgMessaggia {margin-left:5px; align-content:left;vertical-align: text-top;}'
      	);
      	//Crea il div dove andare a appendere gli oggetti dello script
    	$('.mw-htmlform-field-HTMLSelectAndOtherField').after($('<tr>', {id:'msgScriptForm'}));
    	
    	//crea i div per raccogliere gli oggetti talk e up
       	$('#msgScriptForm').append(
            $('<td>', {
                id: "msgScriptdivtalk"
            })
       	);
       	
       	//appende gli oggetti della talk
       	$('#msgScriptdivtalk').append(
            $("<input>", {
                type: "checkbox",
                id: "msgscriptcktalk",
            })            
       	);
       	$('#msgScriptdivtalk').append(
            $("<label>", {
                'for': "msgscriptcktalk",
                text: 'Inserisci nella discussione utente:'
       	    })            
       	);
       	$('#msgScriptForm').append(
            $('<td>', {
                id: "msgScripttdcontent"
            })
       	);
       	$('#msgScripttdcontent').append(
            $("<input>", {
                id: 'msgScripttalkcontent'
            })            
       	);
	
       	//inserisce i link dopo gli oggetti talk
       	$('#msgScripttdcontent').append(
            $("<a>", {
                text: "RC",
                title: "Inserisci {{RC}}",
                href:'#',
                class:"msgscript-link",               
                click:function() {
                    durata= prompt('Inserisci la durata del blocco');
                    $('#msgScripttalkcontent').val('\n{{RC|' + durata + '}}\n--~~~~');
                    return false;
                }
            }),
            $("<a>", {
                text: "blocco",
                title: "Inserisci {{blocco}}",
                href:'#',
                class:"msgscript-link",               
                click:function() {
                    motivo = ($('#mw-input-wpReason').val() ) ? $('#mw-input-wpReason').val() : prompt('Inserisci il motivo del blocco');
                    durata= prompt('Inserisci la durata del blocco'); 
                    $('#msgScripttalkcontent').val('\n{{blocco|' + motivo + '|' + durata + '}}\n--~~~~');
                    return false;
                }
            })
       	);
       	$('#msgScripttdcontent').find('a').slice(1).before(' | ');
       	
//       	$('#msgScriptForm').after(
//            $('<tr>', {
//                id: "msgMessaggia"
//            })
//       	);  
//	//crea il nuovo pulsante di messaggio
//    	$('#msgMessaggia').append(
//            $("<input>", {
//                type:  "button",
//                id:    "msgscriptNotifica",
//                value: "Messaggia",
//                click:function() {
//                    getprotectToken();
//                }
//            })
//       	);

	// Blocco utente
	mw.util.addCSS(
            '#blockScriptForm {margin-top: 15px;}' +
		'.blockscript-firstlink {margin-left:5px;}' +
		'#blockScriptdivtalk {margin-top: 5px;}' +
		'#blockScripttalkcontent, #blockScriptupcontent {margin-left:5px;}'
      	);
      	//Crea il div dove andare a appendere gli oggetti dello script
    	$('.mw-htmlform-submit').after($('<div>', {id:'blockScriptForm'}));
    	
    	//crea i div per raccogliere gli oggetti talk e up
    	$('#blockScriptForm').append(
            $("<div>", {
                id: "blockScriptdivup"
            })
       	);
       	$('#blockScriptForm').append(
            $("<div>", {
                id: "blockScriptdivtalk"
            })
       	);
       	
       	//appende gli oggetti della up
    	$('#blockScriptdivup').append(
            $("<input>", {
                type: "checkbox",
                id: "blockScriptckup",
            })
       	);
       	$('#blockScriptdivup').append(
            $("<label>", {
                'for': "blockScriptckup",
                text: 'Sostituisci la pagina utente con:'
            })            
       	);
       	$('#blockScriptdivup').append(
            $("<input>", {
                id: 'blockScriptupcontent'
            })            
       	);
       	
       	//appende gli oggetti della talk
       	$('#blockScriptdivtalk').append(
            $("<input>", {
                type: "checkbox",
                id: "blockScriptcktalk",
            })            
       	);
       	$('#blockScriptdivtalk').append(
            $("<label>", {
                'for': "blockScriptcktalk",
                text: 'Sostituisci la discussione utente con:'
            })            
       	);
       	$('#blockScriptdivtalk').append(
            $("<input>", {
                id: 'blockScripttalkcontent'
            })            
       	);
       	
       	//inserisce i link dopo gli oggetti up
       	$('#blockScriptdivup').append(
            $("<a>", {
                text: "Bloccoinfinito",
                href:'#',
                title: "Inserisci {{BloccoInfinito}}",
                class:"blockscript-firstlink",               
                click:function() {
                    $('#blockScriptupcontent').val('{{BloccoInfinito}}');
                    return false;
                }
            }),
            $("<a>", {
                text: "SP",
                title: "Inserisci {{SP}}",
                href:'#',
                class:"blockscript-link",               
                click:function() {
                    sock= prompt('Inserisci il nome utente principale (senza [[utente:)');
                    $('#blockScriptupcontent').val('{{SP|' + sock + '}}');
                    return false;
                }
            }),
            $("<a>", {
                text: "Bloccoinfinito + SP",
                title: "Inserisci {{BloccoInfinito}} + {{SP}}",
                href:'#',
                class:"blockscript-link",               
                click:function() {
                    sock= prompt('Inserisci il nome utente principale (senza [[utente:)','');
                    $('#blockScriptupcontent').val('{{BloccoInfinito}}{{SP|' + sock + '}}');
                    return false;
                }
            }),
            $("<a>", {
                text: "NUI",
                title: "Inserisci {{NUI}} --~~~~",
                href:'#',
                class:"blockscript-link",               
                click:function() {
                    $('#blockScriptupcontent').val('{{NUI}} --~~~~');
                    return false;
                }
            })
       	);
       	$('#blockScriptdivup').find('a').slice(1).before(' | ');
	
       	//inserisce i link dopo gli oggetti talk
       	$('#blockScriptdivtalk').append(
            $("<a>", {
                text: "Bloccoinfinito",
                href:'#',
                title: "Inserisci {{BloccoInfinito}}",
                class:"blockscript-firstlink",               
                click:function() {
                    $('#blockScripttalkcontent').val('{{BloccoInfinito}}');
                    return false;
                }
            }),
            $("<a>", {
                text: "SP",
                title: "Inserisci {{SP}}",
                href:'#',
                class:"blockscript-link",               
                click:function() {
                    sock= prompt('Inserisci il nome utente principale (senza [[utente:)');
                    $('#blockScripttalkcontent').val('{{SP|' + sock + '}}');
                    return false;
                }
            }),
            $("<a>", {
                text: "Bloccoinfinito + SP",
                title: "Inserisci {{BloccoInfinito}} + {{SP}}",
                href:'#',
                class:"blockscript-link",               
                click:function() {
                    sock= prompt('Inserisci il nome utente principale (senza [[utente:)','');
                    $('#blockScripttalkcontent').val('{{BloccoInfinito}}{{SP|' + sock + '}}');
                    return false;
                }
            }),
            $("<a>", {
                text: "NUI",
                title: "Inserisci {{NUI}} --~~~~",
                href:'#',
                class:"blockscript-link",               
                click:function() {
                    $('#blockScripttalkcontent').val('{{NUI}} --~~~~');
                    return false;
                }
            })
       	);
       	$('#blockScriptdivtalk').find('a').slice(1).before(' | ');
        
        //crea il nuovo pulsante di blocco
    	$('#blockScriptForm').append(
            $("<input>", {
                type: "button",
                id: "blockScriptBlocca",
                value: "Blocca & proteggi pagine utente",
                click:function() {
                    getprotectToken();
                }
            })
       	);
    }
    
    function ProteggiUtente(targhet){
    	$.post(mw.util.wikiScript('api'),
	       {
   		   format: 'json',
   		   action: 'protect',
		   title: targhet,
		   reason: 'Pagina o sottopagina di utente [[WP:BLOCCO|bloccato infinito]]',
		   token: btoken,
		   expiry:'infinite',
 		   protections:'edit=sysop|move=sysop'                  
	       }
	      ).done(function(data) {
	          try{
	              //genera l'errore in caso di PU non esistente e passa al create=sysop
	              var er = data.protect.title;
	              //la protezione della talk è l'ultima operazione che compie dopo esegue il blocco
	              if (targhet === 'User talk:' + $('#mw-bi-target').val()){
	        		 $('.mw-htmlform-submit').click();
	              }
	          } catch ( e ) {
		      $.post(mw.util.wikiScript('api'),
			     {
				 format: 'json',
				 action: 'protect',
				 title: targhet,
				 reason: 'Pagina o sottopagina di utente [[WP:BLOCCO|bloccato infinito]]',
				 token: btoken,
				 expiry:'infinite',
				 protections:'create=sysop'                  
			     }
			    );
	          }
      	});
    }
    
    function getprotectToken(){
	$.getJSON(
   	    mw.util.wikiScript('api'),
	    {
			format: 'json',
			action: 'query',
			meta: 'tokens',
			type: 'csrf'		                   
	    }
        ).done(function ( data ) {
		    btoken=data.query.tokens.csrftoken;
		    PassAuth();
		});
    }
    
    function PassAuth(){
   	$.getJSON(
   	    mw.util.wikiScript('api'),
	    {
			format: 'json',
			action: 'query',
			list: 'users',
			ususers: $('#mw-bi-target').val()		                   
	    }).done (function (data){
            //se l'utente esiste esegue il resto
            if (data.query.users[0].missing === undefined){
            	
				// Aggiunge cartellino o messaggio nella talk utente
	        	if ($('#msgscriptcktalk').is(':checked') && $('#msgScripttalkcontent').val() !== ''){
			    $.post(mw.util.wikiScript('api'),
				   {
				       format: 'json',
		               action: 'edit',
				       title: 'User talk:' + $('#mw-bi-target').val(),
				       appendtext: $('#msgScripttalkcontent').val(),                                              
		               token: btoken,
		               summary:'notifica di blocco',
		               recreate:''                                	                   
				   }).done (function(){ });
			    //Per uso comune la pagina utente va sempre sostituita
				} else if ($('#blockScriptcktalk').is(':checked') && $('#blockScripttalkcontent').val() !== ''){
		    	    if($('#blockScriptckup').is(':checked')){
						$.post(mw.util.wikiScript('api'),
					       {
							   format: 'json',
						       action: 'edit',
							   title: 'User:' + $('#mw-bi-target').val(),
							   text: $('#blockScriptupcontent').val(),                                              
						       token: btoken,
						       summary:'Utente [[WP:BLOCCO|bloccato infinito]]',
						       recreate:''                                	                   
					       }).done (function(){
				          	ProteggiUtente('User:'+ $('#mw-bi-target').val());
				      		});
		 		    }else{
						ProteggiUtente('User:'+ $('#mw-bi-target').val());
				    }
				    $.post(mw.util.wikiScript('api'),
					   {
					       format: 'json',
				           action: 'edit',
					       title: 'User talk:' + $('#mw-bi-target').val(),
					       text: $('#blockScripttalkcontent').val(),                                              
			               token: btoken,
			               summary:'Utente [[WP:BLOCCO|bloccato infinito]]',
			               recreate:''                                	                   
					   }).done (function(){
				           ProteggiUtente('User talk:'+ $('#mw-bi-target').val());
				          });	        
				}else{
				    alert('Devi almeno sostituire la pagina utente per bloccare');
		        	}
		    }else{
	        	alert ('Non è registrato alcun utente di nome "' + $('#mw-bi-target').val() +'". Verificare il nome inserito.');
		    }
     	});
    }
}( mediaWiki, jQuery ));	
//</nowiki>