-
Notifications
You must be signed in to change notification settings - Fork 3
/
sandbox.js
789 lines (702 loc) · 29.9 KB
/
sandbox.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
//rmCloser
//<nowiki>
var rmCloser = {};
window.rmCloser = rmCloser;
$.when(
mw.loader.using([ 'mediawiki.api', 'ext.gadget.morebits' ]),
$.ready
).then(function() {
var rmCategoryPresent = false;
if (document.getElementById("mw-normal-catlinks")){
var categories = document.getElementById("mw-normal-catlinks").children[1].children;
for(var i=0; i<categories.length; i++){
if(categories[i].innerText == "Requested moves"){
rmCategoryPresent = true;
}
}
}
if (document.getElementById("reqmovetag") !== null && Morebits.pageNameNorm.indexOf("alk:") !== -1 && rmCategoryPresent && !document.getElementById("wikiPreview") && mw.config.get('wgDiffOldId') == null) {
document.getElementById("reqmovetag").innerHTML = "<button id='rmCloserClose'>Close</button><button id='rmCloserRelist'>Relist</button><button id='rmCloserNotify'>Notify WikiProjects</button><span id='rmCloserRelistOptions' style='display:none'><input id='rmCloserRelistComment' placeholder='Relisting comment' oninput='if(this.value.length>20){this.size=this.value.length} else{this.size=20}'/><br><button id='rmCloserConfirm'>Confirm relist</button><button id='rmCloserCancel'>Cancel relist</button></span>";
$('#rmCloserClose').click(rmCloser.callback);
$('#rmCloserRelist').click(rmCloser.confirmRelist);
$('#rmCloserConfirm').click(rmCloser.relist);
$('#rmCloserCancel').click(rmCloser.cancelRelist);
$('#rmCloserNotify').click(rmCloser.notify);
} else if(Morebits.pageNameNorm == "Wikipedia:Requested moves/Technical requests"){
var externalText = document.getElementsByClassName("external text");
var moveLinks = [];
for(var i=0; i<externalText.length; i++){
if(externalText[i].innerHTML == "move"){
moveLinks.push(externalText[i].parentElement.parentElement);
}
}
var parserOutputChildren = document.getElementsByClassName('mw-parser-output')[0].children;
var childrenList = [];
for(var i=0; i<parserOutputChildren.length; i++){
childrenList.push(parserOutputChildren[i].innerHTML);
}
var contestedHeader = childrenList.indexOf('<span class="mw-headline" id="Contested_technical_requests">Contested technical requests</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Wikipedia:Requested_moves/Technical_requests&action=edit&section=3" title="Edit section: Contested technical requests">edit source</a><span class="mw-editsection-bracket">]</span></span>');
var revertUndiscussedHeader = childrenList.indexOf('<span class="mw-headline" id="Requests_to_revert_undiscussed_moves">Requests to revert undiscussed moves</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Wikipedia:Requested_moves/Technical_requests&action=edit&section=4" title="Edit section: Requests to revert undiscussed moves">edit source</a><span class="mw-editsection-bracket">]</span></span>');
for(var i=0; i<moveLinks.length; i++){
var rmAssistIndex = childrenList.indexOf(moveLinks[i].parentElement.innerHTML);
var rmtrButtonSpan = document.createElement("SPAN");
if(rmAssistIndex > contestedHeader && rmAssistIndex < revertUndiscussedHeader){
rmtrButtonSpan.innerHTML = "<button id='rmCloserRMassistDi" + i + "' onclick='rmCloser.rmtrEvaluate(this.id)'>Discuss</button>";
} else{
rmtrButtonSpan.innerHTML = "<button id='rmCloserRMassistMD" + i + "' onclick='rmCloser.rmtrEvaluate(this.id)'>Move directly</button><button id='rmCloserRMassistSP" + i + "' onclick='rmCloser.rmtrEvaluate(this.id)'>Swap Pages</button>";
rmtrButtonSpan.innerHTML += "<button id='rmCloserRMassistCo" + i + "' onclick='rmCloser.rmtrEvaluate(this.id)'>Contest</button>";
}
rmtrButtonSpan.innerHTML += "<button id='rmCloserRMassistRe" + i + "' onclick='rmCloser.rmtrEvaluate(this.id)'>Remove</button><br><span id='rmCloserRMassistHiddenSpan" + i + "'></span><br><hr><br>";
moveLinks[i].parentElement.insertBefore(rmtrButtonSpan,moveLinks[i].nextElementSibling);
}
}
});
rmCloser.confirmRelist = function rmCloserConfirmRelist(e) {
if (e) e.preventDefault();
document.getElementById("rmCloserRelistOptions").style.display = "inline";
document.getElementById("rmCloserClose").style.display = "none";
document.getElementById("rmCloserRelist").style.display = "none";
document.getElementById("rmCloserNotify").style.display = "none";
};
rmCloser.cancelRelist = function rmCloserCancelRelist(e) {
if (e) e.preventDefault();
document.getElementById("rmCloserRelistOptions").style.display = "none";
document.getElementById("rmCloserClose").style.display = "inline";
document.getElementById("rmCloserRelist").style.display = "inline";
document.getElementById("rmCloserNotify").style.display = "inline";
};
rmCloser.advert = ' using [[User:TheTVExpert/rmCloser|rmCloser]]';
rmCloser.callback = function rmCloserCallback(e) {
if (e) e.preventDefault();
rmCloser.Window = new Morebits.simpleWindow(600, 450);
rmCloser.Window.setTitle( "Close requested move" );
rmCloser.Window.setScriptName('rmCloser');
rmCloser.Window.addFooterLink('RM Closing instruction', 'WP:RMCI');
rmCloser.Window.addFooterLink('Script documentation', 'User:TheTVExpert/rmCloser');
rmCloser.Window.addFooterLink('Give feedback', 'User talk:TheTVExpert/rmCloser');
var form = new Morebits.quickForm(rmCloser.evaluate);
var resultField = form.append({
type: 'field',
label: 'Result'
});
resultField.append({
type: 'radio',
name: 'result',
list: [
{
label: 'Moved',
value: 'moved',
event: function() {
document.getElementsByName('customResult')[0].style.display = 'none';
document.getElementsByName('customResult')[0].required = false;
}
},
{
label: 'Not moved',
value: 'not moved',
event: function() {
document.getElementsByName('customResult')[0].style.display = 'none';
document.getElementsByName('customResult')[0].required = false;
}
},
{
label: 'No consensus',
value: 'no consensus',
event: function() {
document.getElementsByName('customResult')[0].style.display = 'none';
document.getElementsByName('customResult')[0].required = false;
}
},
{
label: 'Custom',
value: 'custom',
event: function() {
document.getElementsByName('customResult')[0].style.display = 'inline';
document.getElementsByName('customResult')[0].required = true;
}
}
]
});
resultField.append({
type: 'input',
name: 'customResult'
});
var closingCommentField = form.append({
type: 'field',
label: 'Closing comment'
});
closingCommentField.append({
type: 'textarea',
name: 'closingComment'
});
form.append({ type: 'submit', label: 'Submit' });
var formResult = form.render();
rmCloser.Window.setContent(formResult);
rmCloser.Window.display();
document.getElementsByName('customResult')[0].style.display = 'none';
document.getElementsByName('result')[0].required = true;
};
rmCloser.evaluate = function(e) {
var form = e.target;
rmCloser.params = Morebits.quickForm.getInputData(form);
Morebits.simpleWindow.setButtonsEnabled(false);
Morebits.status.init(form);
var title_obj = mw.Title.newFromText(Morebits.pageNameNorm);
rmCloser.title = title_obj.getSubjectPage().toText();
rmCloser.talktitle = title_obj.getTalkPage().toText();
var result = rmCloser.params.result;
if(result == 'custom'){
result = rmCloser.params.customResult;
}
var closingComment = rmCloser.params.closingComment;
if(closingComment != ""){
closingComment = ' ' + closingComment;
closingComment = closingComment.replace(/\|/g, "{{!}}");
closingComment = closingComment.replace(/=/g, "{{=}}");
}
var talkpage = new Morebits.wiki.page(rmCloser.talktitle, 'Closing move.');
talkpage.load(function(talkpage) {
var text = talkpage.getPageText();
var template = text.match(/{{[Rr]equested move\/dated\|.*\n?[^\[]*}}/)[0];
var templateFound = false;
var numberOfMoves = 0;
var line;
var textToFind = text.split('\n');
for (var i = 0; i < textToFind.length; i++) {
line = textToFind[i];
if(templateFound == false){
if(/{{[Rr]equested move\/dated/.test(line)){
templateFound = true;
}
} else if(templateFound == true){
if (/ \(UTC\)/.test(line)){
break;
} else if(/→/.test(line)){
numberOfMoves++;
}
}
}
var userGroupText = "";
if(Morebits.userIsInGroup('sysop')){
userGroupText = "";
} else if(Morebits.userIsInGroup('extendedmover')){
userGroupText = "|pmc=y";
} else{
userGroupText = "|nac=y";
}
text = text.replace(/{{[Rr]equested move\/dated\|.*\n?[^\[]*}}/, "{{subst:RM top|'''" + result + ".'''" + closingComment + userGroupText +"}}");
var sections = text.match(/^(==)[^=].+\1/gm);
var sectionToFind = /== Requested move.*==/;
sections.reverse();
var moveSection;
if(sectionToFind.test(sections[0])){
text+='\n{{subst:RM bottom}}';
moveSection = sections[0];
} else{
var i;
for(i=0;i<sections.length;i++){
if(sectionToFind.test(sections[i])){
text = text.replace(sections[i-1], '\n{{subst:RM bottom}}\n' + sections[i-1]);
moveSection = sections[i];
break;
}
}
}
var multiMove = false;
var moveSectionPlain = moveSection.slice(3,-3);
var date = '|date=' + moveSectionPlain.slice(15);
var from = '';
if(result == "moved"){
from = '|from=' + rmCloser.title;
}
var destination = template.match(/\|new1=(.*)\|current2=/);
if(destination != null){
multiMove = true;
destination = destination[1];
} else{
destination = template.match(/\|(.*)}}/);
if(destination != null){
destination = destination[1];
}
}
if(destination == "?"){
destination = "";
}
var link = '|link=Special:Permalink/' + talkpage.getCurrentID() + '#' + moveSectionPlain;
var archives = text.match(/{{[Aa]rchives/);
if(archives == null){
archives = text.match(/{{[Aa]rchive box/);
if(archives == null){
archives = text.match(/{{[Aa]rchivebox/);
if(archives == null){
archives = text.match(/==.*==/);
}
}
}
text = text.replace(archives[0], '{{old move'+ date + from + '|destination=' + destination + '|result=' + result + link +'}}\n\n' + archives[0]);
talkpage.setPageText(text);
talkpage.setEditSummary('Closing requested move; ' + result + rmCloser.advert);
talkpage.save(Morebits.status.actionCompleted('Moved closed.'));
if(multiMove == true){
var otherDestinations = [];
var otherPages = [];
for(i=2; i<(numberOfMoves+1); i++){
var text1 = "\\|current" + i + "=(.*)\\|new" + i;
var reg1 = new RegExp(text1);
var curr = template.match(reg1);
var dest;
if(i != numberOfMoves){
var nextNum = i+1;
var text2 = "\\|new" + i + "=(.*)\\|current" + nextNum;
var reg2 = new RegExp(text2);
dest = template.match(reg2);
} else{
var text3 = "\\|new" + i + "=(.*)\\|}}";
var reg3 = new RegExp(text3);
dest = template.match(reg3);
}
if(curr != null && dest != null){
otherPages.push(curr[1].trim());
otherDestinations.push(dest[1].trim());
}
}
var pagesLeft = otherPages.length;
for(var j=0; j<otherPages.length; j++){
var otherTitle_obj = mw.Title.newFromText(otherPages[j]);
rmCloser.otherTalktitle = otherTitle_obj.getTalkPage().toText();
var otherPage = new Morebits.wiki.page(rmCloser.otherTalktitle, 'Adding {{old move}} to ' + rmCloser.otherTalktitle + '.');
otherPage.load(function(otherPage) {
var otherText = otherPage.getPageText();
var title = mw.Title.newFromText(otherPage.getPageName()).getSubjectPage().toText();
var OMcurr = otherPages[otherPages.indexOf(title)];
var OMdest = otherDestinations[otherPages.indexOf(title)];
var otherFrom = '';
if(result == "moved"){
otherFrom = '|from=' + OMcurr;
}
if(OMdest == "?"){
OMdest == "";
}
var otherDestination = '|destination=' + OMdest;
var otherArchives = otherText.match(/{{[Aa]rchives/);
if(otherArchives == null){
otherArchives = otherText.match(/{{[Aa]rchive box/);
if(otherArchives == null){
otherArchives = otherText.match(/{{[Aa]rchivebox/);
if(otherArchives == null){
otherArchives = otherText.match(/==.*==/);
}
}
}
otherText = otherText.replace(otherArchives[0], '{{old move'+ date + otherFrom + otherDestination + '|result=' + result + link +'}}\n\n' + otherArchives[0]);
otherPage.setPageText(otherText);
otherPage.setEditSummary('Closing requested move; ' + result + rmCloser.advert);
otherPage.save(Morebits.status.actionCompleted('Moved closed.'));
pagesLeft--;
});
}
if(result == "moved"){
var waitInterval = setInterval(function(){
if(pagesLeft == 0){
rmCloser.movePages(rmCloser.title,destination,otherPages,otherDestinations,moveSectionPlain);
clearInterval(waitInterval);
}
}, 500);
} else{
setTimeout(function(){ location.reload() }, 2000);
}
} else if(result == "moved"){
var emptyArray = [];
rmCloser.movePages(rmCloser.title,destination,emptyArray,emptyArray,moveSectionPlain);
} else{
setTimeout(function(){ location.reload() }, 2000);
}
});
};
rmCloser.movePages = function rmCloserMovePages(curr1,dest1,currList,destList,sectionTitle){
var numberToRemove = currList.length+1;
rmCloser.talktitle = mw.Title.newFromText(Morebits.pageNameNorm).getTalkPage().toText();
var pageAndSection = rmCloser.talktitle + "#" + sectionTitle;
var moveSummary = 'Moved per [[' + pageAndSection + ']]';
var rmtrReason = 'Per [[' + pageAndSection + ']].';
var form = new Morebits.quickForm();
form.append({
type: 'header',
label: 'Move pages'
});
form.append({
type: 'div',
className: 'rmCloserMovePages' + curr1,
label: curr1 + ' → ' + dest1
});
form.append({
type: 'button',
className: 'rmCloserMovePages' + curr1,
label: 'Move directly',
event: function() {
rmCloser.directMove(curr1,dest1,false,moveSummary);
for(var i=0; i<document.getElementsByClassName('rmCloserMovePages' + curr1).length; i++){
document.getElementsByClassName('rmCloserMovePages' + curr1)[i].style.display = 'none';
}
numberToRemove--;
}
});
if(!Morebits.userIsInGroup('sysop') && !Morebits.userIsInGroup('extendedmover')){
form.append({
type: 'button',
className: 'rmCloserMovePages' + curr1,
label: 'Submit technical request',
event: function() {
rmCloser.submitRMTR(curr1,dest1,rmtrReason);
for(var i=0; i<document.getElementsByClassName('rmCloserMovePages' + curr1).length; i++){
document.getElementsByClassName('rmCloserMovePages' + curr1)[i].style.display = 'none';
}
numberToRemove--;
}
});
} else{
form.append({
type: 'button',
className: 'rmCloserMovePages' + curr1,
label: 'Move directly without leaving a redirect',
event: function() {
rmCloser.directMove(curr1,dest1,true,moveSummary);
for(var i=0; i<document.getElementsByClassName('rmCloserMovePages' + curr1).length; i++){
document.getElementsByClassName('rmCloserMovePages' + curr1)[i].style.display = 'none';
}
numberToRemove--;
}
});
}
for(var i=0; i<currList.length; i++){
form.append({
type: 'div',
className: 'rmCloserMovePages' + currList[i],
label: currList[i] + ' → ' + destList[i]
});
form.append({
type: 'button',
className: 'rmCloserMovePages' + currList[i],
name: currList[i],
extra: destList[i],
label: 'Move directly',
event: function() {
rmCloser.directMove(this.name,this.extra,false,moveSummary);
for(var j=0; j<document.getElementsByClassName('rmCloserMovePages' + this.name).length; j++){
document.getElementsByClassName('rmCloserMovePages' + this.name)[j].style.display = 'none';
}
numberToRemove--;
}
});
if(!Morebits.userIsInGroup('sysop') && !Morebits.userIsInGroup('extendedmover')){
form.append({
type: 'button',
className: 'rmCloserMovePages' + currList[i],
name: currList[i],
extra: destList[i],
label: 'Submit technical request',
event: function() {
rmCloser.submitRMTR(this.name,this.extra,rmtrReason);
for(var j=0; j<document.getElementsByClassName('rmCloserMovePages' + this.name).length; j++){
document.getElementsByClassName('rmCloserMovePages' + this.name)[j].style.display = 'none';
}
numberToRemove--;
}
});
} else{
form.append({
type: 'button',
className: 'rmCloserMovePages' + currList[i],
name: currList[i],
extra: destList[i],
label: 'Move directly without leaving a redirect',
event: function() {
rmCloser.directMove(this.name,this.extra,true,moveSummary);
for(var j=0; j<document.getElementsByClassName('rmCloserMovePages' + this.name).length; j++){
document.getElementsByClassName('rmCloserMovePages' + this.name)[j].style.display = 'none';
}
numberToRemove--;
}
});
}
}
var formResult = form.render();
rmCloser.Window.setContent(formResult);
rmCloser.Window.display();
var moveInterval = setInterval(function(){
if(numberToRemove == 0){
rmCloser.Window.close();
clearInterval(moveInterval);
setTimeout(function(){ location.reload() }, 2000);
}
}, 500);
};
rmCloser.directMove = function rmCloserDirectMove(curr,dest,suppressRedirect,editSummary) {
var pageToMove = new Morebits.wiki.page(curr, 'Moving ' + curr + ' to ' + dest + '.');
pageToMove.setMoveDestination(dest);
pageToMove.setMoveSubpages(true);
pageToMove.setMoveTalkPage(true);
pageToMove.setMoveSuppressRedirect(suppressRedirect);
pageToMove.setEditSummary(editSummary + rmCloser.advert);
pageToMove.move(Morebits.status.actionCompleted('Moved.'));
};
rmCloser.submitRMTR = function rmCloserSubmitRMTR(curr,dest,reason) {
var rmtr = new Morebits.wiki.page('Wikipedia:Requested moves/Technical requests', 'Submitting request at WP:RM/TR');
rmtr.load(function(page) {
var text = rmtr.getPageText();
var textToFind = /---- and enter on a new line.* -->/;
var rmtrText = '{{subst:RMassist|1=' + curr + '|2=' + dest + '|reason=' + reason + '}}';
text = text.replace(textToFind, '$&\n' + rmtrText);
rmtr.setPageText(text);
rmtr.setEditSummary('Add request' + rmCloser.advert);
rmtr.save(Morebits.status.actionCompleted('Requested.'));
});
};
rmCloser.relist = function rmCloserRelist(e) {
if (e) e.preventDefault();
var title_obj = mw.Title.newFromText(Morebits.pageNameNorm);
rmCloser.talktitle = title_obj.getTalkPage().toText();
var talkpage = new Morebits.wiki.page(rmCloser.talktitle, 'Relisting.');
var relistingComment = document.getElementById('rmCloserRelistComment').value;
talkpage.load(function(talkpage) {
var text = talkpage.getPageText();
var templateFound = false;
var sig;
var line;
var textToFind = text.split('\n');
for (var i = 0; i < textToFind.length; i++) {
line = textToFind[i];
if(templateFound == false){
if(/{{[Rr]equested move\/dated/.test(line)){
templateFound = true;
}
} else if(templateFound == true){
if (/ \(UTC\)/.test(line)){
sig = line;
break;
}
}
}
text = text.replace(sig, sig + " {{subst:relisting}}");
if(relistingComment != ''){
var sectionList = text.match(/^(==)[^=].+\1/gm);
var sectionToFindWikitext = /== Requested move.*==/;
sectionList.reverse();
if(sectionToFindWikitext.test(sectionList[0])){
text+='\n:<small>\'\'\'Relisting comment\'\'\': ' + relistingComment + ' ~~~~</small>';
} else{
var i;
for(i=0;i<sectionList.length;i++){
if(sectionToFindWikitext.test(sectionList[i])){
text = text.replace(sectionList[i-1], ':<small>\'\'\'Relisting comment\'\'\': ' + relistingComment + ' ~~~~</small>\n\n' + sectionList[i-1]);
break;
}
}
}
}
talkpage.setPageText(text);
talkpage.setEditSummary('Relisted requested move' + rmCloser.advert);
talkpage.save(Morebits.status.actionCompleted('Relisted.'));
document.getElementById("reqmovetag").innerHTML = "";
setTimeout(function(){ location.reload() }, 2000);
});
};
rmCloser.notify = function rmCloserNotify(e) {
if (e) e.preventDefault();
var wikiProjectTemplates = document.getElementsByClassName("wpb-project_link");
var wikiProjectNames = [];
var wikiProjects = [];
for(var i=0; i<wikiProjectTemplates.length; i++){
var wikiProjectName = wikiProjectTemplates[i].innerHTML;
var wikiProjectTalk = mw.Title.newFromText(wikiProjectTemplates[i].innerHTML).getTalkPage().toText();
wikiProjectNames.push(wikiProjectName);
wikiProjects.push(wikiProjectTalk);
}
if(wikiProjects.length == 0){
mw.notify('No WikiProject banners found on this page');
} else{
var Window = new Morebits.simpleWindow(600, 450);
Window.setTitle( "Notify WikiProjects about requested move" );
Window.setScriptName('rmCloser');
Window.addFooterLink('Script documentation', 'User:TheTVExpert/rmCloser');
Window.addFooterLink('Give feedback', 'User talk:TheTVExpert/rmCloser');
var form = new Morebits.quickForm(rmCloser.notifyEvaluate);
form.append({
type: 'div',
label: 'WikiProjects with banners on this page:'
});
form.append({
type: 'radio',
name: 'wikiProject',
list: wikiProjects.map(function (wp) {
var wplabel = wikiProjectNames[wikiProjects.indexOf(wp)];
return { type: 'option', label: wplabel, value: wp };
})
});
if(wikiProjects[0] != 'none'){
form.append({ type: 'submit', label: 'Notify selected WikiProject' });
}
var formResult = form.render();
Window.setContent(formResult);
Window.display();
document.getElementsByName('wikiProject')[0].required = true;
}
};
rmCloser.notifyEvaluate = function(e) {
var form = e.target;
rmCloser.params = Morebits.quickForm.getInputData(form);
Morebits.simpleWindow.setButtonsEnabled(false);
Morebits.status.init(form);
var wikiProjectToNotify = rmCloser.params.wikiProject;
var talkpage = new Morebits.wiki.page(wikiProjectToNotify, 'Notifying ' + wikiProjectToNotify + '.');
talkpage.setFollowRedirect(true);
talkpage.load(function(talkpage) {
var text = talkpage.getPageText();
var sections = document.getElementsByClassName("mw-headline");
var sectionArray = [];
for(var i=0; i<sections.length; i++){
sectionArray.push(sections[i].innerHTML);
}
sectionArray.reverse();
var sectionToFind = /Requested move [0-9]{1,2} (January|February|March|April|May|June|July|August|September|October|November|December) [0-9]{4}/;
var moveSection;
for(var i=0; i<sectionArray.length; i++){
if(sectionToFind.test(sectionArray[i])){
moveSection = sectionArray[i].match(/Requested move [0-9]{1,2} (January|February|March|April|May|June|July|August|September|October|November|December) [0-9]{4}/)[0];
break;
}
}
rmCloser.talktitle = mw.Title.newFromText(Morebits.pageNameNorm).getTalkPage().toText();
var pageAndSection = rmCloser.talktitle + "#" + moveSection;
var notified;
if(text.match(pageAndSection) != null){
if(confirm("Selected WikiProject may have already been notified of the discussion. Do you wish to proceed?")){
text += "\n\n== Requested move at [[" + pageAndSection + "]] ==\n[[File:Information.svg|30px|left]] There is a requested move discussion at [[" + pageAndSection + "]] that may be of interest to members of this WikiProject. ~~~~";
talkpage.setPageText(text);
talkpage.setEditSummary('Notifying of requested move' + rmCloser.advert);
talkpage.save(Morebits.status.actionCompleted('Notified.'));
notified = true;
} else{
var cancelNotify = new Morebits.status('Error', 'Notification canceled', 'error');
notified = false;
}
} else{
text += "\n\n== Requested move at [[" + pageAndSection + "]] ==\n[[File:Information.svg|30px|left]] There is a requested move discussion at [[" + pageAndSection + "]] that may be of interest to members of this WikiProject. ~~~~";
talkpage.setPageText(text);
talkpage.setEditSummary('Notifying of requested move' + rmCloser.advert);
talkpage.save(Morebits.status.actionCompleted('Notified.'));
notified = true;
}
if(notified){
var discussionPage = new Morebits.wiki.page(rmCloser.talktitle, 'Adding note about notification to requested move');
discussionPage.load(function(discussionPage) {
var discussionPageText = discussionPage.getPageText();
var sectionList = discussionPageText.match(/^(==)[^=].+\1/gm);
var sectionToFindWikitext = /== Requested move.*==/;
sectionList.reverse();
if(sectionToFindWikitext.test(sectionList[0])){
discussionPageText+='\n:<small>Note: [[' + wikiProjectToNotify + '|' + wikiProjectToNotify.slice(15) + ']] has been notified of this discussion. ~~~~</small>';
} else{
var i;
for(i=0;i<sectionList.length;i++){
if(sectionToFindWikitext.test(sectionList[i])){
discussionPageText = discussionPageText.replace(sectionList[i-1], ':<small>Note: [[' + wikiProjectToNotify + '|' + wikiProjectToNotify.slice(15) + ']] has been notified of this discussion. ~~~~</small>\n\n' + sectionList[i-1]);
break;
}
}
}
discussionPage.setPageText(discussionPageText);
discussionPage.setEditSummary('Added note about notifying WikiProject about requested move' + rmCloser.advert);
discussionPage.save(Morebits.status.actionCompleted('Note added.'));
setTimeout(function(){ location.reload() }, 2000);
});
}
});
};
rmCloser.rmtrEvaluate = function rmCloserRMTREvaluate(id) {
var type = id.slice(16,18);
var number = id.slice(18,id.length);
var rmtrPage = new Morebits.wiki.page('Wikipedia:Requested moves/Technical requests', 'Closing technical request');
rmtrPage.load(function(rmtrPage) {
var text = rmtrPage.getPageText();
var rmAssistList = text.match(/\* {{RMassist\/core.*}}/g);
var rmAssistToFind = rmAssistList[number];
var currentTitle = rmAssistToFind.match(/\| 1 = (.*) \| 2 =/)[1];
var destinationTitle = rmAssistToFind.match(/\| 2 = (.*) \| discuss =/)[1];
var rmtrReason = rmAssistToFind.match(/\| reason = (.*) \| sig =/)[1];
var requesterSig = rmAssistToFind.match(/\| sig = (.*) \| requester =/)[1];
var requester = rmAssistToFind.match(/\| requester = (.*)}}/)[1];
var rmAssistToFindEscaped = rmAssistToFind.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&');
var rmAssistToFindRegex = new RegExp(rmAssistToFindEscaped + '(\\n\|.)*?(====\|\\* {{RMassist\\/core)');
if(text.match(rmAssistToFindRegex) == null){
rmAssistToFindRegex = new RegExp(rmAssistToFindEscaped + '(\\n\|.)*');
}
var replacementString = text.match(rmAssistToFindRegex)[2]
if(replacementString == undefined){
replacementString = "";
var rmAssistToFindFull = text.match(rmAssistToFindRegex);
rmAssistToFindFull = rmAssistToFindFull[0];
} else{
var rmAssistToFindFull = text.match(rmAssistToFindRegex);
rmAssistToFindFull = rmAssistToFindFull[0].slice(0,-(replacementString.length+1));
}
var rmAssistToFindFullTrimmed = rmAssistToFindFull.trim();
var temporaryText = text.replace('\n' + rmAssistToFindFullTrimmed,"");
if(temporaryText == text){
text = text.replace(rmAssistToFind,"");
} else{
text = temporaryText;
}
if(type == "MD"){
document.getElementById('rmCloserRMassistHiddenSpan' + number).innerHTML = "";
rmtrPage.setPageText(text);
rmtrPage.setEditSummary('Closing request' + rmCloser.advert);
var pageToMove = new Morebits.wiki.page(currentTitle, 'Moving ' + currentTitle + ' to ' + destinationTitle + '.');
pageToMove.setMoveDestination(destinationTitle);
pageToMove.setMoveSubpages(true);
pageToMove.setMoveTalkPage(true);
pageToMove.setEditSummary('[[Special:Permalink/' + rmtrPage.getCurrentID() + '|Requested]] by ' + requester + ' at [[WP:RM/TR]]: ' + rmtrReason + rmCloser.advert);
pageToMove.move(rmtrPage.save(location.reload()));
} else if(type == "SP"){//Swap pages
document.getElementById('rmCloserRMassistHiddenSpan' + number).innerHTML = "";
console.log(text);
//rmtrPage.setPageText(text);
//rmtrPage.setEditSummary('Closing request' + rmCloser.advert);
//rmtrPage.save(location.reload());
} else if(type == "Di"){
document.getElementById('rmCloserRMassistHiddenSpan' + number).innerHTML = "";
rmtrPage.setPageText(text);
rmtrPage.setEditSummary('Discussing request' + rmCloser.advert);
rmCloser.talktitle = mw.Title.newFromText(currentTitle).getTalkPage().toText();
var talkpage = new Morebits.wiki.page(rmCloser.talktitle, 'Creating requested move');
talkpage.load(function(talkpage) {
var rmPageText = talkpage.getPageText();
rmPageText += "\n\n{{subst:Requested move|" + destinationTitle + "|reason=" + rmtrReason + " " + requesterSig + "\n:<small>This is a contested technical request ([[Special:Permalink/" + rmtrPage.getCurrentID() + "|permalink]]).</small>}}";
talkpage.setPageText(rmPageText);
talkpage.setEditSummary('Creating requested move from technical request' + rmCloser.advert);
talkpage.save(rmtrPage.save(window.location = mw.util.getUrl(rmCloser.talktitle)));
});
} else if(type == "Re"){
document.getElementById('rmCloserRMassistHiddenSpan' + number).innerHTML = "<button id='rmCloserWithdrawn'>Withdrawn</button><button id='rmCloserAlreadyDone'>Already done</button>";
$('#rmCloserWithdrawn').click(function(){
rmtrPage.setPageText(text);
rmtrPage.setEditSummary('Removing withdrawn request' + rmCloser.advert);
rmtrPage.save(location.reload());
});
$('#rmCloserAlreadyDone').click(function(){
rmtrPage.setPageText(text);
rmtrPage.setEditSummary('Removing completed request' + rmCloser.advert);
rmtrPage.save(location.reload());
});
} else if(type == "Co"){
document.getElementById('rmCloserRMassistHiddenSpan' + number).innerHTML = "**{{ping|" + requester + "}} <input id='rmCloserContestReason' placeholder='Contest reason' oninput='if(this.value.length>20){this.size=this.value.length} else{this.size=20}'/> ~~~~ <button id='rmCloserSubmitContestReason'>Submit</button><br>";
$('#rmCloserSubmitContestReason').click(function(){
text = text.replace("==== Contested technical requests ====","$&\n" + rmAssistToFindFullTrimmed + "\n**{{ping|" + requester + "}} " + document.getElementById('rmCloserContestReason').value + " ~~~~");
rmtrPage.setPageText(text);
rmtrPage.setEditSummary('Contesting request' + rmCloser.advert);
rmtrPage.save(location.reload());
});
}
});
}
//</nowiki>