forked from wikimedia-gadgets/twinkle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
twinklewelcome.js
753 lines (693 loc) · 27.6 KB
/
twinklewelcome.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
// <nowiki>
(function($) {
/*
****************************************
*** twinklewelcome.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
*/
Twinkle.welcome = function twinklewelcome() {
if (Twinkle.getPrefill('twinklewelcome')) {
if (Twinkle.getPrefill('twinklewelcome') === 'auto') {
Twinkle.welcome.auto();
} else {
Twinkle.welcome.semiauto();
}
} else {
Twinkle.welcome.normal();
}
};
Twinkle.welcome.auto = function() {
if (mw.util.getParamValue('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() {
const isDiff = mw.util.getParamValue('diff');
if (isDiff) {
// check whether the contributors' talk pages exist yet
const $oldDiffUsernameLine = $('#mw-diff-otitle2');
const $newDiffUsernameLine = $('#mw-diff-ntitle2');
const $oldDiffHasRedlinkedTalkPage = $oldDiffUsernameLine.find('span.mw-usertoollinks a.new:contains(talk)').first();
const $newDiffHasRedlinkedTalkPage = $newDiffUsernameLine.find('span.mw-usertoollinks a.new:contains(talk)').first();
const diffHasRedlinkedTalkPage = $oldDiffHasRedlinkedTalkPage.length > 0 || $newDiffHasRedlinkedTalkPage.length > 0;
if (diffHasRedlinkedTalkPage) {
const spanTag = function(color, content) {
const span = document.createElement('span');
span.style.color = color;
span.appendChild(document.createTextNode(content));
return span;
};
const welcomeNode = document.createElement('strong');
const welcomeLink = document.createElement('a');
welcomeLink.appendChild(spanTag('Black', '['));
welcomeLink.appendChild(spanTag('Goldenrod', 'welcome'));
welcomeLink.appendChild(spanTag('Black', ']'));
welcomeNode.appendChild(welcomeLink);
if ($oldDiffHasRedlinkedTalkPage.length > 0) {
const oHref = $oldDiffHasRedlinkedTalkPage.attr('href');
const oWelcomeNode = welcomeNode.cloneNode(true);
oWelcomeNode.firstChild.setAttribute('href', oHref + '&' + $.param({
twinklewelcome: Twinkle.getPref('quickWelcomeMode') === 'auto' ? 'auto' : 'norm',
vanarticle: Morebits.pageNameNorm
}));
$oldDiffHasRedlinkedTalkPage[0].parentNode.parentNode.appendChild(document.createTextNode(' '));
$oldDiffHasRedlinkedTalkPage[0].parentNode.parentNode.appendChild(oWelcomeNode);
}
if ($newDiffHasRedlinkedTalkPage.length > 0) {
const nHref = $newDiffHasRedlinkedTalkPage.attr('href');
const nWelcomeNode = welcomeNode.cloneNode(true);
nWelcomeNode.firstChild.setAttribute('href', nHref + '&' + $.param({
twinklewelcome: Twinkle.getPref('quickWelcomeMode') === 'auto' ? 'auto' : 'norm',
vanarticle: Morebits.pageNameNorm
}));
$newDiffHasRedlinkedTalkPage[0].parentNode.parentNode.appendChild(document.createTextNode(' '));
$newDiffHasRedlinkedTalkPage[0].parentNode.parentNode.appendChild(nWelcomeNode);
}
}
}
// Users and IPs but not IP ranges
if (mw.config.exists('wgRelevantUserName') && !Morebits.ip.isRange(mw.config.get('wgRelevantUserName'))) {
Twinkle.addPortletLink(() => {
Twinkle.welcome.callback(mw.config.get('wgRelevantUserName'));
}, 'Wel', 'twinkle-welcome', 'Welcome user');
}
};
Twinkle.welcome.welcomeUser = function welcomeUser() {
Morebits.status.init(document.getElementById('mw-content-text'));
$('#catlinks').remove();
const params = {
template: Twinkle.getPref('quickWelcomeTemplate'),
article: Twinkle.getPrefill('vanarticle') || '',
mode: 'auto'
};
const 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';
const 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 twinklewelcomeCallback(uid) {
if (uid === mw.config.get('wgUserName') && !confirm('Are you really sure you want to welcome yourself?...')) {
return;
}
const Window = new Morebits.simpleWindow(600, 420);
Window.setTitle('Welcome user');
Window.setScriptName('Twinkle');
Window.addFooterLink('Welcoming Committee', 'WP:WC');
Window.addFooterLink('Welcome prefs', 'WP:TW/PREF#welcome');
Window.addFooterLink('Twinkle help', 'WP:TW/DOC#welcome');
Window.addFooterLink('Give feedback', 'WT:TW');
const 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: 'unregistered', 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: Twinkle.getPrefill('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.'
});
const previewlink = document.createElement('a');
$(previewlink).click(() => {
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
const evt = document.createEvent('Event');
evt.initEvent('change', true, true);
result.type.dispatchEvent(evt);
};
Twinkle.welcome.populateWelcomeList = function(e) {
const type = e.target.value;
const container = new Morebits.quickForm.element({ type: 'fragment' });
if ((type === 'standard' || type === 'unregistered') && Twinkle.getPref('customWelcomeList').length) {
container.append({ type: 'header', label: 'Custom welcome templates' });
container.append({
type: 'radio',
name: 'template',
list: Twinkle.getPref('customWelcomeList'),
event: function() {
e.target.form.article.disabled = false;
}
});
}
const sets = Twinkle.welcome.templates[type];
$.each(sets, (label, templates) => {
container.append({ type: 'header', label: label });
container.append({
type: 'radio',
name: 'template',
list: $.map(templates, (properties, template) => ({
value: template,
label: '{{' + template + '}}: ' + properties.description + (properties.linkedArticle ? '\u00A0*' : ''), // U+00A0 NO-BREAK SPACE
tooltip: properties.tooltip // may be undefined
})),
event: function(ev) {
ev.target.form.article.disabled = !templates[ev.target.value].linkedArticle;
}
});
});
const rendered = container.render();
$(e.target.form).find('div#welcomeWorkArea').empty().append(rendered);
const firstRadio = e.target.form.template[0];
firstRadio.checked = true;
const vals = Object.values(sets)[0];
e.target.form.article.disabled = vals[firstRadio.value] ? !vals[firstRadio.value].linkedArticle : true;
};
// 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)
// - $EXTRA$ - custom message to be added at the end of the template. not implemented yet.
Twinkle.welcome.templates = {
standard: {
'General welcome templates': {
welcome: {
description: 'standard welcome',
linkedArticle: true,
syntax: '{{subst:welcome|$USERNAME$|art=$ARTICLE$}} ~~~~'
},
'welcome-retro': {
description: 'a welcome message with a small list of helpful links',
linkedArticle: true,
syntax: '{{subst:welcome-retro|$USERNAME$|art=$ARTICLE$}} ~~~~'
},
'welcome-short': {
description: 'a shorter welcome message',
syntax: '{{subst:W-short|$EXTRA$}}'
},
'welcome-cookie': {
description: 'a welcome message with some helpful links and a plate of cookies',
syntax: '{{subst:welcome cookie}} ~~~~'
},
welcoming: {
description: 'welcome message with tutorial links and basic editing tips',
syntax: '{{subst:Welcoming}}'
}
},
'Specific welcome templates': {
'welcome-belated': {
description: 'welcome for users with more substantial contributions',
syntax: '{{subst:welcome-belated|$USERNAME$}}'
},
'welcome student': {
description: 'welcome for students editing as part of an educational class project',
syntax: '$HEADER$ {{subst:welcome student|$USERNAME$}} ~~~~'
},
'welcome teacher': {
description: 'welcome for course instructors involved in an educational class project',
syntax: '$HEADER$ {{subst:welcome teacher|$USERNAME$}} ~~~~'
},
'welcome non-latin': {
description: 'welcome for users with a username containing non-Latin characters',
syntax: '{{subst:welcome non-latin|$USERNAME$}} ~~~~'
},
'welcome mentor': {
description: 'welcome for mentor users to give to their mentees',
syntax: '{{subst:mentor welcome|$USERNAME$}} ~~~~'
},
'welcome draft': {
description: 'welcome for users who write draft articles',
linkedArticle: true,
syntax: '{{subst:welcome draft|art=$ARTICLE$}} ~~~~'
}
},
'Problem user welcome templates': {
'first article': {
description: 'for someone whose first article did not meet page creation guidelines',
linkedArticle: true,
syntax: '{{subst:first article|$ARTICLE$|$USERNAME$}}'
},
'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-auto': {
description: 'for someone who created an autobiographical article',
linkedArticle: true,
syntax: '{{subst:welcome-auto|$USERNAME$|art=$ARTICLE$}} ~~~~'
},
'welcome-copyright': {
description: 'for someone who has been adding copyright violations to articles',
linkedArticle: true,
syntax: '{{subst:welcome-copyright|$ARTICLE$|$USERNAME$}} ~~~~'
},
'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$}}'
},
welcomelaws: {
description: 'welcome with information about copyrights, NPOV, the sandbox, and vandalism',
syntax: '{{subst:welcomelaws|$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$}} ~~~~'
},
welcomeunsourced: {
description: 'for someone whose initial efforts are unsourced',
linkedArticle: true,
syntax: '{{subst:welcomeunsourced|$ARTICLE$|$USERNAME$}} ~~~~'
},
welcomevandal: {
description: 'for someone whose initial efforts appear to be vandalism',
linkedArticle: true,
syntax: '{{subst:welcomevandal|$ARTICLE$|$USERNAME$}}'
},
welcomespam: {
description: 'welcome with additional discussion of anti-spamming policies',
linkedArticle: true,
syntax: '{{subst:welcomespam|$ARTICLE$|$USERNAME$}} ~~~~'
},
welcometest: {
description: 'for someone whose initial efforts appear to be tests',
linkedArticle: true,
syntax: '{{subst:welcometest|$ARTICLE$|$USERNAME$}} ~~~~'
}
}
},
unregistered: {
'Unregistered user welcome templates': {
'welcome-unregistered': {
description: 'for unregistered users; encourages creating an account',
linkedArticle: true,
syntax: '{{subst:welcome-unregistered|art=$ARTICLE$}} ~~~~'
},
thanks: {
description: 'for unregistered users; short; encourages creating an account',
linkedArticle: true,
syntax: '== Welcome! ==\n{{subst:thanks|page=$ARTICLE$}} ~~~~'
},
'welcome-unregistered-test': {
description: 'for unregistered users who have performed test edits',
linkedArticle: true,
syntax: '{{subst:welcome-unregistered-test|$ARTICLE$|$USERNAME$}} ~~~~'
},
'welcome-unregistered-unconstructive': {
description: 'for unregistered users who have vandalized or made unhelpful edits',
linkedArticle: true,
syntax: '{{subst:welcome-unregistered-unconstructive|$ARTICLE$|$USERNAME$}}'
},
'welcome-unregistered-constructive': {
description: 'for unregistered users who fight vandalism or edit constructively',
linkedArticle: true,
syntax: '{{subst:welcome-unregistered-constructive|art=$ARTICLE$}}'
},
'welcome-unregistered-delete': {
description: 'for unregistered users who have removed content from pages',
linkedArticle: true,
syntax: '{{subst:welcome-unregistered-delete|$ARTICLE$|$USERNAME$}} ~~~~'
},
'welcome-unregistered-unsourced': {
description: 'for anonymous users who have added unsourced content',
linkedArticle: true,
syntax: '{{subst:welcome-unregistered-unsourced|$ARTICLE$|$USERNAME$}}'
}
}
},
wikiProject: {
'WikiProject-specific welcome templates': {
'TWA invite': {
description: 'invite the user to The Wikipedia Adventure (not a welcome template)',
syntax: '{{subst:WP:TWA/InviteTW|signature=~~~~}}'
},
'welcome-anatomy': {
description: 'welcome for users with an apparent interest in anatomy topics',
syntax: '{{subst:welcome-anatomy}} ~~~~'
},
'welcome-athletics': {
description: 'welcome for users with an apparent interest in athletics (track and field) topics',
syntax: '{{subst:welcome-athletics}}'
},
'welcome-au': {
description: 'welcome for users with an apparent interest in Australia topics',
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',
syntax: '{{subst:welcome-bio}} ~~~~'
},
'welcome-cal': {
description: 'welcome for users with an apparent interest in California topics',
syntax: '{{subst:welcome-cal}} ~~~~'
},
'welcome-conserv': {
description: 'welcome for users with an apparent interest in conservatism topics',
syntax: '{{subst:welcome-conserv}}'
},
'welcome-cycling': {
description: 'welcome for users with an apparent interest in cycling topics',
syntax: '{{subst:welcome-cycling}} ~~~~'
},
'welcome-dbz': {
description: 'welcome for users with an apparent interest in Dragon Ball topics',
syntax: '{{subst:welcome-dbz|$EXTRA$|sig=~~~~}}'
},
'welcome-et': {
description: 'welcome for users with an apparent interest in Estonia topics',
syntax: '{{subst:welcome-et}}'
},
'welcome-de': {
description: 'welcome for users with an apparent interest in Germany topics',
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',
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',
syntax: '{{subst:welcome-pl}} ~~~~'
},
'welcome-rugbyunion': {
description: 'welcome for users with an apparent interest in rugby union topics',
syntax: '{{subst:welcome-rugbyunion}} ~~~~'
},
'welcome-ru': {
description: 'welcome for users with an apparent interest in Russia topics',
syntax: '{{subst:welcome-ru}} ~~~~'
},
'welcome-starwars': {
description: 'welcome for users with an apparent interest in Star Wars topics',
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',
syntax: '{{subst:welcome-uk}} ~~~~'
},
'welcome-roads': {
description: 'welcome for users with an apparent interest in roads and highways topics',
syntax: '{{subst:welcome-roads}}'
},
'welcome-videogames': {
description: 'welcome for users with an apparent interest in video game topics',
syntax: '{{subst:welcome-videogames}}'
},
'WikiProject Women in Red invite': {
description: 'welcome for users with an interest in writing about women',
syntax: '{{subst:WikiProject Women in Red invite|1=~~~~}}'
}
}
},
nonEnglish: {
'Non-English welcome templates': {
welcomeen: {
description: 'welcome for users whose first language is not listed here',
syntax: '{{subst:welcomeen}}'
},
'welcomeen-ar': {
description: 'welcome for users whose first language appears to be Arabic',
syntax: '== Welcome! ==\n{{subst:welcomeen-ar}}'
},
'welcomeen-sq': {
description: 'welcome for users whose first language appears to be Albanian',
syntax: '== Welcome! ==\n{{subst:welcomeen-sq}}'
},
'welcomeen-zh': {
description: 'welcome for users whose first language appears to be Chinese',
syntax: '== Welcome! ==\n{{subst:welcomeen-zh}}'
},
'welcomeen-nl': {
description: 'welcome for users whose first language appears to be Dutch',
syntax: '== Welcome! ==\n{{subst:welcomeen-nl}}'
},
'welcomeen-fi': {
description: 'welcome for users whose first language appears to be Finnish',
syntax: '== Welcome! ==\n{{subst:welcomeen-fi}}'
},
'welcomeen-fr': {
description: 'welcome for users whose first language appears to be French',
syntax: '== Welcome! ==\n{{subst:welcomeen-fr}}'
},
'welcomeen-de': {
description: 'welcome for users whose first language appears to be German',
syntax: '== Welcome! ==\n{{subst:welcomeen-de}}'
},
'welcomeen-ha': {
description: 'welcome for users whose first language appears to be Hausa',
syntax: '== Welcome! ==\n{{subst:welcomeen-ha}}'
},
'welcomeen-he': {
description: 'welcome for users whose first language appears to be Hebrew',
syntax: '== Welcome! ==\n{{subst:welcomeen-he}}'
},
'welcomeen-hi': {
description: 'welcome for users whose first language appears to be Hindi',
syntax: '== Welcome! ==\n{{subst:welcomeen-hi}}'
},
'welcomeen-id': {
description: 'welcome for users whose first language appears to be Indonesian',
syntax: '== Welcome! ==\n{{subst:welcomeen-id}}'
},
'welcomeen-it': {
description: 'welcome for users whose first language appears to be Italian',
syntax: '== Welcome! ==\n{{subst:welcomeen-it}}'
},
'welcomeen-ja': {
description: 'welcome for users whose first language appears to be Japanese',
syntax: '== Welcome! ==\n{{subst:welcomeen-ja}}'
},
'welcomeen-ko': {
description: 'welcome for users whose first language appears to be Korean',
syntax: '== Welcome! ==\n{{subst:welcomeen-ko}}'
},
'welcomeen-ms': {
description: 'welcome for users whose first language appears to be Malay',
syntax: '== Welcome! ==\n{{subst:welcomeen-ms}}'
},
'welcomeen-ml': {
description: 'welcome for users whose first language appears to be Malayalam',
syntax: '== Welcome! ==\n{{subst:welcomeen-ml}}'
},
'welcomeen-mr': {
description: 'welcome for users whose first language appears to be Marathi',
syntax: '== Welcome! ==\n{{subst:welcomeen-mr}}'
},
'welcomeen-no': {
description: 'welcome for users whose first language appears to be Norwegian',
syntax: '== Welcome! ==\n{{subst:welcomeen-no}}'
},
'welcomeen-or': {
description: 'welcome for users whose first language appears to be Oriya (Odia)',
syntax: '== Welcome! ==\n{{subst:welcomeen-or}}'
},
'welcomeen-fa': {
description: 'welcome for users whose first language appears to be Persian',
syntax: '== Welcome! ==\n{{subst:welcomeen-fa}}'
},
'welcomeen-pl': {
description: 'welcome for users whose first language appears to be Polish',
syntax: '== Welcome! ==\n{{subst:welcomeen-pl}}'
},
'welcomeen-pt': {
description: 'welcome for users whose first language appears to be Portuguese',
syntax: '== Welcome! ==\n{{subst:welcomeen-pt}}'
},
'welcomeen-ro': {
description: 'welcome for users whose first language appears to be Romanian',
syntax: '== Welcome! ==\n{{subst:welcomeen-ro}}'
},
'welcomeen-ru': {
description: 'welcome for users whose first language appears to be Russian',
syntax: '== Welcome! ==\n{{subst:welcomeen-ru}}'
},
'welcomeen-es': {
description: 'welcome for users whose first language appears to be Spanish',
syntax: '== Welcome! ==\n{{subst:welcomeen-es}}'
},
'welcomeen-sv': {
description: 'welcome for users whose first language appears to be Swedish',
syntax: '== Welcome! ==\n{{subst:welcomeen-sv}}'
},
'welcomeen-th': {
description: 'welcome for users whose first language appears to be Thai',
syntax: '== Welcome! ==\n{{subst:welcomeen-th}}'
},
'welcomeen-tl': {
description: 'welcome for users whose first language appears to be Tagalog',
syntax: '== Welcome! ==\n{{subst:welcomeen-tl}}'
},
'welcomeen-tr': {
description: 'welcome for users whose first language appears to be Turkish',
syntax: '== Welcome! ==\n{{subst:welcomeen-tr}}'
},
'welcomeen-uk': {
description: 'welcome for users whose first language appears to be Ukrainian',
syntax: '== Welcome! ==\n{{subst:welcomeen-uk}}'
},
'welcomeen-ur': {
description: 'welcome for users whose first language appears to be Urdu',
syntax: '== Welcome! ==\n{{subst:welcomeen-ur}}'
},
'welcomeen-vi': {
description: 'welcome for users whose first language appears to be Vietnamese',
syntax: '== Welcome! ==\n{{subst:welcomeen-vi}}'
}
}
}
};
Twinkle.welcome.getTemplateWikitext = function(type, template, article) {
// the iteration is required as the type=standard has two groups
let properties;
$.each(Twinkle.welcome.templates[type], (label, templates) => {
properties = templates[template];
if (properties) {
return false; // break
}
});
if (properties) {
return properties.syntax
.replace('$USERNAME$', Twinkle.getPref('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.getPref('customWelcomeSignature') ? ' ~~~~' : '');
};
Twinkle.welcome.callbacks = {
preview: function(form) {
const previewDialog = new Morebits.simpleWindow(750, 400);
previewDialog.setTitle('Welcome template preview');
previewDialog.setScriptName('Welcome user');
previewDialog.setModality(true);
const previewdiv = document.createElement('div');
previewdiv.style.marginLeft = previewdiv.style.marginRight = '0.5em';
previewdiv.style.fontSize = 'small';
previewDialog.setContent(previewdiv);
const previewer = new Morebits.wiki.preview(previewdiv);
const input = Morebits.quickForm.getInputData(form);
previewer.beginRender(Twinkle.welcome.getTemplateWikitext(input.type, input.template, input.article), 'User talk:' + mw.config.get('wgRelevantUserName')); // Force wikitext/correct username
const submit = document.createElement('input');
submit.setAttribute('type', 'submit');
submit.setAttribute('value', 'Close');
previewDialog.addContent(submit);
previewDialog.display();
$(submit).click(() => {
previewDialog.close();
});
},
main: function(pageobj) {
const params = pageobj.getCallbackParameters();
let 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;
}
const welcomeText = Twinkle.welcome.getTemplateWikitext(params.type, params.template, params.article);
if (Twinkle.getPref('topWelcomes')) {
const hasTalkHeader = /^\{\{Talk ?header\}\}/i.test(text);
if (hasTalkHeader) {
text = text.replace(/^\{\{Talk ?header\}\}\n{0,2}/i, '');
text = '{{Talk header}}\n\n' + welcomeText + '\n\n' + text;
text = text.trim();
} else {
text = welcomeText + '\n\n' + text;
}
} else {
text += '\n' + welcomeText;
}
const summaryText = 'Welcome to Wikipedia!';
pageobj.setPageText(text);
pageobj.setEditSummary(summaryText);
pageobj.setChangeTags(Twinkle.changeTags);
pageobj.setWatchlist(Twinkle.getPref('watchWelcomes'));
pageobj.setCreateOption('recreate');
pageobj.save();
}
};
Twinkle.welcome.callback.evaluate = function twinklewelcomeCallbackEvaluate(e) {
const form = e.target;
const params = Morebits.quickForm.getInputData(form); // : type, template, article
params.mode = 'manual';
Morebits.simpleWindow.setButtonsEnabled(false);
Morebits.status.init(form);
const 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';
const 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.addInitCallback(Twinkle.welcome, 'welcome');
}(jQuery));
// </nowiki>