Jump to content
 







Main menu
   


Navigation  



Main page
Contents
Current events
Random article
About Wikipedia
Contact us
Donate
 




Contribute  



Help
Learn to edit
Community portal
Recent changes
Upload file
 








Search  

































Create account

Log in
 









Create account
 Log in
 




Pages for logged out editors learn more  



Contributions
Talk
 

















User:Terasail/COI Request Tool.js: Difference between revisions

















User page
Talk
 

















Read
View source
View history
 








Tools
   


Actions  



Read
View source
View history
 




General  



What links here
Related changes
User contributions
User logs
View user groups
Upload file
Special pages
Permanent link
Page information
Get shortened URL
Download QR code
 




Print/export  



Download as PDF
Printable version
 
















Appearance
   

 





Help
 

From Wikipedia, the free encyclopedia
 

< User:Terasail

Browse history interactively
 Previous edit
Content deleted Content added
m Fixes
Fix for legacy vector
 
(10 intermediate revisions by the same user not shown)
Line 1: Line 1:

//<nowiki>

/*<nowiki>

COI Request Tool

var replyCOIT = {

Created by: Terasail

"Close": ["", "Close", "Closed edit request", "|A"],

*/

"Remove": ["", "Remove", "Removed edit request", ""],

var nonResponseCOI = [

"Comment (No template)": ["", "speechBubbleAdd", "Comment", ""],

{label: "Close", title: "Close request", summary: "Closed edit request", parameter: "answered=yes", response: "", icon: "unFlag", flags: "", text: ""},

"Done:": ["d", "checkAll", "Done", "|A"],

{label: "Open", title: "Reopen request", summary: "Reopened edit request", parameter: "answered=no", response: "", icon: "flag", flags: "", text: ""},

"Partly done:": ["pd", "check", "Partly done", "|P"],

{label: "Remove", title: "Remove entire section", summary: "Removed COI request", parameter: "", response: "", icon: "trash", flags: ["primary", "destructive"], text: ""}

"Already Done:": ["a", "clock", "Already Done", "|A"],

];

"Note:": ["note", "ellipsis", "Note", ""],

var responseCOI = [

"Question:": ["q", "helpNotice", "Question", ""],

{label: "Done", title: "Mark request as done", summary: "Marked COI request as done", parameter: "answered=yes", response: "d", icon: "checkAll", flags: ["primary", "progressive"], text: "Done"},

"Go ahead: I have reviewed these proposed changes and suggest that you go ahead and make the proposed changes to the page.": ["g", "edit", "Go ahead", "|G"],

{label: "Partly done", title: "Mark request as partly done", summary: "Marked COI request as partly done", parameter: "P", response: "pd", icon: "check", flags: "", text: "Partly done:"},

"Not done:": ["n", "notice", "Not done", "|D"],

{label: "Already done", title: "Mark request as already done", summary: "Marked COI request as already done", parameter: "answered=yes", response: "a", icon: "clock", flags: "", text: "Already done:"},

"Not done for now:": ["nfn", "notice", "Not done for now", "|D"],

{label: "Note", title: "Add a note", summary: "Added a note", parameter: "", response: "note", icon: "ellipsis", flags: "", text: "Note:"},

"Not done for now: Please establish a consensus with editors engaged in the subject area before using the {{Request edit}} template for this proposed change.": ["c", "userGroup", "Not done – Needs consensus", "|D|C"],

{label: "Question", title: "Add a question", summary: "Added a question", parameter: "", response: "q", icon: "helpNotice", flags: "", text: "Question:"},

"Not done for now: it's not clear what changes you want to be made. Please mention the specific changes in a 'change X to Y' format.": ["xy", "helpNotice", "Not done – Unclear request", "|D|Unclear request"],

{label: "Go ahead", title: "Go ahead", summary: "User may go ahead and edit themselves", parameter: "G", response: "g", icon: "edit", flags: "", text: "Go ahead: I have reviewed these proposed changes and suggest that you go ahead and make the proposed changes to the page."},

"Undone: This request has been partially undone.": ["udp","undo", "Partly undone", "|D|The requested edit has been partially undone"],

{label: "Not done", title: "Decline request", summary: "Declined COI request", parameter: "D", response: "n", icon: "notice", flags: "", text: "Not done:"},

"Undone: This request has been undone.": ["ud", "undo", "Undone", "|D|The requested edit has been undone"]

{label: "Not done for now", title: "Decline request for now", summary: "Declined request for now", parameter: "D", response: "nfn", icon: "notice", flags: "", text: "Not done for now:"},

};

{label: "Promotional", title: "Decline promotional request", summary: "Declined promotional request", parameter: "D|ADV", response: "mpro", icon: "signature", flags: "", text: "Not done: A majority of the requested changes are currently written in a promotional tone. Please review WP:Neutral point of view and ensure you follow this before submitting any edit requests."},

var COIResponse = [];

{label: "No consensus", title: "No consensus for the change", summary: "Declined request with no consensus for the change", parameter: "D|C", response: "nc", icon: "userGroup", flags: "", text: "Not done: No consensus could be obtained for making the requested change."},

//selectedReply

{label: "Needs reliable sources", title: "Close request pending reliable sources", summary: "COI request declined: Change requires reliable sources", parameter: "D|V", response: "rs", icon: "quotes", flags: "", text: "Not done: please provide reliable sources that support the change you want to be made."},

