This repository has been archived by the owner on Feb 4, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
submissions.js
1661 lines (1574 loc) · 86.7 KB
/
submissions.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>
// Script should be located at [[MediaWiki:Gadget-afchelper.js/submissions.js]]
var afcHelper_PageName = wgPageName.replace(/_/g, ' ');
var afcHelper_AJAXnumber = 0;
var afcHelper_submissionTitle = wgTitle.replace(/Articles for creation\//g, '');
var disambig_re = /Disambig|Mil-unit-dis|Hndis|Geodis|Numberdis/i;
var typetemplate_re = /\{\{\s*documentation\s*(?:\{\{[^\{\}]*\}\}|[^\}\{])*\}\}/i;
var afcdab_re = /\{\{\s*afc submission\s*\|(?:\{\{[^\{\}]*\}\}|[^\}\{])*\|\s*type\s*=\s*dab\s*(?:\{\{[^\{\}]*\}\}|[^\}\{])*\}\}/i;
var afctemplate_re = /\{\{\s*afc submission\s*\|(?:\{\{[^\{\}]*\}\}|[^\}\{])*\|\s*type\s*=\s*template\s*(?:\{\{[^\{\}]*\}\}|[^\}\{])*\}\}/i;
var afc_re = /\{\{\s*afc submission\s*\|(?:\{\{[^\{\}]*\}\}|[^\}\{])*\}\}/i;
var all_afc_re = /\{\{\s*afc submission\s*\|(?:\{\{[^\{\}]*\}\}|[^\}\{])*\}\}/gi;
var pending_afc_re = /(\{\{\s*afc submission\s*\|)(\s*[||r])+((?:\{\{[^\{\}]*\}\}|[^\}\{])*\}\})/i;
var declined_afc_re = /(\{\{\s*afc submission\s*\|)(\s*[d])+((?:\{\{[^\{\}]*\}\}|[^\}\{])*)(\|small=yes)(\}\})/i;
var reviewing_afc_re = /\{\{\s*afc submission\s*\|\s*r\s*((?:\{\{[^\{\}]*\}\}|[^\}\{])*\}\})/i;
var template_status_re = /(\{\{\s*afc submission\s*\|)(\s*|r|d)+((?:\{\{[^\{\}]*\}\}|[^\}\{])*\}\})/i;
var afc_comment_re = /\{\{\s*afc comment(?:\{\{[^\{\}]*\}\}|[^\}\{])*\}\}/i;
var draft_afc_re = /\{\{\s*afc submission\s*\|\s*t(?:\{\{[^\{\}]*\}\}|[^\}\{])*\}\}/i;
var not_draft_afc_re = /\{\{\s*afc submission\s*\|\s*[^t](?:\{\{[^\{\}]*\}\}|[^\}\{])*\}\}/i;
var submissiontemplate_re = /(\{\{\s*afc submission\s*\|\s*([||t|r|d])(?:\{\{[^\{\}]*\}\}|[^\}\{])*)(\|\s*ts\s*=\s*([0-9]{14})|\{\{subst:LOCALTIMESTAMP\}\}|\{\{REVISIONTIMESTAMP\}\})((?:\{\{[^\{\}]*\}\}|[^\}\{]))*\}\}/i;
var exclusive_pending_afc_re = /(\{\{\s*afc submission\s*\|)(\s*[|]\s*)*((?:\{\{[^\{\}]*\}\}|[^\}\{])*\}\})/i;
var afcHelper_pageStatuses = new Array(); // List of all statuses on the page (e.g., ['r','d'])
var afcHelper_cache = {};
var afcHelper_longcomments = {};
var afcHelper_reasonhash = [{
label: 'DUPLICATE ARTICLES',
value: 'Duplicate articles',
disabled: true
}, {
label: 'exists - Submission is duplicated by another article already in mainspace',
value: 'exists',
reason: 'submission already exists in main space'
}, {
label: 'dup - Submission is a duplicate of another existing submission',
value: 'dup',
reason: 'submission is a duplicate of another submission'
}, {
label: 'TEST EDITS',
value: 'Test edits',
disabled: true
}, {
label: 'blank - Submission is blank',
value: 'blank',
reason: 'submission is blank'
}, {
label: 'test - Submission appears to be a test edit',
value: 'test',
reason: 'submission is a test edit'
}, {
label: 'BLP/VANDALISM',
value: 'BLP/Vandalism',
disabled: true
}, {
label: 'van - Submission is vandalism, a negative unsourced BLP, or an attack page (please blank the page and mark it for deletion)',
value: 'van',
reason: 'submission is vandalism, a negative unsourced BLP, or an attack page'
}, {
label: 'ilc - Submission is a BLP that does not meet minimum inline citation requirements (WP:MINREF)',
value: 'ilc',
reason: 'submission does not contain minimum citations'
}, {
label: 'blp - BLP contains unsourced, possibly defamatory claims, but WP:AGF and wait for sources (blank the page but do not CSD it)',
value: 'blp',
reason: 'submission does not conform to BLP'
}, {
label: 'MERGING',
value: 'Merging',
disabled: true
}, {
label: 'mergeto - Submission should be merged into another article (indicate which article in the comment box)',
value: 'mergeto',
reason: 'submission is too short but can be merged'
}, {
label: 'BLATANT [[WP:NOT]] VIOLATIONS',
value: 'Blatant [[WP:NOT]] violations',
disabled: true
}, {
label: 'joke - Submission appears to be a joke or hoax',
value: 'joke',
reason: 'submission appears to be a joke'
}, {
label: 'not - Submission fails [[Wikipedia:What Wikipedia is not]]',
value: 'not',
reason: 'submission is covered by WP:NOT'
}, {
label: 'PROSE ISSUES',
value: 'Prose issues',
disabled: true
}, {
label: 'lang - Submission is not in English',
value: 'lang',
reason: 'submission is not in English'
}, {
label: 'cv - Submission is a copyright violation (blank the article, enter links in the box below, and mark for deletion)',
value: 'cv',
reason: 'submission is a copyright violation'
}, {
label: 'redirect - Submission is a redirect request',
value: 'redirect',
reason: 'submission is a redirect request'
}, {
label: 'news - Submission appears to be a news story of a single event',
value: 'news',
reason: 'submission appears to be a news report of a single event'
}, {
label: 'dict - Submission is a dictionary definition',
value: 'dict',
reason: 'submission is a dictionary definition'
}, {
label: 'plot - Submission consists mostly of a plot summary',
value: 'plot',
reason: 'submission is a plot summary'
}, {
label: 'adv - Submission reads like an advertisement',
value: 'adv',
reason: 'submission is written like an advertisement'
}, {
label: 'context - Submission provides insufficient context',
value: 'context',
reason: 'submission provides insufficient context'
}, {
label: 'essay - Submission reads like an essay',
value: 'essay',
reason: 'submission reads like an essay'
}, {
label: 'npov - Submission is not written in a formal, neutral encyclopedic tone',
value: 'npov',
reason: 'submission is not written from a formal, neutral point of view'
}, {
label: 'NOTABILITY',
value: 'Notability',
disabled: true
}, {
label: 'neo - Submission is about a neologisim that does not meet notability guidelines',
value: 'neo',
reason: 'submission is a neologism'
}, {
label: 'web - Submission is about web content does not meet notability guidelines',
value: 'web',
reason: 'subject appears to be non-notable web content'
}, {
label: 'prof - Submission is about a professor does not meet notability guidelines',
value: 'prof',
reason: 'subject appears to be a non-notable academic'
}, {
label: 'athlete - Submission is about an athlete does not meet notability guidelines',
value: 'athlete',
reason: 'subject appears to be a non-notable athlete'
}, {
label: 'music - Submission is about a musician or musical work does not meet notability guidelines',
value: 'music',
reason: 'subject appears to be a non-notable musical performer or work'
}, {
label: 'film - Submission is about a film does not meet notability guidelines',
value: 'film',
reason: 'subject appears to be a non-notable film'
}, {
label: 'corp - Submission is about a company or organization does not meet notability guidelines',
value: 'corp',
reason: 'subject appears to be a non-notable company or organization'
}, {
label: 'bio - Submission is about a person does not meet notability guidelines',
value: 'bio',
reason: 'subject appears to be a non-notable person'
}, {
label: 'nn - Submission does not meet general notability guidelines (use a more specific reason if possible)',
value: 'nn',
reason: 'subject appears to be non-notable'
}, {
label: 'SOURCING',
value: 'Sourcing',
disabled: true
}, {
label: 'v - Submission is improperly sourced',
value: 'v',
reason: 'submission is unsourced or contains only unreliable sources'
}, {
label: 'OTHER',
value: 'Other',
disabled: true
}, {
label: 'custom - Enter a decline reason in the box below, linking to relevant policies',
value: 'reason',
reason: ''
}, {
label: 'Select a reason for declining',
selected: true,
value: 'reason',
disabled: true,
reason: ''
}];
function afcHelper_init() {
displayMessage('<div id="afcHelper_loadingmsg">Loading the Article for creation helper script...</div>');
if (!wfSupportsAjax()) {
displayMessage('<span class="afcHelper_notice">Uh-oh! Your browser appears to be too old to handle the helper script or does not support AJAX. Please <a href="http://browsehappy.com">upgrade</a> to the latest version of Firefox, Safari, Chrome, or Opera for best results. Sorry about that; please <a href="https://en.wikipedia.org/wiki/Wikipedia_talk:WikiProject_Articles_for_creation/Helper_script" target="_blank">let us know</a> if you need further assistance.</span>');
return;
}
var form = '<div id="afcHelper_initialform">';
form += afcHelper_setup();
form += '<h3>Reviewing ' + afcHelper_PageName + '</h3>';
if (BETA) form += '<div id="afcHelper_betanotice">You are currently running a <b>beta version</b> of the Articles for creation helper script. Some features may not work as intended; please report errors <a href="https://en.wikipedia.org/wiki/Wikipedia_talk:WikiProject_Articles_for_creation/Helper_script" target="_blank">here</a>.</div>';
if ($.inArray("", afcHelper_pageStatuses) != -1 || $.inArray("r", afcHelper_pageStatuses) != -1) {
form += '<button class="afcHelper_button" type="button" id="afcHelper_accept_button" onclick="afcHelper_prompt(\'accept\')">Accept</button>';
form += '<button class="afcHelper_button" type="button" id="afcHelper_decline_button" onclick="afcHelper_prompt(\'decline\')">Decline</button>';
}
if (afcHelper_g13_eligible(afcHelper_PageName) && $.inArray("", afcHelper_pageStatuses) == -1 && $.inArray("r", afcHelper_pageStatuses) == -1) {
form += '<button class="afcHelper_button" type="button" id="afcHelper_accept_button" onclick="afcHelper_prompt(\'accept\')">Accept G13-eligible submission</button>';
form += '<button class="afcHelper_button" type="button" id="afcHelper_g13_button" onclick="afcHelper_act(\'g13\')">Tag the submission for G13 speedy deletion</button>';
form += '<button class="afcHelper_button" type="button" id="afcHelper_postpone_g13_button" onclick="afcHelper_prompt(\'postpone_g13\')">Postpone G13 deletion</button>';
}
if ($.inArray("", afcHelper_pageStatuses) != -1 || $.inArray("r", afcHelper_pageStatuses) != -1 || $.inArray("d", afcHelper_pageStatuses) != -1) form += '<button class="afcHelper_button" type="button" id="afcHelper_comment_button" onclick="afcHelper_prompt(\'comment\')">Comment</button>';
if (afcHelper_pageStatuses === false || $.inArray("t", afcHelper_pageStatuses) != -1 || (($.inArray("d", afcHelper_pageStatuses) != -1) && ($.inArray("", afcHelper_pageStatuses) == -1) && ($.inArray("r", afcHelper_pageStatuses) == -1))) form += '<button class="afcHelper_button" type="button" id="afcHelper_submit_button" onclick="afcHelper_prompt(\'submit\')">Submit</button>';
if (afcHelper_pageStatuses === false) form += '<button class="afcHelper_button" type="button" id="afcHelper_draft_button" onclick="afcHelper_prompt(\'draft\')">Mark as draft submission</button>';
if ($.inArray("r", afcHelper_pageStatuses) != -1) {
form += '<button class="afcHelper_button" type="button" id="afcHelper_unmark_button" onclick="afcHelper_act(\'unmark\')">Unmark as reviewing</button>';
} else if ($.inArray("", afcHelper_pageStatuses) != -1) {
form += '<button class="afcHelper_button" type="button" id="afcHelper_mark_button" onclick="afcHelper_prompt(\'mark\')">Mark as reviewing</button>';
}
if (afcHelper_pageStatuses === false || $.inArray("", afcHelper_pageStatuses) != -1 || $.inArray("r", afcHelper_pageStatuses) != -1 || $.inArray("d", afcHelper_pageStatuses) != -1 || $.inArray("t", afcHelper_pageStatuses) != -1) form += '<button class="afcHelper_button" type="button" id="afcHelper_cleanup_button" onclick="afcHelper_act(\'cleanup\')">Clean the submission</button>';
form += '<div id="afcHelper_extra"></div>';
displayMessage(form);
}
function afcHelper_prompt(type) {
if (type === 'accept') {
if (!afcHelper_underreview()) return;
var afcHelper_assessment = [{
label: 'B-class',
value: 'B'
}, {
label: 'C-class',
value: 'C'
}, {
label: 'Start-class',
value: 'start'
}, {
label: 'Stub-class',
value: 'stub'
}, {
label: 'List-class',
value: 'list'
}, {
label: 'Disambig-class',
value: 'disambig',
selected: (((afcdab_re.test(pagetext)) || (disambig_re.test(pagetext))) ? true : false)
}, {
label: 'Template-class',
value: 'template',
selected: (((afctemplate_re.test(pagetext)) || (typetemplate_re.test(pagetext))) ? true : false)
}, {
label: 'Redirect-class',
value: 'redirect'
}, {
label: 'Portal-class',
value: 'portal'
}, {
label: 'Project-class',
value: 'project'
}, {
label: 'Template-class',
value: 'template'
}, {
label: 'NA-class',
value: 'na'
}, {
label: 'None',
selected: (((afctemplate_re.test(pagetext)) || (disambig_re.test(pagetext)) || (afcdab_re.test(pagetext)) || (typetemplate_re.test(pagetext))) ? false : true),
value: ''
}];
var text = '<h3>Accepting ' + afcHelper_PageName + '</h3>' +
'<label for="afcHelper_movetarget">Move submission to: </label><input type="text" id="afcHelper_movetarget" value="' + afcHelper_escapeHtmlChars(afcHelper_submissionTitle) + '" />' +
'<br /><label for="afcHelper_assessment">Assessment (optional): </label>';
var assessmentSelect = afcHelper_generateSelect("afcHelper_assessment", afcHelper_assessment, null);
text += assessmentSelect;
// First load the list of wikiprojects and store it to afcHelper_wikiprojectindex
$.ajax({
url: mw.config.get('wgServer') + "/w/index.php?title=User:Theo%27s_Little_Bot/afchwikiproject.js&action=raw&ctype=text/javascript",
dataType: "json",
success: function (wikiproject_data) {
var wikiprojectSelect = afcHelper_generateChzn("afcHelper_wikiproject_selection",'Start typing to filter the list of WikiProjects...',wikiproject_data);
var text = '<label for="afcHelper_wikiproject_selection">Choose associated WikiProjects to be automatically be added to the talk page: </label><br>' + wikiprojectSelect;
$('#afcHelper_wikiprojectSelect').html(text);
$("#afcHelper_wikiproject_selection").chosen({no_results_text: "Oops, couldn't find any WikiProjects matching your input!"});
},
fail: function() {
$('#afcHelper_wikiprojectSelect').html('Unable to load WikiProject selection tool.');
}
//async: false
});
// Then generate a dynamic menu for them
text += '<br /><div id="afcHelper_wikiprojectSelect">[Loading WikiProject selection tool...]</div>';
text += '<label for="afcHelper_pagePrepend">Prepend wikicode to page (optional, e.g. maintenance boxes): </label><br><textarea class="afcHelper_expand" rows="1" cols="60" id="afcHelper_pagePrepend" spellcheck="true"></textarea>' +
'<br /><label for="afcHelper_pageAppend">Append wikicode to page (optional, e.g. categories or stub templates): </label><br><textarea class="afcHelper_expand" rows="1" cols="60" id="afcHelper_pageAppend" spellcheck="true"></textarea>' +
'<br /><label for="afcHelper_talkAppend">Append wikicode to talk page (optional, e.g. WikiProject templates): </label><br><textarea class="afcHelper_expand" rows="1" cols="60" id="afcHelper_talkAppend" spellcheck="true"></textarea>' +
'<br /><label for="afcHelper_reqphoto">Does the article need a photo/image? (will add {{<a href="'+ wgArticlePath.replace("$1", 'Template:Reqphoto') + '" title="Template:Reqphoto" target="_blank">reqphoto</a>}} to talk page) </label><input type="checkbox" id="afcHelper_reqphoto"/>' +
'<br /><label for="afcHelper_reqinfobox">Does the article need an infobox? (will add {{<a href="'+ wgArticlePath.replace("$1", 'Template:Reqinfobox') + '" title="Template:Reqinfobox" target="_blank">reqinfobox</a>}} to talk page) </label><input type="checkbox" id="afcHelper_reqinfobox"/>' +
'<br /><label for="afcHelper_biography">Is the article a biography? </label><input type="checkbox" id="afcHelper_biography" onchange=afcHelper_trigger(\'afcHelper_biography_blp\') />' +
'<div id="afcHelper_biography_blp" style="display:none"><label for="afcHelper_dateofbirth">Month and day of birth (if known/given, e.g. <i>November 2</i>): </label><input type="text" id="afcHelper_dateofbirth" spellcheck="true"/>' +
'<br /><label for="afcHelper_yearofbirth">Year of birth (if known/given, e.g. <i>1901</i>): </label><input type="text" id="afcHelper_yearofbirth" />' +
'<br /><label for="afcHelper_listas">Surname, Name (if known/given, for <a href="' + wgArticlePath.replace("$1", 'Wikipedia:Listas') + '" title="Wikipedia:Listas" target="_blank">LISTAS</a> – e.g. <i>Magellan, Ferdinand</i>): </label><input type="text" id="afcHelper_listas" />' +
'<br /><label for="afcHelper_shortdescription">A very short description about the person (e.g. <i>sea explorer</i> – <a href="' + wgArticlePath.replace("$1", 'Wikipedia:Persondata#Short_description') + '" title="Wikipedia:Persondata#Short_description" target="_blank">more details</a>): </label><input type="text" id="afcHelper_shortdescription" spellcheck="true"/>' +
'<br /><label for="afcHelper_alternativesname">Alternative names (e.g. <i>Magallanes, Fernando de</i>): </label><input type="text" id="afcHelper_alternativesname" />' +
'<br /><label for="afcHelper_placeofbirth">Place of birth (if known/given): </label><input type="text" id="afcHelper_placeofbirth" spellcheck="true"/>' +
'<br /><label for="afcHelper_biography_status">Is the article about a living person? </label>' + afcHelper_generateSelect('afcHelper_biography_status', [{
label: 'Living',
value: 'live'
}, {
label: 'Dead',
value: 'dead'
}, {
label: 'Unknown',
selected: true,
value: 'unknown'
}], "afcHelper_trigger(\'afcHelper_biography_status_box\')") + '<div id="afcHelper_biography_status_box" style="display:none"><label for="afcHelper_placeofdeath">Place of death (if known/given): </label><input type="text" id="afcHelper_placeofdeath" spellcheck="true"/>' +
'<br /><label for="afcHelper_dateofdeath">Month and day of death (if known/given, e.g. <i>September 3</i>): </label><input type="text" id="afcHelper_dateofdeath" spellcheck="true"/>' +
'<br /><label for="afcHelper_yearofdeath">Year of death (if known/given): </label><input type="text" id="afcHelper_yearofdeath" />' +
'</div></div><div id="afcHelper_extra_inline"></div>' +
'<button class="afcHelper_button" type="button" id="afcHelper_accept_button" onclick="afcHelper_act(\'accept\')">Accept and publish to mainspace</button>';
$("#afcHelper_extra").html(text);
// Expand textareas on click so they don't take up space, and then...
$('textarea.afcHelper_expand').focus(function () {
$(this).animate({ height: "4em" }, 500);
});
// ...shrink them back on blur if they have no content
$('textarea.afcHelper_expand').blur(function () {
if (!this.value) $(this).animate({ height: "1em" }, 500);
});
} else if (type === 'decline') {
if (!afcHelper_underreview()) return;
var text = '<h3>Declining ' + afcHelper_PageName + '</h3>' + '<label for="afcHelper_reason">Reason for ' + type + ': </label>';
var reasonSelect = afcHelper_generateSelect("afcHelper_reason", afcHelper_reasonhash, "afcHelper_onChange(this)");
text += reasonSelect;
text += '<div id="afcHelper_extra_inline"></div>';
text += '<label for="afcHelper_comments">Additional comments (optional, signature is automatically added): </label><textarea rows="3" cols="60" id="afcHelper_comments" spellcheck="true"></textarea>' +
'<label for="afcHelper_blank">Blank the submission (replace the content with {{<a href="' + wgArticlePath.replace("$1", 'Template:Afc_cleared') + '" title="Template:Afc cleared" target="_blank">afc cleared</a>}}):</label><input type="checkbox" id="afcHelper_blank" onchange=afcHelper_trigger(\'afcHelper_afcccleared\') /><br/>' +
'<div id="afcHelper_extra_afccleared" style="display:none"><label for="afcHelper_afccleared">Trigger the \'csd\' parameter and nominate the submission for speedy deletion?</label> <input type="checkbox" id="afcHelper_blank_csd"/><br/></div>' +
'<label for="afcHelper_notify">Notify author:</label><input type="checkbox" onchange=afcHelper_trigger(\'afcHelper_notify_Teahouse\') id="afcHelper_notify" checked="checked" /><br/>' +
'<div id="afcHelper_notify_Teahouse"><label for="afcHelper_notify_Teahouse">Notify author about <a href="' + wgArticlePath.replace("$1", 'Wikipedia:Teahouse') + '" title="Wikipedia:Teahouse" target="_blank">Wikipedia:Teahouse</a>:</label><input type="checkbox" id="afcHelper_Teahouse" /><br/></div><button type="button" class="afcHelper_button decline" id="afcHelper_prompt_button" onclick="afcHelper_act(\'decline\')">Decline</button>';
$("#afcHelper_extra").html(text);
} else if (type === 'submit') {
// !todo have "first" be pre-selected if submission template includes "t", else have "last" pre-selected
var text = '<h3>Place a submission template on ' + afcHelper_PageName + '</h3>';
text += '<input type="radio" name="afcHelper_submit" id="afcHelper_submit1" value="first" /> <label for="afcHelper_submit1">submit with the original submitter</label><br>' +
'<input type="radio" name="afcHelper_submit" id="afcHelper_submit2" value="last" /> <label for="afcHelper_submit2">submit with the last non-bot editor as the submitter</label><br>' +
'<input type="radio" name="afcHelper_submit" id="afcHelper_submit3" value="creator" checked /> <label for="afcHelper_submit3">submit with the page creator as the submitter</label><br>' +
'<input type="radio" name="afcHelper_submit" id="afcHelper_submit4" value="self" checked /> <label for="afcHelper_submit3">submit with yourself as the submitter</label><br>' +
'<input type="radio" name="afcHelper_submit" id="afcHelper_submit5" value="custom" /> <label for="afcHelper_submit4">submit with a custom submitter:</label> <input type="text" id="afcHelper_custom_submitter" /><br>' +
'<button class="afcHelper_button" type="button" id="afcHelper_submit_button" onclick="afcHelper_act(\'submit\')">Place a submit template</button>';
$("#afcHelper_extra").html(text);
} else if (type === 'draft') {
var text = '<h3>Place a draft submission template on ' + afcHelper_PageName + '</h3>';
text += '<input type="radio" name="afcHelper_draft" id="afcHelper_draft1" value="self" checked /> <label for="afcHelper_submit1">tag with yourself as the submitter</label><br>' +
'<input type="radio" name="afcHelper_draft" id="afcHelper_draft2" value="last" /> <label for="afcHelper_submit2">tag with the last non-bot editor as the submitter</label><br>' +
'<input type="radio" name="afcHelper_draft" id="afcHelper_draft3" value="creator" checked /> <label for="afcHelper_submit3">tag with the page creator as the submitter</label><br>' +
'<input type="radio" name="afcHelper_draft" id="afcHelper_draft4" value="custom" /> <label for="afcHelper_submit4">tag with a custom submitter:</label> <input type="text" id="afcHelper_draft_submitter" /><br>' +
'<button class="afcHelper_button" type="button" id="afcHelper_draft_button" onclick="afcHelper_act(\'draft\')">Place {{AFC draft}} template</button>';
$("#afcHelper_extra").html(text);
} else if (type === 'mark') {
var text = '<h3>Marking submission ' + afcHelper_PageName + ' as under review</h3>' +
'<label for="afcHelper_comments">Additional comment (signature is automatically added): </label><textarea rows="3" cols="60" id="afcHelper_comments" spellcheck="true"></textarea><br/><button type="button" class="afcHelper_button mark" id="afcHelper_prompt_button" onclick="afcHelper_act(\'mark\')">Place under review</button>';
$("#afcHelper_extra").html(text);
} else if (type === 'comment') {
var text = '<h3>Commenting on ' + afcHelper_PageName + ' </h3>' +
'<label for="afcHelper_comments">Comment (signature is automatically added): </label><textarea rows="3" cols="60" id="afcHelper_comments" spellcheck="true"></textarea><br/><button type="button" class="afcHelper_button comment" id="afcHelper_prompt_button" onclick="afcHelper_act(\'comment\')">Add comment</button>';
$("#afcHelper_extra").html(text);
} else if (type === 'postpone_g13') {
var text = '<h3>Additional comment when postponing speedy deletion</h3>' +
'<label for="afcHelper_comments">Comment (signature is automatically added): </label><textarea rows="3" cols="60" id="afcHelper_comments" spellcheck="true"></textarea><br/><button type="button" class="afcHelper_button" id="afcHelper_prompt_button" onclick="afcHelper_act(\'postpone_g13\')">Postpone G13 speedy deletion</button>';
$("#afcHelper_extra").html(text);
}
}
function afcHelper_act(action) {
if (mw.util.getParamValue('action') === 'edit') {
// If page is in edit mode and has been modified, use the contents of the textbox as `pagetext`.
if (confirm('The helper script will use your modified page text from the text box below when processing the page.\n[click "OK" to continue or "Cancel" to abort]'))
pagetext = $('textarea[name=wpTextbox1]').val();
else
return;
}
if (action === 'draft') {
var typeofsubmit = $("input[name=afcHelper_draft]:checked").val();
var customuser = $("#afcHelper_draft_submitter").val();
displayMessage('<ul id="afcHelper_status"></ul><ul id="afcHelper_finish"></ul>');
afcHelper_displaymessagehelper('done','standard');
if (typeofsubmit == "last") {
user = afcHelper_last_nonbot(afcHelper_PageName)['user'];
var submit = "{{subst:AFC draft|" + user + "}}\n";
} else if (typeofsubmit == 'self') {
var submit = "{{subst:AFC draft}}\n";
} else if (typeofsubmit == 'creator') {
var submit = "{{subst:AFC draft|"+afcHelper_page_creator(afcHelper_PageName)+"}}\n";
} else if (typeofsubmit == 'custom' && customuser != null && customuser != "") {
var submit = "{{subst:AFC draft|" + customuser + "}}\n";
} else {
alert("No valid submitter was specified, aborting...");
return;
}
newtext = submit + pagetext;
newtext = afcHelper_cleanup(newtext);
afcHelper_editPage(afcHelper_PageName, newtext, "Tagging [[Wikipedia:Articles for creation]] draft", false);
} else if (action === 'postpone_g13') {
var comment = $("#afcHelper_comments").val();
displayMessage('<ul id="afcHelper_status"></ul><ul id="afcHelper_finish"></ul>');
afcHelper_displaymessagehelper('done','standard');
pagetext = afcHelper_addcomment(comment) + pagetext;
postpone_re = /\{\{AfC postpone G13\s*(?:\|\s*(\d*)\s*)?\}\}/ig;
var match = postpone_re.exec(pagetext);
if (match) {
if (match[1] != undefined) {
addition = "{{AfC postpone G13|"+(parseInt(match[1])+1)+"}}";
} else {
addition = "{{AfC postpone G13|2}}";
}
newtext = pagetext.replace(match[0],addition);
} else {
newtext = pagetext+"\n{{AfC postpone G13|1}}";
}
newtext = afcHelper_cleanup(newtext);
afcHelper_editPage(afcHelper_PageName, newtext, "Postponing [[WP:G13|G13]] speedy deletion", false);
} else if (action === 'g13') {
displayMessage('<ul id="afcHelper_status"></ul><ul id="afcHelper_finish"></ul>');
afcHelper_displaymessagehelper('done','standard');
timestamp = afcHelper_cache.afcHelper_lastedited;
newtext = "{{Db-g13|ts=" + timestamp + "}}\n" + pagetext;
newtext = afcHelper_cleanup(newtext);
afcHelper_editPage(afcHelper_PageName, newtext, "Tagging abandoned [[Wikipedia:Articles for creation]] draft for speedy deletion under [[WP:G13|G13]]", false);
// notify users
var users = new Array();
var templates = pagetext.match(all_afc_re);
var author_re = /\|\s*u=\s*[^\|]*\|/i;
if (templates) {
for (var i = 0; i < templates.length; i++) {
if (author_re.test(templates[i])) {
user = author_re.exec(templates[i])[0];
username = user.split(/=/)[1];
username = username.replace(/\|/g, '');
users.push(username);
}
}
}
users.push(afcHelper_page_creator(afcHelper_PageName)); // page creator
var uniqueUsers = [];
$.each(users, function(i, l) {
if ($.inArray(l, uniqueUsers) === -1) uniqueUsers.push(l);
});
for (var i = 0; i < uniqueUsers.length; i++) {
username = uniqueUsers[i];
usertalkpage = "User talk:" + username;
var usertext = afcHelper_getPageText(usertalkpage, true, true);
usertext += "\n{{subst:Db-afc-notice|" + afcHelper_PageName + "}} ~~~~";
afcHelper_editPage(usertalkpage, usertext, 'Notification: [[WP:G13|G13]] speedy deletion nomination of [[' + afcHelper_PageName + ']]', false, true);
}
afcHelper_logcsd(afcHelper_PageName,"[[CSD:G13]] ({{tl|db-afc}})",uniqueUsers);
} else if (action === 'submit') {
var typeofsubmit = $("input[name=afcHelper_submit]:checked").val();
var customuser = $("#afcHelper_custom_submitter").val();
displayMessage('<ul id="afcHelper_status"></ul><ul id="afcHelper_finish"></ul>');
afcHelper_displaymessagehelper('done','standard');
// First we handle "last", since this uses a different method than the others
if (typeofsubmit == 'last') {
// Get the last non-bot editor to the page
var submitinfo = afcHelper_last_nonbot(afcHelper_PageName);
if (submitinfo) {
dt = new Date(submitinfo['timestamp']);
// output the date in the correct format
date = dt.getUTCFullYear() + ('0' + (dt.getUTCMonth() + 1)).slice(-2) + ('0' + dt.getUTCDate()).slice(-2) + ('0' + dt.getUTCHours()).slice(-2) + ('0' + dt.getUTCMinutes()).slice(-2) + ('0' + dt.getUTCSeconds()).slice(-2);
var submit = "{{AFC submission|||ts=" + date + "|u=" + submitinfo['user'] + "|ns=" + wgNamespaceNumber + "}}\n";
newtext = submit + pagetext;
newtext = afcHelper_cleanup(newtext);
afcHelper_editPage(afcHelper_PageName, newtext, "Submitting [[Wikipedia:Articles for creation]] submission", false);
} else {
alert("Unable to find a non-bot editor; please check the page history.");
}
} else {
if (typeofsubmit == 'first') {
if (afc_re.test(pagetext)) {
var afctemplate = afc_re.exec(pagetext)[0];
var author_re = /\|\s*u=\s*[^\|]*\|/i;
if (author_re.test(afctemplate)) {
var user = author_re.exec(afctemplate)[0];
username = user.split(/=/)[1];
submitter = username.replace(/\|/g, '');
} else {
alert("Could not find the original submitter, aborting...");
return;
}
} else {
alert("Could not find an AfC submission template, aborting...");
return;
}
var submit = "{{subst:submit|user=" + submitter + "}}\n";
} else if (typeofsubmit == 'self') {
var submit = "{{subst:submit}}\n";
} else if (typeofsubmit == 'custom' && customuser != null && customuser != "") {
var submit = "{{subst:submit|user=" + customuser + "}}\n";
} else if (typeofsubmit == 'creator') {
var submit = "{{subst:submit|user="+afcHelper_page_creator(afcHelper_PageName)+"}}\n";
} else {
alert("No valid submitter was specified, aborting...");
return;
}
if (afcHelper_g13_eligible(afcHelper_PageName)) {
postpone_re = /\{\{AfC postpone G13\s*(?:\|\s*(\d*)\s*)?\}\}/ig;
var match = postpone_re.exec(pagetext);
if (match) {
if (match[1] != undefined) {
addition = "{{AfC postpone G13|"+(parseInt(match[1])+1)+"}}";
} else {
addition = "{{AfC postpone G13|2}}";
}
newtext = submit + pagetext.replace(match[0],addition);
} else {
newtext = submit + pagetext + "\n{{AfC postpone G13|1}}";
}
} else {
newtext = submit + pagetext
}
newtext = afcHelper_cleanup(newtext);
afcHelper_editPage(afcHelper_PageName, newtext, "Submitting [[Wikipedia:Articles for creation]] submission", false);
}
} else if (action === 'accept') {
var newtitle = $("#afcHelper_movetarget").val();
var assessment = $("#afcHelper_assessment").val();
var pagePrepend = $("#afcHelper_pagePrepend").val();
var pageAppend = $("#afcHelper_pageAppend").val();
var talkAppend = $("#afcHelper_talkAppend").val();
var biography = $("#afcHelper_biography").attr("checked");
var reqinfobox = $("#afcHelper_reqinfobox").attr("checked");
var reqphoto = $("#afcHelper_reqphoto").attr("checked");
var selectedwikiprojects = new Array();
$("#afcHelper_wikiproject_selection option:selected").each(function() {
selectedwikiprojects.push($(this).val());
});
if (biography) {
var living = $("#afcHelper_biography_status").val(); //dropdown menu
var yearofbirth = $("#afcHelper_yearofbirth").val();
var dateofbirth = $("#afcHelper_dateofbirth").val();
var listas = $("#afcHelper_listas").val();
var shortdescription = $("#afcHelper_shortdescription").val();
var alternativesname = $("#afcHelper_alternativesname").val();
var placeofbirth = $("#afcHelper_placeofbirth").val();
var placeofdeath = '';
var yearofdeath = '';
var dateofdeath = '';
if (living === 'dead') {
yearofdeath = $("#afcHelper_yearofdeath").val();
dateofdeath = $("#afcHelper_dateofdeath").val();
placeofdeath = $("#afcHelper_placeofdeath").val();
}
}
displayMessage('<ul id="afcHelper_status"></ul><ul id="afcHelper_finish"></ul>');
afcHelper_displaymessagehelper('done','standard');
var callback = function() {
var username = '';
// clean up page
if (afc_re.test(pagetext)) {
var afctemplate = afc_re.exec(pagetext)[0];
var author_re = /\|\s*u=\s*[^\|]*\|/i;
if (author_re.test(afctemplate)) {
var user = author_re.exec(afctemplate)[0];
username = user.split(/=/)[1];
username = username.replace(/\|/g, '');
usertalkpage = "User talk:" + username;
var usertext = afcHelper_getPageText(usertalkpage, true, true);
usertext += "\n== Your submission at AfC \[\[" + wgPageName + "|" + newtitle + "\]\] was accepted ==";
usertext += "\n\{\{subst:afc talk|1=" + newtitle + "|class=" + assessment + "|sig=yes\}\}";
afcHelper_editPage(usertalkpage, usertext, 'Your submission at \[\[WP:AFC|Articles for creation\]\], \[\[' + wgPageName + '|' + newtitle + '\]\], was accepted', false, true);
}
}
var recenttext = afcHelper_getPageText("Wikipedia:Articles for creation/recent", true, false);
var newentry = "\{\{afc contrib|" + assessment + "|" + newtitle + "|" + username + "\}\}\n";
var lastentry = recenttext.toLowerCase().lastIndexOf("\{\{afc contrib");
var firstentry = recenttext.toLowerCase().indexOf("\{\{afc contrib");
if (afcHelper_countString(recenttext,'\{\{afc contrib') >= 10){
// Only remove the old entry if there are 10+ entries in the list
recenttext = recenttext.substring(0, lastentry);
}
recenttext = recenttext.substring(0, firstentry) + newentry + recenttext.substring(firstentry);
afcHelper_editPage("Wikipedia:Articles for creation/recent", recenttext, 'Updating recent AFC creations', false, true);
var talktext = "";
if (biography) {
talktext += "\{\{WikiProject Biography|living=";
if (living === 'live') talktext += "yes";
else if (living === 'dead') talktext += "no";
talktext += "|class=" + assessment + "|listas=" + listas;
if (reqphoto) talktext += "|needs-photo=yes";
if (reqinfobox) talktext += "|needs-infobox=yes";
talktext += "\}\}\n";
}
talktext += "\{\{subst:WPAFC/article|class=" + assessment + "\}\}\n";
// For each selected WikiProject, append it to the talk page
for (var i = 0; i < selectedwikiprojects.length; i++) {
var project = selectedwikiprojects[i];
talktext += "{{"+project+"|class="+assessment+"}}\n";
};
if (talkAppend) talktext += talkAppend + "\n";
if (assessment === 'disambig') {
talktext += '\{\{WikiProject Disambiguation\}\}\n';
}
if (reqinfobox && !biography) talktext += "\{\{Infobox requested\}\}\n";
if (reqphoto && !biography) talktext += "\{\{Image requested\}\}\n";
var newtalktitle = newtitle.replace(/(Template|Category|Wikipedia|Portal):/,"$1 talk:");
if (newtalktitle == newtitle) newtalktitle = 'Talk:' + newtitle;
afcHelper_editPage(newtalktitle, talktext, 'Placing [[Wikipedia:Articles for creation]] project banner', false, true);
// clean up the page
pagetext = afcHelper_cleanup(pagetext,'accept');
// [[Template:L]]
var templatel = '\n';
if (biography) {
templatel = '\n\{\{Persondata\n| NAME =' + listas + '\n| ALTERNATIVE NAMES = ' + alternativesname + '\n| SHORT DESCRIPTION = ' + shortdescription + '\n| DATE OF BIRTH = ' + dateofbirth + ', ' + yearofbirth + '\n| PLACE OF BIRTH = ' + placeofbirth;
if (living === 'dead') {
templatel += '\n| DATE OF DEATH = ' + dateofdeath + ', ' + yearofdeath + '\n| PLACE OF DEATH = ' + placeofdeath + '\n\}\}';
} else {
templatel += '\n| DATE OF DEATH = ' + '\n| PLACE OF DEATH = \n\}\}';
}
templatel += '\n\{\{subst:L|';
if (yearofbirth === '') templatel += 'MISSING|';
else templatel += yearofbirth + '|';
if (living === 'dead') {
if (yearofdeath === '') templatel += 'MISSING|';
else templatel += yearofdeath + '|';
} else {
templatel += 'LIVING|';
}
templatel += '|' + listas + '\}\}\n';
}
pagetext = pagePrepend + '\n' + pagetext + templatel + pageAppend;
// test if the submission contains any category and if not, add {{uncategorized}}
cat_re = /\[\[Category/gi;
if (!cat_re.test(pagetext) && (assessment !== 'disambig') && (assessment !== 'redirect') && (assessment !== 'project') && (assessment !== 'portal') && (assessment !== 'template')) {
if (biography) {
pagetext += '\{\{subst:dated|Improve categories\}\}';
} else {
pagetext += '\{\{subst:dated|uncategorized\}\}';
}
}
var stub_re = /stub\}\}/gi;
if ((assessment === 'stub') && (!stub_re.test(pagetext))) {
if (biography) {
pagetext += '\n\{\{bio-stub\}\}';
} else {
pagetext += '\n\{\{stub\}\}';
}
}
// disambig check
if ((assessment === 'disambig') && (!disambig_re.test(pagetext))) {
pagetext += '\n\{\{disambig\}\}';
}
// automatic tagging of linkrot
// TODO: Use non-regex for html
var linkrotre = /((<\s*ref\s*(name\s*=|group\s*=)*\s*.*[\/]{1}>)|(<\s*ref\s*(name\s*=|group\s*=)*\s*[^\/]*>))+(?:(?:https?|ftp|file):\/\/|www\.|ftp\.)(?:\([-A-Z0-9+&@#/%=~_|$?!:,.]*\)|[-A-Z0-9+&@#/%=~_|$?!:,.])*(?:\([-A-Z0-9+&@#/%=~_|$?!:,.]*\)|[A-Z0-9+&@#/%=~_|$])+(\<\/ref\>)+/gi;
if(linkrotre.test(pagetext)){
pagetext = "{{subst:dated|Cleanup-bare URLs}}" + pagetext;
}
//check if page is orphaned (mainspace) and tag it!
if ((assessment !== 'disambig') && (assessment !== 'redirect') && (assessment !== 'project') && (assessment !== 'portal') && (assessment !== 'template')) {
afcHelper_displaymessagehelper('status','orphan');
var request = {
'action': 'query',
'list': 'backlinks',
'format': 'json',
'blnamespace': 0,
'bllimit': 10,
'bltitle' : newtitle
};
var response = JSON.parse(
$.ajax({
url: mw.util.wikiScript('api'),
data: request,
async: false
})
.responseText
);
var isorphaned = response['query']['backlinks'].length;
if (isorphaned) {
$("#afcHelper_orphan").html("Orphan check: all ok. No tagging needed.");
} else {
pagetext = '\{\{subst:dated|Orphan\}\}' + pagetext;
$("#afcHelper_orphan").html("Page is orphaned, adding tag.");
}
}
afcHelper_editPage(newtitle, pagetext, "Cleanup following [[Wikipedia:Articles for creation]] creation", false);
};
afcHelper_movePage(afcHelper_PageName, newtitle, 'Created via \[\[WP:AFC|Articles for creation\]\] (\[\[WP:WPAFC|you can help!\]\])', callback, true);
} else if (action === 'decline') {
var code = $("#afcHelper_reason").val();
for (i = 0; i < (afcHelper_reasonhash.length + 1); i++) {
if ((typeof(afcHelper_reasonhash[i]) !== 'undefined') && (afcHelper_reasonhash[i].value === code)) var reasontext = afcHelper_reasonhash[i].reason;
}
var customreason = $("#afcHelper_comments").val();
var append = false;
var keep = false;
var blank = $("#afcHelper_blank").attr("checked");
var blank_csd = $("#afcHelper_blank_csd").attr("checked");
var notify = $("#afcHelper_notify").attr("checked");
var teahouse = $("#afcHelper_Teahouse").attr("checked");
var extra = '';
if (code === 'cv' || code === 'dup' || code === 'mergeto' || code === 'exists' || code === 'lang' || code === 'plot') {
extra = $("#afcHelper_extra_inlinebox").val();
}
if (extra === null) {
return;
}
displayMessage('<ul id="afcHelper_status"></ul><ul id="afcHelper_finish"></ul>');
afcHelper_displaymessagehelper('done','standard');
// Find the first pending submission or marked as review on the page.
if (!pending_afc_re.test(pagetext)) {
alert("Unable to locate a pending AFC submission template, aborting...");
return;
}
if (code === 'reason' && customreason === '') {
alert("You must enter a reason!");
return;
}
var afctemplate = pending_afc_re.exec(pagetext)[0];
pagetext = pagetext.replace(afctemplate, "");
//data is always between the first pipe and the one before the timestamp.
var firstpipe = afctemplate.indexOf('|');
var endpipe = afctemplate.indexOf('|ts');
var newtemplate = afctemplate.substring(0, firstpipe);
var summary = '';
var newcomment = '';
// overwrite any reason that was there.
newtemplate += '|d|' + (code || 'reason');
if (code === 'reason' || code === null) {
newtemplate += '|3=' + customreason;
} else if (extra !== '') {
newtemplate += '|3=' + extra;
}
newtemplate += '|declinets=\{\{subst:CURRENTTIMESTAMP\}\}|decliner=\{\{subst:REVISIONUSER\}\}' + afctemplate.substring(endpipe);
if (code !== null && code !== 'reason' && customreason !== '') {
newcomment = afcHelper_addcomment(customreason);
}
summary = "Declining submission";
if (code === 'reason' || code === null) {
summarycustom = customreason.match(/[^\s]+/g).slice(0,5).join(" "); // Get the first five words of the custom decline rationale
if (summarycustom != customreason) summarycustom += "..."; // Add an ellipsis if the rationale if >5 words
summary += ': ' + summarycustom;
} else {
summary += ': ' + reasontext;
}
// Stores the author of the submission to afcHelper_authorusername
var author_re = /\|\s*u\s*=\s*(.*?)\|/i;
if (author_re.test(afctemplate)) {
var username = author_re.exec(afctemplate)[1];
if (username !== 'Example') {
afcHelper_authorusername = username;
} else {
afcHelper_authorusername = afcHelper_page_creator(afcHelper_PageName);
}
} else {
afcHelper_authorusername = afcHelper_page_creator(afcHelper_PageName);
}
if (notify) {
usertalkpage = "User talk:" + afcHelper_authorusername;
var usertext = afcHelper_getPageText(usertalkpage, true, true);
var reason = 'Your submission at \[\[Wikipedia:Articles for creation|Articles for creation\]\], \[\[' + afcHelper_PageName + '|' + afcHelper_submissionTitle + '\]\], was declined';
usertext += "\n== Your submission at \[\[Wikipedia:Articles for creation|Articles for creation\]\]: \[\[" + afcHelper_PageName + "|" + afcHelper_submissionTitle + "\]\] ({{subst:CURRENTMONTHNAME}} {{subst:CURRENTDAY}}) ==";
usertext += "\n\{\{subst:afc decline|1=" + afcHelper_submissionTitle.replace(" ", "{{subst:Sp}}");
if (code === 'cv') usertext += "|cv=yes";
usertext += "|sig=yes\}\}";
if (teahouse) {
$('#afcHelper_status').html($("#afcHelper_status").html() + '<div id="afcHelper_get_teahouse"></div>');
$("#afcHelper_get_teahouse").html('<li id="afcHelper_get_teahouse">Checking for existing Teahouse Invitation for <a href="' + wgArticlePath.replace("$1", encodeURI('User_talk:' + username)) + '" title="User talk:' + username + '">User talk:' + username + '</a></li>');
var request = {
'action': 'query',
'prop': 'categories',
'format': 'json',
'indexpageids': true,
'redirects': true,
'titles' : usertalkpage
};
var response = JSON.parse(
$.ajax({
url: mw.util.wikiScript('api'),
data: request,
async: false
})
.responseText
);
var pageid = response['query']['pageids'][0];
var foundTH = 0;
if (pageid !== "-1") {
if (response['query']['redirects']) { /* If there is no redirect, this stops here from getting an error */
var oldusername = response['query']['redirects'][0]['from'];
var newusername = response['query']['redirects'][0]['to'];
if ((typeof(oldusername) !== 'undefined') && (typeof(newusername) !== 'undefined') && (oldusername != newusername)) {
$('#afcHelper_get_teahouse').html($('#afcHelper_get_teahouse').html() + '<li id="afcHelper_get_teahouse2">User talk page is redirect to <a href="' + wgArticlePath.replace("$1", encodeURI('User_talk:' + newusername)) + '" title="User talk:' + newusername + '">User talk:' + newusername + '</a> - checking there for TeaHouse invitations.</li>');
params = "action=query&prop=categories&format=json&indexpageids=1&titles=User_talk:" + encodeURIComponent(newusername);
req.send(params);
response = eval('(' + req.responseText + ')');
pageid = response['query']['pageids'][0];
}
}
if (pageid !== "-1") {
var pagecats = new Array();
pagecats = response['query']['pages'][pageid]['categories'];
}
if ((typeof pagecats !== 'undefined') && (pageid !== "-1")) {
for (var i = 0; i < pagecats.length; i++) {
if ((pagecats[i].title === ("Category:Wikipedians who have received a Teahouse invitation")) || (pagecats[i].title === ("Category:Wikipedians who have received a Teahouse invitation through AfC"))) {
foundTH = 1;
break;
}
}
}
}
if (foundTH === 0) {
$("#afcHelper_get_teahouse").html('<li id="afcHelper_get_teahouse">Sent <a href="' + wgArticlePath.replace("$1", encodeURI('User talk:' + username)) + '" title="User talk:' + username + '">User talk:' + username + '</a> an invitation.</li>');
usertext += "\n\n\n\{\{subst:Wikipedia:Teahouse/AFC_invitation\}\}";
reason += '; adding invitation to the \[\[Wikipedia:Teahouse|Teahouse\]\]!';
} else {
$("#afcHelper_get_teahouse").html('<a href="' + wgArticlePath.replace("$1", encodeURI('User talk:' + username)) + '" title="User talk:' + username + '">' + username + '</a> already has an invitation.');
}
} //end TH stuff
afcHelper_editPage(usertalkpage, usertext, reason, false, true);
}
if (!blank) {
pagetext = newtemplate + newcomment + pagetext;
} else {
if (blank_csd) {
if (code === 'cv') {
// If article is a copyvio add db-g12 to the top
if (extra != "http://" || extra != "") {
pagetext = "\{\{Db-g12|url=" + extra + "\}\}\n" + newtemplate + '\n' + newcomment + '\n\{\{afc cleared\}\}';
} else {
pagetext = "\{\{Db-g12\}\}\n" + newtemplate + '\n' + newcomment + '\n\{\{afc cleared\}\}';
}
// And for good measure log the CSD nomination
afcHelper_logcsd(afcHelper_PageName,"[[CSD:G12]] ({{tl|db-copyvio}})",[afcHelper_authorusername]);
} else {
pagetext = newtemplate + '\n' + newcomment + '\n\{\{afc cleared|csd\}\}';
afcHelper_logcsd(afcHelper_PageName,"{{tl|db-reason}} ([[WP:AFC|Articles for creation]])",[afcHelper_authorusername]);
}
} else {
// If we just need to blank the submission, *just blank it*
pagetext = newtemplate + '\n' + newcomment + '\n\{\{afc cleared\}\}';
}
}
pagetext = afcHelper_cleanup(pagetext);
afcHelper_editPage(afcHelper_PageName, pagetext, summary, false);
} else if (action === 'comment') {
var comment = $("#afcHelper_comments").val();
displayMessage('<ul id="afcHelper_status"></ul><ul id="afcHelper_finish"></ul>');
afcHelper_displaymessagehelper('done','standard');
if (comment !== '') {
pagetext = afcHelper_addcomment(comment) + pagetext;
} else {
alert("No comment was entered, aborting...");
return;
}
pagetext = afcHelper_cleanup(pagetext);
afcHelper_editPage(afcHelper_PageName, pagetext, "Commenting on [[Wikipedia:Articles for creation]] submission", false);
} else if (action === 'mark') {
var comment = $("#afcHelper_comments").val();
if (comment == undefined) comment = window.overwrite_comment; // This handles the overwrite_redirect scenario
displayMessage('<ul id="afcHelper_status"></ul><ul id="afcHelper_finish"></ul>');
afcHelper_displaymessagehelper('done','standard');
if (!exclusive_pending_afc_re.test(pagetext)) {
alert("Unable to locate AFC submission template, aborting...");
return;
}
pagetext = pagetext.replace(exclusive_pending_afc_re, "$1r\|\|$2\|reviewer=\{\{subst:REVISIONUSER\}\}\|reviewts={{subst:CURRENTTIMESTAMP}}\|$3");
pagetext = afcHelper_addcomment(comment) + pagetext;
pagetext = afcHelper_cleanup(pagetext);
afcHelper_editPage(afcHelper_PageName, pagetext, "Marking [[Wikipedia:Articles for creation]] submission as being reviewed", false);
} else if (action === 'unmark') {
if (!afcHelper_underreview()) return;
displayMessage('<ul id="afcHelper_status"></ul><ul id="afcHelper_finish"></ul>');
afcHelper_displaymessagehelper('done','standard');
if (!reviewing_afc_re.test(pagetext)) {
alert("Unable to locate AFC submission template or page is not marked as being reviewed, aborting...");
return;
}
var template = reviewing_afc_re.exec(pagetext)[0];
var newtemplate = template.replace(reviewing_afc_re, "\{\{AFC submission\|$1");
newtemplate = newtemplate.replace(/\|\s*reviewer=\s*[^\|]*\|/i, "");
newtemplate = newtemplate.replace(/\|\s*reviewts=\s*([0-9]{14})[^\|]*\|/i, "");
pagetext = pagetext.replace(template, newtemplate);
pagetext = afcHelper_cleanup(pagetext);
afcHelper_editPage(afcHelper_PageName, pagetext, "Unmarking [[Wikipedia:Articles for creation]] submission as being reviewed", false);
} else if (action === 'cleanup') {
displayMessage('<ul id="afcHelper_status"></ul><ul id="afcHelper_finish"></ul>');
pagetext = afcHelper_cleanup(pagetext);
var text = afcHelper_getPageText(afcHelper_PageName, true, false);
if (text === pagetext) {
afcHelper_displaymessagehelper('done','cleanednochange');
} else {
afcHelper_editPage(afcHelper_PageName, pagetext, "Cleaning [[Wikipedia:Articles for creation]] submission", false);
afcHelper_displaymessagehelper('done','standard');
}
}
// Display the "Done" text only after all ajax requests are completed
$(document).ajaxStop(function () {
$("#afcHelper_finished_main").css("display", "");
});
}
function afcHelper_movePage(oldtitle, newtitle, summary, callback, overwrite_redirect) {
var token = mw.user.tokens.get('editToken');
$("#afcHelper_finished_wrapper").html('<span id="afcHelper_AJAX_finished_' + afcHelper_AJAXnumber + '" style="display:none">' + $("#afcHelper_finished_wrapper").html() + '</span>');
var func_id = afcHelper_AJAXnumber;
afcHelper_AJAXnumber++;
$('#afcHelper_status').html($('#afcHelper_status').html() + '<li id="afcHelper_move' + escape(oldtitle) + '">Moving <a href="' + wgArticlePath.replace("$1", encodeURI(oldtitle)) + '" title="' + oldtitle + '">' + oldtitle + '</a> to <a href="' + wgArticlePath.replace("$1", encodeURI(newtitle)) + '" title="' + newtitle + '">' + newtitle + '</a></li>');
var request = {
'action': 'move',
'from': oldtitle,
'to': newtitle,
'reason': summary + afcHelper_advert,
'format': 'json',
'token': token
};
var response = JSON.parse(
$.ajax({
type: "POST",
url: mw.util.wikiScript('api'),
data: request,
async: false
})
.responseText
);
error = true;
try {
if (typeof(response['move']) !== "undefined") {
$('#afcHelper_move' + jqEsc(oldtitle)).html('Moved <a href="' + wgArticlePath.replace("$1", encodeURI(oldtitle)) + '" title="' + oldtitle + '">' + oldtitle + '</a>');
error = false;
} else {
// TODO theo combine error messages so we don't have so many redundant elses
if (overwrite_redirect) {
if (response['error']['code'] == "articleexists") {
text = afcHelper_getPageText(newtitle);
if (text.search(/#redirect\s*\[\[/gi) != -1) { // Should probably use &redirects= to check if it's a redirect, rather than this hack...but this seemed simpler and more concise, rather than yet another API call
if ($.inArray('sysop', mw.config.get('wgUserGroups')) !== -1) {
del = confirm("The target title, " + newtitle + ", is a redirect. Would you like to automatically delete it under {{db-move}} and then accept and move the submission?");
if (del) {
$('#afcHelper_move' + jqEsc(oldtitle)).html('<div id="afcHelper_delete' + escape(oldtitle)+'"></div>'); // to allow for messages from the editor
deleted = afcHelper_deletePage(newtitle, "[[CSD:G6]]: redirect in the way of move of accepted [[Wikipedia:Articles for creation]] submission");
if (deleted) {
afcHelper_movePage(oldtitle, newtitle, summary, callback, overwrite_redirect); // Then just move the page again as if nothing happened
return; // So we don't run callback() twice
} else {
$('#afcHelper_move' + jqEsc(oldtitle)).html('<span style="color:red"><b>Unable to automatically delete <a href="' + wgArticlePath.replace("$1", encodeURI(oldtitle)) + '" title="' + oldtitle + '">' + oldtitle + '</a></b></span>');
}
} else {
$('#afcHelper_move' + jqEsc(oldtitle)).html('<span style="color:red"><b>Move failed on <a href="' + wgArticlePath.replace("$1", encodeURI(oldtitle)) + '" title="' + oldtitle + '">' + oldtitle + '</a></b></span>. Error info: User canceled automatically deleting the blocking redirect');
}
} else {
del = confirm("The target title, "+newtitle+", is a redirect. Would you like to automatically tag it for deletion under {{db-move}} to make way for the approved submission?");
if (del) {
rat = "{{db-move|1="+oldtitle+"|2=redirect preventing move of accepted [[WP:AFC|article submission]].}}\n";
afcHelper_editPage(newtitle, rat+text, "Tagging redirect in the way of [[Wikipedia:Articles for creation]] submission for deletion under {{[[Template:Db-move|db-move]]}}");
window.overwrite_comment = 'This article submission has been approved, but a [[WP:REDIRECT|redirect]] is blocking it from being moved into the article space. An administrator should delete the redirect and move the article within the next few days. Thanks for your patience!';
$('#afcHelper_move' + jqEsc(oldtitle)).html('<div id="afcHelper_edit' + escape(oldtitle)+'"></div>'); // to allow for messages from the editor
afcHelper_act('mark'); // We mark the submission as "under review"
$('#afcHelper_move' + jqEsc(oldtitle)).html($('#afcHelper_move' + jqEsc(oldtitle)).html() + '<div><b>Successfully tagged redirect page <a href="' + wgArticlePath.replace("$1", encodeURI(newtitle)) + '" title="' + newtitle + '">' + newtitle + '</a> for deletion</b> under {{db-move}}. The article should be moved by the administrator who deletes the redirect.</div>');
} else {
$('#afcHelper_move' + jqEsc(oldtitle)).html('<span style="color:red"><b>Move failed on <a href="' + wgArticlePath.replace("$1", encodeURI(oldtitle)) + '" title="' + oldtitle + '">' + oldtitle + '</a></b></span>. Error info: User canceled automatically tagging the target for deletion');
}
}
} else {
$('#afcHelper_move' + jqEsc(oldtitle)).html('<span style="color:red"><b>Move failed on <a href="' + wgArticlePath.replace("$1", encodeURI(oldtitle)) + '" title="' + oldtitle + '">' + oldtitle + '</a></b></span>. Error info: <b>' + response['error']['code'] + '</b>: ' + response['error']['info']);
}
} else {
$('#afcHelper_move' + jqEsc(oldtitle)).html('<span style="color:red"><b>Move failed on <a href="' + wgArticlePath.replace("$1", encodeURI(oldtitle)) + '" title="' + oldtitle + '">' + oldtitle + '</a></b></span>. Error info: <b>' + response['error']['code'] + '</b>: ' + response['error']['info']);