Usuario:Dreitmen/twinklewarn.js

Nota: Después de guardar, debes recargar la caché de tu navegador para ver los cambios:

  • Mozilla: Pulsa Recargar (o Ctrl-R)
  • Internet Explorer / Opera: Ctrl-F5
  • Safari: Cmd-R
  • Konqueror Ctrl-R.
// If TwinkleConfig aint exist.
if( typeof( TwinkleConfig ) == 'undefined' ) {
	TwinkleConfig = {};
}
 
/**
TwinkleConfig.showSharedIPNotice may take arguments:
true: to show shared ip notice if an IP address
false: to not print the notice
*/
if( typeof( TwinkleConfig.showSharedIPNotice ) == 'undefined' ) {
	TwinkleConfig.showSharedIPNotice = true;
}
 
/**
TwinkleConfig.watchWarnings (boolean)
if true, watch the page which has been dispatched an warning or notice, if false, default applies
*/
if( typeof( TwinkleConfig.watchWarnings ) == 'undefined' ) {
	TwinkleConfig.watchWarnings = false;
}
 
/**
TwinkleConfig.summaryAd (string)
If ad should be added or not to summary, default  [[w:es:WP:TW|TW]]
*/
if( typeof( TwinkleConfig.summaryAd ) == 'undefined' ) {
	TwinkleConfig.summaryAd = " ([[w:es:WP:TW|TW]])";
}
 
function twinklewarn() {
	if( wgNamespaceNumber == 3 ) {
		mw.util.addPortletLink( 'p-cactions', (twinkleConfigExists ? "javascript:twinklewarn.callback()" : 'javascript:alert("Tu cuenta es muy nueva para usar TW.");'), "aviso", "tw-warn", "Advertir al usuario", "");
	}
}
$(twinklewarn);
 
twinklewarn.callback = function twinklewarnCallback() {
	var Window = new SimpleWindow( 600, 400 );
	Window.setTitle( "Advertencia al usuario" ); 
	var form = new QuickForm( twinklewarn.callback.evaluate );
 
	var main_select = form.append( {
			type:'field',
			label:'Escoge la advertencia', 
			tooltip:'Escoge primero el grupo principal de advertencias, después escoge la advertencia apropiada.'
		} );
 
	var main_group = main_select.append( {
			type:'select',
			name:'main_group',
			event:twinklewarn.callback.change_category 
		} );
 
	main_group.append( { type:'option', label:'Aviso General (1)', value:'level1', selected:true } );
	main_group.append( { type:'option', label:'Advertencia (2)', value:'level2' } );
	main_group.append( { type:'option', label:'Segunda advertencia (3)', value:'level3' } );
	main_group.append( { type:'option', label:'Última advertencia (4)', value:'level4' } );
	main_group.append( { type:'option', label:'Bloqueo (5)', value:'level4im' } );
	main_group.append( { type:'option', label:'Notificaciones', value:'singlenotice' } );
	if( userIsInGroup( 'autoconfirmed' ) ) {
		main_group.append( { type:'option', label:'Bloqueo', value:'block' } );
	}
 
	main_select.append( { type:'select', name:'sub_group' } ); //Will be empty to begin with.
 
	form.append( { 
			type:'input',
			name:'article',
			label:'Artículo enlazado',
			value:( QueryString.exists( 'vanarticle' ) ? QueryString.get( 'vanarticle' ) : '' ),
			tooltip:'Si la plantilla lo permite, un artículo debe de ser enlazado para indicar la procedencia de la advertencia'
		} );
 
 
	var more = form.append( { type:'field', label:'Rellena con una razón opcional y aprieta Aceptar' } );
	more.append( { type:'textarea', label:'Mas:', name:'reason', tooltip:'Tal vez una razón, o un comentario' } );
	more.append( { type:'submit', label:'Aceptar' } );
	var result = form.render();
	Window.setContent( result );
	Window.display();
	result.main_group.root = result;
 
	// We must init the first choice (General Note);
	var evt = document.createEvent( "Event" );
	evt.initEvent( 'change', true, true );
	result.main_group.dispatchEvent( evt );
 
}
 