function executeCOI(currentBox, replyOption, inputText, answered) {

{label: "Removing content", title: "Decline request removing well-cited content", summary: "Declined request removing well-cited content", parameter: "D|R", response: "rm", icon: "restore", flags: "", text: "Not done: The proposed changes are removing content that is well-cited or where sources exist."},

OO.ui.confirm("Confirm in order to reply to this edit request.").done(function(confirmed) {

{label: "Partly promotional", title: "Decline partly promotional request for now", summary: "Declined partly promotional request for now", parameter: "D|ADV", response: "pro", icon: "signature", flags: "", text: "Not done for now: Some of the requested changes are currently written in a promotional tone. Please review WP:Neutral point of view and make changes where appropriate to follow this before reopening the request."},

if (confirmed) {

{label: "Needs consensus", title: "Close request pending consensus", summary: "COI request declined: Change requires consensus first", parameter: "D|D", response: "c", icon: "userGroup", flags: "", text: "Please establish a consensus with editors engaged in the subject area before using the {{Edit COI}} template for this proposed change."},

currentBox.getElementsByTagName('tr')[2].remove();

{label: "Unclear request", title: "Decline and mark as unclear", summary: "COI request closed as it is unclear what change is requested", parameter: "D|Unclear request", response: "xy", icon: "helpNotice", flags: "", text: "it's not clear what changes you want to be made. Please mention the specific changes in a \"change X to Y\" format."},

currentBox.children[0].children[0].children[1].remove();

{label: "Unspecific", title: "Decline unspecific request", summary: "Declined unspecific request", parameter: "D|S", response: "s", icon: "speechBubbles", flags: "", text: "Not done for now: The current request is not specific enough to make changes to the page. Consider developing changes in a new talk section or visit the conflict of interest noticeboard for serious issues."},

currentBox.children[0].children[0].children[1].remove();

{label: "Balance issues", title: "Decline request with balance issues", summary: "Declined request with balance issues", parameter: "D|O", response: "b", icon: "notice", flags: "", text: "Not done for now: The proposed changes create some balance issues with the article. These will need to be addressed before any changes can be made."},

var infoBox = new OO.ui.MessageWidget( {

{label: "Partly undo", title: "Partly undo request", summary: "COI request has been partly undone", parameter: "P|The requested edit has been partially undone", response: "udp", icon: "undo", flags: "", text: "Undone: This request has been partially undone."},

icon: 'pageSettings',

{label: "Undo", title: "Undo request", summary: "COI request has been undone", parameter: "D|The requested edit has been undone", response: "ud", icon: "undo", flags: "", text: "Undone: This request has been undone."}

type: 'notice',

];

label: 'Processing request — Edit request starting, getting section data to edit.'

var editRequests = $('.editrequest');

});

var COIRequests = [];

var firstRowC = currentBox.children[1].children[0];

for (let i = 0; i < editRequests.length; i++) {

firstRowC.style = "padding-bottom:10px";

if (typeof(editRequests[i].attributes['data-origlevel']) == 'undefined') {

firstRowC.innerHTML = "";

$(editRequests[i].children[0]).append('<tr><td colspan="2" class="response-cell" style="text-align:center;"></td></tr>');

progressBar = new OO.ui.ProgressBarWidget( {

COIRequests.push(editRequests[i]);

progress: false

}

});

}

$(firstRowC).append(progressBar.$element);


$(firstRowC).append(infoBox.$element);

if (COIRequests.length > 0) {

progressBar.$element[0].style = "margin:auto";

mw.loader.using(["oojs-ui-core", "oojs-ui-widgets", "oojs-ui-windows"]).done(function() {

infoBox.$element[0].style = "margin:10px auto 0px; max-width:50em; text-align:left";

mw.loader.load(["oojs-ui.styles.icons-alerts", "oojs-ui.styles.icons-interactions", "oojs-ui.styles.icons-moderation", "oojs-ui.styles.icons-editing-core", "oojs-ui.styles.icons-editing-advanced", "oojs-ui.styles.icons-user"]);

var header = "";

loadCOITool();

var curElement = currentBox.parentNode; //Table tag

do {

curElement = curElement.previousElementSibling;

if (curElement.getElementsByClassName("mw-headline").length == 1) {

header = curElement.getElementsByClassName("mw-headline")[0].id;

}

}

while (header == "");

var conVal = mw.config.values;

var api = new mw.Api();

api.get( {

action: "parse",

page: conVal.wgPageName,

prop: "sections|wikitext"

}).done(function(data) {

infoBox.setLabel("Processing request — Making changes to the edit request");

var sections = data.parse.sections;

var wikitext = data.parse.wikitext["*"];

var sectionIndx = -1;

var sectionNum = -1;

var endSection = -1;

for (var j = 0; j < sections.length; j++) {

var tempSec = sections[j];

if (tempSec.anchor == header && !isNaN(Number(tempSec.index))) {

sectionNum = tempSec.number;

sectionIndx = tempSec.index;

endSection = sectionIndx;

} else if (tempSec.number.indexOf(sectionNum) == 0) {

endSection = tempSec.index;

}

}

var offset = sections[sectionIndx - 1].byteoffset;

if (endSection < sections.length) {

wikitext = wikitext.slice(offset, sections[endSection].byteoffset);

} else {

wikitext = wikitext.slice(offset, wikitext.length);

}

var templateR = replyOption[3];

var tempType = "{{request edit";

var wikitextU = wikitext.toUpperCase();

var templateS = wikitextU.indexOf("{{REQ");

if (templateS == -1) {

templateS = wikitextU.indexOf("{{EDIT");

}

if (templateS == -1) {

templateS = wikitextU.indexOf("{{COI");

}

if (templateS == -1) {

infoBox.setLabel('Failed to find {{Request edit}} template, please report to "User talk:Terasail/COI Request Tool"');

infoBox.setType("error");

} else {

var templateE = wikitextU.indexOf("}}", templateS) + 2;

if (answered == false) {

templateR = "";

}

if (templateR != "" || answered == false) {

wikitext = wikitext.slice(0, templateS) + "{{Request edit" + templateR + "}}" + wikitext.slice(templateE);

}

var editSummary = "/* " + header.replaceAll("_", " ") + " */ " + replyOption[2] + " ([[User:Terasail/COI_Request_Tool|COI Request Tool]])";

if (replyOption[1] != "Close") {

var lastMsg = wikitext.lastIndexOf("\n", wikitext.lastIndexOf("(UTC)")) + 1;

wikitext = wikitext.trim() + "\n:";

while(lastMsg == wikitext.indexOf(":", lastMsg)) {

lastMsg++;

wikitext += ":";

}

if (replyOption[0] != "") {

wikitext += "{{subst:ECOI|" + replyOption[0] + "}}";

}

inputText = inputText.replaceAll("~~~~", "");

wikitext += " " + inputText;

wikitext = wikitext.trim() + " ~~~~";

if (replyOption[1] == "Remove") {

wikitext = "";

}

}

if (infoBox.type != "error") {

infoBox.setType("success");

infoBox.setLabel("Saving '" + replyOption[2] + "' response to the talk page. (This may take a few seconds)");

api.postWithEditToken({

action: 'edit',

title: conVal.wgPageName,

text: wikitext,

section: sectionIndx,

summary: editSummary

}).done(function(result) {

window.location = "https" + "://en.wikipedia.org/w/index.php?title=" + mw.config.values.wgPageName.replaceAll("&", "%26") + "&type=revision&diff=cur&oldid=prev";

});

}

}

});

}

});

});

}

}



