forked from wikimedia-gadgets/twinkle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtwinklexfd.js
2229 lines (1993 loc) · 84.5 KB
/
twinklexfd.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
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// <nowiki>
(function($) {
/*
****************************************
*** twinklexfd.js: XFD module
****************************************
* Mode of invocation: Tab ("XFD")
* Active on: Existing, non-special pages, except for file pages with no local (non-Commons) file which are not redirects
*/
Twinkle.xfd = function twinklexfd() {
// Disable on:
// * special pages
// * non-existent pages
// * files on Commons, whether there is a local page or not (unneeded local pages of files on Commons are eligible for CSD F2, or R4 if it's a redirect)
if (mw.config.get('wgNamespaceNumber') < 0 || !mw.config.get('wgArticleId') || (mw.config.get('wgNamespaceNumber') === 6 && document.getElementById('mw-sharedupload'))) {
return;
}
var tooltip = 'Start a discussion for deleting';
if (mw.config.get('wgIsRedirect')) {
tooltip += ' or retargeting this redirect';
} else {
switch (mw.config.get('wgNamespaceNumber')) {
case 0:
tooltip += ' or moving this article';
break;
case 10:
tooltip += ' or merging this template';
break;
case 828:
tooltip += ' or merging this module';
break;
case 6:
tooltip += ' this file';
break;
case 14:
tooltip += ', merging or renaming this category';
break;
default:
tooltip += ' this page';
break;
}
}
Twinkle.addPortletLink(Twinkle.xfd.callback, 'XFD', 'tw-xfd', tooltip);
};
var utils = {
/** Get ordinal number figure */
num2order: function(num) {
switch (num) {
case 1: return '';
case 2: return '2nd';
case 3: return '3rd';
default: return num + 'th';
}
},
/**
* Remove namespace name from title if present
* Exception-safe wrapper around mw.Title
* @param {string} title
*/
stripNs: function(title) {
var title_obj = mw.Title.newFromUserInput(title);
if (!title_obj) {
return title; // user entered invalid input; do nothing
}
return title_obj.getNameText();
},
/**
* Add namespace name to page title if not already given
* CAUTION: namespace name won't be added if a namespace (*not* necessarily
* the same as the one given) already is there in the title
* @param {string} title
* @param {number} namespaceNumber
*/
addNs: function(title, namespaceNumber) {
var title_obj = mw.Title.newFromUserInput(title, namespaceNumber);
if (!title_obj) {
return title; // user entered invalid input; do nothing
}
return title_obj.toText();
},
/**
* Provide Wikipedian TLA style: AfD, RfD, CfDS, RM, SfD, etc.
* @param {string} venue
* @returns {string}
*/
toTLACase: function(venue) {
return venue
.toString()
// Everybody up, inclduing rm and the terminal s in cfds
.toUpperCase()
// Lowercase the central f in a given TLA and normalize sfd-t and sfr-t
.replace(/(.)F(.)(?:-.)?/, '$1f$2');
}
};
Twinkle.xfd.currentRationale = null;
// error callback on Morebits.status.object
Twinkle.xfd.printRationale = function twinklexfdPrintRationale() {
if (Twinkle.xfd.currentRationale) {
Morebits.status.printUserText(Twinkle.xfd.currentRationale, 'Your deletion rationale is provided below, which you can copy and paste into a new XFD dialog if you wish to try again:');
// only need to print the rationale once
Twinkle.xfd.currentRationale = null;
}
};
Twinkle.xfd.callback = function twinklexfdCallback() {
var Window = new Morebits.simpleWindow(700, 400);
Window.setTitle('Start a deletion discussion (XfD)');
Window.setScriptName('Twinkle');
Window.addFooterLink('About deletion discussions', 'WP:XFD');
Window.addFooterLink('XfD prefs', 'WP:TW/PREF#xfd');
Window.addFooterLink('Twinkle help', 'WP:TW/DOC#xfd');
Window.addFooterLink('Give feedback', 'WT:TW');
var form = new Morebits.quickForm(Twinkle.xfd.callback.evaluate);
var categories = form.append({
type: 'select',
name: 'venue',
label: 'Deletion discussion venue:',
tooltip: 'When activated, a default choice is made, based on what namespace you are in. This default should be the most appropriate.',
event: Twinkle.xfd.callback.change_category
});
var namespace = mw.config.get('wgNamespaceNumber');
categories.append({
type: 'option',
label: 'AfD (Articles for deletion)',
selected: namespace === 0, // Main namespace
value: 'afd'
});
categories.append({
type: 'option',
label: 'TfD (Templates for discussion)',
selected: [ 10, 828 ].indexOf(namespace) !== -1, // Template and module namespaces
value: 'tfd'
});
categories.append({
type: 'option',
label: 'FfD (Files for discussion)',
selected: namespace === 6, // File namespace
value: 'ffd'
});
categories.append({
type: 'option',
label: 'CfD (Categories for discussion)',
selected: namespace === 14 || (namespace === 10 && /-stub$/.test(Morebits.pageNameNorm)), // Category namespace and stub templates
value: 'cfd'
});
categories.append({
type: 'option',
label: 'CfD/S (Categories for speedy renaming)',
value: 'cfds'
});
categories.append({
type: 'option',
label: 'MfD (Miscellany for deletion)',
selected: [ 0, 6, 10, 14, 828 ].indexOf(namespace) === -1 || Morebits.pageNameNorm.indexOf('Template:User ', 0) === 0,
// Other namespaces, and userboxes in template namespace
value: 'mfd'
});
categories.append({
type: 'option',
label: 'RfD (Redirects for discussion)',
selected: mw.config.get('wgIsRedirect'),
value: 'rfd'
});
categories.append({
type: 'option',
label: 'RM (Requested moves)',
selected: false,
value: 'rm'
});
form.append({
type: 'div',
id: 'wrong-venue-warn',
style: 'color: red; font-style: italic'
});
form.append({
type: 'checkbox',
list: [
{
label: 'Notify page creator if possible',
value: 'notify',
name: 'notifycreator',
tooltip: "A notification template will be placed on the creator's talk page if this is true.",
checked: true
}
]
});
form.append({
type: 'field',
label: 'Work area',
name: 'work_area'
});
var previewlink = document.createElement('a');
$(previewlink).click(function() {
Twinkle.xfd.callbacks.preview(result); // |result| is defined below
});
previewlink.style.cursor = 'pointer';
previewlink.textContent = 'Preview';
form.append({ type: 'div', id: 'xfdpreview', label: [ previewlink ] });
form.append({ type: 'div', id: 'twinklexfd-previewbox', style: 'display: none' });
form.append({ type: 'submit' });
var result = form.render();
Window.setContent(result);
Window.display();
result.previewer = new Morebits.wiki.preview($(result).find('div#twinklexfd-previewbox').last()[0]);
// We must init the controls
var evt = document.createEvent('Event');
evt.initEvent('change', true, true);
result.venue.dispatchEvent(evt);
};
Twinkle.xfd.callback.wrongVenueWarning = function twinklexfdWrongVenueWarning(venue) {
var text = '';
var namespace = mw.config.get('wgNamespaceNumber');
switch (venue) {
case 'afd':
if (namespace !== 0) {
text = 'AfD is generally appropriate only for articles.';
} else if (mw.config.get('wgIsRedirect')) {
text = 'Please use RfD for redirects.';
}
break;
case 'tfd':
if (namespace === 10 && /-stub$/.test(Morebits.pageNameNorm)) {
text = 'Use CfD for stub templates.';
} else if (Morebits.pageNameNorm.indexOf('Template:User ') === 0) {
text = 'Please use MfD for userboxes';
}
break;
case 'cfd':
if ([ 10, 14 ].indexOf(namespace) === -1) {
text = 'CfD is only for categories and stub templates.';
}
break;
case 'cfds':
if (namespace !== 14) {
text = 'CfDS is only for categories.';
}
break;
case 'ffd':
if (namespace !== 6) {
text = 'FFD is selected but this page doesn\'t look like a file!';
}
break;
case 'rm':
if (namespace === 14) { // category
text = 'Please use CfD or CfDS for category renames.';
} else if ([118, 119, 2, 3].indexOf(namespace) > -1) { // draft, draft talk, user, user talk
text = 'RMs are not permitted in draft and userspace, unless they are uncontroversial technical requests.';
}
break;
default: // mfd or rfd
break;
}
$('#wrong-venue-warn').text(text);
};
Twinkle.xfd.callback.change_category = function twinklexfdCallbackChangeCategory(e) {
var value = e.target.value;
var form = e.target.form;
var old_area = Morebits.quickForm.getElements(e.target.form, 'work_area')[0];
var work_area = null;
var oldreasontextbox = form.getElementsByTagName('textarea')[0];
var oldreason = oldreasontextbox ? oldreasontextbox.value : '';
var appendReasonBox = function twinklexfdAppendReasonBox() {
work_area.append({
type: 'textarea',
name: 'reason',
label: 'Reason:',
value: oldreason,
tooltip: 'You can use wikimarkup in your reason. Twinkle will automatically sign your post.'
});
};
Twinkle.xfd.callback.wrongVenueWarning(value);
form.previewer.closePreview();
switch (value) {
case 'afd':
work_area = new Morebits.quickForm.element({
type: 'field',
label: 'Articles for deletion',
name: 'work_area'
});
work_area.append({
type: 'div',
label: '', // Added later by Twinkle.makeFindSourcesDiv()
id: 'twinkle-xfd-findsources',
style: 'margin-bottom: 5px; margin-top: -5px;'
});
work_area.append({
type: 'checkbox',
list: [
{
label: 'Wrap deletion tag with <noinclude>',
value: 'noinclude',
name: 'noinclude',
tooltip: 'Will wrap the deletion tag in <noinclude> tags, so that it won\'t transclude. This option is not normally required.'
}
]
});
work_area.append({
type: 'select',
name: 'xfdcat',
label: 'Choose what category this nomination belongs in:',
list: [
{ type: 'option', label: 'Unknown', value: '?', selected: true },
{ type: 'option', label: 'Media and music', value: 'M' },
{ type: 'option', label: 'Organisation, corporation, or product', value: 'O' },
{ type: 'option', label: 'Biographical', value: 'B' },
{ type: 'option', label: 'Society topics', value: 'S' },
{ type: 'option', label: 'Web or internet', value: 'W' },
{ type: 'option', label: 'Games or sports', value: 'G' },
{ type: 'option', label: 'Science and technology', value: 'T' },
{ type: 'option', label: 'Fiction and the arts', value: 'F' },
{ type: 'option', label: 'Places and transportation', value: 'P' },
{ type: 'option', label: 'Indiscernible or unclassifiable topic', value: 'I' },
{ type: 'option', label: 'Debate not yet sorted', value: 'U' }
]
});
work_area.append({
type: 'select',
multiple: true,
name: 'delsortCats',
label: 'Choose deletion sorting categories:',
tooltip: 'Select a few categories that are specifically relevant to the subject of the article. Be as precise as possible; categories like People and USA should only be used when no other categories apply.'
});
// grab deletion sort categories from en-wiki
Morebits.wiki.getCachedJson('Wikipedia:WikiProject_Deletion_sorting/Computer-readable.json').then(function(delsortCategories) {
var $select = $('[name="delsortCats"]');
$.each(delsortCategories, function(groupname, list) {
var $optgroup = $('<optgroup>').attr('label', groupname);
var $delsortCat = $select.append($optgroup);
list.forEach(function(item) {
var $option = $('<option>').val(item).text(item);
$delsortCat.append($option);
});
});
});
appendReasonBox();
work_area = work_area.render();
old_area.parentNode.replaceChild(work_area, old_area);
Twinkle.makeFindSourcesDiv('#twinkle-xfd-findsources');
$(work_area).find('[name=delsortCats]')
.attr('data-placeholder', 'Select delsort pages')
.select2({
width: '100%',
matcher: Morebits.select2.matcher,
templateResult: Morebits.select2.highlightSearchMatches,
language: {
searching: Morebits.select2.queryInterceptor
},
// Link text to the page itself
templateSelection: function(choice) {
return $('<a>').text(choice.text).attr({
href: mw.util.getUrl('Wikipedia:WikiProject_Deletion_sorting/' + choice.text),
target: '_blank'
});
}
});
mw.util.addCSS(
// Remove black border
'.select2-container--default.select2-container--focus .select2-selection--multiple { border: 1px solid #aaa; }' +
// Reduce padding
'.select2-results .select2-results__option { padding-top: 1px; padding-bottom: 1px; }' +
'.select2-results .select2-results__group { padding-top: 1px; padding-bottom: 1px; } ' +
// Adjust font size
'.select2-container .select2-dropdown .select2-results { font-size: 13px; }' +
'.select2-container .selection .select2-selection__rendered { font-size: 13px; }' +
// Make the tiny cross larger
'.select2-selection__choice__remove { font-size: 130%; }'
);
break;
case 'tfd':
work_area = new Morebits.quickForm.element({
type: 'field',
label: 'Templates for discussion',
name: 'work_area'
});
var templateOrModule = mw.config.get('wgPageContentModel') === 'Scribunto' ? 'module' : 'template';
work_area.append({
type: 'select',
label: 'Choose type of action wanted:',
name: 'xfdcat',
event: function(e) {
var target = e.target,
tfdtarget = target.form.tfdtarget;
// add/remove extra input box
if (target.value === 'tfm' && !tfdtarget) {
tfdtarget = new Morebits.quickForm.element({
name: 'tfdtarget',
type: 'input',
label: 'Other ' + templateOrModule + ' to be merged:',
tooltip: 'Required. Should not include the ' + Morebits.string.toUpperCaseFirstChar(templateOrModule) + ': namespace prefix.',
required: true
});
target.parentNode.appendChild(tfdtarget.render());
} else {
$(Morebits.quickForm.getElementContainer(tfdtarget)).remove();
tfdtarget = null;
}
},
list: [
{ type: 'option', label: 'Deletion', value: 'tfd', selected: true },
{ type: 'option', label: 'Merge', value: 'tfm' }
]
});
work_area.append({
type: 'select',
name: 'templatetype',
label: 'Deletion tag display style:',
tooltip: 'Which <code>type=</code> parameter to pass to the TfD tag template.',
list: templateOrModule === 'module' ? [
{ type: 'option', value: 'module', label: 'Module', selected: true }
] : [
{ type: 'option', value: 'standard', label: 'Standard', selected: true },
{ type: 'option', value: 'sidebar', label: 'Sidebar/infobox', selected: $('.infobox').length },
{ type: 'option', value: 'inline', label: 'Inline template', selected: $('.mw-parser-output > p .Inline-Template').length },
{ type: 'option', value: 'tiny', label: 'Tiny inline' },
{ type: 'option', value: 'disabled', label: 'Disabled' }
]
});
work_area.append({
type: 'checkbox',
list: [
{
label: 'Wrap deletion tag with <noinclude> (for substituted templates only)',
value: 'noinclude',
name: 'noinclude',
tooltip: 'Will wrap the deletion tag in <noinclude> tags, so that it won\'t get substituted along with the template.',
disabled: templateOrModule === 'module',
checked: !!$('.box-Subst_only').length // Default to checked if page carries {{subst only}}
}
]
});
work_area.append({
type: 'checkbox',
list: [
{
label: 'Notify talk pages of affected user scripts',
value: 'devpages',
name: 'devpages',
tooltip: 'A notification will be sent to Twinkle, AWB, and Ultraviolet\'s talk pages if those user scripts are marked as using this template.',
checked: true
}
]
});
appendReasonBox();
work_area = work_area.render();
old_area.parentNode.replaceChild(work_area, old_area);
break;
case 'mfd':
work_area = new Morebits.quickForm.element({
type: 'field',
label: 'Miscellany for deletion',
name: 'work_area'
});
work_area.append({
type: 'checkbox',
list: [
{
label: 'Wrap deletion tag with <noinclude>',
value: 'noinclude',
name: 'noinclude',
tooltip: 'Will wrap the deletion tag in <noinclude> tags, so that it won\'t transclude. Select this option for userboxes.'
}
]
});
if ((mw.config.get('wgNamespaceNumber') === 2 /* User: */ || mw.config.get('wgNamespaceNumber') === 3 /* User talk: */) && mw.config.exists('wgRelevantUserName')) {
work_area.append({
type: 'checkbox',
list: [
{
label: 'Notify owner of userspace (if they are not the page creator)',
value: 'notifyuserspace',
name: 'notifyuserspace',
tooltip: 'If the user in whose userspace this page is located is not the page creator (for example, the page is a rescued article stored as a userspace draft), notify the userspace owner as well.',
checked: true
}
]
});
}
appendReasonBox();
work_area = work_area.render();
old_area.parentNode.replaceChild(work_area, old_area);
break;
case 'ffd':
work_area = new Morebits.quickForm.element({
type: 'field',
label: 'Discussion venues for files',
name: 'work_area'
});
appendReasonBox();
work_area = work_area.render();
old_area.parentNode.replaceChild(work_area, old_area);
break;
case 'cfd':
work_area = new Morebits.quickForm.element({
type: 'field',
label: 'Categories for discussion',
name: 'work_area'
});
var isCategory = mw.config.get('wgNamespaceNumber') === 14;
work_area.append({
type: 'select',
label: 'Choose type of action wanted:',
name: 'xfdcat',
event: function(e) {
var value = e.target.value,
cfdtarget = e.target.form.cfdtarget,
cfdtarget2 = e.target.form.cfdtarget2;
// update enabled status
cfdtarget.disabled = value === 'cfd' || value === 'sfd-t';
if (isCategory) {
// update label
if (value === 'cfs') {
Morebits.quickForm.setElementLabel(cfdtarget, 'Target categories: ');
} else if (value === 'cfc') {
Morebits.quickForm.setElementLabel(cfdtarget, 'Target article: ');
} else {
Morebits.quickForm.setElementLabel(cfdtarget, 'Target category: ');
}
// add/remove extra input box
if (value === 'cfs') {
if (cfdtarget2) {
cfdtarget2.disabled = false;
$(cfdtarget2).show();
} else {
cfdtarget2 = document.createElement('input');
cfdtarget2.setAttribute('name', 'cfdtarget2');
cfdtarget2.setAttribute('type', 'text');
cfdtarget2.setAttribute('required', 'true');
cfdtarget.parentNode.appendChild(cfdtarget2);
}
} else {
$(cfdtarget2).prop('disabled', true);
$(cfdtarget2).hide();
}
} else { // Update stub template label
Morebits.quickForm.setElementLabel(cfdtarget, 'Target stub template: ');
}
},
list: isCategory ? [
{ type: 'option', label: 'Deletion', value: 'cfd', selected: true },
{ type: 'option', label: 'Merge', value: 'cfm' },
{ type: 'option', label: 'Renaming', value: 'cfr' },
{ type: 'option', label: 'Split', value: 'cfs' },
{ type: 'option', label: 'Convert into article', value: 'cfc' }
] : [
{ type: 'option', label: 'Stub Deletion', value: 'sfd-t', selected: true },
{ type: 'option', label: 'Stub Renaming', value: 'sfr-t' }
]
});
work_area.append({
type: 'input',
name: 'cfdtarget',
label: 'Target category:', // default, changed above
disabled: true,
required: true, // only when enabled
value: ''
});
appendReasonBox();
work_area = work_area.render();
old_area.parentNode.replaceChild(work_area, old_area);
break;
case 'cfds':
work_area = new Morebits.quickForm.element({
type: 'field',
label: 'Categories for speedy renaming',
name: 'work_area'
});
work_area.append({
type: 'select',
label: 'C2 sub-criterion:',
name: 'xfdcat',
tooltip: 'See WP:CFDS for full explanations.',
list: [
{ type: 'option', label: 'C2A: Typographic and spelling fixes', value: 'C2A', selected: true },
{ type: 'option', label: 'C2B: Naming conventions and disambiguation', value: 'C2B' },
{ type: 'option', label: 'C2C: Consistency with names of similar categories', value: 'C2C' },
{ type: 'option', label: 'C2D: Rename to match article name', value: 'C2D' },
{ type: 'option', label: 'C2E: Author request', value: 'C2E' },
{ type: 'option', label: 'C2F: One eponymous article', value: 'C2F' }
]
});
work_area.append({
type: 'input',
name: 'cfdstarget',
label: 'New name:',
value: '',
required: true
});
appendReasonBox();
work_area = work_area.render();
old_area.parentNode.replaceChild(work_area, old_area);
break;
case 'rfd':
work_area = new Morebits.quickForm.element({
type: 'field',
label: 'Redirects for discussion',
name: 'work_area'
});
work_area.append({
type: 'checkbox',
list: [
{
label: 'Notify target page if possible',
value: 'relatedpage',
name: 'relatedpage',
tooltip: "A notification template will be placed on the talk page of this redirect's target if this is true.",
checked: true
}
]
});
appendReasonBox();
work_area = work_area.render();
old_area.parentNode.replaceChild(work_area, old_area);
break;
case 'rm':
work_area = new Morebits.quickForm.element({
type: 'field',
label: 'Requested moves',
name: 'work_area'
});
work_area.append({
type: 'checkbox',
list: [
{
label: 'Uncontroversial technical request',
value: 'rmtr',
name: 'rmtr',
tooltip: 'Use this option when you are unable to perform this uncontroversial move yourself because of a technical reason (e.g. a page already exists at the new title, or the page is protected)',
checked: false,
event: function() {
form.newname.required = this.checked;
},
subgroup: {
type: 'checkbox',
list: [
{
label: 'Opt out of discussion if the request is contested',
value: 'rmtr-discuss',
name: 'rmtr-discuss',
tooltip: 'Use this option if you prefer to withdraw the request if contested, rather than discuss it. This suppresses the "discuss" link, which may be used to convert your request to a discussion on the talk page.',
checked: false
}
]
}
}
]
});
work_area.append({
type: 'input',
name: 'newname',
label: 'New title:',
tooltip: 'Required for technical requests. Otherwise, if unsure of the appropriate title, you may leave it blank.'
});
appendReasonBox();
work_area = work_area.render();
old_area.parentNode.replaceChild(work_area, old_area);
break;
default:
work_area = new Morebits.quickForm.element({
type: 'field',
label: 'Nothing for anything',
name: 'work_area'
});
work_area = work_area.render();
old_area.parentNode.replaceChild(work_area, old_area);
break;
}
// Return to checked state when switching, but no creator notification for CFDS or RM
form.notifycreator.disabled = value === 'cfds' || value === 'rm';
form.notifycreator.checked = !form.notifycreator.disabled;
};
Twinkle.xfd.callbacks = {
// Requires having the tag text (params.tagText) set ahead of time
autoEditRequest: function(pageobj, params) {
var talkName = new mw.Title(pageobj.getPageName()).getTalkPage().toText();
if (talkName === pageobj.getPageName()) {
pageobj.getStatusElement().error('Page protected and nowhere to add an edit request, aborting');
} else {
pageobj.getStatusElement().warn('Page protected, requesting edit');
var editRequest = '{{subst:Xfd edit protected|page=' + pageobj.getPageName() +
'|discussion=' + params.discussionpage + (params.venue === 'rfd' ? '|rfd=yes' : '') +
'|tag=<nowiki>' + params.tagText + '\u003C/nowiki>}}'; // U+003C: <
var talk_page = new Morebits.wiki.page(talkName, 'Automatically posting edit request on talk page');
talk_page.setNewSectionTitle('Edit request to complete ' + utils.toTLACase(params.venue) + ' nomination');
talk_page.setNewSectionText(editRequest);
talk_page.setCreateOption('recreate');
talk_page.setWatchlist(Twinkle.getPref('xfdWatchPage'));
talk_page.setFollowRedirect(true); // should never be needed, but if the article is moved, we would want to follow the redirect
talk_page.setChangeTags(Twinkle.changeTags);
talk_page.setCallbackParameters(params);
talk_page.newSection(null, function() {
talk_page.getStatusElement().warn('Unable to add edit request, the talk page may be protected');
});
}
},
getDiscussionWikitext: function(venue, params) {
if (venue === 'cfds') { // CfD/S takes a completely different style
return '* [[:' + Morebits.pageNameNorm + ']] to [[:' + params.cfdstarget + ']]\u00A0\u2013 ' +
params.xfdcat + (params.reason ? ': ' + Morebits.string.formatReasonText(params.reason) : '.') + ' ~~~~';
// U+00A0 NO-BREAK SPACE; U+2013 EN RULE
}
if (venue === 'rm') {
// even if invoked from talk page, propose the subject page for move
var pageName = new mw.Title(Morebits.pageNameNorm).getSubjectPage().toText();
var rmtrDiscuss = params['rmtr-discuss'] ? '|discuss=no' : '';
var rmtr = '{{subst:RMassist|1=' + pageName + '|2=' + params.newname + rmtrDiscuss + '|reason=' + params.reason + '}}';
var requestedMove = '{{subst:Requested move|current1=' + pageName + '|new1=' + params.newname + '|reason=' + params.reason + '}}';
return params.rmtr ? rmtr : requestedMove;
}
var text = '{{subst:' + venue + '2';
var reasonKey = venue === 'ffd' ? 'Reason' : 'text';
// Add a reason unconditionally, so that at least a signature is added
text += '|' + reasonKey + '=' + Morebits.string.formatReasonText(params.reason, true);
if (venue === 'afd' || venue === 'mfd') {
text += '|pg=' + Morebits.pageNameNorm;
if (venue === 'afd') {
text += '|cat=' + params.xfdcat;
}
} else if (venue === 'rfd') {
text += '|redirect=' + Morebits.pageNameNorm;
} else {
text += '|1=' + mw.config.get('wgTitle');
if (mw.config.get('wgPageContentModel') === 'Scribunto') {
text += '|module=Module:';
}
}
if (params.rfdtarget) {
text += '|target=' + params.rfdtarget + (params.section ? '#' + params.section : '');
} else if (params.tfdtarget) {
text += '|2=' + params.tfdtarget;
} else if (params.cfdtarget) {
text += '|2=' + params.cfdtarget;
if (params.cfdtarget2) {
text += '|3=' + params.cfdtarget2;
}
} else if (params.uploader) {
text += '|Uploader=' + params.uploader;
}
text += '}}';
if (venue === 'rfd' || venue === 'tfd' || venue === 'cfd') {
text += '\n';
}
// Don't delsort if delsortCats is undefined (TFD, FFD, etc.)
// Don't delsort if delsortCats is an empty array (AFD where user chose no categories)
if (Array.isArray(params.delsortCats) && params.delsortCats.length) {
text += '\n{{subst:Deletion sorting/multi|' + params.delsortCats.join('|') + '|sig=~~~~}}';
}
return text;
},
showPreview: function(form, venue, params) {
var templatetext = Twinkle.xfd.callbacks.getDiscussionWikitext(venue, params);
if (venue === 'rm') { // RM templates are sensitive to page title
form.previewer.beginRender(templatetext, params.rmtr ? 'Wikipedia:Requested moves/Technical requests' : new mw.Title(Morebits.pageNameNorm).getTalkPage().toText());
} else {
form.previewer.beginRender(templatetext, 'WP:TW'); // Force wikitext
}
},
preview: function(form) {
// venue, reason, xfdcat, tfdtarget, cfdtarget, cfdtarget2, cfdstarget, delsortCats, newname
var params = Morebits.quickForm.getInputData(form);
var venue = params.venue;
// Remove CfD or TfD namespace prefixes if given
if (params.tfdtarget) {
params.tfdtarget = utils.stripNs(params.tfdtarget);
} else if (params.cfdtarget) {
params.cfdtarget = utils.stripNs(params.cfdtarget);
if (params.cfdtarget2) {
params.cfdtarget2 = utils.stripNs(params.cfdtarget2);
}
} else if (params.cfdstarget) { // Add namespace if not given (CFDS)
params.cfdstarget = utils.addNs(params.cfdstarget, 14);
}
if (venue === 'ffd') {
// Fetch the uploader
var page = new Morebits.wiki.page(mw.config.get('wgPageName'));
page.lookupCreation(function() {
params.uploader = page.getCreator();
Twinkle.xfd.callbacks.showPreview(form, venue, params);
});
} else if (venue === 'rfd') { // Find the target
Twinkle.xfd.callbacks.rfd.findTarget(params, function(params) {
Twinkle.xfd.callbacks.showPreview(form, venue, params);
});
} else if (venue === 'cfd') { // Swap in CfD subactions
Twinkle.xfd.callbacks.showPreview(form, params.xfdcat, params);
} else {
Twinkle.xfd.callbacks.showPreview(form, venue, params);
}
},
/**
* Unified handler for sending {{Xfd notice}} notifications
* Also handles userspace logging
* @param {object} params
* @param {string} notifyTarget The user or page being notified
* @param {boolean} [noLog=false] Whether to skip logging to userspace
* XfD log, especially useful in cases in where multiple notifications
* may be sent out (MfD, TfM, RfD)
* @param {string} [actionName] Alternative description of the action
* being undertaken. Required if not notifying a user talk page.
*/
notifyUser: function(params, notifyTarget, noLog, actionName) {
// Ensure items with User talk or no namespace prefix both end
// up at user talkspace as expected, but retain the
// prefix-less username for addToLog
notifyTarget = mw.Title.newFromText(notifyTarget, 3);
var targetNS = notifyTarget.getNamespaceId();
var usernameOrTarget = notifyTarget.getRelativeText(3);
notifyTarget = notifyTarget.toText();
if (targetNS === 3) {
// Disallow warning yourself
if (usernameOrTarget === mw.config.get('wgUserName')) {
Morebits.status.warn('You (' + usernameOrTarget + ') created this page; skipping user notification');
// if we thought we would notify someone but didn't,
// then jump to logging.
Twinkle.xfd.callbacks.addToLog(params, null);
return;
}
// Default is notifying the initial contributor, but MfD also
// notifies userspace page owner
actionName = actionName || 'Notifying initial contributor (' + usernameOrTarget + ')';
}
var notifytext = '\n{{subst:' + params.venue + ' notice';
// Venue-specific parameters
switch (params.venue) {
case 'afd':
case 'mfd':
notifytext += params.numbering !== '' ? '|order= ' + params.numbering : '';
break;
case 'tfd':
if (params.xfdcat === 'tfm') {
notifytext = '\n{{subst:Tfm notice|2=' + params.tfdtarget;
}
break;
case 'cfd':
notifytext += '|action=' + params.action + (mw.config.get('wgNamespaceNumber') === 10 ? '|stub=yes' : '');
break;
default: // ffd, rfd
break;
}
notifytext += '|1=' + Morebits.pageNameNorm + '}} ~~~~';
// Link to the venue; object used here rather than repetitive items in switch
var venueNames = {
afd: 'Articles for deletion',
tfd: 'Templates for discussion',
mfd: 'Miscellany for deletion',
cfd: 'Categories for discussion',
ffd: 'Files for discussion',
rfd: 'Redirects for discussion'
};
var editSummary = 'Notification: [[' + params.discussionpage + '|listing]] of [[:' +
Morebits.pageNameNorm + ']] at [[WP:' + venueNames[params.venue] + ']].';
var usertalkpage = new Morebits.wiki.page(notifyTarget, actionName);
usertalkpage.setAppendText(notifytext);
usertalkpage.setEditSummary(editSummary);
usertalkpage.setChangeTags(Twinkle.changeTags);
usertalkpage.setCreateOption('recreate');
// Different pref for RfD target notifications
if (params.venue === 'rfd' && targetNS !== 3) {
usertalkpage.setWatchlist(Twinkle.getPref('xfdWatchRelated'));
} else {
usertalkpage.setWatchlist(Twinkle.getPref('xfdWatchUser'));
}
usertalkpage.setFollowRedirect(true, false);
if (noLog) {
usertalkpage.append();
} else {
usertalkpage.append(function onNotifySuccess() {
// Don't treat RfD target or MfD userspace owner as initialContrib in log
if (!params.notifycreator) {
notifyTarget = null;
}
// add this nomination to the user's userspace log
Twinkle.xfd.callbacks.addToLog(params, usernameOrTarget);
}, function onNotifyError() {
// if user could not be notified, log nomination without mentioning that notification was sent
Twinkle.xfd.callbacks.addToLog(params, null);
});
}
},
addToLog: function(params, initialContrib) {
if (!Twinkle.getPref('logXfdNominations') || Twinkle.getPref('noLogOnXfdNomination').indexOf(params.venue) !== -1) {
return;
}
var usl = new Morebits.userspaceLogger(Twinkle.getPref('xfdLogPageName'));// , 'Adding entry to userspace log');
usl.initialText =
"This is a log of all [[WP:XFD|deletion discussion]] nominations made by this user using [[WP:TW|Twinkle]]'s XfD module.\n\n" +
'If you no longer wish to keep this log, you can turn it off using the [[Wikipedia:Twinkle/Preferences|preferences panel]], and ' +
'nominate this page for speedy deletion under [[WP:CSD#U1|CSD U1]].' +
(Morebits.userIsSysop ? '\n\nThis log does not track XfD-related deletions made using Twinkle.' : '');
var editsummary;
if (params.discussionpage) {
editsummary = 'Logging [[' + params.discussionpage + '|' + utils.toTLACase(params.venue) + ' nomination]] of [[:' + Morebits.pageNameNorm + ']].';
} else {
editsummary = 'Logging ' + utils.toTLACase(params.venue) + ' nomination of [[:' + Morebits.pageNameNorm + ']].';
}
// If a logged file is deleted but exists on commons, the wikilink will be blue, so provide a link to the log
var fileLogLink = mw.config.get('wgNamespaceNumber') === 6 ? ' ([{{fullurl:Special:Log|page=' + mw.util.wikiUrlencode(mw.config.get('wgPageName')) + '}} log])' : '';
// CFD/S and RM don't have canonical links
var nominatedLink = params.discussionpage ? '[[' + params.discussionpage + '|nominated]]' : 'nominated';
var appendText = '# [[:' + Morebits.pageNameNorm + ']]:' + fileLogLink + ' ' + nominatedLink + ' at [[WP:' + params.venue.toUpperCase() + '|' + utils.toTLACase(params.venue) + ']]';
switch (params.venue) {
case 'tfd':
if (params.xfdcat === 'tfm') {
appendText += ' (merge)';
if (params.tfdtarget) {
var contentModel = mw.config.get('wgPageContentModel') === 'Scribunto' ? 'Module:' : 'Template:';
appendText += '; Other ' + contentModel.toLowerCase() + ' [[';
if (!new RegExp('^:?' + Morebits.namespaceRegex([10, 828]) + ':', 'i').test(params.tfdtarget)) {
appendText += contentModel;
}
appendText += params.tfdtarget + ']]';
}
}
break;
case 'mfd':