// This is all the messages that might be dispatched by the code
twinklewarn.messages = {
	level1: {
		"Aviso prueba1": { 
			label:"Pruebas de edición", 
			summary:"Aviso: Pruebas de edición" 
		},
		"Aviso spam1": { 
			label:"Spam", 
			summary:"Aviso: Spam" 
		},
		"Au-noesforo1": { 
			label:"No es un foro", 
			summary:"Aviso: No es un foro" 
		},
		"Spam": { 
			label:"Spam por el nombre de usuario", 
			summary:"Aviso: Spam" 		
		},
	},
	level2: {
		"Aviso prueba2": { 
			label:"Vandalismo", 
			summary:"Advertencia: Vandalismo" 
		},
		"Aviso blanqueo": { 
			label:"Blanqueo", 
			summary:"Advertencia: Blanqueo" 
		},
		"Aviso spam2": { 
			label:"Spam", 
			summary:"Advertencia: Spam" 
		},
		"Au-noesforo2": { 
			label:"No es un foro", 
			summary:"Advertencia: No es un foro" 
		}
	},
	level3: {
		"Aviso prueba3": { 
			label:"Vandalismo", 
			summary:"Segunda advertencia: Vandalismo" 
		},
		"Aviso spam3": { 
			label:"Spam", 
			summary:"Segunda advertencia: Spam" 
		},
		"Au-noesforo3": { 
			label:"No es un foro", 
			summary:"Segunda advertencia: No es un foro" 
		}
	},
	level4: {
		"Aviso prueba4": { 
			label:"Vandalismo", 
			summary:"Última advertencia: Vandalismo" 
		},
		"Planvand": { 
			label:"Primera y última advertencia", 
			summary:"Última advertencia: Vandalismo" 
		},
		"Aviso spam4": { 
			label:"Spam", 
			summary:"Última advertencia: Spam" 
		},
		"Au-noesforo4": { 
			label:"No es un foro", 
			summary:"Última advertencia: No es un foro" 
		}
	},
	level4im: {
		"Aviso bloqueado": { 
			label:"Bloqueo", 
			summary:"Advertencia: Cuenta bloqueada" 
		}
	},
	singlenotice: {
		"Aviso PVN": { 
			label:"Ediciones polémicas", 
			summary:"Aviso: Ediciones polémicas" 
		},
		"Aviso etiqueta": { 
			label:"Etiqueta", 
			summary:"Aviso: Etiqueta" 
 
		},
		"Aviso promocional": { 
			label:"Autopromoción", 
			summary:"Aviso: Autopromoción"
		},
		"Aviso wikificar": { 
			label:"Manual de Estilo", 
			summary:"Aviso: Manual de Estilo" 
		},
 
		"Aviso FP": { 
			label:"Fuente primaria", 
			summary:"Aviso: Fuente primaria" 
		},
		"UQC": { 
			label:"Retirar carteles", 
			summary:"Aviso: Retirar carteles"		
		},
		"Aviso copyedit": { 
			label:"Ortografía, gramática y estilo", 
			summary:"Aviso: Copyedit" 
		},
		"Aviso referencias": { 
			label:"Artículos sin referencias", 
			summary:"Aviso: Referencias" 
		},
		"Aviso BR": { 
			label:"Borrado rápido", 
			summary:"Aviso: borrado rápido" 
		},
		"Aviso SRA": { 
			label:"Sin relevancia aparente", 
			summary:"Aviso: Sin relevancia aparente" 
		},
		"Aviso contextualizar": { 
			label:"Sin contextualizar", 
			summary:"Aviso: Sin contextualizar" 
		},
 
		"Aviso copyvio": { 
			label:"Copyvio", 
			summary:"Aviso:Copyvio" 
		},
		"Aviso imagen": { 
			label:"Aviso imagen", 
			summary:"Aviso: Imagen" 
		},
		"Aviso promocional": { 
			label:"Aviso Spam/Autopromoción", 
			summary:"Aviso: Spam/Autopromoción" 
		},
		"Aviso sin sentido": { 
			label:"Creación de artículos sin sentido", 
			summary:"Aviso: Creación de artículos sin sentido" 
		},
		"Aviso votonulo": { 
			label:"Voto anulado", 
			summary:"Aviso: Voto nulo" 
		},
		"Escalafón Wikipedia": { 
			label:"Aviso sobre el ranking de wikipedia", 
			summary:"Aviso:Ranking wikipedia" 
		},
		"Imagen retirada": { 
			label:"Imagen retirada", 
			summary:"Aviso: Imagen retirada" 
		},
		"Nombre de usuario inapropiado": { 
			label:"Nombre de usuario inapropiado", 
			summary:"Aviso: Nombre de usuario inapropiado" 
		},
		"Aviso infraesbozo": { 
			label:"Creación de infraesbozo", 
			summary:"Aviso: Infraesbozo" 
		},
		"No des bienvenidas": { 
			label:"No des bienvenidas", 
			summary:"Aviso: No des bienvenidas" 
		},
		"Topónimos": { 
			label:"Topónimos (Violación a WP:CT)", 
			summary:"Aviso: Violación a [[WP:CT|Convención de títulos]]" 
		},
		"Recordar": { 
			label:"Acerca del material multimedia", 
			summary:"Recordatorio: Material Multimedia"
		}
	},
	singlewarn: {
		"uw-3rr": { 
			label:"Potentially violating the three revert rule", 
			summary:"Warning: Potentially violating the three revert rule" 
		},/*
		"uw-attack": { 
			label:"Creating attack pages", 
			summary:"Warning: Creating attack pages" 
		},*/
		"uw-bv": { 
			label:"Blatant vandalism", 
			summary:"Warning: Blatant vandalism" 
		},
		"uw-canvass": { 
			label:"Canvassing", 
			summary:"Warning: Canvassing" 
		},
		"uw-copyright": { 
			label:"Copyright violation", 
			summary:"Warning: Copyright violation" 
		},
		"uw-copyright-link": { 
			label:"Linking to copyrighted works violation", 
			summary:"Warning: Linking to copyrighted works violation" 
		},
		"uw-hoax": { 
			label:"Creating hoaxes", 
			summary:"Warning: Creating hoaxes" 
		},
		"uw-legal": { 
			label:"Making legal threats", 
			summary:"Warning: Making legal threats" 
		},
		"uw-longterm": { 
			label:"Long term pattern of vandalism", 
			summary:"Warning: Long term pattern of vandalism" 
		},
		"uw-multipleIPs": { 
			label:"Usage of multiple IPs", 
			summary:"Warning: Usage of multiple IPs" 
		},
		"uw-pinfo": { 
			label:"Personal info", 
			summary:"Warning: Personal info" 
		},
		"uw-redirect": { 
			label:"Creating malicious redirects", 
			summary:"Warning: Creating malicious redirects"
		},
		"uw-upv": { 
			label:"Userpage vandalism", 
			summary:"Warning: Userpage vandalism"
		},
		"uw-tempabuse": { 
			label:"Improper use of warning or blocking template", 
			summary:"Warning: Improper use of warning or blocking template"
		},
		"uw-trivia": { 
			label:"Adding useless trivia", 
			summary:"Warning: Adding useless trivia"
		},
		"uw-wrongsummary": { 
			label:"Using inaccurate or inappropriate edit summaries", 
			summary:"Warning: Using inaccurate or inappropriate edit summaries"
		},
		"uw-username": { 
			label:"Username is against policy", 
			summary:"Warning: Username is against policy"
		},
		"uw-userpage": { 
			label:"Userpage or subpage is against policy", 
			summary:"Warning: Userpage or subpage is against policy"
		},
		"uw-ra": { 
			label:"Racially motivated edit", 
			summary:"Warning: Racially motivated edit"
		}
	},
	block: {
		"Usuario:TwinkleUser/Bloqueo": {
			'label':"Bloqueo",
			'summary':"Advertencia: Cuenta bloqueada (con fecha límite)"
		}
	}
};
 
 
twinklewarn.callback.change_category = function twinklewarnCallbackChangeCategory(e) {
	var value = e.target.value;
	var sub_group = e.target.root.sub_group;
	var messages = twinklewarn.messages[ value ];
	sub_group.main_group = value;
	var old_subvalue = sub_group.value;
	if( old_subvalue ) {
		old_subvalue = old_subvalue.replace(/\d*(im)?$/, '' );
		var old_subvalue_re = new RegExp( RegExp.escape( old_subvalue ) + "(\\d*(?:im)?)$" );
	}
 
	while( sub_group.hasChildNodes() ){
		sub_group.removeChild( sub_group.firstChild );
	}
 
	for( var i in messages ) {
		var selected = false;
		if( old_subvalue && old_subvalue_re.test( i ) ) {
			selected = true;
		}
		var elem = new QuickForm.element( { type:'option', label:"[" + i + "]: " + messages[i].label, value:i, selected: selected } );
 
		sub_group.appendChild( elem.render() );
	}
 
	if( value == 'block' ) {
		var more = new QuickForm.element( {
				type: 'input',
				name: 'block_timer',
				label: 'Tiempo de bloqueo: ',
				tooltip: 'Indica cuánto tiempo va a durar el bloqueo'
			} );
		e.target.root.insertBefore( more.render(), e.target.root.lastChild );
		e.target.root.article.disabled = true;
	} else if( e.target.root.block_timer ) {
		e.target.root.removeChild( e.target.root.block_timer.parentNode );
		e.target.root.article.disabled = false;
	}
}
 