function loadButtons(currentBox) {

async function loadCOITool() {

// Get page watchers, visitors and user watch status.

var replyListC = Object.entries(replyCOIT);

let watchStatus = [];

var mainResponseC = [[replyListC[8][1], "Go ahead", "User may make the change themselves"], [replyListC[12][1], "Unclear: X-Y", "Unclear request"], [replyListC[11][1], "WP:Consensus", "Change needs consensus"]];

let watchQuery = await ApiGetCOI({

$(currentBox).append('<tr><td colspan=2><div style="display: flex; justify-content: center;"></div></td></tr><tr style="display:none"><td colspan=2 style="padding-bottom:10px; text-align:center"></td></tr>');

action: "query",

var firstRowC = currentBox.children[1].children[0].children[0];

prop: "info",

//Create dropdown menu

pageids: mw.config.get("wgArticleId"),

var dropMenu = new OO.ui.DropdownWidget( {

inprop: "watchers|visitingwatchers|watched",

label: "Select reply option - Add additional text below",

format: "json"

menu: {items: []}

});

});

let watchData = watchQuery.query.pages[mw.config.get("wgArticleId")];

for (var count = 2; count < replyListC.length; count++) {

let watched = watchData.watched;

var newOption = new OO.ui.MenuOptionWidget({

let expiry = watchData.watchlistexpiry;

label: replyListC[count][0],

if (expiry) {

icon: replyListC[count][1][1]

watched = Math.ceil((new Date(expiry).getTime() - Date.now()) / 1000 / 60 / 60 / 24) + " days";

}

watchStatus.push(watchData.watchers || "less than 30", watchData.visitingwatchers || "<30", watched);

//Increment through all COI requests & add respond button

for (let i = 0; i < COIRequests.length; i++) {

let respondButton = new OO.ui.ButtonWidget({

icon: "edit",

label: "Respond",

flags: "progressive",

title: "Open the response menu for this request"

}).on("click", function() {

loadCOIResponse(COIRequests[i], respondButton, watchStatus);

respondButton.setDisabled(true);

});

});

respondButton.$element[0].style = "margin:5px";

dropMenu.menu.addItems([newOption]);

$($('.response-cell')[i]).append(respondButton.$element);

}

}

}

dropMenu.$element[0].style = "text-align:left; margin:0px";


$(currentBox.children[2].children[0]).append(dropMenu.$element);

function loadCOIResponse(COIRequest, respondButton, watchStatus) {

//Create input box

let responseBoxHTML = '<table class="response-box" style="border:1px solid #A2A9B1; border-radius:2px; padding:10px 16px 0; margin:auto; max-width:55em; width:100%; clear:both;"><tr><td style="color:#808080"><div style="font-style:italic; margin-left:1em;">There are currently ' + watchStatus[0] + ' users watching this page (' + watchStatus[1] + ' have viewed recent edits).</div><div>Quick options:</div></td></tr><tr style="display: flex; justify-content: center;"><td class="response-quick"></td></tr><tr><td style="color:#808080">Custom response:</td></tr><tr style="text-align:center;"><td class="response-custom"></td></tr><tr style="background:#F6F6F6;"><td class="response-preview" style="display:none;"><div style="color:#808080">Preview:</div><div></div></td></tr><tr style="display: flex; justify-content: right;"><td class="response-controls"></td></tr></table>';

var inputText = new OO.ui.MultilineTextInputWidget({autosize: true, label: "Automatically signed"});

$(responseBoxHTML).insertAfter(COIRequest, respondButton);

inputText.$element[0].style = "margin:auto";

let responseBox = COIRequest.nextElementSibling;

$(currentBox.children[2].children[0]).append(inputText.$element);

let responseQuick = $(responseBox).find('.response-quick')[0];

//Create horizontal layout

let responseCustom = $(responseBox).find('.response-custom')[0];

var hzCLayout = new OO.ui.HorizontalLayout();

let responsePreview = $(responseBox).find('.response-preview')[0];

//Toggle answer button

let responseControls = $(responseBox).find('.response-controls')[0];

var answerCB = new OO.ui.CheckboxInputWidget({selected: true});

//Done button

//Quick Responses

//Create a HorizontalLayout & Fieldset for quick responses

var doneCB = new OO.ui.ButtonWidget( {

let quickLayout = new OO.ui.HorizontalLayout();

icon: "checkAll",

let quickFieldset = new OO.ui.FieldsetLayout();

flags: ["primary", "progressive"],

quickFieldset.addItems([new OO.ui.FieldLayout(new OO.ui.Widget({content: [quickLayout]}), {align: 'top'})]);

label: "Done",

$(responseQuick).append(quickFieldset.$element);

title: "Mark as done"

let quickNonResponses = [2];//Remove button

});

if ($(COIRequest).find('hr').length > 0) {//If request is closed

doneCB.on("click", function() {

quickNonResponses.push(0);//Close button

if (doneCB.getLabel() == "Submit") {

} else {

executeCOI(currentBox, replyCOIT[dropMenu.getLabel()], inputText.value, answerCB.selected);

quickNonResponses.push(1);//Open button

} else {

}

executeCOI(currentBox, replyListC[3][1], inputText.value, answerCB.selected);

for (let i = 0; i < quickNonResponses.length; i++) {

}

let tempVal = quickNonResponses[i];

});

let tempButton = new OO.ui.ButtonWidget({

hzCLayout.addItems([doneCB]);

flags: nonResponseCOI[tempVal].flags,

//Quick access buttons

icon: nonResponseCOI[tempVal].icon,

mainResponseC.forEach(function(item) {

title: nonResponseCOI[tempVal].title,

item[3] = new OO.ui.ButtonWidget({

invisibleLabel: true

label: item[1],

}).on("click", function () {

title: item[2]

saveResponseCOI([COIRequest, responseQuick, responsePreview, responseControls], nonResponseCOI[tempVal], "", "nochange", undefined);

});

});

quickLayout.addItems([tempButton]);

item[3].on("click", function() {

}

executeCOI(currentBox, item[0], "", answerCB.selected);

let quickResponses = [0, 5, 8, 10];//Done, Go ahead, Consensus, Unclear

for (let i = 0; i < quickResponses.length; i++) {

let tempVal = quickResponses[i];

let tempButton = new OO.ui.ButtonWidget({

flags: responseCOI[tempVal].flags,

label: responseCOI[tempVal].label,

title: responseCOI[tempVal].title

}).on("click", function () {

saveResponseCOI([COIRequest, responseQuick, responsePreview, responseControls], responseCOI[tempVal], "", "nochange", undefined);

});

});

hzCLayout.addItems([item[3]]);

quickLayout.addItems([tempButton]);

});

}

//Custom Responses

//Responses button

//Response dropdown

var respondCB = new OO.ui.ButtonWidget( {

let responseDropdown = new OO.ui.DropdownWidget({

icon: "add",

label: "More",

label: "Select reply option - Add additional text below",

menu: {items: []}

title: "Extra reply options"

}).on("labelChange", function () {

submitButton.setDisabled(false);

previewCOI(responseDropdown.menu.findSelectedItem().getData(), responseText.value, responsePreview);

});

});

for (let i = 0; i < responseCOI.length; i++) {

hzCLayout.addItems([respondCB]);

let tempWidget = new OO.ui.MenuOptionWidget({

respondCB.on("click", function() {

label: responseCOI[i].text,

if (currentBox.children[2].style.display == "") {

icon: responseCOI[i].icon,

respondCB.setIcon("add");

data: responseCOI[i]

respondCB.setLabel("More");

});

currentBox.children[2].style = "display:none";

responseDropdown.menu.addItems([tempWidget]);

doneCB.setLabel("Done");

}

doneCB.setTitle("Mark as done");

responseDropdown.$element[0].style = "margin:auto; text-align:left;";

} else {

$(responseCustom).append(responseDropdown.$element);

respondCB.setIcon("subtract");

//Response text

respondCB.setLabel("Less");

var responseText = new OO.ui.MultilineTextInputWidget({

currentBox.children[2].style = "";

autosize: true, rows: 4, label: "Additional text"

doneCB.setLabel("Submit");

}).on("change", function () {

doneCB.setTitle("Submit response");

if (responseDropdown.menu.findSelectedItem()) {

previewCOI(responseDropdown.menu.findSelectedItem().getData(), responseText.value, responsePreview);

}

}

});

});

responseText.$element[0].style = "margin:5px auto;";

hzCLayout.addItems([answerCB, new OO.ui.LabelWidget({label: "Close"})]);

$(responseCustom).append(responseText.$element);

//Create first row fieldset

//Response Controls

var fieldsetC = new OO.ui.FieldsetLayout();

//Create a HorizontalLayout & Fieldset for response controls

// Add an horizontal field layout

let controlsLayout = new OO.ui.HorizontalLayout();

fieldsetC.addItems([

new OO.ui.FieldLayout(

let controlsFieldset = new OO.ui.FieldsetLayout();

controlsFieldset.addItems([new OO.ui.FieldLayout(new OO.ui.Widget({content: [controlsLayout]}), {align: 'top'})]);

new OO.ui.Widget({

$(responseControls).append(controlsFieldset.$element);

content: [hzCLayout]

//Cancel Button

}),

let cancelButton = new OO.ui.ButtonWidget({

)

icon: "cancel",

]);

flags: "destructive",

$(firstRowC).append(fieldsetC.$element);

label: "Cancel",

//Close request

framed: false,

var closeB = new OO.ui.ButtonWidget( {

title: "Cancel the response & close this menu"

icon: "unFlag",

}).on("click", function () {

invisibleLabel: true,

respondButton.setDisabled(false);

title: "Mark as answered"

responseBox.remove();

});

});

controlsLayout.addItems([cancelButton]);

closeB.$element[0].style = "margin:10px 10px 0px";

//Watchlist dropdown

$(currentBox.children[0].children[0]).append(closeB.$element);

let watchOptions = [{data: "infinite", label: "Permanent"}, {data: "1 day", label: "1 day"}, {data: "3 days", label: "3 days"}, {data: "1 week", label: "1 week"}, {data: "1 month", label: "1 month"}];

closeB.on("click", function() {

let watchValue = "infinite";

executeCOI(currentBox, replyCOIT.Close, "", true)

if (!!watchStatus[2]) {

watchOptions.unshift({data: "nochange", label: watchStatus[2]});

watchValue = "nochange";

}

let watchlistLayout = new OO.ui.HorizontalLayout();

let watchlistDropdown = new OO.ui.DropdownInputWidget({

value: watchValue,

options: watchOptions,

disabled: (watchStatus[2] == undefined)

});

});

watchlistLayout.addItems([watchlistDropdown]);

//Remove request

//Watchlist checkbox & label

var removeB = new OO.ui.ButtonWidget( {

let watchlistCheckbox = new OO.ui.CheckboxInputWidget({

icon: "trash",

selected: (watchStatus[2] != undefined)

flags: ["primary", "destructive"],

}).on("change", function (newStatus) {

invisibleLabel: true,

watchlistDropdown.setDisabled(!newStatus);

title: "Remove entire section!"

});

});

let watchlistLabel = new OO.ui.LabelWidget({label: "Watch this page"}).on("change", function (newStatus) {

removeB.$element[0].style = "margin:10px";

removeB.on("click", function() {

executeCOI(currentBox, replyCOIT.Remove, "", false);

});

$(currentBox.children[0].children[0]).append(removeB.$element);

}



function addReplyButton(currentBox, boxType) {

var replyB = new OO.ui.ButtonWidget( {

icon: "edit",

flags: "progressive",

invisibleLabel: true

});

});

//Submit Button

replyB.$element[0].style = "margin:5px 0px";

let submitButton = new OO.ui.ButtonWidget({

$(currentBox.children[0].children[0]).append(replyB.$element);

icon: "checkAll",

replyB.on("click", function() {

flags: ["primary", "progressive"],

currentBox.parentElement.setAttribute("class", "plainlinks tmbox tmbox-notice editrequest");

label: "Submit",

var img = currentBox.children[0].children[0].children[0]

title: "Submit the response",

img.width = 53;

disabled: true

img.height = 53;

}).on("click", function () {

img.src = "//upload.wikimedia.org/wikipedia/commons/f/f4/Info_talk.png"

saveResponseCOI([COIRequest, responseQuick, responsePreview, responseControls], responseDropdown.menu.findSelectedItem().getData(), responseText.value, watchlistCheckbox.selected, watchlistDropdown.value);

img.scrset = "";

currentBox.children[0].children[1].innerHTML = '<div style="text-align:center; font-size:125%">Please read the instructions for the parameters used by this template for accepting and declining them, and review the request below and make the edit if it is well sourced, neutral, and follows other Wikipedia guidelines and policies.</div>'

replyB.$element.remove();

loadButtons(currentBox);

});

});

controlsLayout.addItems([cancelButton, watchlistCheckbox, watchlistLabel, watchlistLayout, submitButton]);

}

}



