Usuario:K-F.U.N 2/friendlywelcome.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é.
// <nowiki>
// If FriendlyConfig aint exist.
if( typeof( FriendlyConfig ) == 'undefined' ) {
FriendlyConfig = {};
}
/**
FriendlyConfig.summaryAd ( string )
If ad should be added or not to summary, default [[WP:TW|TW]]
*/
if( typeof( FriendlyConfig.summaryAd ) == 'undefined' ) {
FriendlyConfig.summaryAd = " Usando ([[w:es:WP:TW|TW]])";
}
/**
FriendlyConfig.topWelcomes ( boolean )
*/
if( typeof( FriendlyConfig.topWelcomes ) == 'undefined' ) {
FriendlyConfig.topWelcomes = true;
}
/**
FriendlyConfig.watchWelcomes ( boolean )
*/
if( typeof( FriendlyConfig.watchWelcomes ) == 'undefined' ) {
FriendlyConfig.watchWelcomes = false;
}
/**
FriendlyConfig.insertHeadings ( boolean )
*/
if( typeof( FriendlyConfig.insertHeadings ) == 'undefined' ) {
FriendlyConfig.insertHeadings = true;
}
/**
FriendlyConfig.welcomeHeading ( string )
*/
if( typeof( FriendlyConfig.welcomeHeading ) == 'undefined' ) {
FriendlyConfig.welcomeHeading = "== Bienvenido ==";
}
/**
FriendlyConfig.insertUsername ( boolean )
*/
if( typeof( FriendlyConfig.insertUsername ) == 'undefined' ) {
FriendlyConfig.insertUsername = true;
}
/**
FriendlyConfig.insertSignature ( boolean )
*/
if( typeof( FriendlyConfig.insertSignature ) == 'undefined' ) {
FriendlyConfig.insertSignature = true;
}
/**
FriendlyConfig.markWelcomesAsMinor ( boolean )
*/
if( typeof( FriendlyConfig.markWelcomesAsMinor ) == 'undefined' ) {
FriendlyConfig.markWelcomesAsMinor = true;
}
/**
FriendlyConfig.quickWelcomeMode ( String )
*/
if( typeof( FriendlyConfig.quickWelcomeMode ) == 'undefined' ) {
FriendlyConfig.quickWelcomeMode = "auto";
}
/**
FriendlyConfig.quickWelcomeTemplate ( String )
*/
if( typeof( FriendlyConfig.quickWelcomeTemplate ) == 'undefined' ) {
FriendlyConfig.quickWelcomeTemplate = "Bienvenio";
}
/**
FriendlyConfig.maskTemplateInSummary ( boolean )
*/
if( typeof( FriendlyConfig.maskTemplateInSummary ) == 'undefined' ) {
FriendlyConfig.maskTemplateInSummary = true;
}
$( function() {
if( QueryString.exists( 'friendlywelcome' ) ) {
if( QueryString.get( 'friendlywelcome' == 'auto' ) ) {
friendlywelcome.auto();
} else {
friendlywelcome.semiauto();
}
} else {
friendlywelcome.normal();
}
}
);
friendlywelcome = {
auto: function() {
if( QueryString.get( 'action' ) != 'edit' ) {
// userpage not empty, aborting auto-welcome
return;
}
return friendlywelcome.welcome();
},
semiauto: function() {
friendlywelcome.callback( wgTitle.split( '/' )[0].replace( /\"/, "\\\"") );
},
normal: function() {
if( QueryString.exists( 'diff' ) ) {
// all nodes with "New user account"
var oSet1 = '//div[@id="mw-diff-otitle2"]';
var nSet1 = '//div[@id="mw-diff-ntitle2"]';
// all nodes with empty talk page
var oSet2 = '//div[@id="mw-diff-otitle2"][contains(a[2][@class="new"], "Talk")]';
var nSet2 = '//div[@id="mw-diff-ntitle2"][contains(a[2][@class="new"], "Talk")]';
// intersection of set1 and set2 is new user accounts with empty talk pages
var oXPath = '(' + oSet1 + ')[count(.|' + oSet2 + ')=count(' + oSet2 + ')]';
var nXPath = '(' + nSet1 + ')[count(.|' + nSet2 + ')=count(' + nSet2 + ')]';
var oList = document.evaluate( oXPath, document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null );
var nList = document.evaluate( nXPath, document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null );
var spanTag = function( color, content ) {
var span = document.createElement( 'span' );
span.style.color = color;
span.appendChild( document.createTextNode( content ) );
return span;
}
var welcomeNode = document.createElement('strong');
var welcomeLink = document.createElement('a');
welcomeLink.appendChild( spanTag( 'Black', '[' ) );
welcomeLink.appendChild( spanTag( 'Goldenrod', 'bienvenida' ) );
welcomeLink.appendChild( spanTag( 'Black', ']' ) );
welcomeNode.appendChild(welcomeLink);
for(var i = 0; i < oList.snapshotLength; ++i ) {
var current = oList.snapshotItem(i);
var href = document.evaluate( 'a[2]/@href', current, null, XPathResult.STRING_TYPE, null ).stringValue;
var tmpNode = welcomeNode.cloneNode( true );
tmpNode.firstChild.setAttribute( 'href', href + '&' + QueryString.create( { 'friendlywelcome': 'norm' } )
+ '&' + QueryString.create( { 'vanarticle': wgPageName.replace(/_/g, ' ') } ) );
current.appendChild( document.createTextNode( ' ' ) );
current.appendChild( tmpNode );
}
for(var i = 0; i < nList.snapshotLength; ++i ) {
var current = nList.snapshotItem(i);
var href = document.evaluate( 'a[2]/@href', current, null, XPathResult.STRING_TYPE, null ).stringValue;
var tmpNode = welcomeNode.cloneNode( true );
tmpNode.firstChild.setAttribute( 'href', href + '&' + QueryString.create( { 'friendlywelcome': 'norm' } )
+ '&' + QueryString.create( { 'vanarticle': wgPageName.replace(/_/g, ' ') } ) );
current.appendChild( document.createTextNode( ' ' ) );
current.appendChild( tmpNode );
}
}
if( wgNamespaceNumber == 3 ) {
var username = wgTitle.split( '/' )[0].replace( /\"/, "\\\""); // only first part before any slashes
mw.util.addPortletLink( 'p-cactions', "javascript:friendlywelcome.callback(\"" + username + "\")", "bienvenida", "friendly-welcome", "Dar bienvenida", "");
}
}
}
friendlywelcome.welcome = function welcomeUser() {
Status.init( document.getElementById('bodyContent') );
var params = {
value: FriendlyConfig.quickWelcomeTemplate,
article: QueryString.exists( 'vanarticle' ) ? QueryString.get( 'vanarticle' ) : '',
mode: 'auto'
};
var query = {
'title': wgPageName,
'action': 'submit'
};
Wikipedia.actionCompleted.redirect = wgPageName;
Wikipedia.actionCompleted.notice = "Terminado, por favor, espere un momento";
var wikipedia_wiki = new Wikipedia.wiki( 'User talk page modification', query, friendlywelcome.callbacks.main );
wikipedia_wiki.params = params;
wikipedia_wiki.get();
}
friendlywelcome.callback = function friendlywelcomeCallback( uid ) {
if( uid == wgUserName ){
alert( 'No te puedes dar bienvenida a ti mismo' );
return;
}
var Window = new SimpleWindow( 600, 400 );
Window.setTitle( "Dar bienvenida al usuario" );
var form = new QuickForm( friendlywelcome.callback.evaluate, 'change' );
form.append( {
type: 'input',
name: 'article',
label: 'Enlace al artículo (si lo permite la plantilla)',
value:( QueryString.exists( 'vanarticle' ) ? QueryString.get( 'vanarticle' ) : '' ),
tooltip: 'Un artículo puede ponerse si la plantilla lo permite.',
event: function( event ) {
event.stopPropagation();
}
}
);
form.append( { type:'header', label:'Plantillas normales' } );
form.append( { type: 'radio', name: 'welcomingCommittee', list: friendlywelcome.welcomingCommitteeList } );
var result = form.render();
Window.setContent( result );
Window.display();
}
friendlywelcome.welcomingCommitteeList = [
{
label: 'Bienvenida a usuario',
value: 'Bienvenido usuario',
tooltip: 'Esta plantilla sirve para dar la bienvenida a un usuario' },
{
label: 'Bienvenida a IP',
value: 'Bienvenida a IP',
tooltip: 'Bienvenida a un usuario IP' },
{
label: 'Bienvenida Twinkle',
value: 'User:Robinsonsmay/Welcome',
tooltip: 'Esta plantilla sirve para dar la bienvenida a un usuario la estilo TW' },
]
// Set to true if template already has heading
friendlywelcome.headingHash = {
'Bienvenido usuario': false,
'Bienvenida a IP': false,
'User:Robinsonsmay/Welcome': false,
}
// Set to true if template already has signature
friendlywelcome.signatureHash = {
'Bienvenido usuario': true,
'Bienvenida a IP': true,
'User:Robinsonsmay/Welcome': true,
}
/* Set to true if template supports article
* name from art template parameter
*/
friendlywelcome.artHash = {
'Bienvenido usuario': false,
'Bienvenida a IP': false,
'User:Robinsonsmay/Welcome': false,
}
/* Set to true if template supports article
* name from vanarticle url parameter
*/
friendlywelcome.vandalHash = {
'Bienvenido usuario': false,
'Bienvenida a IP': false,
'User:Robinsonsmay/Welcome': false,
}
friendlywelcome.callbacks = {
main: function( self ) {
var form = self.responseXML.getElementById( 'editform' );
// abort if mode is auto and form is not empty
if( form.wpTextbox1.value != '\n' && self.params.mode == 'auto' ) {
Status.info( 'Warning', 'User talk page not empty; aborting automatic welcome' );
Wikipedia.actionCompleted.event();
return;
}
var text = '';
Status.info( 'Info', 'Will add the welcome template to the '
+ ( FriendlyConfig.topWelcomes ? 'top' : 'bottom' )
+ ' of the user\'s talk page.' );
if( !FriendlyConfig.topWelcomes ) {
text += form.wpTextbox1.value + '\n\n';
}
if( !friendlywelcome.headingHash[ self.params.value ] && FriendlyConfig.insertHeadings ) {
Status.info( 'Info', 'Se esta creando un header' );
text += FriendlyConfig.welcomeHeading + "\n";
}
Status.info( 'Info', 'Sustituyendo {{' + self.params.value + '}} ' );
text += '\{\{subst:' + self.params.value;
if( friendlywelcome.artHash[ self.params.value ] ) {
if( FriendlyConfig.insertUsername ) {
Status.info( 'Info', 'Añadiendo tu firma' );
text += '|' + wgUserName;
}
if( self.params.article != '' ) {
Status.info( 'Info', 'Añadiendo el nombre del artículo' );
text += '|art=' + self.params.article;
}
} else if( friendlywelcome.vandalHash[ self.params.value ] ) {
if( self.params.article != '' ) {
Status.info( 'Info', 'Will add vandalized article link to the template' );
}
text += '|' + self.params.article;
if( FriendlyConfig.insertUsername ) {
Status.info( 'Info', 'Se está añadiendo tu firma' );
text += '|' + wgUserName;
}
} else if( FriendlyConfig.insertUsername ) {
Status.info( 'Info', 'Se está añadiendo tu firma' );
text += '|' + wgUserName;
}
text += '\}\} \~\~\~\~';
if( !friendlywelcome.signatureHash[ self.params.value ] && FriendlyConfig.insertSignature ) {
Status.info( 'Info', 'se está añadiendo tu firma' );
text += ' \n\~\~\~\~';
}
if( FriendlyConfig.topWelcomes ) {
text += '\n\n' + form.wpTextbox1.value;
}
var postData = {
'wpMinoredit': FriendlyConfig.markWelcomesAsMinor ? 1 : undefined,
'wpWatchthis': form.wpWatchthis.checked ? 1 : (FriendlyConfig.watchWelcomes ? 1 : undefined),
'wpStarttime': form.wpStarttime.value,
'wpEdittime': form.wpEdittime.value,
'wpAutoSummary': form.wpAutoSummary.value,
'wpEditToken': form.wpEditToken.value,
'wpSection': '',
'wpSummary': 'Bienvenida' + FriendlyConfig.summaryAd,
'wpTextbox1': text
};
self.post( postData );
}
}
friendlywelcome.callback.evaluate = function friendlywelcomeCallbackEvaluate(e) {
// Ignore if a change to the text field triggered this event
if( e.target.name == 'article' ) {
return;
}
var params = {
value: e.target.value,
article: e.target.form.article.value,
mode: 'manual'
};
Status.init( e.target.form );
var query = {
'title': wgPageName,
'action': 'submit'
};
Wikipedia.actionCompleted.redirect = wgPageName;
Wikipedia.actionCompleted.notice = "Se ha terminado de dar la bienvenida";
var wikipedia_wiki = new Wikipedia.wiki( 'User talk page modification', query, friendlywelcome.callbacks.main );
wikipedia_wiki.params = params;
wikipedia_wiki.get();
}
// </nowiki>