MediaWiki:Gadget-friendlywelcome.js: Difference between revisions

From TestWiki
Content added Content deleted
imported>Amorymeltzer
(Repo at 53b6bf4: Enable on every user-related page (#547); Enable on every user-related page)
imported>Amorymeltzer
(Repo at d404881: Greatly expand style guidelines, enforce linting rules (#657))
 
Line 1: Line 1:
//<nowiki>
// <nowiki>




(function($){
(function($) {




Line 16: Line 16:


Twinkle.welcome = function friendlywelcome() {
Twinkle.welcome = function friendlywelcome() {
if( Morebits.queryString.exists( 'friendlywelcome' ) ) {
if (Morebits.queryString.exists('friendlywelcome')) {
if( Morebits.queryString.get( 'friendlywelcome' ) === 'auto' ) {
if (Morebits.queryString.get('friendlywelcome') === 'auto') {
Twinkle.welcome.auto();
Twinkle.welcome.auto();
} else {
} else {
Line 28: Line 28:


Twinkle.welcome.auto = function() {
Twinkle.welcome.auto = function() {
if( Morebits.queryString.get( 'action' ) !== 'edit' ) {
if (Morebits.queryString.get('action') !== 'edit') {
// userpage not empty, aborting auto-welcome
// userpage not empty, aborting auto-welcome
return;
return;
Line 37: Line 37:


Twinkle.welcome.semiauto = function() {
Twinkle.welcome.semiauto = function() {
Twinkle.welcome.callback( mw.config.get( 'wgRelevantUserName' ) );
Twinkle.welcome.callback(mw.config.get('wgRelevantUserName'));
};
};


Twinkle.welcome.normal = function() {
Twinkle.welcome.normal = function() {
if( Morebits.queryString.exists( 'diff' ) ) {
if (Morebits.queryString.exists('diff')) {
// check whether the contributors' talk pages exist yet
// check whether the contributors' talk pages exist yet
var $oList = $("#mw-diff-otitle2").find("span.mw-usertoollinks a.new:contains(talk)").first();
var $oList = $('#mw-diff-otitle2').find('span.mw-usertoollinks a.new:contains(talk)').first();
var $nList = $("#mw-diff-ntitle2").find("span.mw-usertoollinks a.new:contains(talk)").first();
var $nList = $('#mw-diff-ntitle2').find('span.mw-usertoollinks a.new:contains(talk)').first();


if( $oList.length > 0 || $nList.length > 0 ) {
if ($oList.length > 0 || $nList.length > 0) {
var spanTag = function( color, content ) {
var spanTag = function(color, content) {
var span = document.createElement( 'span' );
var span = document.createElement('span');
span.style.color = color;
span.style.color = color;
span.appendChild( document.createTextNode( content ) );
span.appendChild(document.createTextNode(content));
return span;
return span;
};
};
Line 56: Line 56:
var welcomeNode = document.createElement('strong');
var welcomeNode = document.createElement('strong');
var welcomeLink = document.createElement('a');
var welcomeLink = document.createElement('a');
welcomeLink.appendChild( spanTag( 'Black', '[' ) );
welcomeLink.appendChild(spanTag('Black', '['));
welcomeLink.appendChild( spanTag( 'Goldenrod', 'welcome' ) );
welcomeLink.appendChild(spanTag('Goldenrod', 'welcome'));
welcomeLink.appendChild( spanTag( 'Black', ']' ) );
welcomeLink.appendChild(spanTag('Black', ']'));
welcomeNode.appendChild(welcomeLink);
welcomeNode.appendChild(welcomeLink);


if( $oList.length > 0 ) {
if ($oList.length > 0) {
var oHref = $oList.attr("href");
var oHref = $oList.attr('href');


var oWelcomeNode = welcomeNode.cloneNode( true );
var oWelcomeNode = welcomeNode.cloneNode(true);
oWelcomeNode.firstChild.setAttribute( 'href', oHref + '&' + Morebits.queryString.create( {
oWelcomeNode.firstChild.setAttribute('href', oHref + '&' + Morebits.queryString.create({
'friendlywelcome': Twinkle.getFriendlyPref('quickWelcomeMode') === 'auto' ? 'auto': 'norm',
'friendlywelcome': Twinkle.getFriendlyPref('quickWelcomeMode') === 'auto' ? 'auto' : 'norm',
'vanarticle': Morebits.pageNameNorm
'vanarticle': Morebits.pageNameNorm
} ) );
}));
$oList[0].parentNode.parentNode.appendChild( document.createTextNode( ' ' ) );
$oList[0].parentNode.parentNode.appendChild(document.createTextNode(' '));
$oList[0].parentNode.parentNode.appendChild( oWelcomeNode );
$oList[0].parentNode.parentNode.appendChild(oWelcomeNode);
}
}


if( $nList.length > 0 ) {
if ($nList.length > 0) {
var nHref = $nList.attr("href");
var nHref = $nList.attr('href');


var nWelcomeNode = welcomeNode.cloneNode( true );
var nWelcomeNode = welcomeNode.cloneNode(true);
nWelcomeNode.firstChild.setAttribute( 'href', nHref + '&' + Morebits.queryString.create( {
nWelcomeNode.firstChild.setAttribute('href', nHref + '&' + Morebits.queryString.create({
'friendlywelcome': Twinkle.getFriendlyPref('quickWelcomeMode') === 'auto' ? 'auto': 'norm',
'friendlywelcome': Twinkle.getFriendlyPref('quickWelcomeMode') === 'auto' ? 'auto' : 'norm',
'vanarticle': Morebits.pageNameNorm
'vanarticle': Morebits.pageNameNorm
} ) );
}));
$nList[0].parentNode.parentNode.appendChild( document.createTextNode( ' ' ) );
$nList[0].parentNode.parentNode.appendChild(document.createTextNode(' '));
$nList[0].parentNode.parentNode.appendChild( nWelcomeNode );
$nList[0].parentNode.parentNode.appendChild(nWelcomeNode);
}
}
}
}
}
}
if( mw.config.get( 'wgRelevantUserName' ) ) {
if (mw.config.get('wgRelevantUserName')) {
Twinkle.addPortletLink( function(){ Twinkle.welcome.callback(mw.config.get( 'wgRelevantUserName' )); }, "Wel", "friendly-welcome", "Welcome user" );
Twinkle.addPortletLink(function() {
Twinkle.welcome.callback(mw.config.get('wgRelevantUserName'));
}, 'Wel', 'friendly-welcome', 'Welcome user');
}
}
};
};


Twinkle.welcome.welcomeUser = function welcomeUser() {
Twinkle.welcome.welcomeUser = function welcomeUser() {
Morebits.status.init( document.getElementById('mw-content-text') );
Morebits.status.init(document.getElementById('mw-content-text'));
$( '#catlinks' ).remove();
$('#catlinks').remove();


var params = {
var params = {
value: Twinkle.getFriendlyPref('quickWelcomeTemplate'),
value: Twinkle.getFriendlyPref('quickWelcomeTemplate'),
article: Morebits.queryString.exists( 'vanarticle' ) ? Morebits.queryString.get( 'vanarticle' ) : '',
article: Morebits.queryString.exists('vanarticle') ? Morebits.queryString.get('vanarticle') : '',
mode: 'auto'
mode: 'auto'
};
};
Line 103: Line 105:
var userTalkPage = mw.config.get('wgFormattedNamespaces')[3] + ':' + mw.config.get('wgRelevantUserName');
var userTalkPage = mw.config.get('wgFormattedNamespaces')[3] + ':' + mw.config.get('wgRelevantUserName');
Morebits.wiki.actionCompleted.redirect = userTalkPage;
Morebits.wiki.actionCompleted.redirect = userTalkPage;
Morebits.wiki.actionCompleted.notice = "Welcoming complete, reloading talk page in a few seconds";
Morebits.wiki.actionCompleted.notice = 'Welcoming complete, reloading talk page in a few seconds';


var wikipedia_page = new Morebits.wiki.page(userTalkPage, "User talk page modification");
var wikipedia_page = new Morebits.wiki.page(userTalkPage, 'User talk page modification');
wikipedia_page.setFollowRedirect(true);
wikipedia_page.setFollowRedirect(true);
wikipedia_page.setCallbackParameters(params);
wikipedia_page.setCallbackParameters(params);
Line 111: Line 113:
};
};


Twinkle.welcome.callback = function friendlywelcomeCallback( uid ) {
Twinkle.welcome.callback = function friendlywelcomeCallback(uid) {
if( uid === mw.config.get('wgUserName') && !confirm( 'Are you really sure you want to welcome yourself?...' ) ){
if (uid === mw.config.get('wgUserName') && !confirm('Are you really sure you want to welcome yourself?...')) {
return;
return;
}
}


var Window = new Morebits.simpleWindow( 600, 420 );
var Window = new Morebits.simpleWindow(600, 420);
Window.setTitle( "Welcome user" );
Window.setTitle('Welcome user');
Window.setScriptName( "Twinkle" );
Window.setScriptName('Twinkle');
Window.addFooterLink( "Welcoming Committee", "WP:WC" );
Window.addFooterLink('Welcoming Committee', 'WP:WC');
Window.addFooterLink( "Twinkle help", "WP:TW/DOC#welcome" );
Window.addFooterLink('Twinkle help', 'WP:TW/DOC#welcome');


var form = new Morebits.quickForm( Twinkle.welcome.callback.evaluate );
var form = new Morebits.quickForm(Twinkle.welcome.callback.evaluate);


form.append({
form.append({
type: 'select',
type: 'select',
name: 'type',
name: 'type',
label: 'Type of welcome: ',
label: 'Type of welcome: ',
event: Twinkle.welcome.populateWelcomeList,
event: Twinkle.welcome.populateWelcomeList,
list: [
list: [
{ type: 'option', value: 'standard', label: 'Standard welcomes', selected: !mw.util.isIPAddress(mw.config.get('wgRelevantUserName')) },
{ type: 'option', value: 'standard', label: 'Standard welcomes', selected: !mw.util.isIPAddress(mw.config.get('wgRelevantUserName')) },
{ type: 'option', value: 'anonymous', label: 'IP user welcomes', selected: mw.util.isIPAddress(mw.config.get('wgRelevantUserName')) },
{ type: 'option', value: 'anonymous', label: 'IP user welcomes', selected: mw.util.isIPAddress(mw.config.get('wgRelevantUserName')) },
{ type: 'option', value: 'wikiProject', label: 'WikiProject welcomes' },
{ type: 'option', value: 'wikiProject', label: 'WikiProject welcomes' },
{ type: 'option', value: 'nonEnglish', label: 'Non-English welcomes' }
{ type: 'option', value: 'nonEnglish', label: 'Non-English welcomes' }
]
]
});
});


form.append( {
form.append({
type: 'div',
type: 'div',
id: 'welcomeWorkArea',
id: 'welcomeWorkArea',
className: 'morebits-scrollbox'
className: 'morebits-scrollbox'
} );
});


form.append( {
form.append({
type: 'input',
type: 'input',
name: 'article',
name: 'article',
label: '* Linked article (if supported by template):',
label: '* Linked article (if supported by template):',
value:( Morebits.queryString.exists( 'vanarticle' ) ? Morebits.queryString.get( 'vanarticle' ) : '' ),
value: Morebits.queryString.exists('vanarticle') ? Morebits.queryString.get('vanarticle') : '',
tooltip: 'An article might be linked from within the welcome if the template supports it. Leave empty for no article to be linked. Templates that support a linked article are marked with an asterisk.'
tooltip: 'An article might be linked from within the welcome if the template supports it. Leave empty for no article to be linked. Templates that support a linked article are marked with an asterisk.'
} );
});


var previewlink = document.createElement( 'a' );
var previewlink = document.createElement('a');
$(previewlink).click(function(){
$(previewlink).click(function() {
Twinkle.welcome.callbacks.preview(result); // |result| is defined below
Twinkle.welcome.callbacks.preview(result); // |result| is defined below
});
});
previewlink.style.cursor = "pointer";
previewlink.style.cursor = 'pointer';
previewlink.textContent = 'Preview';
previewlink.textContent = 'Preview';
form.append( { type: 'div', name: 'welcomepreview', label: [ previewlink ] } );
form.append({ type: 'div', name: 'welcomepreview', label: [ previewlink ] });


form.append( { type: 'submit' } );
form.append({ type: 'submit' });


var result = form.render();
var result = form.render();
Window.setContent( result );
Window.setContent(result);
Window.display();
Window.display();


// initialize the welcome list
// initialize the welcome list
var evt = document.createEvent( "Event" );
var evt = document.createEvent('Event');
evt.initEvent( 'change', true, true );
evt.initEvent('change', true, true);
result.type.dispatchEvent( evt );
result.type.dispatchEvent(evt);
};
};


Line 174: Line 176:
var type = e.target.value;
var type = e.target.value;


var container = new Morebits.quickForm.element({ type: "fragment" });
var container = new Morebits.quickForm.element({ type: 'fragment' });


if ((type === "standard" || type === "anonymous") && Twinkle.getFriendlyPref("customWelcomeList").length) {
if ((type === 'standard' || type === 'anonymous') && Twinkle.getFriendlyPref('customWelcomeList').length) {
container.append({ type: 'header', label: 'Custom welcome templates' });
container.append({ type: 'header', label: 'Custom welcome templates' });
container.append({
container.append({
type: 'radio',
type: 'radio',
name: 'template',
name: 'template',
list: Twinkle.getFriendlyPref("customWelcomeList"),
list: Twinkle.getFriendlyPref('customWelcomeList'),
event: Twinkle.welcome.selectTemplate
event: Twinkle.welcome.selectTemplate
});
});
Line 192: Line 194:
list: list.map(function(obj) {
list: list.map(function(obj) {
var properties = Twinkle.welcome.templates[obj];
var properties = Twinkle.welcome.templates[obj];
var result = (properties ? {
var result = properties ? {
value: obj,
value: obj,
label: "{{" + obj + "}}: " + properties.description + (properties.linkedArticle ? "\u00A0*" : ""), // U+00A0 NO-BREAK SPACE
label: '{{' + obj + '}}: ' + properties.description + (properties.linkedArticle ? '\u00A0*' : ''), // U+00A0 NO-BREAK SPACE
tooltip: properties.tooltip // may be undefined
tooltip: properties.tooltip // may be undefined
} : {
} : {
value: obj,
value: obj,
label: "{{" + obj + "}}"
label: '{{' + obj + '}}'
});
};
return result;
return result;
}),
}),
Line 207: Line 209:


switch (type) {
switch (type) {
case "standard":
case 'standard':
container.append({ type: 'header', label: 'General welcome templates' });
container.append({ type: 'header', label: 'General welcome templates' });
appendTemplates([
appendTemplates([
"welcome",
'welcome',
"welcome-short",
'welcome-short',
"welcome-personal",
'welcome-personal',
"welcome-graphical",
'welcome-graphical',
"welcome-menu",
'welcome-menu',
"welcome-screen",
'welcome-screen',
"welcome-belated",
'welcome-belated',
"welcome student",
'welcome student',
"welcome teacher",
'welcome teacher',
"welcome non-latin"
'welcome non-latin'
]);
]);
container.append({ type: 'header', label: 'Problem user welcome templates' });
container.append({ type: 'header', label: 'Problem user welcome templates' });
appendTemplates([
appendTemplates([
"welcomelaws",
'welcomelaws',
"first article",
'first article',
"welcometest",
'welcometest',
"welcomevandal",
'welcomevandal',
"welcomenpov",
'welcomenpov',
"welcomespam",
'welcomespam',
"welcomeunsourced",
'welcomeunsourced',
"welcomeauto",
'welcomeauto',
"welcome-COI",
'welcome-COI',
"welcome-delete",
'welcome-delete',
"welcome-image"
'welcome-image'
]);
]);
break;
break;
case "anonymous":
case 'anonymous':
container.append({ type: 'header', label: 'Anonymous user welcome templates' });
container.append({ type: 'header', label: 'Anonymous user welcome templates' });
appendTemplates([
appendTemplates([
"welcome-anon",
'welcome-anon',
"welcome-anon-test",
'welcome-anon-test',
"welcome-anon-unconstructive",
'welcome-anon-unconstructive',
"welcome-anon-constructive",
'welcome-anon-constructive',
"welcome-anon-delete"
'welcome-anon-delete'
]);
]);
break;
break;
case "wikiProject":
case 'wikiProject':
container.append({ type: 'header', label: 'WikiProject-specific welcome templates' });
container.append({ type: 'header', label: 'WikiProject-specific welcome templates' });
appendTemplates([
appendTemplates([
"welcome-anatomy",
'welcome-anatomy',
"welcome-athletics",
'welcome-athletics',
"welcome-au",
'welcome-au',
"welcome-bd",
'welcome-bd',
"welcome-bio",
'welcome-bio',
"welcome-cal",
'welcome-cal',
"welcome-conserv",
'welcome-conserv',
"welcome-cycling",
'welcome-cycling',
"welcome-dbz",
'welcome-dbz',
"welcome-et",
'welcome-et',
"welcome-de",
'welcome-de',
"welcome-in",
'welcome-in',
"welcome-math",
'welcome-math',
"welcome-med",
'welcome-med',
"welcome-no",
'welcome-no',
"welcome-pk",
'welcome-pk',
"welcome-phys",
'welcome-phys',
"welcome-pl",
'welcome-pl',
"welcome-roads",
'welcome-roads',
"welcome-rugbyunion",
'welcome-rugbyunion',
"welcome-ru",
'welcome-ru',
"welcome-starwars",
'welcome-starwars',
"welcome-ch",
'welcome-ch',
"welcome-uk",
'welcome-uk',
"welcome-videogames",
'welcome-videogames',
"TWA invite"
'TWA invite'
]);
]);
break;
break;
case "nonEnglish":
case 'nonEnglish':
container.append({ type: 'header', label: 'Non-English welcome templates' });
container.append({ type: 'header', label: 'Non-English welcome templates' });
appendTemplates([
appendTemplates([
"welcomeen",
'welcomeen',
"welcomeen-sq",
'welcomeen-sq',
"welcomeen-ar",
'welcomeen-ar',
"welcomeen-zh",
'welcomeen-zh',
"welcomeen-nl",
'welcomeen-nl',
"welcomeen-fi",
'welcomeen-fi',
"welcomeen-fr",
'welcomeen-fr',
"welcomeen-de",
'welcomeen-de',
"welcomeen-he",
'welcomeen-he',
"welcomeen-ja",
'welcomeen-ja',
"welcomeen-ko",
'welcomeen-ko',
"welcomeen-ml",
'welcomeen-ml',
"welcomeen-mr",
'welcomeen-mr',
"welcomeen-or",
'welcomeen-or',
"welcomeen-pt",
'welcomeen-pt',
"welcomeen-ro",
'welcomeen-ro',
"welcomeen-ru",
'welcomeen-ru',
"welcomeen-es",
'welcomeen-es',
"welcomeen-sv",
'welcomeen-sv',
"welcomeen-uk"
'welcomeen-uk'
]);
]);
break;
break;
Line 308: Line 310:


var rendered = container.render();
var rendered = container.render();
$(e.target.form).find("div#welcomeWorkArea").empty().append(rendered);
$(e.target.form).find('div#welcomeWorkArea').empty().append(rendered);


var firstRadio = e.target.form.template[0];
var firstRadio = e.target.form.template[0];
Line 317: Line 319:
Twinkle.welcome.selectTemplate = function(e) {
Twinkle.welcome.selectTemplate = function(e) {
var properties = Twinkle.welcome.templates[e.target.values];
var properties = Twinkle.welcome.templates[e.target.values];
e.target.form.article.disabled = (properties ? !properties.linkedArticle : false);
e.target.form.article.disabled = properties ? !properties.linkedArticle : false;
};
};


Line 332: Line 334:
// GENERAL WELCOMES
// GENERAL WELCOMES


"welcome": {
'welcome': {
description: "standard welcome",
description: 'standard welcome',
linkedArticle: true,
linkedArticle: true,
syntax: "{{subst:welcome|$USERNAME$|art=$ARTICLE$}} ~~~~"
syntax: '{{subst:welcome|$USERNAME$|art=$ARTICLE$}} ~~~~'
},
},
"welcome-short": {
'welcome-short': {
description: "a shorter welcome message",
description: 'a shorter welcome message',
linkedArticle: false,
linkedArticle: false,
syntax: "{{subst:welcome-short|$USERNAME$}} $EXTRA$ ~~~~"
syntax: '{{subst:welcome-short|$USERNAME$}} $EXTRA$ ~~~~'
},
},
"welcome-personal": {
'welcome-personal': {
description: "more personal welcome, including a plate of cookies",
description: 'more personal welcome, including a plate of cookies',
linkedArticle: false,
linkedArticle: false,
syntax: "{{subst:welcome-personal|$USERNAME$}} ~~~~"
syntax: '{{subst:welcome-personal|$USERNAME$}} ~~~~'
},
},
"welcome-graphical": {
'welcome-graphical': {
description: "colorful welcome message with table of about 20 links",
description: 'colorful welcome message with table of about 20 links',
linkedArticle: false,
linkedArticle: false,
syntax: "$HEADER$ {{subst:welcome-graphical|$EXTRA$}}"
syntax: '$HEADER$ {{subst:welcome-graphical|$EXTRA$}}'
},
},
"welcome-menu": {
'welcome-menu': {
description: "welcome message with large table of about 60 links",
description: 'welcome message with large table of about 60 links',
linkedArticle: false,
linkedArticle: false,
syntax: "{{subst:welcome-menu}}"
syntax: '{{subst:welcome-menu}}'
},
},
"welcome-screen": {
'welcome-screen': {
description: "welcome message with clear, annotated table of 10 links",
description: 'welcome message with clear, annotated table of 10 links',
linkedArticle: false,
linkedArticle: false,
syntax: "$HEADER$ {{subst:welcome-screen}}"
syntax: '$HEADER$ {{subst:welcome-screen}}'
},
},
"welcome-belated": {
'welcome-belated': {
description: "welcome for users with more substantial contributions",
description: 'welcome for users with more substantial contributions',
linkedArticle: false,
linkedArticle: false,
syntax: "{{subst:welcome-belated|$USERNAME$}}"
syntax: '{{subst:welcome-belated|$USERNAME$}}'
},
},
"welcome student": {
'welcome student': {
description: "welcome for students editing as part of an educational class project",
description: 'welcome for students editing as part of an educational class project',
linkedArticle: false,
linkedArticle: false,
syntax: "$HEADER$ {{subst:welcome student|$USERNAME$}} ~~~~"
syntax: '$HEADER$ {{subst:welcome student|$USERNAME$}} ~~~~'
},
},
"welcome teacher": {
'welcome teacher': {
description: "welcome for course instructors involved in an educational class project",
description: 'welcome for course instructors involved in an educational class project',
linkedArticle: false,
linkedArticle: false,
syntax: "$HEADER$ {{subst:welcome teacher|$USERNAME$}} ~~~~"
syntax: '$HEADER$ {{subst:welcome teacher|$USERNAME$}} ~~~~'
},
},
"welcome non-latin": {
'welcome non-latin': {
description: "welcome for users with a username containing non-Latin characters",
description: 'welcome for users with a username containing non-Latin characters',
linkedArticle: false,
linkedArticle: false,
syntax: "{{subst:welcome non-latin|$USERNAME$}} ~~~~"
syntax: '{{subst:welcome non-latin|$USERNAME$}} ~~~~'
},
},


// PROBLEM USER WELCOMES
// PROBLEM USER WELCOMES


"welcomelaws": {
'welcomelaws': {
description: "welcome with information about copyrights, NPOV, the sandbox, and vandalism",
description: 'welcome with information about copyrights, NPOV, the sandbox, and vandalism',
linkedArticle: false,
linkedArticle: false,
syntax: "{{subst:welcomelaws|$USERNAME$}} ~~~~"
syntax: '{{subst:welcomelaws|$USERNAME$}} ~~~~'
},
},
"first article": {
'first article': {
description: "for someone whose first article did not meet page creation guidelines",
description: 'for someone whose first article did not meet page creation guidelines',
linkedArticle: true,
linkedArticle: true,
syntax: "{{subst:first article|$ARTICLE$|$USERNAME$}}"
syntax: '{{subst:first article|$ARTICLE$|$USERNAME$}}'
},
},
"welcometest": {
'welcometest': {
description: "for someone whose initial efforts appear to be tests",
description: 'for someone whose initial efforts appear to be tests',
linkedArticle: true,
linkedArticle: true,
syntax: "{{subst:welcometest|$ARTICLE$|$USERNAME$}} ~~~~"
syntax: '{{subst:welcometest|$ARTICLE$|$USERNAME$}} ~~~~'
},
},
"welcomevandal": {
'welcomevandal': {
description: "for someone whose initial efforts appear to be vandalism",
description: 'for someone whose initial efforts appear to be vandalism',
linkedArticle: true,
linkedArticle: true,
syntax: "{{subst:welcomevandal|$ARTICLE$|$USERNAME$}}"
syntax: '{{subst:welcomevandal|$ARTICLE$|$USERNAME$}}'
},
},
"welcomenpov": {
'welcomenpov': {
description: "for someone whose initial efforts do not adhere to the neutral point of view policy",
description: 'for someone whose initial efforts do not adhere to the neutral point of view policy',
linkedArticle: true,
linkedArticle: true,
syntax: "{{subst:welcomenpov|$ARTICLE$|$USERNAME$}} ~~~~"
syntax: '{{subst:welcomenpov|$ARTICLE$|$USERNAME$}} ~~~~'
},
},
"welcomespam": {
'welcomespam': {
description: "welcome with additional discussion of anti-spamming policies",
description: 'welcome with additional discussion of anti-spamming policies',
linkedArticle: true,
linkedArticle: true,
syntax: "{{subst:welcomespam|$ARTICLE$|$USERNAME$}} ~~~~"
syntax: '{{subst:welcomespam|$ARTICLE$|$USERNAME$}} ~~~~'
},
},
"welcomeunsourced": {
'welcomeunsourced': {
description: "for someone whose initial efforts are unsourced",
description: 'for someone whose initial efforts are unsourced',
linkedArticle: true,
linkedArticle: true,
syntax: "{{subst:welcomeunsourced|$ARTICLE$|$USERNAME$}} ~~~~"
syntax: '{{subst:welcomeunsourced|$ARTICLE$|$USERNAME$}} ~~~~'
},
},
"welcomeauto": {
'welcomeauto': {
description: "for someone who created an autobiographical article",
description: 'for someone who created an autobiographical article',
linkedArticle: true,
linkedArticle: true,
syntax: "{{subst:welcomeauto|$USERNAME$|art=$ARTICLE$}} ~~~~"
syntax: '{{subst:welcomeauto|$USERNAME$|art=$ARTICLE$}} ~~~~'
},
},
"welcome-COI": {
'welcome-COI': {
description: "for someone who has edited in areas where they may have a conflict of interest",
description: 'for someone who has edited in areas where they may have a conflict of interest',
linkedArticle: true,
linkedArticle: true,
syntax: "{{subst:welcome-COI|$USERNAME$|art=$ARTICLE$}} ~~~~"
syntax: '{{subst:welcome-COI|$USERNAME$|art=$ARTICLE$}} ~~~~'
},
},
"welcome-delete": {
'welcome-delete': {
description: "for someone who has been removing information from articles",
description: 'for someone who has been removing information from articles',
linkedArticle: true,
linkedArticle: true,
syntax: "{{subst:welcome-delete|$ARTICLE$|$USERNAME$}} ~~~~"
syntax: '{{subst:welcome-delete|$ARTICLE$|$USERNAME$}} ~~~~'
},
},
"welcome-image": {
'welcome-image': {
description: "welcome with additional information about images (policy and procedure)",
description: 'welcome with additional information about images (policy and procedure)',
linkedArticle: true,
linkedArticle: true,
syntax: "{{subst:welcome-image|$USERNAME$|art=$ARTICLE$}}"
syntax: '{{subst:welcome-image|$USERNAME$|art=$ARTICLE$}}'
},
},


// ANONYMOUS USER WELCOMES
// ANONYMOUS USER WELCOMES


"welcome-anon": {
'welcome-anon': {
description: "for anonymous users; encourages creating an account",
description: 'for anonymous users; encourages creating an account',
linkedArticle: true,
linkedArticle: true,
syntax: "{{subst:welcome-anon|art=$ARTICLE$}} ~~~~"
syntax: '{{subst:welcome-anon|art=$ARTICLE$}} ~~~~'
},
},
"welcome-anon-test": {
'welcome-anon-test': {
description: "for anonymous users who have performed test edits",
description: 'for anonymous users who have performed test edits',
linkedArticle: true,
linkedArticle: true,
syntax: "{{subst:welcome-anon-test|$ARTICLE$|$USERNAME$}} ~~~~"
syntax: '{{subst:welcome-anon-test|$ARTICLE$|$USERNAME$}} ~~~~'
},
},
"welcome-anon-unconstructive": {
'welcome-anon-unconstructive': {
description: "for anonymous users who have vandalized or made unhelpful edits",
description: 'for anonymous users who have vandalized or made unhelpful edits',
linkedArticle: true,
linkedArticle: true,
syntax: "{{subst:welcome-anon-unconstructive|$ARTICLE$|$USERNAME$}}"
syntax: '{{subst:welcome-anon-unconstructive|$ARTICLE$|$USERNAME$}}'
},
},
"welcome-anon-constructive": {
'welcome-anon-constructive': {
description: "for anonymous users who fight vandalism or edit constructively",
description: 'for anonymous users who fight vandalism or edit constructively',
linkedArticle: true,
linkedArticle: true,
syntax: "{{subst:welcome-anon-constructive|art=$ARTICLE$}}"
syntax: '{{subst:welcome-anon-constructive|art=$ARTICLE$}}'
},
},
"welcome-anon-delete": {
'welcome-anon-delete': {
description: "for anonymous users who have removed content from pages",
description: 'for anonymous users who have removed content from pages',
linkedArticle: true,
linkedArticle: true,
syntax: "{{subst:welcome-anon-delete|$ARTICLE$|$USERNAME$}} ~~~~"
syntax: '{{subst:welcome-anon-delete|$ARTICLE$|$USERNAME$}} ~~~~'
},
},


// WIKIPROJECT-SPECIFIC WELCOMES
// WIKIPROJECT-SPECIFIC WELCOMES


"welcome-anatomy": {
'welcome-anatomy': {
description: "welcome for users with an apparent interest in anatomy topics",
description: 'welcome for users with an apparent interest in anatomy topics',
linkedArticle: false,
linkedArticle: false,
syntax: "{{subst:welcome-anatomy}} ~~~~"
syntax: '{{subst:welcome-anatomy}} ~~~~'
},
},
"welcome-athletics": {
'welcome-athletics': {
description: "welcome for users with an apparent interest in athletics (track and field) topics",
description: 'welcome for users with an apparent interest in athletics (track and field) topics',
linkedArticle: false,
linkedArticle: false,
syntax: "{{subst:welcome-athletics}}"
syntax: '{{subst:welcome-athletics}}'
},
},
"welcome-au": {
'welcome-au': {
description: "welcome for users with an apparent interest in Australia topics",
description: 'welcome for users with an apparent interest in Australia topics',
linkedArticle: false,
linkedArticle: false,
syntax: "{{subst:welcome-au}} ~~~~"
syntax: '{{subst:welcome-au}} ~~~~'
},
},
"welcome-bd": {
'welcome-bd': {
description: "welcome for users with an apparent interest in Bangladesh topics",
description: 'welcome for users with an apparent interest in Bangladesh topics',
linkedArticle: true,
linkedArticle: true,
syntax: "{{subst:welcome-bd|$USERNAME$||$EXTRA$|art=$ARTICLE$}} ~~~~"
syntax: '{{subst:welcome-bd|$USERNAME$||$EXTRA$|art=$ARTICLE$}} ~~~~'
},
},
"welcome-bio": {
'welcome-bio': {
description: "welcome for users with an apparent interest in biographical topics",
description: 'welcome for users with an apparent interest in biographical topics',
linkedArticle: false,
linkedArticle: false,
syntax: "{{subst:welcome-bio}} ~~~~"
syntax: '{{subst:welcome-bio}} ~~~~'
},
},
"welcome-cal": {
'welcome-cal': {
description: "welcome for users with an apparent interest in California topics",
description: 'welcome for users with an apparent interest in California topics',
linkedArticle: false,
linkedArticle: false,
syntax: "{{subst:welcome-cal}} ~~~~"
syntax: '{{subst:welcome-cal}} ~~~~'
},
},
"welcome-conserv": {
'welcome-conserv': {
description: "welcome for users with an apparent interest in conservatism topics",
description: 'welcome for users with an apparent interest in conservatism topics',
linkedArticle: false,
linkedArticle: false,
syntax: "{{subst:welcome-conserv}}"
syntax: '{{subst:welcome-conserv}}'
},
},
"welcome-cycling": {
'welcome-cycling': {
description: "welcome for users with an apparent interest in cycling topics",
description: 'welcome for users with an apparent interest in cycling topics',
linkedArticle: false,
linkedArticle: false,
syntax: "{{subst:welcome-cycling}} ~~~~"
syntax: '{{subst:welcome-cycling}} ~~~~'
},
},
"welcome-dbz": {
'welcome-dbz': {
description: "welcome for users with an apparent interest in Dragon Ball topics",
description: 'welcome for users with an apparent interest in Dragon Ball topics',
linkedArticle: false,
linkedArticle: false,
syntax: "{{subst:welcome-dbz|$EXTRA$|sig=~~~~}}"
syntax: '{{subst:welcome-dbz|$EXTRA$|sig=~~~~}}'
},
},
"welcome-et": {
'welcome-et': {
description: "welcome for users with an apparent interest in Estonia topics",
description: 'welcome for users with an apparent interest in Estonia topics',
linkedArticle: false,
linkedArticle: false,
syntax: "{{subst:welcome-et}}"
syntax: '{{subst:welcome-et}}'
},
},
"welcome-de": {
'welcome-de': {
description: "welcome for users with an apparent interest in Germany topics",
description: 'welcome for users with an apparent interest in Germany topics',
linkedArticle: false,
linkedArticle: false,
syntax: "{{subst:welcome-de}} ~~~~"
syntax: '{{subst:welcome-de}} ~~~~'
},
},
"welcome-in": {
'welcome-in': {
description: "welcome for users with an apparent interest in India topics",
description: 'welcome for users with an apparent interest in India topics',
linkedArticle: true,
linkedArticle: true,
syntax: "{{subst:welcome-in|$USERNAME$|art=$ARTICLE$}} ~~~~"
syntax: '{{subst:welcome-in|$USERNAME$|art=$ARTICLE$}} ~~~~'
},
},
"welcome-math": {
'welcome-math': {
description: "welcome for users with an apparent interest in mathematical topics",
description: 'welcome for users with an apparent interest in mathematical topics',
linkedArticle: true,
linkedArticle: true,
syntax: "{{subst:welcome-math|$USERNAME$|art=$ARTICLE$}} ~~~~"
syntax: '{{subst:welcome-math|$USERNAME$|art=$ARTICLE$}} ~~~~'
},
},
"welcome-med": {
'welcome-med': {
description: "welcome for users with an apparent interest in medicine topics",
description: 'welcome for users with an apparent interest in medicine topics',
linkedArticle: true,
linkedArticle: true,
syntax: "{{subst:welcome-med|$USERNAME$|art=$ARTICLE$}} ~~~~"
syntax: '{{subst:welcome-med|$USERNAME$|art=$ARTICLE$}} ~~~~'
},
},
"welcome-no": {
'welcome-no': {
description: "welcome for users with an apparent interest in Norway topics",
description: 'welcome for users with an apparent interest in Norway topics',
linkedArticle: false,
linkedArticle: false,
syntax: "{{subst:welcome-no}} ~~~~"
syntax: '{{subst:welcome-no}} ~~~~'
},
},
"welcome-pk": {
'welcome-pk': {
description: "welcome for users with an apparent interest in Pakistan topics",
description: 'welcome for users with an apparent interest in Pakistan topics',
linkedArticle: true,
linkedArticle: true,
syntax: "{{subst:welcome-pk|$USERNAME$|art=$ARTICLE$}} ~~~~"
syntax: '{{subst:welcome-pk|$USERNAME$|art=$ARTICLE$}} ~~~~'
},
},
"welcome-phys": {
'welcome-phys': {
description: "welcome for users with an apparent interest in physics topics",
description: 'welcome for users with an apparent interest in physics topics',
linkedArticle: true,
linkedArticle: true,
syntax: "{{subst:welcome-phys|$USERNAME$|art=$ARTICLE$}} ~~~~"
syntax: '{{subst:welcome-phys|$USERNAME$|art=$ARTICLE$}} ~~~~'
},
},
"welcome-pl": {
'welcome-pl': {
description: "welcome for users with an apparent interest in Poland topics",
description: 'welcome for users with an apparent interest in Poland topics',
linkedArticle: false,
linkedArticle: false,
syntax: "{{subst:welcome-pl}} ~~~~"
syntax: '{{subst:welcome-pl}} ~~~~'
},
},
"welcome-rugbyunion": {
'welcome-rugbyunion': {
description: "welcome for users with an apparent interest in rugby union topics",
description: 'welcome for users with an apparent interest in rugby union topics',
linkedArticle: false,
linkedArticle: false,
syntax: "{{subst:welcome-rugbyunion}} ~~~~"
syntax: '{{subst:welcome-rugbyunion}} ~~~~'
},
},
"welcome-ru": {
'welcome-ru': {
description: "welcome for users with an apparent interest in Russia topics",
description: 'welcome for users with an apparent interest in Russia topics',
linkedArticle: false,
linkedArticle: false,
syntax: "{{subst:welcome-ru}} ~~~~"
syntax: '{{subst:welcome-ru}} ~~~~'
},
},
"welcome-starwars": {
'welcome-starwars': {
description: "welcome for users with an apparent interest in Star Wars topics",
description: 'welcome for users with an apparent interest in Star Wars topics',
linkedArticle: false,
linkedArticle: false,
syntax: "{{subst:welcome-starwars}} ~~~~"
syntax: '{{subst:welcome-starwars}} ~~~~'
},
},
"welcome-ch": {
'welcome-ch': {
description: "welcome for users with an apparent interest in Switzerland topics",
description: 'welcome for users with an apparent interest in Switzerland topics',
linkedArticle: true,
linkedArticle: true,
syntax: "{{subst:welcome-ch|$USERNAME$|art=$ARTICLE$}} ~~~~"
syntax: '{{subst:welcome-ch|$USERNAME$|art=$ARTICLE$}} ~~~~'
},
},
"welcome-uk": {
'welcome-uk': {
description: "welcome for users with an apparent interest in Ukraine topics",
description: 'welcome for users with an apparent interest in Ukraine topics',
linkedArticle: false,
linkedArticle: false,
syntax: "{{subst:welcome-uk}} ~~~~"
syntax: '{{subst:welcome-uk}} ~~~~'
},
},
"welcome-roads": {
'welcome-roads': {
description: "welcome for users with an apparent interest in roads and highways topics",
description: 'welcome for users with an apparent interest in roads and highways topics',
linkedArticle: false,
linkedArticle: false,
syntax: "{{subst:welcome-roads}}"
syntax: '{{subst:welcome-roads}}'
},
},
"welcome-videogames": {
'welcome-videogames': {
description: "welcome for users with an apparent interest in video game topics",
description: 'welcome for users with an apparent interest in video game topics',
linkedArticle: false,
linkedArticle: false,
syntax: "{{subst:welcome-videogames}}"
syntax: '{{subst:welcome-videogames}}'
},
},
"TWA invite": {
'TWA invite': {
description: "invite the user to The Wikipedia Adventure (not a welcome template)",
description: 'invite the user to The Wikipedia Adventure (not a welcome template)',
linkedArticle: false,
linkedArticle: false,
syntax: "{{WP:TWA/InviteTW|signature=~~~~}}"
syntax: '{{WP:TWA/InviteTW|signature=~~~~}}'
},
},


// NON-ENGLISH WELCOMES
// NON-ENGLISH WELCOMES


"welcomeen": {
'welcomeen': {
description: "welcome for users whose first language is not listed here",
description: 'welcome for users whose first language is not listed here',
linkedArticle: false,
linkedArticle: false,
syntax: "{{subst:welcomeen}}"
syntax: '{{subst:welcomeen}}'
},
},
"welcomeen-ar": {
'welcomeen-ar': {
description: "welcome for users whose first language appears to be Arabic",
description: 'welcome for users whose first language appears to be Arabic',
linkedArticle: false,
linkedArticle: false,
syntax: "{{subst:welcomeen-ar}}"
syntax: '{{subst:welcomeen-ar}}'
},
},
"welcomeen-sq": {
'welcomeen-sq': {
description: "welcome for users whose first language appears to be Albanian",
description: 'welcome for users whose first language appears to be Albanian',
linkedArticle: false,
linkedArticle: false,
syntax: "{{subst:welcomeen-sq}}"
syntax: '{{subst:welcomeen-sq}}'
},
},
"welcomeen-zh": {
'welcomeen-zh': {
description: "welcome for users whose first language appears to be Chinese",
description: 'welcome for users whose first language appears to be Chinese',
linkedArticle: false,
linkedArticle: false,
syntax: "{{subst:welcomeen-zh}}"
syntax: '{{subst:welcomeen-zh}}'
},
},
"welcomeen-nl": {
'welcomeen-nl': {
description: "welcome for users whose first language appears to be Dutch",
description: 'welcome for users whose first language appears to be Dutch',
linkedArticle: false,
linkedArticle: false,
syntax: "{{subst:welcomeen-nl}}"
syntax: '{{subst:welcomeen-nl}}'
},
},
"welcomeen-fi": {
'welcomeen-fi': {
description: "welcome for users whose first language appears to be Finnish",
description: 'welcome for users whose first language appears to be Finnish',
linkedArticle: false,
linkedArticle: false,
syntax: "{{subst:welcomeen-fi}}"
syntax: '{{subst:welcomeen-fi}}'
},
},
"welcomeen-fr": {
'welcomeen-fr': {
description: "welcome for users whose first language appears to be French",
description: 'welcome for users whose first language appears to be French',
linkedArticle: false,
linkedArticle: false,
syntax: "{{subst:welcomeen-fr}}"
syntax: '{{subst:welcomeen-fr}}'
},
},
"welcomeen-de": {
'welcomeen-de': {
description: "welcome for users whose first language appears to be German",
description: 'welcome for users whose first language appears to be German',
linkedArticle: false,
linkedArticle: false,
syntax: "{{subst:welcomeen-de}}"
syntax: '{{subst:welcomeen-de}}'
},
},
"welcomeen-he": {
'welcomeen-he': {
description: "welcome for users whose first language appears to be Hebrew",
description: 'welcome for users whose first language appears to be Hebrew',
linkedArticle: false,
linkedArticle: false,
syntax: "{{subst:welcomeen-he}}"
syntax: '{{subst:welcomeen-he}}'
},
},
"welcomeen-ja": {
'welcomeen-ja': {
description: "welcome for users whose first language appears to be Japanese",
description: 'welcome for users whose first language appears to be Japanese',
linkedArticle: false,
linkedArticle: false,
syntax: "{{subst:welcomeen-ja}}"
syntax: '{{subst:welcomeen-ja}}'
},
},
"welcomeen-ko": {
'welcomeen-ko': {
description: "welcome for users whose first language appears to be Korean",
description: 'welcome for users whose first language appears to be Korean',
linkedArticle: false,
linkedArticle: false,
syntax: "{{subst:welcomeen-ko}}"
syntax: '{{subst:welcomeen-ko}}'
},
},
"welcomeen-ml": {
'welcomeen-ml': {
description: "welcome for users whose first language appears to be Malayalam",
description: 'welcome for users whose first language appears to be Malayalam',
linkedArticle: false,
linkedArticle: false,
syntax: "{{subst:welcomeen-ml}}"
syntax: '{{subst:welcomeen-ml}}'
},
},
"welcomeen-mr": {
'welcomeen-mr': {
description: "welcome for users whose first language appears to be Marathi",
description: 'welcome for users whose first language appears to be Marathi',
linkedArticle: false,
linkedArticle: false,
syntax: "{{subst:welcomeen-mr}}"
syntax: '{{subst:welcomeen-mr}}'
},
},
"welcomeen-or": {
'welcomeen-or': {
description: "welcome for users whose first language appears to be Oriya (Odia)",
description: 'welcome for users whose first language appears to be Oriya (Odia)',
linkedArticle: false,
linkedArticle: false,
syntax: "{{subst:welcomeen-or}}"
syntax: '{{subst:welcomeen-or}}'
},
},
"welcomeen-pt": {
'welcomeen-pt': {
description: "welcome for users whose first language appears to be Portuguese",
description: 'welcome for users whose first language appears to be Portuguese',
linkedArticle: false,
linkedArticle: false,
syntax: "{{subst:welcomeen-pt}}"
syntax: '{{subst:welcomeen-pt}}'
},
},
"welcomeen-ro": {
'welcomeen-ro': {
description: "welcome for users whose first language appears to be Romanian",
description: 'welcome for users whose first language appears to be Romanian',
linkedArticle: false,
linkedArticle: false,
syntax: "{{subst:welcomeen-ro}}"
syntax: '{{subst:welcomeen-ro}}'
},
},
"welcomeen-ru": {
'welcomeen-ru': {
description: "welcome for users whose first language appears to be Russian",
description: 'welcome for users whose first language appears to be Russian',
linkedArticle: false,
linkedArticle: false,
syntax: "{{subst:welcomeen-ru}}"
syntax: '{{subst:welcomeen-ru}}'
},
},
"welcomeen-es": {
'welcomeen-es': {
description: "welcome for users whose first language appears to be Spanish",
description: 'welcome for users whose first language appears to be Spanish',
linkedArticle: false,
linkedArticle: false,
syntax: "{{subst:welcomeen-es}}"
syntax: '{{subst:welcomeen-es}}'
},
},
"welcomeen-sv": {
'welcomeen-sv': {
description: "welcome for users whose first language appears to be Swedish",
description: 'welcome for users whose first language appears to be Swedish',
linkedArticle: false,
linkedArticle: false,
syntax: "{{subst:welcomeen-sv}}"
syntax: '{{subst:welcomeen-sv}}'
},
},
"welcomeen-uk": {
'welcomeen-uk': {
description: "welcome for users whose first language appears to be Ukrainian",
description: 'welcome for users whose first language appears to be Ukrainian',
linkedArticle: false,
linkedArticle: false,
syntax: "{{subst:welcomeen-uk}}"
syntax: '{{subst:welcomeen-uk}}'
}
}
};
};
Line 710: Line 712:
if (properties) {
if (properties) {
return properties.syntax.
return properties.syntax.
replace("$USERNAME$", Twinkle.getFriendlyPref("insertUsername") ? mw.config.get("wgUserName") : "").
replace('$USERNAME$', Twinkle.getFriendlyPref('insertUsername') ? mw.config.get('wgUserName') : '').
replace("$ARTICLE$", article ? article : "").
replace('$ARTICLE$', article ? article : '').
replace(/\$HEADER\$\s*/, "== Welcome ==\n\n").
replace(/\$HEADER\$\s*/, '== Welcome ==\n\n').
replace("$EXTRA$", ""); // EXTRA is not implemented yet
replace('$EXTRA$', ''); // EXTRA is not implemented yet
} else {
return "{{subst:" + template + (article ? ("|art=" + article) : "") + "}}" +
(Twinkle.getFriendlyPref("customWelcomeSignature") ? " ~~~~" : "");
}
}
return '{{subst:' + template + (article ? '|art=' + article : '') + '}}' +
(Twinkle.getFriendlyPref('customWelcomeSignature') ? ' ~~~~' : '');
};
};


Line 723: Line 724:
preview: function(form) {
preview: function(form) {
var previewDialog = new Morebits.simpleWindow(750, 400);
var previewDialog = new Morebits.simpleWindow(750, 400);
previewDialog.setTitle("Welcome template preview");
previewDialog.setTitle('Welcome template preview');
previewDialog.setScriptName("Welcome user");
previewDialog.setScriptName('Welcome user');
previewDialog.setModality(true);
previewDialog.setModality(true);


var previewdiv = document.createElement("div");
var previewdiv = document.createElement('div');
previewdiv.style.marginLeft = previewdiv.style.marginRight = "0.5em";
previewdiv.style.marginLeft = previewdiv.style.marginRight = '0.5em';
previewdiv.style.fontSize = "small";
previewdiv.style.fontSize = 'small';
previewDialog.setContent(previewdiv);
previewDialog.setContent(previewdiv);


var previewer = new Morebits.wiki.preview(previewdiv);
var previewer = new Morebits.wiki.preview(previewdiv);
previewer.beginRender(Twinkle.welcome.getTemplateWikitext(form.getChecked("template"), form.article.value), 'User talk:' + mw.config.get('wgRelevantUserName')); // Force wikitext/correct username
previewer.beginRender(Twinkle.welcome.getTemplateWikitext(form.getChecked('template'), form.article.value), 'User talk:' + mw.config.get('wgRelevantUserName')); // Force wikitext/correct username


var submit = document.createElement("input");
var submit = document.createElement('input');
submit.setAttribute("type", "submit");
submit.setAttribute('type', 'submit');
submit.setAttribute("value", "Close");
submit.setAttribute('value', 'Close');
previewDialog.addContent(submit);
previewDialog.addContent(submit);


Line 746: Line 747:
});
});
},
},
main: function( pageobj ) {
main: function(pageobj) {
var params = pageobj.getCallbackParameters();
var params = pageobj.getCallbackParameters();
var text = pageobj.getPageText();
var text = pageobj.getPageText();


// abort if mode is auto and form is not empty
// abort if mode is auto and form is not empty
if( pageobj.exists() && params.mode === 'auto' ) {
if (pageobj.exists() && params.mode === 'auto') {
Morebits.status.info( 'Warning', 'User talk page not empty; aborting automatic welcome' );
Morebits.status.info('Warning', 'User talk page not empty; aborting automatic welcome');
Morebits.wiki.actionCompleted.event();
Morebits.wiki.actionCompleted.event();
return;
return;
Line 759: Line 760:
var welcomeText = Twinkle.welcome.getTemplateWikitext(params.value, params.article);
var welcomeText = Twinkle.welcome.getTemplateWikitext(params.value, params.article);


if( Twinkle.getFriendlyPref('topWelcomes') ) {
if (Twinkle.getFriendlyPref('topWelcomes')) {
text = welcomeText + '\n\n' + text;
text = welcomeText + '\n\n' + text;
} else {
} else {
text += "\n" + welcomeText;
text += '\n' + welcomeText;
}
}


var summaryText = "Welcome to Wikipedia!";
var summaryText = 'Welcome to Wikipedia!';
pageobj.setPageText(text);
pageobj.setPageText(text);
pageobj.setEditSummary(summaryText + Twinkle.getPref('summaryAd'));
pageobj.setEditSummary(summaryText + Twinkle.getPref('summaryAd'));
Line 778: Line 779:


var params = {
var params = {
value: form.getChecked("template"),
value: form.getChecked('template'),
article: form.article.value,
article: form.article.value,
mode: 'manual'
mode: 'manual'
};
};


Morebits.simpleWindow.setButtonsEnabled( false );
Morebits.simpleWindow.setButtonsEnabled(false);
Morebits.status.init( form );
Morebits.status.init(form);


var userTalkPage = mw.config.get('wgFormattedNamespaces')[3] + ':' + mw.config.get('wgRelevantUserName');
var userTalkPage = mw.config.get('wgFormattedNamespaces')[3] + ':' + mw.config.get('wgRelevantUserName');
Morebits.wiki.actionCompleted.redirect = userTalkPage;
Morebits.wiki.actionCompleted.redirect = userTalkPage;
Morebits.wiki.actionCompleted.notice = "Welcoming complete, reloading talk page in a few seconds";
Morebits.wiki.actionCompleted.notice = 'Welcoming complete, reloading talk page in a few seconds';


var wikipedia_page = new Morebits.wiki.page(userTalkPage, "User talk page modification");
var wikipedia_page = new Morebits.wiki.page(userTalkPage, 'User talk page modification');
wikipedia_page.setFollowRedirect(true);
wikipedia_page.setFollowRedirect(true);
wikipedia_page.setCallbackParameters(params);
wikipedia_page.setCallbackParameters(params);
Line 798: Line 799:




//</nowiki>
// </nowiki>

Latest revision as of 19:48, 12 June 2019

// <nowiki>


(function($) {


/*
 ****************************************
 *** friendlywelcome.js: Welcome module
 ****************************************
 * Mode of invocation:     Tab ("Wel"), or from links on diff pages
 * Active on:              Any page with relevant user name (userspace,
 *                         contribs, etc.) and diff pages
 * Config directives in:   FriendlyConfig
 */

Twinkle.welcome = function friendlywelcome() {
	if (Morebits.queryString.exists('friendlywelcome')) {
		if (Morebits.queryString.get('friendlywelcome') === 'auto') {
			Twinkle.welcome.auto();
		} else {
			Twinkle.welcome.semiauto();
		}
	} else {
		Twinkle.welcome.normal();
	}
};

Twinkle.welcome.auto = function() {
	if (Morebits.queryString.get('action') !== 'edit') {
		// userpage not empty, aborting auto-welcome
		return;
	}

	Twinkle.welcome.welcomeUser();
};

Twinkle.welcome.semiauto = function() {
	Twinkle.welcome.callback(mw.config.get('wgRelevantUserName'));
};

Twinkle.welcome.normal = function() {
	if (Morebits.queryString.exists('diff')) {
		// check whether the contributors' talk pages exist yet
		var $oList = $('#mw-diff-otitle2').find('span.mw-usertoollinks a.new:contains(talk)').first();
		var $nList = $('#mw-diff-ntitle2').find('span.mw-usertoollinks a.new:contains(talk)').first();

		if ($oList.length > 0 || $nList.length > 0) {
			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', 'welcome'));
			welcomeLink.appendChild(spanTag('Black', ']'));
			welcomeNode.appendChild(welcomeLink);

			if ($oList.length > 0) {
				var oHref = $oList.attr('href');

				var oWelcomeNode = welcomeNode.cloneNode(true);
				oWelcomeNode.firstChild.setAttribute('href', oHref + '&' + Morebits.queryString.create({
					'friendlywelcome': Twinkle.getFriendlyPref('quickWelcomeMode') === 'auto' ? 'auto' : 'norm',
					'vanarticle': Morebits.pageNameNorm
				}));
				$oList[0].parentNode.parentNode.appendChild(document.createTextNode(' '));
				$oList[0].parentNode.parentNode.appendChild(oWelcomeNode);
			}

			if ($nList.length > 0) {
				var nHref = $nList.attr('href');

				var nWelcomeNode = welcomeNode.cloneNode(true);
				nWelcomeNode.firstChild.setAttribute('href', nHref + '&' + Morebits.queryString.create({
					'friendlywelcome': Twinkle.getFriendlyPref('quickWelcomeMode') === 'auto' ? 'auto' : 'norm',
					'vanarticle': Morebits.pageNameNorm
				}));
				$nList[0].parentNode.parentNode.appendChild(document.createTextNode(' '));
				$nList[0].parentNode.parentNode.appendChild(nWelcomeNode);
			}
		}
	}
	if (mw.config.get('wgRelevantUserName')) {
		Twinkle.addPortletLink(function() {
			Twinkle.welcome.callback(mw.config.get('wgRelevantUserName'));
		}, 'Wel', 'friendly-welcome', 'Welcome user');
	}
};

Twinkle.welcome.welcomeUser = function welcomeUser() {
	Morebits.status.init(document.getElementById('mw-content-text'));
	$('#catlinks').remove();

	var params = {
		value: Twinkle.getFriendlyPref('quickWelcomeTemplate'),
		article: Morebits.queryString.exists('vanarticle') ? Morebits.queryString.get('vanarticle') : '',
		mode: 'auto'
	};

	var userTalkPage = mw.config.get('wgFormattedNamespaces')[3] + ':' + mw.config.get('wgRelevantUserName');
	Morebits.wiki.actionCompleted.redirect = userTalkPage;
	Morebits.wiki.actionCompleted.notice = 'Welcoming complete, reloading talk page in a few seconds';

	var wikipedia_page = new Morebits.wiki.page(userTalkPage, 'User talk page modification');
	wikipedia_page.setFollowRedirect(true);
	wikipedia_page.setCallbackParameters(params);
	wikipedia_page.load(Twinkle.welcome.callbacks.main);
};

Twinkle.welcome.callback = function friendlywelcomeCallback(uid) {
	if (uid === mw.config.get('wgUserName') && !confirm('Are you really sure you want to welcome yourself?...')) {
		return;
	}

	var Window = new Morebits.simpleWindow(600, 420);
	Window.setTitle('Welcome user');
	Window.setScriptName('Twinkle');
	Window.addFooterLink('Welcoming Committee', 'WP:WC');
	Window.addFooterLink('Twinkle help', 'WP:TW/DOC#welcome');

	var form = new Morebits.quickForm(Twinkle.welcome.callback.evaluate);

	form.append({
		type: 'select',
		name: 'type',
		label: 'Type of welcome: ',
		event: Twinkle.welcome.populateWelcomeList,
		list: [
			{ type: 'option', value: 'standard', label: 'Standard welcomes', selected: !mw.util.isIPAddress(mw.config.get('wgRelevantUserName')) },
			{ type: 'option', value: 'anonymous', label: 'IP user welcomes', selected: mw.util.isIPAddress(mw.config.get('wgRelevantUserName')) },
			{ type: 'option', value: 'wikiProject', label: 'WikiProject welcomes' },
			{ type: 'option', value: 'nonEnglish', label: 'Non-English welcomes' }
		]
	});

	form.append({
		type: 'div',
		id: 'welcomeWorkArea',
		className: 'morebits-scrollbox'
	});

	form.append({
		type: 'input',
		name: 'article',
		label: '* Linked article (if supported by template):',
		value: Morebits.queryString.exists('vanarticle') ? Morebits.queryString.get('vanarticle') : '',
		tooltip: 'An article might be linked from within the welcome if the template supports it. Leave empty for no article to be linked.  Templates that support a linked article are marked with an asterisk.'
	});

	var previewlink = document.createElement('a');
	$(previewlink).click(function() {
		Twinkle.welcome.callbacks.preview(result);  // |result| is defined below
	});
	previewlink.style.cursor = 'pointer';
	previewlink.textContent = 'Preview';
	form.append({ type: 'div', name: 'welcomepreview', label: [ previewlink ] });

	form.append({ type: 'submit' });

	var result = form.render();
	Window.setContent(result);
	Window.display();

	// initialize the welcome list
	var evt = document.createEvent('Event');
	evt.initEvent('change', true, true);
	result.type.dispatchEvent(evt);
};

Twinkle.welcome.populateWelcomeList = function(e) {
	var type = e.target.value;

	var container = new Morebits.quickForm.element({ type: 'fragment' });

	if ((type === 'standard' || type === 'anonymous') && Twinkle.getFriendlyPref('customWelcomeList').length) {
		container.append({ type: 'header', label: 'Custom welcome templates' });
		container.append({
			type: 'radio',
			name: 'template',
			list: Twinkle.getFriendlyPref('customWelcomeList'),
			event: Twinkle.welcome.selectTemplate
		});
	}

	var appendTemplates = function(list) {
		container.append({
			type: 'radio',
			name: 'template',
			list: list.map(function(obj) {
				var properties = Twinkle.welcome.templates[obj];
				var result = properties ? {
					value: obj,
					label: '{{' + obj + '}}: ' + properties.description + (properties.linkedArticle ? '\u00A0*' : ''),  // U+00A0 NO-BREAK SPACE
					tooltip: properties.tooltip  // may be undefined
				} : {
					value: obj,
					label: '{{' + obj + '}}'
				};
				return result;
			}),
			event: Twinkle.welcome.selectTemplate
		});
	};

	switch (type) {
		case 'standard':
			container.append({ type: 'header', label: 'General welcome templates' });
			appendTemplates([
				'welcome',
				'welcome-short',
				'welcome-personal',
				'welcome-graphical',
				'welcome-menu',
				'welcome-screen',
				'welcome-belated',
				'welcome student',
				'welcome teacher',
				'welcome non-latin'
			]);
			container.append({ type: 'header', label: 'Problem user welcome templates' });
			appendTemplates([
				'welcomelaws',
				'first article',
				'welcometest',
				'welcomevandal',
				'welcomenpov',
				'welcomespam',
				'welcomeunsourced',
				'welcomeauto',
				'welcome-COI',
				'welcome-delete',
				'welcome-image'
			]);
			break;
		case 'anonymous':
			container.append({ type: 'header', label: 'Anonymous user welcome templates' });
			appendTemplates([
				'welcome-anon',
				'welcome-anon-test',
				'welcome-anon-unconstructive',
				'welcome-anon-constructive',
				'welcome-anon-delete'
			]);
			break;
		case 'wikiProject':
			container.append({ type: 'header', label: 'WikiProject-specific welcome templates' });
			appendTemplates([
				'welcome-anatomy',
				'welcome-athletics',
				'welcome-au',
				'welcome-bd',
				'welcome-bio',
				'welcome-cal',
				'welcome-conserv',
				'welcome-cycling',
				'welcome-dbz',
				'welcome-et',
				'welcome-de',
				'welcome-in',
				'welcome-math',
				'welcome-med',
				'welcome-no',
				'welcome-pk',
				'welcome-phys',
				'welcome-pl',
				'welcome-roads',
				'welcome-rugbyunion',
				'welcome-ru',
				'welcome-starwars',
				'welcome-ch',
				'welcome-uk',
				'welcome-videogames',
				'TWA invite'
			]);
			break;
		case 'nonEnglish':
			container.append({ type: 'header', label: 'Non-English welcome templates' });
			appendTemplates([
				'welcomeen',
				'welcomeen-sq',
				'welcomeen-ar',
				'welcomeen-zh',
				'welcomeen-nl',
				'welcomeen-fi',
				'welcomeen-fr',
				'welcomeen-de',
				'welcomeen-he',
				'welcomeen-ja',
				'welcomeen-ko',
				'welcomeen-ml',
				'welcomeen-mr',
				'welcomeen-or',
				'welcomeen-pt',
				'welcomeen-ro',
				'welcomeen-ru',
				'welcomeen-es',
				'welcomeen-sv',
				'welcomeen-uk'
			]);
			break;
		default:
			container.append({ type: 'div', label: 'Twinkle.welcome.populateWelcomeList: something went wrong' });
			break;
	}

	var rendered = container.render();
	$(e.target.form).find('div#welcomeWorkArea').empty().append(rendered);

	var firstRadio = e.target.form.template[0];
	firstRadio.checked = true;
	Twinkle.welcome.selectTemplate({ target: firstRadio });
};

Twinkle.welcome.selectTemplate = function(e) {
	var properties = Twinkle.welcome.templates[e.target.values];
	e.target.form.article.disabled = properties ? !properties.linkedArticle : false;
};


// A list of welcome templates and their properties and syntax

// The four fields that are available are "description", "linkedArticle", "syntax", and "tooltip".
// The three magic words that can be used in the "syntax" field are:
//   - $USERNAME$  - replaced by the welcomer's username, depending on user's preferences
//   - $ARTICLE$   - replaced by an article name, if "linkedArticle" is true
//   - $HEADER$    - adds a level 2 header (most templates already include this)

Twinkle.welcome.templates = {
	// GENERAL WELCOMES

	'welcome': {
		description: 'standard welcome',
		linkedArticle: true,
		syntax: '{{subst:welcome|$USERNAME$|art=$ARTICLE$}} ~~~~'
	},
	'welcome-short': {
		description: 'a shorter welcome message',
		linkedArticle: false,
		syntax: '{{subst:welcome-short|$USERNAME$}} $EXTRA$ ~~~~'
	},
	'welcome-personal': {
		description: 'more personal welcome, including a plate of cookies',
		linkedArticle: false,
		syntax: '{{subst:welcome-personal|$USERNAME$}} ~~~~'
	},
	'welcome-graphical': {
		description: 'colorful welcome message with table of about 20 links',
		linkedArticle: false,
		syntax: '$HEADER$ {{subst:welcome-graphical|$EXTRA$}}'
	},
	'welcome-menu': {
		description: 'welcome message with large table of about 60 links',
		linkedArticle: false,
		syntax: '{{subst:welcome-menu}}'
	},
	'welcome-screen': {
		description: 'welcome message with clear, annotated table of 10 links',
		linkedArticle: false,
		syntax: '$HEADER$ {{subst:welcome-screen}}'
	},
	'welcome-belated': {
		description: 'welcome for users with more substantial contributions',
		linkedArticle: false,
		syntax: '{{subst:welcome-belated|$USERNAME$}}'
	},
	'welcome student': {
		description: 'welcome for students editing as part of an educational class project',
		linkedArticle: false,
		syntax: '$HEADER$ {{subst:welcome student|$USERNAME$}} ~~~~'
	},
	'welcome teacher': {
		description: 'welcome for course instructors involved in an educational class project',
		linkedArticle: false,
		syntax: '$HEADER$ {{subst:welcome teacher|$USERNAME$}} ~~~~'
	},
	'welcome non-latin': {
		description: 'welcome for users with a username containing non-Latin characters',
		linkedArticle: false,
		syntax: '{{subst:welcome non-latin|$USERNAME$}} ~~~~'
	},

	// PROBLEM USER WELCOMES

	'welcomelaws': {
		description: 'welcome with information about copyrights, NPOV, the sandbox, and vandalism',
		linkedArticle: false,
		syntax: '{{subst:welcomelaws|$USERNAME$}} ~~~~'
	},
	'first article': {
		description: 'for someone whose first article did not meet page creation guidelines',
		linkedArticle: true,
		syntax: '{{subst:first article|$ARTICLE$|$USERNAME$}}'
	},
	'welcometest': {
		description: 'for someone whose initial efforts appear to be tests',
		linkedArticle: true,
		syntax: '{{subst:welcometest|$ARTICLE$|$USERNAME$}} ~~~~'
	},
	'welcomevandal': {
		description: 'for someone whose initial efforts appear to be vandalism',
		linkedArticle: true,
		syntax: '{{subst:welcomevandal|$ARTICLE$|$USERNAME$}}'
	},
	'welcomenpov': {
		description: 'for someone whose initial efforts do not adhere to the neutral point of view policy',
		linkedArticle: true,
		syntax: '{{subst:welcomenpov|$ARTICLE$|$USERNAME$}} ~~~~'
	},
	'welcomespam': {
		description: 'welcome with additional discussion of anti-spamming policies',
		linkedArticle: true,
		syntax: '{{subst:welcomespam|$ARTICLE$|$USERNAME$}} ~~~~'
	},
	'welcomeunsourced': {
		description: 'for someone whose initial efforts are unsourced',
		linkedArticle: true,
		syntax: '{{subst:welcomeunsourced|$ARTICLE$|$USERNAME$}} ~~~~'
	},
	'welcomeauto': {
		description: 'for someone who created an autobiographical article',
		linkedArticle: true,
		syntax: '{{subst:welcomeauto|$USERNAME$|art=$ARTICLE$}} ~~~~'
	},
	'welcome-COI': {
		description: 'for someone who has edited in areas where they may have a conflict of interest',
		linkedArticle: true,
		syntax: '{{subst:welcome-COI|$USERNAME$|art=$ARTICLE$}} ~~~~'
	},
	'welcome-delete': {
		description: 'for someone who has been removing information from articles',
		linkedArticle: true,
		syntax: '{{subst:welcome-delete|$ARTICLE$|$USERNAME$}} ~~~~'
	},
	'welcome-image': {
		description: 'welcome with additional information about images (policy and procedure)',
		linkedArticle: true,
		syntax: '{{subst:welcome-image|$USERNAME$|art=$ARTICLE$}}'
	},

	// ANONYMOUS USER WELCOMES

	'welcome-anon': {
		description: 'for anonymous users; encourages creating an account',
		linkedArticle: true,
		syntax: '{{subst:welcome-anon|art=$ARTICLE$}} ~~~~'
	},
	'welcome-anon-test': {
		description: 'for anonymous users who have performed test edits',
		linkedArticle: true,
		syntax: '{{subst:welcome-anon-test|$ARTICLE$|$USERNAME$}} ~~~~'
	},
	'welcome-anon-unconstructive': {
		description: 'for anonymous users who have vandalized or made unhelpful edits',
		linkedArticle: true,
		syntax: '{{subst:welcome-anon-unconstructive|$ARTICLE$|$USERNAME$}}'
	},
	'welcome-anon-constructive': {
		description: 'for anonymous users who fight vandalism or edit constructively',
		linkedArticle: true,
		syntax: '{{subst:welcome-anon-constructive|art=$ARTICLE$}}'
	},
	'welcome-anon-delete': {
		description: 'for anonymous users who have removed content from pages',
		linkedArticle: true,
		syntax: '{{subst:welcome-anon-delete|$ARTICLE$|$USERNAME$}} ~~~~'
	},

	// WIKIPROJECT-SPECIFIC WELCOMES

	'welcome-anatomy': {
		description: 'welcome for users with an apparent interest in anatomy topics',
		linkedArticle: false,
		syntax: '{{subst:welcome-anatomy}} ~~~~'
	},
	'welcome-athletics': {
		description: 'welcome for users with an apparent interest in athletics (track and field) topics',
		linkedArticle: false,
		syntax: '{{subst:welcome-athletics}}'
	},
	'welcome-au': {
		description: 'welcome for users with an apparent interest in Australia topics',
		linkedArticle: false,
		syntax: '{{subst:welcome-au}} ~~~~'
	},
	'welcome-bd': {
		description: 'welcome for users with an apparent interest in Bangladesh topics',
		linkedArticle: true,
		syntax: '{{subst:welcome-bd|$USERNAME$||$EXTRA$|art=$ARTICLE$}} ~~~~'
	},
	'welcome-bio': {
		description: 'welcome for users with an apparent interest in biographical topics',
		linkedArticle: false,
		syntax: '{{subst:welcome-bio}} ~~~~'
	},
	'welcome-cal': {
		description: 'welcome for users with an apparent interest in California topics',
		linkedArticle: false,
		syntax: '{{subst:welcome-cal}} ~~~~'
	},
	'welcome-conserv': {
		description: 'welcome for users with an apparent interest in conservatism topics',
		linkedArticle: false,
		syntax: '{{subst:welcome-conserv}}'
	},
	'welcome-cycling': {
		description: 'welcome for users with an apparent interest in cycling topics',
		linkedArticle: false,
		syntax: '{{subst:welcome-cycling}} ~~~~'
	},
	'welcome-dbz': {
		description: 'welcome for users with an apparent interest in Dragon Ball topics',
		linkedArticle: false,
		syntax: '{{subst:welcome-dbz|$EXTRA$|sig=~~~~}}'
	},
	'welcome-et': {
		description: 'welcome for users with an apparent interest in Estonia topics',
		linkedArticle: false,
		syntax: '{{subst:welcome-et}}'
	},
	'welcome-de': {
		description: 'welcome for users with an apparent interest in Germany topics',
		linkedArticle: false,
		syntax: '{{subst:welcome-de}} ~~~~'
	},
	'welcome-in': {
		description: 'welcome for users with an apparent interest in India topics',
		linkedArticle: true,
		syntax: '{{subst:welcome-in|$USERNAME$|art=$ARTICLE$}} ~~~~'
	},
	'welcome-math': {
		description: 'welcome for users with an apparent interest in mathematical topics',
		linkedArticle: true,
		syntax: '{{subst:welcome-math|$USERNAME$|art=$ARTICLE$}} ~~~~'
	},
	'welcome-med': {
		description: 'welcome for users with an apparent interest in medicine topics',
		linkedArticle: true,
		syntax: '{{subst:welcome-med|$USERNAME$|art=$ARTICLE$}} ~~~~'
	},
	'welcome-no': {
		description: 'welcome for users with an apparent interest in Norway topics',
		linkedArticle: false,
		syntax: '{{subst:welcome-no}} ~~~~'
	},
	'welcome-pk': {
		description: 'welcome for users with an apparent interest in Pakistan topics',
		linkedArticle: true,
		syntax: '{{subst:welcome-pk|$USERNAME$|art=$ARTICLE$}} ~~~~'
	},
	'welcome-phys': {
		description: 'welcome for users with an apparent interest in physics topics',
		linkedArticle: true,
		syntax: '{{subst:welcome-phys|$USERNAME$|art=$ARTICLE$}} ~~~~'
	},
	'welcome-pl': {
		description: 'welcome for users with an apparent interest in Poland topics',
		linkedArticle: false,
		syntax: '{{subst:welcome-pl}} ~~~~'
	},
	'welcome-rugbyunion': {
		description: 'welcome for users with an apparent interest in rugby union topics',
		linkedArticle: false,
		syntax: '{{subst:welcome-rugbyunion}} ~~~~'
	},
	'welcome-ru': {
		description: 'welcome for users with an apparent interest in Russia topics',
		linkedArticle: false,
		syntax: '{{subst:welcome-ru}} ~~~~'
	},
	'welcome-starwars': {
		description: 'welcome for users with an apparent interest in Star Wars topics',
		linkedArticle: false,
		syntax: '{{subst:welcome-starwars}} ~~~~'
	},
	'welcome-ch': {
		description: 'welcome for users with an apparent interest in Switzerland topics',
		linkedArticle: true,
		syntax: '{{subst:welcome-ch|$USERNAME$|art=$ARTICLE$}} ~~~~'
	},
	'welcome-uk': {
		description: 'welcome for users with an apparent interest in Ukraine topics',
		linkedArticle: false,
		syntax: '{{subst:welcome-uk}} ~~~~'
	},
	'welcome-roads': {
		description: 'welcome for users with an apparent interest in roads and highways topics',
		linkedArticle: false,
		syntax: '{{subst:welcome-roads}}'
	},
	'welcome-videogames': {
		description: 'welcome for users with an apparent interest in video game topics',
		linkedArticle: false,
		syntax: '{{subst:welcome-videogames}}'
	},
	'TWA invite': {
		description: 'invite the user to The Wikipedia Adventure (not a welcome template)',
		linkedArticle: false,
		syntax: '{{WP:TWA/InviteTW|signature=~~~~}}'
	},

	// NON-ENGLISH WELCOMES

	'welcomeen': {
		description: 'welcome for users whose first language is not listed here',
		linkedArticle: false,
		syntax: '{{subst:welcomeen}}'
	},
	'welcomeen-ar': {
		description: 'welcome for users whose first language appears to be Arabic',
		linkedArticle: false,
		syntax: '{{subst:welcomeen-ar}}'
	},
	'welcomeen-sq': {
		description: 'welcome for users whose first language appears to be Albanian',
		linkedArticle: false,
		syntax: '{{subst:welcomeen-sq}}'
	},
	'welcomeen-zh': {
		description: 'welcome for users whose first language appears to be Chinese',
		linkedArticle: false,
		syntax: '{{subst:welcomeen-zh}}'
	},
	'welcomeen-nl': {
		description: 'welcome for users whose first language appears to be Dutch',
		linkedArticle: false,
		syntax: '{{subst:welcomeen-nl}}'
	},
	'welcomeen-fi': {
		description: 'welcome for users whose first language appears to be Finnish',
		linkedArticle: false,
		syntax: '{{subst:welcomeen-fi}}'
	},
	'welcomeen-fr': {
		description: 'welcome for users whose first language appears to be French',
		linkedArticle: false,
		syntax: '{{subst:welcomeen-fr}}'
	},
	'welcomeen-de': {
		description: 'welcome for users whose first language appears to be German',
		linkedArticle: false,
		syntax: '{{subst:welcomeen-de}}'
	},
	'welcomeen-he': {
		description: 'welcome for users whose first language appears to be Hebrew',
		linkedArticle: false,
		syntax: '{{subst:welcomeen-he}}'
	},
	'welcomeen-ja': {
		description: 'welcome for users whose first language appears to be Japanese',
		linkedArticle: false,
		syntax: '{{subst:welcomeen-ja}}'
	},
	'welcomeen-ko': {
		description: 'welcome for users whose first language appears to be Korean',
		linkedArticle: false,
		syntax: '{{subst:welcomeen-ko}}'
	},
	'welcomeen-ml': {
		description: 'welcome for users whose first language appears to be Malayalam',
		linkedArticle: false,
		syntax: '{{subst:welcomeen-ml}}'
	},
	'welcomeen-mr': {
		description: 'welcome for users whose first language appears to be Marathi',
		linkedArticle: false,
		syntax: '{{subst:welcomeen-mr}}'
	},
	'welcomeen-or': {
		description: 'welcome for users whose first language appears to be Oriya (Odia)',
		linkedArticle: false,
		syntax: '{{subst:welcomeen-or}}'
	},
	'welcomeen-pt': {
		description: 'welcome for users whose first language appears to be Portuguese',
		linkedArticle: false,
		syntax: '{{subst:welcomeen-pt}}'
	},
	'welcomeen-ro': {
		description: 'welcome for users whose first language appears to be Romanian',
		linkedArticle: false,
		syntax: '{{subst:welcomeen-ro}}'
	},
	'welcomeen-ru': {
		description: 'welcome for users whose first language appears to be Russian',
		linkedArticle: false,
		syntax: '{{subst:welcomeen-ru}}'
	},
	'welcomeen-es': {
		description: 'welcome for users whose first language appears to be Spanish',
		linkedArticle: false,
		syntax: '{{subst:welcomeen-es}}'
	},
	'welcomeen-sv': {
		description: 'welcome for users whose first language appears to be Swedish',
		linkedArticle: false,
		syntax: '{{subst:welcomeen-sv}}'
	},
	'welcomeen-uk': {
		description: 'welcome for users whose first language appears to be Ukrainian',
		linkedArticle: false,
		syntax: '{{subst:welcomeen-uk}}'
	}
};

Twinkle.welcome.getTemplateWikitext = function(template, article) {
	var properties = Twinkle.welcome.templates[template];
	if (properties) {
		return properties.syntax.
			replace('$USERNAME$', Twinkle.getFriendlyPref('insertUsername') ? mw.config.get('wgUserName') : '').
			replace('$ARTICLE$', article ? article : '').
			replace(/\$HEADER\$\s*/, '== Welcome ==\n\n').
			replace('$EXTRA$', '');  // EXTRA is not implemented yet
	}
	return '{{subst:' + template + (article ? '|art=' + article : '') + '}}' +
			(Twinkle.getFriendlyPref('customWelcomeSignature') ? ' ~~~~' : '');
};

Twinkle.welcome.callbacks = {
	preview: function(form) {
		var previewDialog = new Morebits.simpleWindow(750, 400);
		previewDialog.setTitle('Welcome template preview');
		previewDialog.setScriptName('Welcome user');
		previewDialog.setModality(true);

		var previewdiv = document.createElement('div');
		previewdiv.style.marginLeft = previewdiv.style.marginRight = '0.5em';
		previewdiv.style.fontSize = 'small';
		previewDialog.setContent(previewdiv);

		var previewer = new Morebits.wiki.preview(previewdiv);
		previewer.beginRender(Twinkle.welcome.getTemplateWikitext(form.getChecked('template'), form.article.value), 'User talk:' + mw.config.get('wgRelevantUserName')); // Force wikitext/correct username

		var submit = document.createElement('input');
		submit.setAttribute('type', 'submit');
		submit.setAttribute('value', 'Close');
		previewDialog.addContent(submit);

		previewDialog.display();

		$(submit).click(function() {
			previewDialog.close();
		});
	},
	main: function(pageobj) {
		var params = pageobj.getCallbackParameters();
		var text = pageobj.getPageText();

		// abort if mode is auto and form is not empty
		if (pageobj.exists() && params.mode === 'auto') {
			Morebits.status.info('Warning', 'User talk page not empty; aborting automatic welcome');
			Morebits.wiki.actionCompleted.event();
			return;
		}

		var welcomeText = Twinkle.welcome.getTemplateWikitext(params.value, params.article);

		if (Twinkle.getFriendlyPref('topWelcomes')) {
			text = welcomeText + '\n\n' + text;
		} else {
			text += '\n' + welcomeText;
		}

		var summaryText = 'Welcome to Wikipedia!';
		pageobj.setPageText(text);
		pageobj.setEditSummary(summaryText + Twinkle.getPref('summaryAd'));
		pageobj.setWatchlist(Twinkle.getFriendlyPref('watchWelcomes'));
		pageobj.setCreateOption('recreate');
		pageobj.save();
	}
};

Twinkle.welcome.callback.evaluate = function friendlywelcomeCallbackEvaluate(e) {
	var form = e.target;

	var params = {
		value: form.getChecked('template'),
		article: form.article.value,
		mode: 'manual'
	};

	Morebits.simpleWindow.setButtonsEnabled(false);
	Morebits.status.init(form);

	var userTalkPage = mw.config.get('wgFormattedNamespaces')[3] + ':' + mw.config.get('wgRelevantUserName');
	Morebits.wiki.actionCompleted.redirect = userTalkPage;
	Morebits.wiki.actionCompleted.notice = 'Welcoming complete, reloading talk page in a few seconds';

	var wikipedia_page = new Morebits.wiki.page(userTalkPage, 'User talk page modification');
	wikipedia_page.setFollowRedirect(true);
	wikipedia_page.setCallbackParameters(params);
	wikipedia_page.load(Twinkle.welcome.callbacks.main);
};
})(jQuery);


// </nowiki>