function previewCOI(responseOption, responseText, tableCell) {

var COIRequestBoxes = document.getElementsByClassName("plainlinks tmbox tmbox-notice editrequest");

let restTransform = "https://en.wikipedia.org/api/rest_v1/transform/wikitext/to/html/" + encodeURI(mw.config.get("wgPageName"));

if (COIRequestBoxes) {

if (responseOption.response != "") {

mw.loader.using(["oojs-ui-core", "oojs-ui-widgets", "oojs-ui-windows"]).done(function() {

responseText = "{{ECOI|" + responseOption.response + "}} " + responseText;

mw.loader.load(["oojs-ui.styles.icons-alerts", "oojs-ui.styles.icons-interactions", "oojs-ui.styles.icons-moderation", "oojs-ui.styles.icons-user", "oojs-ui.styles.icons-editing-core"]);

}

for (var i = 0; i < COIRequestBoxes.length; i++) {

if (responseText != "") {

var currentBox = COIRequestBoxes[i].children[0];

let nickname = " " + mw.user.options.values.nickname;

var edReqCheck = currentBox.children[0].children[1];

if (nickname == " ") {//Create default signature if no nickname

if (edReqCheck.innerText.search("conflict") != -1) { //Check that it is a conflict edit request

nickname = mw.user.getName();

if (edReqCheck.innerText.search("The requested edits backlog is") != -1) { //For unanswered boxes

nickname = " [[User:" + nickname + "|" + nickname + "]] ([[User talk:" + nickname + "|talk]])";

loadButtons(currentBox);

}

} else { //For answered boxes

let dateObj = new Date();

addReplyButton(currentBox);

let dateNow = dateObj.toLocaleDateString('en-GB', {

timeZone: 'UTC',

year: 'numeric',

month: 'long',

day: 'numeric'

});

let timeNow = dateObj.toLocaleTimeString('en-GB', {timeZone: 'UTC', hour: '2-digit', minute: '2-digit'});

responseText = responseText + nickname + " " + timeNow + ", " + dateNow + " (UTC)";

responseText = responseText.replaceAll(/{{subst:/gi, "{{");

responseText = responseText.replaceAll(/\s*~~~~\s*/g, "");

$.post(restTransform, 'wikitext=' + encodeURIComponent(responseText) + '&body_only=true',

function (html) {

tableCell.style = "padding:8px 1em 2px;";

tableCell.children[1].innerHTML = html;

}

);

} else {

tableCell.style = "display:none;";

}

}


async function saveResponseCOI(requestBox, responseOption, responseText, watchPage, watchValue) {

await new Promise(function(resolve) {

OO.ui.confirm("Confirm in order to reply to this edit request.").done(function(confirmed) { if (confirmed) {

resolve();

} else {

return;

}});

});

//Create label box & remove quick actions

requestBox[1].innerHTML = "";

requestBox[3].remove();

let statusMessage = new OO.ui.MessageWidget({

icon: 'pageSettings',

type: 'notice',

label: 'Processing request — Edit request starting, getting section data to edit.'

});

statusMessage.$element[0].style = "margin:5px 0; max-width:50em";

$(requestBox[1]).append(statusMessage.$element);

//Create progress bar

let progressBar = new OO.ui.ProgressBarWidget({

progress: false

});

$(requestBox[1]).append(progressBar.$element);

//Set preview for output

previewCOI(responseOption, responseText, requestBox[2]);

// Find header

let header = "";

let sectionIndex = 0;

let tempElement = requestBox[0];

let sectionQuery = await ApiGetCOI({

action: "parse",

page: mw.config.get("wgPageName"),

prop: "sections"

});

let sections = sectionQuery.parse.sections;

do {

tempElement = tempElement.previousElementSibling;

if (tempElement.classList.contains("mw-heading")) {

if (tempElement.parentElement.tagName == "SECTION") { //Need to support both while new parser is being implemented

header = $(tempElement).find("h1,h2,h3,h4,h5,h6")[0].id;

sectionIndex = parseInt(tempElement.parentElement.dataset.mwSectionId);

} else {

if (tempElement.getElementsByClassName("mw-headline").length > 0) { //Vector 2022

header = tempElement.getElementsByClassName("mw-headline")[0].id;

} else { //Vector Legacy

header = $(tempElement).find("h1,h2,h3,h4,h5,h6")[0].id;

}

for (let i = 0; i < sections.length; i++) {

if (sections[i].anchor == header) {

sectionIndex = parseInt(sections[i].index);

}

}

}

}

}

}

}

}

while (header == "");

statusMessage.setLabel("Processing request — Making changes to the edit request");

let editSummary = "/* " + header.replaceAll("_", " ") + " */ " + responseOption.summary + " ([[User:Terasail/COI_Request_Tool|COI Request Tool]])";

let wikitextQuery = await ApiGetCOI({

action: "parse",

page: mw.config.get("wgPageName"),

section: sectionIndex,

prop: "wikitext|revid"

});

let wikitext = wikitextQuery.parse.wikitext["*"];

let latestRevision = wikitextQuery.parse.revid;

if (responseOption.parameter != "") {

let template = "{{Edit COI|" + responseOption.parameter + "}}";

wikitext = wikitext.replace(/{{ *(Edit[ _])?COI(-protected|([ _](edit|request)){2})?( *\| *([=A-Z])*)* *}}/i, template);

}

if (responseOption.response != "") {

wikitext += "\n:{{subst:ECOI|" + responseOption.response + "}}";

wikitext += responseText.replaceAll(/\s*~~~~\s*/g, "") + " ~~~~";

}

if (responseOption.label == "Remove") {

wikitext = "";

editSummary = editSummary.replace(/[^]+\*\/ /, "");

}

statusMessage.setType("success");

statusMessage.setLabel("Processing request — Saving changes to the talk page.");

if (latestRevision != mw.config.values.wgRevisionId) {

await new Promise(function(resolve) {

OO.ui.confirm("There has been a new revision to the page, do you wish to continue?").done(function(confirmed) { if (confirmed) {

resolve();

} else {

return;

}});

});

}

if (watchPage) {

if (watchPage != "nochange") {

watchPage = "watch";

}

} else {

watchPage = "unwatch";

}

let apiParams = {

action: 'edit',

title: mw.config.get("wgPageName"),

text: wikitext,

section: sectionIndex,

summary: editSummary,

watchlist: watchPage

};

if (watchPage == "watch") {

apiParams.watchlistexpiry = watchValue;

}

let reloadURL = "/w/index.php?title=" + encodeURI(mw.config.get("wgPageName")) + "&type=revision&diff=cur&oldid=prev";

new mw.Api().postWithEditToken(apiParams).done(function () {

window.location = reloadURL;

});

}


function ApiGetCOI(params) {

return new Promise(function(resolve) {

new mw.Api().get(params)

.done(function (data) {resolve(data);})

.fail(function (data) {console.error(data);});

});

});

}

}


Latest revision as of 10:19, 6 July 2024

/*<nowiki>
 COI Request Tool
 Created by: Terasail
*/
var nonResponseCOI = [
 {label: "Close", title: "Close request", summary: "Closed edit request", parameter: "answered=yes", response: "", icon: "unFlag", flags: "", text: ""},
 {label: "Open", title: "Reopen request", summary: "Reopened edit request", parameter: "answered=no", response: "", icon: "flag", flags: "", text: ""},
 {label: "Remove", title: "Remove entire section", summary: "Removed COI request", parameter: "", response: "", icon: "trash", flags: ["primary", "destructive"], text: ""}
];
var responseCOI = [
 {label: "Done", title: "Mark request as done", summary: "Marked COI request as done", parameter: "answered=yes", response: "d", icon: "checkAll", flags: ["primary", "progressive"], text: "Done"},
 {label: "Partly done", title: "Mark request as partly done", summary: "Marked COI request as partly done", parameter: "P", response: "pd", icon: "check", flags: "", text: "Partly done:"},
 {label: "Already done", title: "Mark request as already done", summary: "Marked COI request as already done", parameter: "answered=yes", response: "a", icon: "clock", flags: "", text: "Already done:"},
 {label: "Note", title: "Add a note", summary: "Added a note", parameter: "", response: "note", icon: "ellipsis", flags: "", text: "Note:"},
 {label: "Question", title: "Add a question", summary: "Added a question", parameter: "", response: "q", icon: "helpNotice", flags: "", text: "Question:"},
 {label: "Go ahead", title: "Go ahead", summary: "User may go ahead and edit themselves", parameter: "G", response: "g", icon: "edit", flags: "", text: "Go ahead: I have reviewed these proposed changes and suggest that you go ahead and make the proposed changes to the page."},
 {label: "Not done", title: "Decline request", summary: "Declined COI request", parameter: "D", response: "n", icon: "notice", flags: "", text: "Not done:"},
 {label: "Not done for now", title: "Decline request for now", summary: "Declined request for now", parameter: "D", response: "nfn", icon: "notice", flags: "", text: "Not done for now:"},
 {label: "Promotional", title: "Decline promotional request", summary: "Declined promotional request", parameter: "D|ADV", response: "mpro", icon: "signature", flags: "", text: "Not done: A majority of the requested changes are currently written in a promotional tone. Please review WP:Neutral point of view and ensure you follow this before submitting any edit requests."},
 {label: "No consensus", title: "No consensus for the change", summary: "Declined request with no consensus for the change", parameter: "D|C", response: "nc", icon: "userGroup", flags: "", text: "Not done: No consensus could be obtained for making the requested change."},
 {label: "Needs reliable sources", title: "Close request pending reliable sources", summary: "COI request declined: Change requires reliable sources", parameter: "D|V", response: "rs", icon: "quotes", flags: "", text: "Not done: please provide reliable sources that support the change you want to be made."},
 {label: "Removing content", title: "Decline request removing well-cited content", summary: "Declined request removing well-cited content", parameter: "D|R", response: "rm", icon: "restore", flags: "", text: "Not done: The proposed changes are removing content that is well-cited or where sources exist."},
 {label: "Partly promotional", title: "Decline partly promotional request for now", summary: "Declined partly promotional request for now", parameter: "D|ADV", response: "pro", icon: "signature", flags: "", text: "Not done for now: Some of the requested changes are currently written in a promotional tone. Please review WP:Neutral point of view and make changes where appropriate to follow this before reopening the request."},
 {label: "Needs consensus", title: "Close request pending consensus", summary: "COI request declined: Change requires consensus first", parameter: "D|D", response: "c", icon: "userGroup", flags: "", text: "Please establish a consensus with editors engaged in the subject area before using the {{Edit COI}} template for this proposed change."},
 {label: "Unclear request", title: "Decline and mark as unclear", summary: "COI request closed as it is unclear what change is requested", parameter: "D|Unclear request", response: "xy", icon: "helpNotice", flags: "", text: "it's not clear what changes you want to be made. Please mention the specific changes in a \"change X to Y\" format."},
 {label: "Unspecific", title: "Decline unspecific request", summary: "Declined unspecific request", parameter: "D|S", response: "s", icon: "speechBubbles", flags: "", text: "Not done for now: The current request is not specific enough to make changes to the page. Consider developing changes in a new talk section or visit the conflict of interest noticeboard for serious issues."},
 {label: "Balance issues", title: "Decline request with balance issues", summary: "Declined request with balance issues", parameter: "D|O", response: "b", icon: "notice", flags: "", text: "Not done for now: The proposed changes create some balance issues with the article. These will need to be addressed before any changes can be made."},
 {label: "Partly undo", title: "Partly undo request", summary: "COI request has been partly undone", parameter: "P|The requested edit has been partially undone", response: "udp", icon: "undo", flags: "", text: "Undone: This request has been partially undone."},
 {label: "Undo", title: "Undo request", summary: "COI request has been undone", parameter: "D|The requested edit has been undone", response: "ud", icon: "undo", flags: "", text: "Undone: This request has been undone."}
];
var editRequests = $('.editrequest');
var COIRequests = [];
for (let i = 0; i < editRequests.length; i++) {
 if (typeof(editRequests[i].attributes['data-origlevel']) == 'undefined') {
  $(editRequests[i].children[0]).append('<tr><td colspan="2" class="response-cell" style="text-align:center;"></td></tr>');
  COIRequests.push(editRequests[i]);
 }
}

if (COIRequests.length > 0) {
 mw.loader.using(["oojs-ui-core", "oojs-ui-widgets", "oojs-ui-windows"]).done(function() {
  mw.loader.load(["oojs-ui.styles.icons-alerts", "oojs-ui.styles.icons-interactions", "oojs-ui.styles.icons-moderation", "oojs-ui.styles.icons-editing-core", "oojs-ui.styles.icons-editing-advanced", "oojs-ui.styles.icons-user"]);
  loadCOITool();
 });
}

async function loadCOITool() {
 // Get page watchers, visitors and user watch status.
 let watchStatus = [];
 let watchQuery = await ApiGetCOI({
  action: "query",
  prop: "info",
  pageids: mw.config.get("wgArticleId"),
  inprop: "watchers|visitingwatchers|watched",
  format: "json"
 });
 let watchData = watchQuery.query.pages[mw.config.get("wgArticleId")];
 let watched = watchData.watched;
 let expiry = watchData.watchlistexpiry;
 if (expiry) {
  watched = Math.ceil((new Date(expiry).getTime() - Date.now()) / 1000 / 60 / 60 / 24) + " days";
 }
 watchStatus.push(watchData.watchers || "less than 30", watchData.visitingwatchers || "<30", watched);
 //Increment through all COI requests & add respond button
 for (let i = 0; i < COIRequests.length; i++) {
  let respondButton = new OO.ui.ButtonWidget({
   icon: "edit",
   label: "Respond",
   flags: "progressive",
   title: "Open the response menu for this request"
  }).on("click", function() {
   loadCOIResponse(COIRequests[i], respondButton, watchStatus);
   respondButton.setDisabled(true);
  });
  respondButton.$element[0].style = "margin:5px";
  $($('.response-cell')[i]).append(respondButton.$element);
 }
}

function loadCOIResponse(COIRequest, respondButton, watchStatus) {
 let responseBoxHTML = '<table class="response-box" style="border:1px solid #A2A9B1; border-radius:2px; padding:10px 16px 0; margin:auto; max-width:55em; width:100%; clear:both;"><tr><td style="color:#808080"><div style="font-style:italic; margin-left:1em;">There are currently ' + watchStatus[0] + ' users watching this page (' + watchStatus[1] + ' have viewed recent edits).</div><div>Quick options:</div></td></tr><tr style="display: flex; justify-content: center;"><td class="response-quick"></td></tr><tr><td style="color:#808080">Custom response:</td></tr><tr style="text-align:center;"><td class="response-custom"></td></tr><tr style="background:#F6F6F6;"><td class="response-preview" style="display:none;"><div style="color:#808080">Preview:</div><div></div></td></tr><tr style="display: flex; justify-content: right;"><td class="response-controls"></td></tr></table>';
 $(responseBoxHTML).insertAfter(COIRequest, respondButton);
 let responseBox = COIRequest.nextElementSibling;
 let responseQuick = $(responseBox).find('.response-quick')[0];
 let responseCustom = $(responseBox).find('.response-custom')[0];
 let responsePreview = $(responseBox).find('.response-preview')[0];
 let responseControls = $(responseBox).find('.response-controls')[0];
 //Quick Responses
 //Create a HorizontalLayout & Fieldset for quick responses
 let quickLayout = new OO.ui.HorizontalLayout();
 let quickFieldset = new OO.ui.FieldsetLayout();
 quickFieldset.addItems([new OO.ui.FieldLayout(new OO.ui.Widget({content: [quickLayout]}), {align: 'top'})]);
 $(responseQuick).append(quickFieldset.$element);
 let quickNonResponses = [2];//Remove button
 if ($(COIRequest).find('hr').length > 0) {//If request is closed
  quickNonResponses.push(0);//Close button
 } else {
  quickNonResponses.push(1);//Open button
 }
 for (let i = 0; i < quickNonResponses.length; i++) {
  let tempVal = quickNonResponses[i];
  let tempButton = new OO.ui.ButtonWidget({
   flags: nonResponseCOI[tempVal].flags,
   icon: nonResponseCOI[tempVal].icon,
   title: nonResponseCOI[tempVal].title,
   invisibleLabel: true
  }).on("click", function () {
   saveResponseCOI([COIRequest, responseQuick, responsePreview, responseControls], nonResponseCOI[tempVal], "", "nochange", undefined);
  });
  quickLayout.addItems([tempButton]);
 }
 let quickResponses = [0, 5, 8, 10];//Done, Go ahead, Consensus, Unclear
 for (let i = 0; i < quickResponses.length; i++) {
  let tempVal = quickResponses[i];
  let tempButton = new OO.ui.ButtonWidget({
   flags: responseCOI[tempVal].flags,
   label: responseCOI[tempVal].label,
   title: responseCOI[tempVal].title
  }).on("click", function () {
   saveResponseCOI([COIRequest, responseQuick, responsePreview, responseControls], responseCOI[tempVal], "", "nochange", undefined);
  });
  quickLayout.addItems([tempButton]);
 }
 //Custom Responses
 //Response dropdown
 let responseDropdown = new OO.ui.DropdownWidget({
  label: "Select reply option - Add additional text below",
  menu: {items: []}
 }).on("labelChange", function () {
  submitButton.setDisabled(false);
  previewCOI(responseDropdown.menu.findSelectedItem().getData(), responseText.value, responsePreview);
 });
 for (let i = 0; i < responseCOI.length; i++) {
  let tempWidget = new OO.ui.MenuOptionWidget({
   label: responseCOI[i].text,
   icon: responseCOI[i].icon,
   data: responseCOI[i]
  });
  responseDropdown.menu.addItems([tempWidget]);
 }
 responseDropdown.$element[0].style = "margin:auto; text-align:left;";
 $(responseCustom).append(responseDropdown.$element);
 //Response text
 var responseText = new OO.ui.MultilineTextInputWidget({
  autosize: true, rows: 4, label: "Additional text"
 }).on("change", function () {
  if (responseDropdown.menu.findSelectedItem()) {
   previewCOI(responseDropdown.menu.findSelectedItem().getData(), responseText.value, responsePreview);
  }
 });
 responseText.$element[0].style = "margin:5px auto;";
 $(responseCustom).append(responseText.$element);
 //Response Controls
 //Create a HorizontalLayout & Fieldset for response controls
 let controlsLayout = new OO.ui.HorizontalLayout();
 let controlsFieldset = new OO.ui.FieldsetLayout();
 controlsFieldset.addItems([new OO.ui.FieldLayout(new OO.ui.Widget({content: [controlsLayout]}), {align: 'top'})]);
 $(responseControls).append(controlsFieldset.$element);
 //Cancel Button
 let cancelButton = new OO.ui.ButtonWidget({
  icon: "cancel",
  flags: "destructive",
  label: "Cancel",
  framed: false,
  title: "Cancel the response & close this menu"
 }).on("click", function () {
  respondButton.setDisabled(false);
  responseBox.remove();
 });
 controlsLayout.addItems([cancelButton]);
 //Watchlist dropdown
 let watchOptions = [{data: "infinite", label: "Permanent"}, {data: "1 day", label: "1 day"}, {data: "3 days", label: "3 days"}, {data: "1 week", label: "1 week"}, {data: "1 month", label: "1 month"}];
 let watchValue = "infinite";
 if (!!watchStatus[2]) {
  watchOptions.unshift({data: "nochange", label: watchStatus[2]});
  watchValue = "nochange";
 }
 let watchlistLayout = new OO.ui.HorizontalLayout();
 let watchlistDropdown = new OO.ui.DropdownInputWidget({
  value: watchValue,
  options: watchOptions,
  disabled: (watchStatus[2] == undefined)
 });
 watchlistLayout.addItems([watchlistDropdown]);
 //Watchlist checkbox & label
 let watchlistCheckbox = new OO.ui.CheckboxInputWidget({
  selected: (watchStatus[2] != undefined)
 }).on("change", function (newStatus) {
  watchlistDropdown.setDisabled(!newStatus);
 });
 let watchlistLabel = new OO.ui.LabelWidget({label: "Watch this page"}).on("change", function (newStatus) {

 });
 //Submit Button
 let submitButton = new OO.ui.ButtonWidget({
  icon: "checkAll",
  flags: ["primary", "progressive"],
  label: "Submit",
  title: "Submit the response",
  disabled: true
 }).on("click", function () {
  saveResponseCOI([COIRequest, responseQuick, responsePreview, responseControls], responseDropdown.menu.findSelectedItem().getData(), responseText.value, watchlistCheckbox.selected, watchlistDropdown.value);
 });
 controlsLayout.addItems([cancelButton, watchlistCheckbox, watchlistLabel, watchlistLayout, submitButton]);
}

function previewCOI(responseOption, responseText, tableCell) {
 let restTransform = "https://en.wikipedia.org/api/rest_v1/transform/wikitext/to/html/" + encodeURI(mw.config.get("wgPageName"));
 if (responseOption.response != "") {
  responseText = "{{ECOI|" + responseOption.response + "}} " + responseText;
 }
 if (responseText != "") {
  let nickname = " " + mw.user.options.values.nickname;
  if (nickname == " ") {//Create default signature if no nickname
   nickname = mw.user.getName();
   nickname = " [[User:" + nickname + "|" + nickname + "]] ([[User talk:" + nickname + "|talk]])";
  }
  let dateObj = new Date();
  let dateNow = dateObj.toLocaleDateString('en-GB', {
   timeZone: 'UTC',
   year: 'numeric',
   month: 'long',
   day: 'numeric'
  });
  let timeNow = dateObj.toLocaleTimeString('en-GB', {timeZone: 'UTC', hour: '2-digit', minute: '2-digit'});
  responseText = responseText + nickname + " " + timeNow + ", " + dateNow + " (UTC)";
  responseText = responseText.replaceAll(/{{subst:/gi, "{{");
  responseText = responseText.replaceAll(/\s*~~~~\s*/g, "");
  $.post(restTransform, 'wikitext=' + encodeURIComponent(responseText) + '&body_only=true',
   function (html) {
    tableCell.style = "padding:8px 1em 2px;";
    tableCell.children[1].innerHTML = html;
   }
  );
 } else {
  tableCell.style = "display:none;";
 }
}

async function saveResponseCOI(requestBox, responseOption, responseText, watchPage, watchValue) {
 await new Promise(function(resolve) {
  OO.ui.confirm("Confirm in order to reply to this edit request.").done(function(confirmed) { if (confirmed) {
   resolve();
  } else {
   return;
  }});
 });
 //Create label box & remove quick actions
 requestBox[1].innerHTML = "";
 requestBox[3].remove();
 let statusMessage = new OO.ui.MessageWidget({
  icon: 'pageSettings',
  type: 'notice',
  label: 'Processing request — Edit request starting, getting section data to edit.'
 });
 statusMessage.$element[0].style = "margin:5px 0; max-width:50em";
 $(requestBox[1]).append(statusMessage.$element);
 //Create progress bar
 let progressBar = new OO.ui.ProgressBarWidget({
  progress: false
 });
 $(requestBox[1]).append(progressBar.$element);
 //Set preview for output
 previewCOI(responseOption, responseText, requestBox[2]);
 // Find header
 let header = "";
 let sectionIndex = 0;
 let tempElement = requestBox[0];
 let sectionQuery = await ApiGetCOI({
  action: "parse",
  page: mw.config.get("wgPageName"),
  prop: "sections"
 });
 let sections = sectionQuery.parse.sections;
 do {
  tempElement = tempElement.previousElementSibling;
  if (tempElement.classList.contains("mw-heading")) {
   if (tempElement.parentElement.tagName == "SECTION") { //Need to support both while new parser is being implemented
    header = $(tempElement).find("h1,h2,h3,h4,h5,h6")[0].id;
    sectionIndex = parseInt(tempElement.parentElement.dataset.mwSectionId);
   } else {
    if (tempElement.getElementsByClassName("mw-headline").length > 0) { //Vector 2022
     header = tempElement.getElementsByClassName("mw-headline")[0].id;
    } else { //Vector Legacy
     header = $(tempElement).find("h1,h2,h3,h4,h5,h6")[0].id;
    }
    for (let i = 0; i < sections.length; i++) {
     if (sections[i].anchor == header) {
      sectionIndex = parseInt(sections[i].index);
     }
    }
   }
  }
 }
 while (header == "");
 statusMessage.setLabel("Processing request — Making changes to the edit request");
 let editSummary = "/* " + header.replaceAll("_", " ") + " */ " + responseOption.summary + " ([[User:Terasail/COI_Request_Tool|COI Request Tool]])";
 let wikitextQuery = await ApiGetCOI({
  action: "parse",
  page: mw.config.get("wgPageName"),
  section: sectionIndex,
  prop: "wikitext|revid"
 });
 let wikitext = wikitextQuery.parse.wikitext["*"];
 let latestRevision = wikitextQuery.parse.revid;
 if (responseOption.parameter != "") {
  let template = "{{Edit COI|" + responseOption.parameter + "}}";
  wikitext = wikitext.replace(/{{ *(Edit[ _])?COI(-protected|([ _](edit|request)){2})?( *\| *([=A-Z])*)* *}}/i, template);
 }
 if (responseOption.response != "") {
  wikitext += "\n:{{subst:ECOI|" + responseOption.response + "}}";
  wikitext += responseText.replaceAll(/\s*~~~~\s*/g, "") + " ~~~~";
 }
 if (responseOption.label == "Remove") {
  wikitext = "";
  editSummary = editSummary.replace(/[^]+\*\/ /, "");
 }
 statusMessage.setType("success");
 statusMessage.setLabel("Processing request — Saving changes to the talk page.");
 if (latestRevision != mw.config.values.wgRevisionId) {
  await new Promise(function(resolve) {
   OO.ui.confirm("There has been a new revision to the page, do you wish to continue?").done(function(confirmed) { if (confirmed) {
    resolve();
   } else {
    return;
   }});
  });
 }
 if (watchPage) {
  if (watchPage != "nochange") {
   watchPage = "watch";
  }
 } else {
  watchPage = "unwatch";
 }
 let apiParams = {
  action: 'edit',
  title: mw.config.get("wgPageName"),
  text: wikitext,
  section: sectionIndex,
  summary: editSummary,
  watchlist: watchPage
 };
 if (watchPage == "watch") {
  apiParams.watchlistexpiry = watchValue;
 }
 let reloadURL = "/w/index.php?title=" + encodeURI(mw.config.get("wgPageName")) + "&type=revision&diff=cur&oldid=prev";
 new mw.Api().postWithEditToken(apiParams).done(function () {
  window.location = reloadURL;
 });
}

function ApiGetCOI(params) {
 return new Promise(function(resolve) {
  new mw.Api().get(params)
  .done(function (data) {resolve(data);})
  .fail(function (data) {console.error(data);});
 });
}
//</nowiki>[[Category:Wikipedia scripts]]

Retrieved from "https://en.wikipedia.org/w/index.php?title=User:Terasail/COI_Request_Tool.js&oldid=1232924012"

Category: 
Wikipedia scripts
 



This page was last edited on 6 July 2024, at 10:19 (UTC).

Text is available under the Creative Commons Attribution-ShareAlike License 4.0; additional terms may apply. By using this site, you agree to the Terms of Use and Privacy Policy. Wikipedia® is a registered trademark of the Wikimedia Foundation, Inc., a non-profit organization.



Privacy policy

About Wikipedia

Disclaimers

Contact Wikipedia

Code of Conduct

Developers

Statistics

Cookie statement

Mobile view



Wikimedia Foundation
Powered by MediaWiki