twinklewarn.callbacks = {
	main: function( self ) {
		var form = self.responseXML.getElementById( 'editform' );
		var text = form.wpTextbox1.value;
 
		var history_re = /\<\!\-\-\ Plantilla\:(Aviso prueba\.*?)\ \-\-\>.*?(\d{1,2}:\d{1,2}, \d{1,2} \w+ \d{4}) \(UTC\)/g;
		var history = {};
		var latest = { date:new Date( 0 ), type:'' };
 
		var current;
 
 
		while( ( current = history_re.exec( text ) ) != undefined ) {
			var current_date = new Date( current[2] + ' UTC' );
			if( !( current[1] in history ) ||  history[ current[1] ] < current_date ) {
				history[ current[1] ] = current_date;
			}
			if( current_date > latest.date ) {
				latest.date = current_date;
				latest.type = current[1];
			}
		}
 
		var date = new Date();
 
		if( self.params.sub_group in history ) {
			var temp_time = new Date( history[ self.params.sub_group ] );
			temp_time.setUTCHours( temp_time.getUTCHours() + 24 );
 
			if( temp_time > date ) {
				Status.info( 'Info', "Se ha añadido  " + self.params.sub_group + " en las últimas 24 horas" );
				if( !confirm( "Continuar añadiendo avisos?" ) ) {
					self.statelem.info( 'abortando a petición del usuario' );
					return;
				}
			}
		}
 
		latest.date.setUTCMinutes( latest.date.getUTCMinutes() + 1 ); // after long debate, one minute is max
 
		if( latest.date > date ) {
			Status.info('Info', "Se ha añadido " + latest.type + " en el último minuto" );
				if( !confirm( "Will you still add a warning/notice?" ) ) {
					self.statelem.info( 'abortando a petición del usuario' );
					return;
				}
		}
 
 
 
 
		if( self.params.main_group == 'block' ) {
			var time = null;
			if( /te?mp|^\s*$|min/.exec( self.params.block_timer ) ) {
				time = '';
			} else if( /indef|\*|max/.exec( self.params.block_timer ) ) {
				time = '|indef=yes';
			} else {
				time = '|' + self.params.block_timer;
			}
 
			text += " \{\{subst:" + self.params.sub_group + time +"\}\}";
		} else {
			text += "\{\{subst:Usuario:Pericallis/denuncia|\{\{subst:" + self.params.sub_group + ( self.params.article ? '|' + self.params.article : '' ) + "\}\}" + (self.params.reason ? " ''" + self.params.reason + "'' ": ' ' ) + "\~\~\~\~ \}\}<br>";
		}
 
		if ( TwinkleConfig.showSharedIPNotice && isIPAddress( wgTitle ) ) {
			Status.info( 'Info', 'Colocando una notificación de IP compartida' );
			switch( QueryString.get( 'type' ) ) {
			case 'vand':
				text +=  "\n:''Si utilizas una IP compartida y estás seguro de que no hiciste ediciones vandálicas, puedes [[Ayuda:Registro|registrarte]] para evitar avisos futuros.'' ";
				break;
			default:
				text +=  "\n:''Si utilizas una IP compartida y estás seguro de que no hiciste ediciones vandálicas, puedes [[Ayuda:Registro|registrarte]] para evitar avisos futuros.'' ";
				break;
			}
		}
 
		var postData = {
			'wpMinoredit': form.wpMinoredit.checked ? 1 : undefined,
			'wpWatchthis': TwinkleConfig.watchWarnings ? 1 : form.wpWatchthis.checked ? 1 : undefined,
			'wpStarttime': form.wpStarttime.value,
			'wpEdittime': form.wpEdittime.value,
			'wpAutoSummary': form.wpAutoSummary.value,
			'wpEditToken': form.wpEditToken.value,
			'wpSection': '',
			'wpSummary': twinklewarn.messages[self.params.main_group][self.params.sub_group].summary + ( self.params.article ? ' en [[' + self.params.article + ']]'  : '' ) + '.' + TwinkleConfig.summaryAd,
			'wpTextbox1': text
		};
 
		self.post( postData );
	}
}
 
twinklewarn.callback.evaluate = function twinklewarnCallbackEvaluate(e) {
 
	// First, grab all the values provided by the form
 
	var params = {
		reason: e.target.reason.value,
		main_group: e.target.main_group.value,
		sub_group: e.target.sub_group.value,
		article: e.target.article.value.replace( /^(Image|Category):/i, ':$1:' ),
		block_timer: e.target.block_timer ? e.target.block_timer.value : null
	}
 
	Status.init( e.target );
 
	var query = { 
		'title': wgPageName, 
		'action': 'submit'
	};
	Wikipedia.actionCompleted.redirect = wgPageName;
	Wikipedia.actionCompleted.notice = "Advertencia completa, recargando la discusión en unos segundos";
	var wikipedia_wiki = new Wikipedia.wiki( 'Modificación a la página de discusión de usuario', query, twinklewarn.callbacks.main );
	wikipedia_wiki.params = params;
	wikipedia_wiki.get();
}