-
Notifications
You must be signed in to change notification settings - Fork 7
/
script.js
853 lines (780 loc) · 30.5 KB
/
script.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
// <nowiki>
$(document).ready(function () {
//CSS loader
mw.loader.addStyleTag( '.heading { font-size: 22px; text-align: center; margin: 10px; width:100%; font-weight: bold }');
mw.loader.addStyleTag( '.help { font-size: 13px; font-style: italic }');
mw.loader.addStyleTag( '.status { font: 13px sans-serif; margin: 5px; width: 70%; font-style: italic; width: 100% }');
mw.loader.addStyleTag( '.messageStatus { font: 12px sans-serif; margin-left: 1rem; margin: 5px; width: 70%; font-style: italic; width: 100% }');
mw.loader.addStyleTag( '.welcomebutton { display: inline-grid; text-align: center; margin: 13px; width: 43% }' );
mw.loader.addStyleTag( '.button { display: inline-block; text-align: center; margin-top: 10px; margin-bottom: 10px }' );
mw.loader.addStyleTag( '.container { width: 415px; height:150px }');
mw.loader.addStyleTag( '.status:empty { display: none }');
mw.loader.addStyleTag( '.copyright { font-size: 10.5px; color: grey; line-height: 140% }');
// It is important to make sure that OOUI is loaded before we can make use of it.
mw.loader.using("oojs-ui", "mediawiki.api").done(function () {
// OOUI widgets for main menu welcome panel
welcomeheading = new OO.ui.LabelWidget({
label: "Welcome to the Edit Wizard \n",
classes: ["heading"],
}),
welcomebutton1 = new OO.ui.ButtonWidget({
label: "Add Fact",
classes: ["welcomebutton"],
flags: ["primary", "progressive"],
}),
welcomebutton2 = new OO.ui.ButtonWidget({
label: "Fix Factual Error",
classes: ["welcomebutton"],
flags: ["primary", "progressive"],
}),
welcomebutton3 = new OO.ui.ButtonWidget({
label: "Remove Content",
classes: ["welcomebutton"],
flags: ["primary", "progressive"],
}),
welcomebutton4 = new OO.ui.ButtonWidget({
label: "Do Something Else",
classes: ["welcomebutton"],
flags: ["primary", "progressive"],
}),
welcomepanel = new OO.ui.PanelLayout({
content: [
welcomeheading,
welcomebutton1,
welcomebutton2,
welcomebutton3,
welcomebutton4,
],
padded: true,
}),
// OOUI widgets for Link to the source panel
linkheading = new OO.ui.LabelWidget({
label: "Give a source for your fact",
classes: ["label"],
}),
linkhelp = new OO.ui.PopupButtonWidget({
icon: "info",
classes: ["help"],
framed: false,
label: "More information",
invisibleLabel: true,
popup: {
head: true,
icon: "infoFilled",
label: "More information",
$content: $(
"<p>This is the link of the source of your quote.\u200e</p>"
),
padded: true,
align: "center",
width: "300px",
autoFlip: true,
},
}),
linkinput = new OO.ui.TextInputWidget({
placeholder: "Enter the URL",
classes: ["box"],
}),
linkstatus = new OO.ui.MessageWidget({
inline: true,
classes: ["status"],
showClose: true,
icon:"none",
}),
linkverifybutton = new OO.ui.ButtonWidget({
label: "Verify",
classes: ["button"],
flags: ["primary", "progressive"],
}),
linkbackbutton = new OO.ui.ButtonWidget({
label: "Back",
classes: ["button"],
flags: ["primary", "progressive"],
}),
linkbutton = new OO.ui.ButtonWidget({
label: "Next",
classes: ["button"],
flags: ["primary", "progressive"],
}),
linkpanel = new OO.ui.PanelLayout({
content: [
linkheading,
linkhelp,
linkinput,
linkstatus,
linkbackbutton,
linkverifybutton,
linkbutton,
],
padded: true,
}),
// OOUI widgets for selecting the paragraph panel
selectfieldsetcontent = new OO.ui.FieldsetLayout({
label: "Click on the paragraph where your fact should go and click Next",
classes: ["label"],
}),
selectstatus = new OO.ui.MessageWidget({
inline: true,
classes: ["status"],
showClose: true,
icon:"none",
}),
selectbutton = new OO.ui.ButtonWidget({
label: "Next",
classes: ["button"],
flags: ["primary", "progressive"],
}),
selectbackbutton = new OO.ui.ButtonWidget({
label: "Back",
classes: ["button"],
flags: ["primary", "progressive"],
}),
selectpanel = new OO.ui.PanelLayout({
content: [
selectfieldsetcontent,
selectstatus,
selectbackbutton,
selectbutton,
],
padded: true,
}),
//OOUI widgets for selecting text panel
select2fieldsetcontent = new OO.ui.FieldsetLayout({
label: "Select the text where you want to fix the fact and click Next",
classes: ["label"],
}),
select2status = new OO.ui.MessageWidget({
inline: true,
classes: ["status"],
showClose: true,
icon:"none",
}),
select2button = new OO.ui.ButtonWidget({
label: "Next",
classes: ["button"],
flags: ["primary", "progressive"],
}),
select2backbutton = new OO.ui.ButtonWidget({
label: "Back",
classes: ["button"],
flags: ["primary", "progressive"],
}),
select2panel = new OO.ui.PanelLayout({
content: [
select2fieldsetcontent,
select2status,
select2backbutton,
select2button,
],
padded: true,
}),
// OOUI widgets for giving the quote panel
quoteheading = new OO.ui.LabelWidget({
label: "Quote from your source that supports your fact",
classes: ["label"],
}),
quotehelp = new OO.ui.PopupButtonWidget({
icon: "info",
classes: ["help"],
framed: false,
label: "More information",
invisibleLabel: true,
popup: {
head: true,
icon: "infoFilled",
label: "More information",
$content: $(
"<p>Type the quote text from the above-mentioned source you want to edit.\u200e</p>"
),
padded: true,
align: "backwards",
autoFlip: true,
},
}),
quoteinput = new OO.ui.MultilineTextInputWidget({
autosize: false,
classes: ["box"],
rows: 3,
placeholder: "Enter the Quote from the source",
}),
quotestatus = new OO.ui.MessageWidget({
inline: true,
classes: ["status"],
showClose: true,
icon:"none",
}),
quotebutton = new OO.ui.ButtonWidget({
label: "Next",
classes: ["button"],
flags: ["primary", "progressive"],
}),
quotebackbutton = new OO.ui.ButtonWidget({
label: "Back",
classes: ["button"],
flags: ["primary", "progressive"],
}),
quotepanel = new OO.ui.PanelLayout({
content: [
quoteheading,
quotehelp,
quoteinput,
quotestatus,
quotebackbutton,
quotebutton,
],
padded: true,
}),
// OOUI widgets for re-writing the quote panel
requoteheading = new OO.ui.LabelWidget({
label: "Rewrite the quote in your own words",
classes: ["label"],
}),
requotehelp = new OO.ui.PopupButtonWidget({
icon: "info",
classes: ["help"],
framed: false,
label: "More information",
invisibleLabel: true,
popup: {
head: true,
icon: "infoFilled",
label: "More information",
$content: $("<p>Rephrase the quote in your own words.\u200e</p>"),
padded: true,
width: "280px",
align: "center",
autoFlip: true,
},
}),
requoteinput = new OO.ui.MultilineTextInputWidget({
autosize: false,
classes: ["box"],
rows: 3,
placeholder: "Enter the rephrased Quote",
}),
requotestatus = new OO.ui.MessageWidget({
inline: true,
classes: ["status"],
showClose: true,
icon:"none",
}),
requotebutton = new OO.ui.ButtonWidget({
label: "Send Edit Request",
classes: ["button"],
flags: ["primary", "progressive"],
}),
requotebackbutton = new OO.ui.ButtonWidget({
label: "Back",
classes: ["button"],
flags: ["primary", "progressive"],
}),
copyrightText = new OO.ui.LabelWidget({
label: $( '<p>By publishing changes, you agree to the <a href="https://foundation.wikimedia.org/wiki/Terms_of_Use/en">Terms of Use</a>, and you irrevocably agree to release your contribution under the <a href="https://en.wikipedia.org/wiki/Wikipedia:Text_of_Creative_Commons_Attribution-ShareAlike_3.0_Unported_License">CC BY-SA 3.0 License</a> and the <a href="https://en.wikipedia.org/wiki/Wikipedia:Text_of_the_GNU_Free_Documentation_License">GFDL</a>. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.</p>' ),
classes: ["copyright"],
}),
requotepanel = new OO.ui.PanelLayout({
content: [
requoteheading,
requotehelp,
requoteinput,
requotestatus,
requotebackbutton,
requotebutton,
copyrightText,
],
padded: true,
});
// OOUI widgets for deleting options panel
deleteheading = new OO.ui.LabelWidget({
label: "Reason to Delete",
classes: ["label"],
}),
deleteDropdown = new OO.ui.DropdownWidget( {
label: 'Select one',
$overlay: true,
menu: {
items: [
new OO.ui.MenuOptionWidget( {
data: 'Irrelevant',
label: 'Irrelevant'
} ),
new OO.ui.MenuOptionWidget( {
data: 'Incorrect',
label: 'Incorrect'
} ),
new OO.ui.MenuOptionWidget( {
data: 'Misleading',
label: 'Misleading'
} ),
new OO.ui.MenuOptionWidget( {
data: 'Redundant',
label: 'Redundant'
} )
]
}
} )
deletebutton = new OO.ui.ButtonWidget({
label: "Send Edit Request",
classes: ["button"],
flags: ["primary", "progressive"],
}),
deletebackbutton = new OO.ui.ButtonWidget({
label: "Back",
classes: ["button"],
flags: ["primary", "progressive"],
}),
copyrightText = new OO.ui.LabelWidget({
label: $( '<p>By publishing changes, you agree to the <a href="https://foundation.wikimedia.org/wiki/Terms_of_Use/en">Terms of Use</a>, and you irrevocably agree to release your contribution under the <a href="https://en.wikipedia.org/wiki/Wikipedia:Text_of_Creative_Commons_Attribution-ShareAlike_3.0_Unported_License">CC BY-SA 3.0 License</a> and the <a href="https://en.wikipedia.org/wiki/Wikipedia:Text_of_the_GNU_Free_Documentation_License">GFDL</a>. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.</p>' ),
classes: ["copyright"],
}),
deletepanel = new OO.ui.PanelLayout({
content: [
deleteheading,
deleteDropdown,
deletebackbutton,
deletebutton,
copyrightText,
],
padded: true,
});
// Stack layout for all the panels
var stack = new OO.ui.StackLayout({
classes: ["container"],
items: [welcomepanel, linkpanel, selectpanel, select2panel, quotepanel, requotepanel, deletepanel],
});
// All the functional buttons
// All welcome panel(main menu) buttons
welcomebutton1.on('click', addFactPanel);
welcomebutton2.on('click', fixFactualError);
welcomebutton3.on('click', deleteFact);
welcomebutton4.on('click', doSomethingElse);
// All next buttons
select2button.on('click', handleselectNext2);
linkverifybutton.on('click', handlelinkVerify);
linkbutton.on('click', ref);
linkbutton.on('click', getSelectionText);
linkbutton.on('click', handlelinkNext);
quotebutton.on('click', handlequoteNext);
selectbutton.on('click', handleselectNext);
// All publish(send edit request) buttons
requotebutton.on('click', handlePublish);
deletebutton.on('click', handlePublishForDelete);
// All back buttons
quotebackbutton.on('click', handlequoteBack);
requotebackbutton.on('click', handlerequoteBack);
selectbackbutton.on('click', handleselectBack);
select2backbutton.on('click', handleselectBack2);
linkbackbutton.on('click', handlelinkBack);
deletebackbutton.on('click', deleteBack);
// To particularly know which option the user has opted from the main menu
var options = 0;
// To add the first add fact panel(ie link to the source panel)
function addFactPanel(){
options = 1;
stack.setItem( linkpanel );
}
let check = 0; //check = 0 (verify button not clicked); check = 1 (source ok can proceed next); check = 2 (source blacklisted cannot proceed next); check = 3 (not a valid URL cannot proceed next)
// To call the backend API to verify the source URL
async function handlelinkVerify(){
var linkValue = linkinput.getValue();
// var linkURL = linkinput.getValue();
// console.log(linkURL);
// const linkValue = new URL(linkURL.includes('//') ? linkURL : `//${linkURL}`, 'https://foo.bar').origin;
linkstatus.setType("none");
linkstatus.setIcon("null");
linkstatus.setLabel("Loading...");
if (linkValue === "") {
linkstatus.setType("warning");
linkstatus.setLabel("The input cannot be left empty");
}
else{
//Making an API call to the backend to verify the source
const host = window.ERW_DEV_MODE ? 'https://edit-wizard.toolforge.org' : 'http://localhost:3000';
const response = await fetch(`https://edit-wizard.toolforge.org/api/v1/verifySource`, {
method: "POST",
body: JSON.stringify({ linkValue}),
headers: { 'Content-Type': 'application/json'},
})
const { comment, flag, kind } = await response.json()
// flag = 0 (Source probably OK); flag = 1 (blacklisted or unreliable source); flag = 2 (not a valid URL)
if(flag==2){
check = 3;
linkstatus.setType("error");
linkstatus.setLabel("This is not a valid URL");
}
else if (flag==1) {
check = 1;
linkstatus.setType("warning");
linkstatus.setLabel(comment);
if (kind == "blacklisted" || kind == "unreliable") {
check = 2;
linkstatus.setType("error");
linkstatus.setLabel(comment);
}
}
else if (flag==0){
check = 1;
linkstatus.setType("success");
linkstatus.setLabel("Source probably OK");
}
}
}
let linkurl, website; // For saving the source URL and website title
// To handle the URL panel next button and calling the citoid API to add reference for citing the source
async function handlelinkNext(){
var linkValue = linkinput.getValue();
// var linkURL = linkinput.getValue();
// const linkValue = new URL(linkURL.includes('//') ? linkURL : `//${linkURL}`, 'https://foo.bar').origin;
const query= encodeURIComponent(linkValue);
//API call to make a request from Citoid
if (linkValue!= "") {
fetch(`https://en.wikipedia.org/api/rest_v1/data/citation/mediawiki/${query}`, {
headers: {
'Content-Type': 'application/json',
'Api-User-Agent': 'w:en:User:Ankit18gupta/MyScript.js'
}
})
.then(response => response.json())
.then(citationArray => {
linkurl = citationArray[0].url;
website = citationArray[0].title;
})
.catch((error) => {
console.log("Error: ",error);
});
}
// If the linkValue is empty, prompt a warning
if (linkValue === "") {
linkstatus.setType("warning");
linkstatus.setLabel("The input cannot be left empty");
}
else if(check == 0){
linkstatus.setType("warning");
linkstatus.setLabel("Please verify the source first");
}
else if(check == 2){
linkstatus.setType("error");
linkstatus.setLabel("This is a unreliable source, we cannot proceed");
}
else if(check == 3){
linkstatus.setType("error");
linkstatus.setLabel("This is not a valid URL, we cannot proceed");
}
else if(check == 1){
if(options == 2){
stack.setItem( quotepanel );
}
else{
stack.setItem( selectpanel );
}
}
check=0;
}
// To include formatted reference in edit request(from citoid)
var reference=''; //To save the reference result
function ref(){
const linkValue = linkinput.getValue();
const query= encodeURIComponent(linkValue);
//API call to make a request from Citoid
fetch(`https://en.wikipedia.org/api/rest_v1/data/citation/mediawiki/${query}`, {
headers: {
'Content-Type': 'application/json',
'Api-User-Agent': 'w:en:User:Ankit18gupta/MyScript.js'
}
})
.then(response => response.json())
.then(citationArray => {
fetch('https://en.wikipedia.org/w/api.php?action=templatedata&titles=Template:Cite%20web&format=json', {
headers: {
'Content-Type': 'application/json',
'Api-User-Agent': 'w:en:User:Ankit18gupta/MyScript.js'
}
})
.then(response => response.json())
.then(translateArray => {
const finalArray = Object
.fromEntries(
Object
.entries(citationArray[0])
.filter(([key, value]) => (key in translateArray.pages['1252907'].maps.citoid))
.map(([key, value]) => [translateArray.pages['1252907'].maps.citoid[key], value])
);
for (const key in finalArray) {
reference = `${reference}|${key}=${finalArray[key]} `;
}
reference = `<ref>{{Cite web ${reference}}}</ref>`;
})
.catch((error) => {
console.log("Error: ",error);
});
})
.catch((error) => {
console.log("Error: ",error);
});
}
// To get the Selected Paragraph Text
var text = "", sel;
function getSelectionText() {
document.getElementById("mw-content-text").addEventListener("click",function(e) {
// e.target was the clicked element
sel = e.target;
if (e.target && e.target.nodeName == "P") {
text = e.target.innerText;
}
});
return text;
}
// Funtion to get the target Section
function getSelectionSection(){
var e = sel;
var found_it = false;
while (e.tagName.toLowerCase() !== 'body') {
if (e.tagName.toLowerCase() === 'h2') {
found_it = true;
break;
}
if (e.previousElementSibling) {
e = e.previousElementSibling;
} else {
e = e.parentNode;
}
}
return e.firstChild.textContent;
}
let selectValue, selectionSection; // To save the selected paragraph and the selected paragraphs's section from the article
// To handle the Next button of Select paragraph panel
function handleselectNext(){
selectValue = text;
// If the selectValue is empty, prompt a warning
if (selectValue === "") {
selectstatus.setType("warning");
selectstatus.setLabel("Please click on the paragraph before continuing");
}
else{
selectionSection = getSelectionSection();
stack.setItem( quotepanel );
}
}
// To handle the Next button of quote panel and calling the API from backend to verify if the quote text comes from the source
async function handlequoteNext(){
const quoteValue = quoteinput.getValue();
const linkValue = linkinput.getValue();
// quotestatus.setType("none");
// quotestatus.setIcon("null");
// quotestatus.setLabel("Loading...");
// //Calling the API to the backend to verify if the quote comes from the source
// const host = window.ERW_DEV_MODE ? 'https://edit-wizard.toolforge.org' : 'http://localhost:3000';
// const response = await fetch(`https://edit-wizard.toolforge.org/api/v1/verifyQuote`, {
// method: "POST",
// body: JSON.stringify({ linkValue, quoteValue }),
// headers: { 'Content-Type': 'application/json' },
// })
// const { isParagraphTextOnPage } = await response.json()
if (quoteValue === "") {
quotestatus.setType("warning");
quotestatus.setLabel("The input cannot be left empty");
}
// else if(!isParagraphTextOnPage) {
// quotestatus.setType("error");
// quotestatus.setLabel("The quote does not match. Please make sure the quote is copied/pasted exactly from the source");
// }
// else if (isParagraphTextOnPage) {
// quotestatus.setType("success");
// quotestatus.setLabel("Verified!");
// stack.setItem( requotepanel );
// if(options == 2){
// requoteinput.setValue(selectValue2);
// requoteheading.setLabel("Enter the fixed fact");
// }
else{
quotestatus.setType("success");
quotestatus.setLabel("Verified!");
stack.setItem( requotepanel );
if(options == 2){
requoteinput.setValue(selectValue2);
requoteheading.setLabel("Enter the fixed fact");
}
}
}
// To add the fix factual error panel(ie select text panel)
function fixFactualError(){
options = 2;
select2fieldsetcontent.setLabel("Select the text where you want to fix the fact and click Next");
stack.setItem( select2panel );
}
// Function to get the Selected text for fix factual error
function getSelectionText2() {
var text = "";
if (window.getSelection) {
text = window.getSelection().toString();
} else if (document.selection && document.selection.type !== "Control") {
text = document.selection.createRange().text;
}
return text;
}
// Funtion to get the target Section for fix factual error
function getSelectionSection2(){
var e = window.getSelection().anchorNode.parentElement;
var found_it = false;
while (e.tagName.toLowerCase() !== 'body') {
if (e.tagName.toLowerCase() === 'h2') {
found_it = true;
break;
}
if (e.previousElementSibling) {
e = e.previousElementSibling;
} else {
e = e.parentNode;
}
}
return e.firstChild.textContent;
}
var selectValue2, selectionSection2; // to save the selected text and selected text's section from the artice
// To handle the Next button of Select text panel
function handleselectNext2(){
selectValue2 = getSelectionText2();
// If the selectValue is empty, prompt a warning
if (selectValue2 === "") {
select2status.setType("warning");
select2status.setLabel("Please select the text before continuing");
}
else if(options == 3){
stack.setItem( deletepanel );
}
else{
selectionSection2 = getSelectionSection2();
stack.setItem( linkpanel );
// selected = 0;
$("#edit-wizard-link span").html("Edit Wizard");
}
}
// To add the first delete fact panel(ie select text panel)
function deleteFact(){
options = 3;
select2fieldsetcontent.setLabel("Select the text you want to delete and click Next");
stack.setItem( select2panel );
}
// Redirect to the visual editor
function doSomethingElse(){
const editURL = mw.util.getUrl(null,{action: 'edit'});
window.location.href = editURL;
}
// To handle the back button of delete panel
function deleteBack(){
stack.setItem( select2panel );
}
// To handle the back button of URL to source panel
function handlelinkBack(){
if(options == 1){
stack.setItem( welcomepanel );
}
if(options == 2){
stack.setItem( select2panel );
}
}
// To handle the back button of select paragraph panel
function handleselectBack(){
stack.setItem( linkpanel );
}
// To handle the back button of select text panel
function handleselectBack2(){
stack.setItem( welcomepanel );
}
// To handle the back button of quote panel
function handlequoteBack(){
if(options == 1)
stack.setItem( selectpanel );
if(options == 2)
stack.setItem( linkpanel );
}
// To handle the back button of requote panel
function handlerequoteBack(){
stack.setItem( quotepanel );
}
// Helper function for handlePublish function to call the mw API to access and send the edit request to the talk page of current article
function editPage( info ) {
var api = new mw.Api();
api.postWithToken("csrf", {
action: 'edit',
title: info.title,
appendtext: info.text,
summary: info.summary
} ).then(function( data ) {
OO.ui.alert( 'Edit Request sent to talk page..!' );
} ).catch( function(code, data) {
console.log( api.getErrorMessage( data ).text());
} );
}
// To handle the send edit request button to send the edit request to the talk page
function handlePublish(){
const refer = reference;
const linkValue = linkinput.getValue();
const quoteValue = quoteinput.getValue();
const requoteValue = requoteinput.getValue();
const firstthree = quoteValue.split(' ').slice(0,3).join(' ');
const array = quoteValue.split(' ');
const len = array.length - 3;
const lastthree = quoteValue.split(' ').slice(len).join(' ');
if (requoteValue === "") {
requotestatus.$element.show();
requotestatus.setType("warning");
requotestatus.setLabel("The input cannot be left empty");
}
else{
requotestatus.$element.hide();
// API calls code goes here
editPage({
title: (new mw.Title(mw.config.get("wgPageName"))).getTalkPage().toText(),
text: '\n== Edit Request made by {{subst:REVISIONUSER}} ~~~~~ == \n' + '<br><b>Citation:</b> ' + `[${linkValue} ${website}]` + '<br><b>Section to Edit:</b> ' + selectionSection + '<br><b>Spot where to add the fact:</b> ' + selectValue + '<br><b>Quote:</b> ' + 'Quote starts here - ' + firstthree + '...' + lastthree + '<br><b>Rephrased Quote:</b> ' + "<syntaxhighlight lang='html'>" +requoteValue + refer + "</syntaxhighlight>" + '<br><b>Rendered:</b> '+ requoteValue + refer +'<br> ~~~~',
summary: 'Edit Request to add a fact'
});
if(options == 2){
editPage({
title: (new mw.Title(mw.config.get("wgPageName"))).getTalkPage().toText(),
text: '\n== Edit Request made by {{subst:REVISIONUSER}} ~~~~~ == \n' + '<br><b>Citation:</b> ' + `[${linkValue} ${website}]` + '<br><b>Section to Fix:</b> ' + selectionSection2 + '<br><b>Spot where the fact is to be fixed:</b> ' + selectValue2 + '<br><b>Quote:</b> ' + 'Quote starts here - ' + firstthree + '...' + lastthree + '<br><b>Fixed Fact:</b> ' + "<syntaxhighlight lang='html'>" +requoteValue + refer + "</syntaxhighlight>" + '<br><b>Rendered:</b> '+ requoteValue + refer +'<br> ~~~~',
summary: 'Edit Request to fix the error'
});
}
}
}
// To handle the send edit request button to send the edit request to the talk page particularly for delete option
function handlePublishForDelete(){
const deleteReason = deleteDropdown.getMenu().findSelectedItem().getData();
editPage({
title: (new mw.Title(mw.config.get("wgPageName"))).getTalkPage().toText(),
text: '\n== Edit Request made by {{subst:REVISIONUSER}} ~~~~~ == \n' + '<br><b>Section where to Delete:</b> ' + selectionSection2 + '<br><b>Text to be deleted:</b> ' + selectValue2 + '<br><b>Reason to delete:</b> ' + deleteReason + '<br> ~~~~',
summary: 'Edit Request to delete the text'
});
}
// To add the edit wizard tab on the top navigation bar
var node = mw.util.addPortletLink(
'p-views',
"#",
'Edit Wizard',
'edit-wizard-link',
'Edit Wizard',
"",
"#ca-history",
);
// A popup widget is instantiated
var popUp = new OO.ui.PopupWidget({
align: "forwards",
$floatableContainer: $(node),
$content: stack.$element,
padded: true,
popup: false,
width: 440,
height: 250,
head: true,
// hideWhenOutOfView: false,
// autoClose: false,
hideCloseButton: false,
});
$(node).on('click', function(e){
popUp.toggle();
e.preventDefault();
})
$(document.body).append(popUp.$element);
});
});
// </nowiki>