Usuario:Sistemo/twinklewarn.js
Nota: Después de guardar, debes refrescar la caché de tu navegador para ver los cambios. Internet Explorer: mantén presionada Ctrl mientras pulsas Actualizar. Firefox: mientras presionas Mayús pulsas el botón Actualizar, (o presiona Ctrl-Shift-R). Los usuarios de Google Chrome y Safari pueden simplemente pulsar el botón Recargar. Para más detalles e instrucciones acerca de otros exploradores, véase Ayuda:Cómo limpiar la caché.
// 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 = true;
}
/**
TwinkleConfig.summaryAd (string)
If ad should be added or not to summary, default [[WP:TWINKLE|TWINKLE]]
*/
if( typeof( TwinkleConfig.summaryAd ) == 'undefined' ) {
TwinkleConfig.summaryAd = " using [[WP:TW|TW]]";
}
function twinklewarn() {
if( wgNamespaceNumber == 3 ) {
mw.util.addPortletLink( 'p-cactions', (twinkleConfigExists ? "javascript:twinklewarn.callback()" : 'javascript:alert("Your account is too new to use Twinkle.");'), "advertencia", "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:'Desiste (3)', value:'level3' } );
main_group.append( { type:'option', label:'Última advertencia (4)', value:'level4' } );
main_group.append( { type:'option', label:'Bloqueo (5)', value:'level4im' } );
if( userIsInGroup( 'sysop' ) ) {
main_group.append( { type:'option', label:'Blocking', 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: {
"prueba": {
label:"Pruebas de edición",
summary:"Aviso: Pruebas de edición"
},
"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"
},
"Au-noesforo1": {
label:"No es un foro",
summary:"Aviso: No es un foro"
},
"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 vandalismo": {
label:"Artículo borrado",
summary:"Aviso: Artículo borrado"
},
"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"
},
"LetradeCanción": {
label:"Aviso sobre letra de canción",
summary:"Aviso: Letra de canción"
},
"Nombre de usuario inapropiado": {
label:"Nombre de usuario inapropiado",
summary:"Aviso: Nombre de usuario inapropiado"
},
"Infraesbozo": {
label:"Creación de infraesbozo",
summary:"Aviso: Infraesbozo"
},
"No des bienvenidas": {
label:"No des bienvenidas",
summary:"Aviso: No des bienvenidas"
},
"Prueba0c": {
label:"Spam",
summary:"Aviso: Spam"
},
"Prueba0": {
label:"Ediciones polémicas",
summary:"Aviso: Ediciones polémicas"
},
"Prueba0a": {
label:"Wikipetiqueta",
summary:"Aviso: Wikipetiqueta"
},
"Prueba0b": {
label:"Manual de Estilo",
summary:"Aviso: Manual de Estilo"
},
"Prueba0d": {
label:"Autopromoción",
summary:"Aviso: Autopromoción"
},
"Spam": {
label:"Spam por el nombre de usuario",
summary:"Aviso: Spam"
},
"Sugerencia": {
label:"Nuevo artículo sin formato",
summary:"Aviso: Artículo sin formato"
},
"Topónimos": {
label:"Topónimos (Violación a [[WP:CT]])",
summary:"Aviso: Violación a [[WP:CT|Convección de títulos]]"
},
"Recordar": {
label:"Acerca del material multimedia",
summary:"Recordatorio: Material Multimedia"
}
},
level2: {
"Prueba2": {
label:"Vandalismo",
summary:"Advertencia: Vandalismo"
},
"Prueba2a": {
label:"Blanqueo",
summary:"Advertencia: Blanqueo"
},
"Prueba2c": {
label:"Spam",
summary:"Advertencia: Spam"
},
"Au-noesforo2": {
label:"No es un foro",
summary:"Advertencia: No es un foro"
}
},
level3: {
"Prueba3": {
label:"Vandalismo",
summary:"Segunda advertencia: Vandalismo"
},
"Prueba3c": {
label:"Spam",
summary:"Segunda advertencia: Spam"
},
"Au-noesforo3": {
label:"No es un foro",
summary:"Segunda advertencia: No es un foro"
}
},
level4: {
"Prueba4": {
label:"Vandalismo",
summary:"Última advertencia: Vandalismo"
},
"Prueba4c": {
label:"Spam",
summary:"Última advertencia: Spam"
},
"Au-noesforo4": {
label:"No es un foro",
summary:"Última advertencia: No es un foro"
}
},
level4im: {
"Prueba5": {
label:"Bloqueo",
summary:"Advertencia: Cuenta bloqueada"
}
},
singlenotice: {
"uw-2redirect": {
label:"Creating double redirects through bad page moves",
summary:"Notice: Creating double redirects through bad page moves"
},
"uw-aiv": {
label:"Bad AIV report",
summary:"Notice: Bad AIV report"
},
"uw-articlesig": {
label:"Adding signatures to article space",
summary:"Notice: Adding signatures to article space"
},
"uw-autobiography": {
label:"Creating autobiographies",
summary:"Notice: Creating autobiographies"
},
"uw-badcat": {
label:"Adding incorrect categories",
summary:"Notice: Adding incorrect categories"
},
"uw-bite": {
label:"\"Biting\" newcomers",
summary:"Notice: \"Biting\" newcomers"
},
"uw-coi": {
label:"Conflict of Interest",
summary:"Notice: Conflict of Interest"
},
"uw-c&pmove": {
label:"Cut and paste moves",
summary:"notice: Cut and paste moves"
},
"uw-date": {
label:"Unnecessarily changing date formats",
summary:"Notice: Unnecessarily changing date formats"
},
"uw-deadlink": {
label:"Removing proper sources containing dead links",
summary:"Notice: Removing proper sources containing dead links"
},
"uw-editsummary": {
label:"Not using edit summary",
summary:"Notice: Not using edit summary"
},
"uw-english": {
label:"Not communicating in English",
summary:"Notice: Not communicating in English"
},
"uw-hangon": {
label:"User forgets to place a hang-on reasoning to the talk page",
summary:"Notice: User forgets to place a hang-on reasoning to the talk page"
},
"uw-italicize": {
label:"Italicize books, films, albums, magazines, TV series, etc within articles",
summary:"Notice: Italicize books, films, albums, magazines, TV series, etc within articles"
},
"uw-lang": {
label:"Unnecessarily changing between British and American English",
summary:"Notice: Unnecessarily changing between British and American English"
},
"uw-linking": {
label:"For excessive addition of redlinks or repeated blue links",
summary:"Notice: For excessive addition of redlinks or repeated blue links"
},
"uw-minor": {
label:"Incorrect use of minor edits check box",
summary:"Notice: Incorrect use of minor edits check box"
},
"uw-nonfree": {
label:"Uploading replaceable non-free images",
summary:"Notice: Uploading replaceable non-free images"
},
"uw-notaiv": {
label:"Do not report complex abuse to AIV",
summary:"Notice: Do not report complex abuse to AIV"
},
"uw-notvote": {
label:"We use consensus, not voting",
summary:"Notice: We use consensus, not voting"
},
"uw-preview": {
label:"Use preview button to avoid mistakes",
summary:"Notice: Use preview button to avoid mistakes"
},
"uw-selfrevert": {
label:"Reverting self tests",
summary:"Notice: Reverting self tests"
},
"uw-samename": {
label:"Rename request impossible",
summary:"Notice: Rename request impossible"
},
"uw-sandbox": {
label:"Removal of the Sandbox header",
summary:"Notice: Removal of the Sandbox header"
},
"uw-spellcheck": {
label:"Review spelling, etc.",
summary:"Notice: Review spelling, etc."
},
"uw-socialnetwork": {
label:"Wikipedia is not a social network",
summary:"Notice: Wikipedia is not a social network"
},
"uw-subst": {
label:"Remember to subst: templates",
summary:"Notice: Remember to subst: templates"
},
"uw-talkinarticle": {
label:"Talk in article",
summary:"Notice: Talk in article"
},
"uw-tilde": {
label:"Not signing posts",
summary:"Notice: Not signing posts"
},
"uw-uaa": {
label:"Reporting of username to WP:UAA not accepted",
summary:"Notice: Reporting of username to WP:UAA not accepted"
},
"uw-warn": {
label:"Warning vandals",
summary:"Notice: Warning vandals"
}
},
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: {
"uw-block1": {
'label':"Block level 1",
'summary':"You have been temporarily blocked"
},
"uw-block2": {
'label':"Block level 2",
'summary':"You have been blocked"
},
"uw-block3": {
'label':"Block level 3",
'summary':"You have been indefinitely blocked"
},
"uw-ablock": {
'label':"Anonymous block",
'summary':"Your IP address has been blocked"
},
"uw-sblock": {
'label':"Spam block",
'summary':"You have been blocked for spamming"
},
"uw-vblock": {
'label':"Vandalism",
'summary':"You have been blocked for vandalism"
},
"uw-voablock": {
'label':"Vandalism-only account",
'summary':"You have been blocked for using a vandalism-only account"
},
"uw-dblock": {
'label':"Delete block",
'summary':"You have been blocked for deletion"
},
"uw-3block": {
'label':"3RR block",
'summary':"You have been blocked for violation of the [[WP:3RR|3RR]] rule"
},
"uw-ublock": {
'label':"Username block",
'summary':"You have been blocked for violation of the [[WP:U|username policy]]"
},
"uw-uhblock": {
'label':"Username hard block",
'summary':"You have been blocked for blatant violation of the [[WP:U|username policy]]"
},
"uw-lblock": {
'label':"Legal Threat Block",
'summary':"You have been blocked for [[Wikipedia:No legal threats|making legal threats]]"
},
"uw-hblock": {
'label':"Harassment Block",
'summary':"You have been blocked for attempting to [[Wikipedia:Harassment|harass]] other users"
},
"uw-npblock": {
'label':"Creating Nonsense Pages Block",
'summary':"You have been blocked for [[Wikipedia:Patent_nonsense|creating nonsense pages]]"
}
}
};
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: 'Period of blocking: ',
tooltip: 'The period the blocking is due for, for example 24 hours, 2 weeks, indefinite etc...'
} );
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 = /\<\!\-\-\ Template\:(uw\-.*?)\ \-\-\>.*?(\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', "an identical " + self.params.sub_group + " has been issued in the last 24 hours" );
if( !confirm( "Will you still add a warning/notice?" ) ) {
self.statelem.info( 'aborted per user request' );
return;
}
}
}
latest.date.setUTCMinutes( latest.date.getUTCMinutes() + 1 ); // after long debate, one minute is max
if( latest.date > date ) {
Status.info('Info', "a " + latest.type + " has been issued in the last minute" );
if( !confirm( "Will you still add a warning/notice?" ) ) {
self.statelem.info( 'aborted per user request' );
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 = '|time=' + self.params.block_timer;
}
text += " \{\{subst:" + self.params.sub_group + time + (self.params.reason ? '|reason=' + self.params.reason : '' ) + "|sig=true\}\}";
} else {
text += "\{\{subst:" + self.params.sub_group + ( self.params.article ? '|' + self.params.article : '' ) + "\}\}" + (self.params.reason ? " ''" + self.params.reason + "'' ": ' ' ) + "\~\~\~\~";
}
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,
'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();
}