forked from wikimedia-gadgets/twinkle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtwinklearv.js
985 lines (880 loc) · 33 KB
/
twinklearv.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
// <nowiki>
(function($) {
/*
****************************************
*** twinklearv.js: ARV module
****************************************
* Mode of invocation: Tab ("ARV")
* Active on: Any page with relevant user name (userspace, contribs, etc.)
*/
Twinkle.arv = function twinklearv() {
const username = mw.config.get('wgRelevantUserName');
if (!username || username === mw.config.get('wgUserName')) {
return;
}
const isIP = mw.util.isIPAddress(username, true);
// Ignore ranges wider than the CIDR limit
if (Morebits.ip.isRange(username) && !Morebits.ip.validCIDR(username)) {
return;
}
const userType = isIP ? 'IP' + (Morebits.ip.isRange(username) ? ' range' : '') : 'user';
Twinkle.addPortletLink(() => {
Twinkle.arv.callback(username, isIP);
}, 'ARV', 'tw-arv', 'Report ' + userType + ' to administrators');
};
Twinkle.arv.callback = function (uid, isIP) {
const Window = new Morebits.simpleWindow(600, 500);
Window.setTitle('Advance Reporting and Vetting'); // Backronym
Window.setScriptName('Twinkle');
Window.addFooterLink('AIV guide', 'WP:GAIV');
Window.addFooterLink('UAA guide', 'WP:UAAI');
Window.addFooterLink('SPI guide', 'Wikipedia:Sockpuppet investigations/SPI/Guide to filing cases');
Window.addFooterLink('ARV prefs', 'WP:TW/PREF#arv');
Window.addFooterLink('Twinkle help', 'WP:TW/DOC#arv');
Window.addFooterLink('Give feedback', 'WT:TW');
const form = new Morebits.quickForm(Twinkle.arv.callback.evaluate);
const categories = form.append({
type: 'select',
name: 'category',
label: 'Select report type:',
event: Twinkle.arv.callback.changeCategory
});
categories.append({
type: 'option',
label: 'Vandalism (WP:AIV)',
value: 'aiv'
});
categories.append({
type: 'option',
label: 'Username (WP:UAA)',
value: 'username',
disabled: isIP
});
categories.append({
type: 'option',
label: 'Sockpuppeteer (WP:SPI)',
value: 'sock'
});
categories.append({
type: 'option',
label: 'Sockpuppet (WP:SPI)',
value: 'puppet'
});
categories.append({
type: 'option',
label: 'Edit warring (WP:AN3)',
value: 'an3',
disabled: Morebits.ip.isRange(uid) // rvuser template doesn't support ranges
});
form.append({
type: 'div',
label: '',
style: 'color: red',
id: 'twinkle-arv-blockwarning'
});
form.append({
type: 'field',
label: 'Work area',
name: 'work_area'
});
form.append({ type: 'submit' });
form.append({
type: 'hidden',
name: 'uid',
value: uid
});
const result = form.render();
Window.setContent(result);
Window.display();
// Check if the user is blocked, update notice
const query = {
action: 'query',
list: 'blocks',
bkprop: 'range|flags',
format: 'json'
};
if (isIP) {
query.bkip = uid;
} else {
query.bkusers = uid;
}
new Morebits.wiki.api("Checking the user's block status", query, ((apiobj) => {
const blocklist = apiobj.getResponse().query.blocks;
if (blocklist.length) {
// If an IP is blocked *and* rangeblocked, only use whichever is more recent
const block = blocklist[0];
let message = (isIP ? 'This IP ' + (Morebits.ip.isRange(uid) ? 'range' : 'address') : 'This account') + ' is ' + (block.partial ? 'partially' : 'already') + ' blocked';
// Start and end differ, range blocked
message += block.rangestart !== block.rangeend ? ' as part of a rangeblock.' : '.';
if (block.partial) {
$('#twinkle-arv-blockwarning').css('color', 'black'); // Less severe
}
$('#twinkle-arv-blockwarning').text(message);
}
})).post();
// We must init the
const evt = document.createEvent('Event');
evt.initEvent('change', true, true);
result.category.dispatchEvent(evt);
};
Twinkle.arv.callback.changeCategory = function (e) {
const value = e.target.value;
const root = e.target.form;
const old_area = Morebits.quickForm.getElements(root, 'work_area')[0];
let work_area = null;
switch (value) {
case 'aiv':
/* falls through */
default:
work_area = new Morebits.quickForm.element({
type: 'field',
label: 'Report user for vandalism',
name: 'work_area'
});
work_area.append({
type: 'input',
name: 'page',
label: 'Primary linked page:',
tooltip: 'Leave blank to not link to the page in the report',
value: Twinkle.getPrefill('vanarticle') || '',
event: function(e) {
const value = e.target.value;
const root = e.target.form;
if (value === '') {
root.badid.disabled = root.goodid.disabled = true;
} else {
root.badid.disabled = false;
root.goodid.disabled = root.badid.value === '';
}
}
});
work_area.append({
type: 'input',
name: 'badid',
label: 'Revision ID for target page when vandalised:',
tooltip: 'Leave blank for no diff link',
value: Twinkle.getPrefill('vanarticlerevid') || '',
disabled: !Twinkle.getPrefill('vanarticle'),
event: function(e) {
const value = e.target.value;
const root = e.target.form;
root.goodid.disabled = value === '';
}
});
work_area.append({
type: 'input',
name: 'goodid',
label: 'Last good revision ID before vandalism of target page:',
tooltip: 'Leave blank for diff link to previous revision',
value: Twinkle.getPrefill('vanarticlegoodrevid') || '',
disabled: !Twinkle.getPrefill('vanarticle') || Twinkle.getPrefill('vanarticlerevid')
});
work_area.append({
type: 'checkbox',
name: 'arvtype',
list: [
{
label: 'Vandalism after final (level 4 or 4im) warning given',
value: 'final'
},
{
label: 'Vandalism after recent (within 1 day) release of block',
value: 'postblock'
},
{
label: 'Evidently a vandalism-only account',
value: 'vandalonly',
disabled: mw.util.isIPAddress(root.uid.value, true)
},
{
label: 'Account is a promotion-only account',
value: 'promoonly',
disabled: mw.util.isIPAddress(root.uid.value, true)
},
{
label: 'Account is evidently a spambot or a compromised account',
value: 'spambot'
}
]
});
work_area.append({
type: 'textarea',
name: 'reason',
label: 'Comment:'
});
work_area = work_area.render();
old_area.parentNode.replaceChild(work_area, old_area);
break;
case 'username':
work_area = new Morebits.quickForm.element({
type: 'field',
label: 'Report username violation',
name: 'work_area'
});
work_area.append({
type: 'header',
label: 'Type(s) of inappropriate username',
tooltip: 'Wikipedia does not allow usernames that are misleading, promotional, offensive or disruptive. Domain names and email addresses are likewise prohibited. These criteria apply to both usernames and signatures. Usernames that are inappropriate in another language, or that represent an inappropriate name with misspellings and substitutions, or do so indirectly or by implication, are still considered inappropriate.'
});
work_area.append({
type: 'checkbox',
name: 'arvtype',
list: [
{
label: 'Misleading username',
value: 'misleading',
tooltip: 'Misleading usernames imply relevant, misleading things about the contributor. For example, misleading points of fact, an impression of undue authority, or usernames giving the impression of a bot account.'
},
{
label: 'Promotional username',
value: 'promotional',
tooltip: 'Promotional usernames are advertisements for a company, website or group. Please do not report these names to UAA unless the user has also made promotional edits related to the name.'
},
{
label: 'Offensive username',
value: 'offensive',
tooltip: 'Offensive usernames make harmonious editing difficult or impossible.'
},
{
label: 'Disruptive username',
value: 'disruptive',
tooltip: 'Disruptive usernames include outright trolling or personal attacks, or otherwise show a clear intent to disrupt Wikipedia.'
}
]
});
work_area.append({
type: 'textarea',
name: 'reason',
label: 'Comment:'
});
work_area = work_area.render();
old_area.parentNode.replaceChild(work_area, old_area);
break;
case 'puppet':
work_area = new Morebits.quickForm.element({
type: 'field',
label: 'Report suspected sockpuppet',
name: 'work_area'
});
work_area.append(
{
type: 'input',
name: 'sockmaster',
label: 'Sockpuppeteer',
tooltip: 'The username of the sockpuppeteer (sockmaster) without the "User:" prefix'
}
);
work_area.append({
type: 'textarea',
label: 'Evidence:',
name: 'evidence',
tooltip: 'Your evidence should make it clear that each of these users is likely to be abusing multiple accounts. Usually this means diffs, page histories or other information that justifies why the users are a) the same and b) disruptive. This should be just evidence and information needed to judge the matter. Avoid all other discussion that is not evidence of sockpuppetry.'
});
work_area.append({
type: 'checkbox',
list: [
{
label: 'Request CheckUser',
name: 'checkuser',
tooltip: 'CheckUser is a tool used to obtain technical evidence related to a sockpuppetry allegation. It will not be used without good cause, which you must clearly demonstrate. Make sure your evidence explains why using the tool is appropriate. It will not be used to publicly connect user accounts and IP addresses.'
}
]
});
work_area = work_area.render();
old_area.parentNode.replaceChild(work_area, old_area);
break;
case 'sock':
work_area = new Morebits.quickForm.element({
type: 'field',
label: 'Report suspected sockpuppeteer',
name: 'work_area'
});
work_area.append(
{
type: 'dyninput',
name: 'sockpuppet',
label: 'Sockpuppets',
sublabel: 'Sock:',
tooltip: 'The username of the sockpuppet without the "User:" prefix',
min: 2
});
work_area.append({
type: 'textarea',
label: 'Evidence:',
name: 'evidence',
tooltip: 'Your evidence should make it clear that each of these users is likely to be abusing multiple accounts. Usually this means diffs, page histories or other information that justifies why the users are a) the same and b) disruptive. This should be just evidence and information needed to judge the matter. Avoid all other discussion that is not evidence of sockpuppetry.'
});
work_area.append({
type: 'checkbox',
list: [ {
label: 'Request CheckUser',
name: 'checkuser',
tooltip: 'CheckUser is a tool used to obtain technical evidence related to a sockpuppetry allegation. It will not be used without good cause, which you must clearly demonstrate. Make sure your evidence explains why using the tool is appropriate. It will not be used to publicly connect user accounts and IP addresses.'
} ]
});
work_area = work_area.render();
old_area.parentNode.replaceChild(work_area, old_area);
break;
case 'an3':
work_area = new Morebits.quickForm.element({
type: 'field',
label: 'Report edit warring',
name: 'work_area'
});
work_area.append({
type: 'input',
name: 'page',
label: 'Page',
tooltip: 'The page being reported'
});
work_area.append({
type: 'button',
name: 'load',
label: 'Load',
event: function(e) {
const root = e.target.form;
const date = new Morebits.date().subtract(48, 'hours'); // all since 48 hours
// Run for each AN3 field
const getAN3Entries = function(field, rvuser, titles) {
const $field = $(root).find('[name=' + field + ']');
$field.find('.entry').remove();
new mw.Api().get({
action: 'query',
prop: 'revisions',
format: 'json',
rvprop: 'sha1|ids|timestamp|parsedcomment|comment',
rvlimit: 500, // intentionally limited
rvend: date.toISOString(),
rvuser: rvuser,
indexpageids: true,
titles: titles
}).done((data) => {
const pageid = data.query.pageids[0];
const page = data.query.pages[pageid];
if (!page.revisions) {
$('<span class="entry">None found</span>').appendTo($field);
} else {
for (let i = 0; i < page.revisions.length; ++i) {
const rev = page.revisions[i];
const $entry = $('<div/>', {
class: 'entry'
});
const $input = $('<input/>', {
type: 'checkbox',
name: 's_' + field,
value: rev.revid
});
$input.data('revinfo', rev);
$input.appendTo($entry);
let comment = '<span>';
// revdel/os
if (typeof rev.commenthidden === 'string') {
comment += '(comment hidden)';
} else {
comment += '"' + rev.parsedcomment + '"';
}
comment += ' at <a href="' + mw.config.get('wgScript') + '?diff=' + rev.revid + '">' + new Morebits.date(rev.timestamp).calendar() + '</a></span>';
$entry.append(comment).appendTo($field);
}
}
// add free form input for resolves
if (field === 'resolves') {
const $free_entry = $('<div/>', {
class: 'entry'
});
const $free_input = $('<input/>', {
type: 'text',
name: 's_resolves_free'
});
const $free_label = $('<label/>', {
for: 's_resolves_free',
html: 'URL link of diff with additional discussions: '
});
$free_entry.append($free_label).append($free_input).appendTo($field);
}
}).fail(() => {
$('<span class="entry">API failure, reload page and try again</span>').appendTo($field);
});
};
// warnings
const uid = root.uid.value;
getAN3Entries('warnings', mw.config.get('wgUserName'), 'User talk:' + uid);
// diffs and resolves require a valid page
const page = root.page.value;
if (page) {
// diffs
getAN3Entries('diffs', uid, page);
// resolutions
const t = new mw.Title(page);
const talk_page = t.getTalkPage().getPrefixedText();
getAN3Entries('resolves', mw.config.get('wgUserName'), talk_page);
} else {
$(root).find('[name=diffs]').find('.entry').remove();
$(root).find('[name=resolves]').find('.entry').remove();
}
}
});
work_area.append({
type: 'field',
name: 'diffs',
label: 'User\'s reverts (within last 48 hours)',
tooltip: 'Select the edits you believe are reverts'
});
work_area.append({
type: 'field',
name: 'warnings',
label: 'Warnings given to subject',
tooltip: 'You must have warned the subject before reporting'
});
work_area.append({
type: 'field',
name: 'resolves',
label: 'Resolution initiatives',
tooltip: 'You should have tried to resolve the issue on the talk page first'
});
work_area.append({
type: 'textarea',
label: 'Comment:',
name: 'comment'
});
work_area = work_area.render();
old_area.parentNode.replaceChild(work_area, old_area);
break;
}
};
Twinkle.arv.callback.evaluate = function(e) {
var form = e.target;
var reason = '';
var input = Morebits.quickForm.getInputData(form);
var uid = form.uid.value;
switch (input.category) {
// Report user for vandalism
case 'aiv':
/* falls through */
default:
reason = Twinkle.arv.callback.getAivReasonWikitext(input);
if (reason === null) {
alert('You must specify some reason');
return;
}
Morebits.simpleWindow.setButtonsEnabled(false);
Morebits.status.init(form);
Morebits.wiki.actionCompleted.redirect = 'Wikipedia:Administrator intervention against vandalism';
Morebits.wiki.actionCompleted.notice = 'Reporting complete';
var aivPage = new Morebits.wiki.page('Wikipedia:Administrator intervention against vandalism', 'Processing AIV request');
aivPage.setPageSection(1);
aivPage.setFollowRedirect(true);
aivPage.load(() => {
const text = aivPage.getPageText();
const $aivLink = '<a target="_blank" href="/wiki/WP:AIV">WP:AIV</a>';
// check if user has already been reported
if (new RegExp('\\{\\{\\s*(?:(?:[Ii][Pp])?[Vv]andal|[Uu]serlinks)\\s*\\|\\s*(?:1=)?\\s*' + Morebits.string.escapeRegExp(input.uid) + '\\s*\\}\\}').test(text)) {
aivPage.getStatusElement().error('Report already present, will not add a new one');
Morebits.status.printUserText(reason, 'The comments you typed are provided below, in case you wish to manually post them under the existing report for this user at ' + $aivLink + ':');
return;
}
// then check for any bot reports
const tb2Page = new Morebits.wiki.page('Wikipedia:Administrator intervention against vandalism/TB2', 'Checking bot reports');
tb2Page.load(() => {
const tb2Text = tb2Page.getPageText();
const tb2statelem = tb2Page.getStatusElement();
if (new RegExp('\\{\\{\\s*(?:(?:[Ii][Pp])?[Vv]andal|[Uu]serlinks)\\s*\\|\\s*(?:1=)?\\s*' + Morebits.string.escapeRegExp(input.uid) + '\\s*\\}\\}').test(tb2Text)) {
if (confirm('The user ' + input.uid + ' has already been reported by a bot. Do you wish to make the report anyway?')) {
tb2statelem.info('Proceeded despite bot report');
} else {
tb2statelem.error('Report from a bot is already present, stopping');
Morebits.status.printUserText(reason, 'The comments you typed are provided below, in case you wish to manually post them at ' + $aivLink + ':');
return;
}
} else {
tb2statelem.info('No conflicting bot reports');
}
aivPage.getStatusElement().status('Adding new report...');
aivPage.setEditSummary('Reporting [[Special:Contributions/' + input.uid + '|' + input.uid + ']].');
aivPage.setChangeTags(Twinkle.changeTags);
aivPage.setAppendText(Twinkle.arv.callback.buildAivReport(input));
aivPage.append();
});
});
break;
// Report inappropriate username
case 'username':
var censorUsername = input.arvtype.includes('offensive'); // check if the username is marked offensive
reason = Twinkle.arv.callback.getUsernameReportWikitext(input);
Morebits.simpleWindow.setButtonsEnabled(false);
Morebits.status.init(form);
Morebits.wiki.actionCompleted.redirect = 'Wikipedia:Usernames for administrator attention';
Morebits.wiki.actionCompleted.notice = 'Reporting complete';
var uaaPage = new Morebits.wiki.page('Wikipedia:Usernames for administrator attention', 'Processing UAA request');
uaaPage.setFollowRedirect(true);
uaaPage.load(() => {
const text = uaaPage.getPageText();
// check if user has already been reported
if (new RegExp('\\{\\{\\s*user-uaa\\s*\\|\\s*(1\\s*=\\s*)?' + Morebits.string.escapeRegExp(input.uid) + '\\s*(\\||\\})').test(text)) {
uaaPage.getStatusElement().error('User is already listed.');
const $uaaLink = '<a target="_blank" href="/wiki/WP:UAA">WP:UAA</a>';
Morebits.status.printUserText(reason, 'The comments you typed are provided below, in case you wish to manually post them under the existing report for this user at ' + $uaaLink + ':');
return;
}
uaaPage.getStatusElement().status('Adding new report...');
uaaPage.setEditSummary('Reporting ' + (censorUsername ? 'an offensive username.' : '[[Special:Contributions/' + input.uid + '|' + input.uid + ']].'));
uaaPage.setChangeTags(Twinkle.changeTags);
// Blank newline per [[Special:Permalink/996949310#Spacing]]; see also [[WP:LISTGAP]] and [[WP:INDENTGAP]]
uaaPage.setPageText(text + '\n' + reason + '\n*');
uaaPage.save();
});
break;
// WP:SPI
case 'sock':
/* falls through */
case 'puppet':
var sockParameters = {
evidence: form.evidence.value.trim(),
checkuser: form.checkuser.checked
};
var puppetReport = form.category.value === 'puppet';
if (puppetReport && !form.sockmaster.value.trim()) {
alert('You have not entered a sockmaster account for this puppet. Consider reporting this account as a sockpuppeteer instead.');
return;
} else if (!puppetReport && !form.sockpuppet[0].value.trim()) {
alert('You have not entered any sockpuppet account(s) for this sockmaster. Consider reporting this account as a sockpuppet instead.');
return;
}
sockParameters.uid = puppetReport ? form.sockmaster.value.trim() : uid;
sockParameters.sockpuppets = puppetReport ? [uid] : Morebits.array.uniq($.map($('input:text[name=sockpuppet]', form), (o) => $(o).val() || null));
Morebits.simpleWindow.setButtonsEnabled(false);
Morebits.status.init(form);
Twinkle.arv.processSock(sockParameters);
break;
case 'an3':
var diffs = $.map($('input:checkbox[name=s_diffs]:checked', form), (o) => $(o).data('revinfo'));
if (diffs.length < 3 && !confirm('You have selected fewer than three offending edits. Do you wish to make the report anyway?')) {
return;
}
var warnings = $.map($('input:checkbox[name=s_warnings]:checked', form), (o) => $(o).data('revinfo'));
if (!warnings.length && !confirm('You have not selected any edits where you warned the offender. Do you wish to make the report anyway?')) {
return;
}
var resolves = $.map($('input:checkbox[name=s_resolves]:checked', form), (o) => $(o).data('revinfo'));
var free_resolves = $('input[name=s_resolves_free]').val();
var an3_next = function(free_resolves) {
if (!resolves.length && !free_resolves && !confirm('You have not selected any edits where you tried to resolve the issue. Do you wish to make the report anyway?')) {
return;
}
const an3Parameters = {
uid: uid,
page: form.page.value.trim(),
comment: form.comment.value.trim(),
diffs: diffs,
warnings: warnings,
resolves: resolves,
free_resolves: free_resolves
};
Morebits.simpleWindow.setButtonsEnabled(false);
Morebits.status.init(form);
Twinkle.arv.processAN3(an3Parameters);
};
if (free_resolves) {
let query;
let diff, oldid;
const specialDiff = /Special:Diff\/(\d+)(?:\/(\S+))?/i.exec(free_resolves);
if (specialDiff) {
if (specialDiff[2]) {
oldid = specialDiff[1];
diff = specialDiff[2];
} else {
diff = specialDiff[1];
}
} else {
diff = mw.util.getParamValue('diff', free_resolves);
oldid = mw.util.getParamValue('oldid', free_resolves);
}
const title = mw.util.getParamValue('title', free_resolves);
const diffNum = /^\d+$/.test(diff); // used repeatedly
// rvdiffto in prop=revisions is deprecated, but action=compare doesn't return
// timestamps ([[phab:T247686]]) so we can't rely on it unless necessary.
// Likewise, we can't rely on a meaningful comment for diff=cur.
// Additionally, links like Special:Diff/123/next, Special:Diff/123/456, or ?diff=next&oldid=123
// would each require making use of rvdir=newer in the revisions API.
// That requires a title parameter, so we have to use compare instead of revisions.
if (oldid && (diff === 'cur' || (!title && (diff === 'next' || diffNum)))) {
query = {
action: 'compare',
fromrev: oldid,
prop: 'ids|title',
format: 'json'
};
if (diffNum) {
query.torev = diff;
} else {
query.torelative = diff;
}
} else {
query = {
action: 'query',
prop: 'revisions',
rvprop: 'ids|timestamp|comment',
format: 'json',
indexpageids: true
};
if (diff && oldid) {
if (diff === 'prev') {
query.revids = oldid;
} else {
query.titles = title;
query.rvdir = 'newer';
query.rvstartid = oldid;
if (diff === 'next' && title) {
query.rvlimit = 2;
} else if (diffNum) {
// Diffs may or may not be consecutive, no limit
query.rvendid = diff;
}
}
} else {
// diff=next|prev|cur with no oldid
// Implies title= exists otherwise it's not a valid diff link (well, it is, but to the Main Page)
if (diff && /^\D+$/.test(diff)) {
query.titles = title;
} else {
query.revids = diff || oldid;
}
}
}
new mw.Api().get(query).done((data) => {
let page;
if (data.compare && data.compare.fromtitle === data.compare.totitle) {
page = data;
} else if (data.query) {
const pageid = data.query.pageids[0];
page = data.query.pages[pageid];
} else {
return;
}
an3_next(page);
}).fail((data) => {
console.log('API failed :(', data); // eslint-disable-line no-console
});
} else {
an3_next();
}
break;
}
};
Twinkle.arv.callback.getAivReasonWikitext = function(input) {
var text = '';
var type = input.arvtype;
if (!type.length && input.reason === '') {
return null;
}
type = type.map((v) => {
switch (v) {
case 'final':
return 'vandalism after final warning';
case 'postblock':
return 'vandalism after recent release of block';
case 'vandalonly':
return 'actions evidently indicate a vandalism-only account';
case 'promoonly':
return 'account is being used only for promotional purposes';
case 'spambot':
return 'account is evidently a spambot or a compromised account';
default:
return 'unknown reason';
}
}).join('; ');
if (input.page !== '') {
// Allow links to redirects, files, and categories
text = 'On {{No redirect|:' + input.page + '}}';
if (input.badid !== '') {
text += ' ({{diff|' + input.page + '|' + input.badid + '|' + input.goodid + '|diff}})';
}
text += ':';
}
if (type) {
text += ' ' + type;
}
if (input.reason !== '') {
var textEndsInPunctuationOrBlank = /([.?!;:]|^)$/.test(text);
text += textEndsInPunctuationOrBlank ? '' : '.';
var textIsBlank = text === '';
text += textIsBlank ? '' : ' ';
text += input.reason;
}
text = text.trim();
var textEndsInPunctuation = /[.?!;]$/.test(text);
if (!textEndsInPunctuation) {
text += '.';
}
text += ' ~~~~';
text = text.replace(/\r?\n/g, '\n*:'); // indent newlines
return text;
};
Twinkle.arv.callback.buildAivReport = function(input) {
return '\n*{{vandal|' + (/=/.test(input.uid) ? '1=' : '') + input.uid + '}} – ' + Twinkle.arv.callback.getAivReasonWikitext(input);
};
Twinkle.arv.callback.getUsernameReportWikitext = function(input) {
// generate human-readable string, e.g. "misleading and promotional username"
if (input.arvtype.length <= 2) {
input.arvtype = input.arvtype.join(' and ');
} else {
input.arvtype = [ input.arvtype.slice(0, -1).join(', '), input.arvtype.slice(-1) ].join(' and ');
}
// a or an?
var adjective = 'a';
if (/[aeiouwyh]/.test(input.arvtype[0] || '')) { // non 100% correct, but whatever, including 'h' for Cockney
adjective = 'an';
}
var text = '*{{user-uaa|1=' + input.uid + '}} – ';
if (input.arvtype.length) {
text += 'Violation of the username policy as ' + adjective + ' ' + input.arvtype + ' username. ';
}
if (input.reason !== '') {
text += Morebits.string.toUpperCaseFirstChar(input.reason);
var endsInPeriod = /\.$/.test(input.reason);
if (!endsInPeriod) {
text += '.';
}
text += ' ';
}
text += '~~~~';
text = text.replace(/\r?\n/g, '\n*:'); // indent newlines
return text;
};
Twinkle.arv.processSock = function(params) {
Morebits.wiki.addCheckpoint(); // prevent notification events from causing an erronous "action completed"
// prepare the SPI report
let text = '\n{{subst:SPI report|' +
params.sockpuppets.map((sock, index) => (index + 1) + '=' + sock).join('|') + '\n|evidence=' + params.evidence + ' \n';
if (params.checkuser) {
text += '|checkuser=yes';
}
text += '}}';
const reportpage = 'Wikipedia:Sockpuppet investigations/' + params.uid;
Morebits.wiki.actionCompleted.redirect = reportpage;
Morebits.wiki.actionCompleted.notice = 'Reporting complete';
const spiPage = new Morebits.wiki.page(reportpage, 'Retrieving discussion page');
spiPage.setFollowRedirect(true);
spiPage.setEditSummary('Adding new report for [[Special:Contributions/' + params.uid + '|' + params.uid + ']].');
spiPage.setChangeTags(Twinkle.changeTags);
spiPage.setAppendText(text);
spiPage.setWatchlist(Twinkle.getPref('spiWatchReport'));
spiPage.append();
Morebits.wiki.removeCheckpoint(); // all page updates have been started
};
Twinkle.arv.processAN3 = function(params) {
// prepare the AN3 report
let minid;
for (let i = 0; i < params.diffs.length; ++i) {
if (params.diffs[i].parentid && (!minid || params.diffs[i].parentid < minid)) {
minid = params.diffs[i].parentid;
}
}
new mw.Api().get({
action: 'query',
prop: 'revisions',
format: 'json',
rvprop: 'sha1|ids|timestamp|comment',
rvlimit: 100, // intentionally limited
rvstartid: minid,
rvexcludeuser: params.uid,
indexpageids: true,
titles: params.page
}).done((data) => {
Morebits.wiki.addCheckpoint(); // prevent notification events from causing an erronous "action completed"
// In case an edit summary was revdel'd
const hasHiddenComment = function(rev) {
if (!rev.comment && typeof rev.commenthidden === 'string') {
return '(comment hidden)';
}
return '"' + rev.comment + '"';
};
let orig;
if (data.length) {
const sha1 = data[0].sha1;
for (let i = 1; i < data.length; ++i) {
if (data[i].sha1 === sha1) {
orig = data[i];
break;
}
}
if (!orig) {
orig = data[0];
}
}
let origtext = '';
if (orig) {
origtext = '{{diff2|' + orig.revid + '|' + orig.timestamp + '}} ' + hasHiddenComment(orig);
}
const grouped_diffs = {};
let parentid, lastid;
for (let j = 0; j < params.diffs.length; ++j) {
const cur = params.diffs[j];
if ((cur.revid && cur.revid !== parentid) || lastid === null) {
lastid = cur.revid;
grouped_diffs[lastid] = [];
}
parentid = cur.parentid;
grouped_diffs[lastid].push(cur);
}
const difftext = $.map(grouped_diffs, (sub) => {
let ret = '';
if (sub.length >= 2) {
const last = sub[0];
const first = sub.slice(-1)[0];
const label = 'Consecutive edits made from ' + new Morebits.date(first.timestamp).format('HH:mm, D MMMM YYYY', 'utc') + ' (UTC) to ' + new Morebits.date(last.timestamp).format('HH:mm, D MMMM YYYY', 'utc') + ' (UTC)';
ret = '# {{diff|oldid=' + first.parentid + '|diff=' + last.revid + '|label=' + label + '}}\n';
}
ret += sub.reverse().map((v) => (sub.length >= 2 ? '#' : '') + '# {{diff2|' + v.revid + '|' + new Morebits.date(v.timestamp).format('HH:mm, D MMMM YYYY', 'utc') + ' (UTC)}} ' + hasHiddenComment(v)).join('\n');
return ret;
}).reverse().join('\n');
const warningtext = params.warnings.reverse().map((v) => '# ' + ' {{diff2|' + v.revid + '|' + new Morebits.date(v.timestamp).format('HH:mm, D MMMM YYYY', 'utc') + ' (UTC)}} ' + hasHiddenComment(v)).join('\n');
let resolvetext = params.resolves.reverse().map((v) => '# ' + ' {{diff2|' + v.revid + '|' + new Morebits.date(v.timestamp).format('HH:mm, D MMMM YYYY', 'utc') + ' (UTC)}} ' + hasHiddenComment(v)).join('\n');
if (params.free_resolves) {
const page = params.free_resolves;
if (page.compare) {
resolvetext += '\n# ' + ' {{diff|oldid=' + page.compare.fromrevid + '|diff=' + page.compare.torevid + '|label=Consecutive edits on ' + page.compare.totitle + '}}';
} else if (page.revisions) {
const revCount = page.revisions.length;
let rev;
if (revCount < 3) { // diff=prev or next
rev = revCount === 1 ? page.revisions[0] : page.revisions[1];
resolvetext += '\n# ' + ' {{diff2|' + rev.revid + '|' + new Morebits.date(rev.timestamp).format('HH:mm, D MMMM YYYY', 'utc') + ' (UTC) on ' + page.title + '}} ' + hasHiddenComment(rev);
} else { // diff and oldid are nonconsecutive
rev = page.revisions[0];
const revLatest = page.revisions[revCount - 1];
const label = 'Consecutive edits made from ' + new Morebits.date(rev.timestamp).format('HH:mm, D MMMM YYYY', 'utc') + ' (UTC) to ' + new Morebits.date(revLatest.timestamp).format('HH:mm, D MMMM YYYY', 'utc') + ' (UTC) on ' + page.title;
resolvetext += '\n# {{diff|oldid=' + rev.revid + '|diff=' + revLatest.revid + '|label=' + label + '}}\n';
}
}
}
let comment = params.comment.replace(/~*$/g, '').trim();
if (comment) {
comment += ' ~~~~';
}
const text = '\n\n' + '{{subst:AN3 report|diffs=' + difftext + '|warnings=' + warningtext + '|resolves=' + resolvetext + '|pagename=' + params.page + '|orig=' + origtext + '|comment=' + comment + '|uid=' + params.uid + '}}';
const reportpage = 'Wikipedia:Administrators\' noticeboard/Edit warring';
Morebits.wiki.actionCompleted.redirect = reportpage;
Morebits.wiki.actionCompleted.notice = 'Reporting complete';
const an3Page = new Morebits.wiki.page(reportpage, 'Retrieving discussion page');
an3Page.setFollowRedirect(true);
an3Page.setEditSummary('Adding new report for [[Special:Contributions/' + params.uid + '|' + params.uid + ']].');
an3Page.setChangeTags(Twinkle.changeTags);
an3Page.setAppendText(text);
an3Page.append();
// notify user
const notifyText = '\n\n{{subst:an3-notice|1=' + mw.util.wikiUrlencode(params.uid) + '|auto=1}} ~~~~';
const talkPage = new Morebits.wiki.page('User talk:' + params.uid, 'Notifying edit warrior');
talkPage.setFollowRedirect(true);
talkPage.setEditSummary('Notifying about edit warring noticeboard discussion.');
talkPage.setChangeTags(Twinkle.changeTags);
talkPage.setAppendText(notifyText);
talkPage.append();
Morebits.wiki.removeCheckpoint(); // all page updates have been started
}).fail((data) => {
console.log('API failed :(', data); // eslint-disable-line no-console
});
};
Twinkle.addInitCallback(Twinkle.arv, 'arv');
}(jQuery));
// </nowiki>