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

Content deleted Content added
Fix quick response linking to wrong reply
Account for {{COI edit}}
 
(11 intermediate revisions by the same user not shown)
Line 1:
//*<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: please provide reliable sources that support the change you want to be made.": ["rs", "link", "Not done - Needs reliable sources", "|D"],
{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."},
"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: "Not done", title: "Decline request", summary: "Declined COI request", parameter: "D", response: "n", icon: "notice", flags: "", text: "Not done:"},
"Undone: This request has been partially undone.": ["udp","undo", "Partly undone", "|D|The requested edit has been partially 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:"},
"Undone: This request has been undone.": ["ud", "undo", "Undone", "|D|The requested edit has been undone"]
{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."},
var COIResponse = [];
{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."},
//selectedReply
{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."},
function executeCOI(currentBox, replyOption, inputText, answered) {
{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."},
OO.ui.confirm("Confirm in order to reply to this edit request.").done(function(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."},
if (confirmed) {
{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.getElementsByTagName('tr')[2].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."},
currentBox.children[0].children[0].children[1].remove();
{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."},
var infoBox = new OO.ui.MessageWidget( {
{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."}
icon: 'pageSettings',
];
type: 'notice',
var editRequests = $('.editrequest');
label: 'Processing request — Edit request starting, getting section data to edit.'
var COIRequests = [];
});
for (let i = 0; i < editRequests.length; i++) {
var firstRowC = currentBox.children[1].children[0];
if (typeof(editRequests[i].attributes['data-origlevel']) == 'undefined') {
firstRowC.style = "padding-bottom:10px";
$(editRequests[i].children[0]).append('<tr><td colspan="2" class="response-cell" style="text-align:center;"></td></tr>');
firstRowC.innerHTML = "";
COIRequests.push(editRequests[i]);
progressBar = new OO.ui.ProgressBarWidget( {
}
progress: false
}
});
 
$(firstRowC).append(progressBar.$element);
if (COIRequests.length > 0) {
$(firstRowC).append(infoBox.$element);
mw.loader.using(["oojs-ui-core", "oojs-ui-widgets", "oojs-ui-windows"]).done(function() {
progressBar.$element[0].style = "margin:auto";
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"]);
infoBox.$element[0].style = "margin:10px auto 0px; max-width:50em; text-align:left";
loadCOITool();
var header = "";
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";
});
}
}
});
}
});
}
 
async function loadButtonsloadCOITool(currentBox) {
// 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[13][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";
}
if (watched == undefined && typeof(autoWatchRequests) != "undefined" && autoWatchRequests == true) {
watched = '';
}
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><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>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>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});
//DoneQuick buttonResponses
//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);
});
hzCLayoutquickLayout.addItems([item[3]tempButton]);
});
//Custom Responses
//Responses button
//Response dropdown
var respondCB = new OO.ui.ButtonWidget( {
let responseDropdown = new OO.ui.DropdownWidget({
icon: "add",
label: "MoreSelect 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([
let controlsFieldset = new OO.ui.FieldLayoutFieldsetLayout();
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"});
removeB.$element[0].style = "margin:10px";
//Submit Button
removeB.on("click", function() {
let submitButton = new OO.ui.ButtonWidget({
executeCOI(currentBox, replyCOIT.Remove, "", false);
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]);
$(currentBox.children[0].children[0]).append(removeB.$element);
}
 
function addReplyButtonpreviewCOI(currentBoxresponseOption, boxTyperesponseText, tableCell) {
let restTransform = "https://en.wikipedia.org/api/rest_v1/transform/wikitext/to/html/" + encodeURI(mw.config.get("wgPageName"));
var replyB = new OO.ui.ButtonWidget( {
if (responseOption.response != "") {
icon: "edit",
responseText = "{{ECOI|" + responseOption.response + "}} " + responseText;
flags: "progressive",
}
invisibleLabel: true
if (responseText != "") {
});
let nickname = " " + mw.user.options.values.nickname;
replyB.$element[0].style = "margin:5px 0px";
if (nickname == " ") {//Create default signature if no nickname
$(currentBox.children[0].children[0]).append(replyB.$element);
nickname = mw.user.getName();
replyB.on("click", function() {
nickname = " [[User:" + nickname + "|" + nickname + "]] ([[User talk:" + nickname + "|talk]])";
currentBox.parentElement.setAttribute("class", "plainlinks tmbox tmbox-notice editrequest");
}
var img = currentBox.children[0].children[0].children[0]
img.widthlet dateObj = 53new Date();
let dateNow = dateObj.toLocaleDateString('en-GB', {
img.height = 53;
timeZone: 'UTC',
img.src = "//upload.wikimedia.org/wikipedia/commons/f/f4/Info_talk.png"
year: 'numeric',
img.scrset = "";
month: 'long',
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>'
day: 'numeric'
replyB.$element.remove();
});
loadButtons(currentBox);
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) {
var COIRequestBoxes = document.getElementsByClassName("plainlinks tmbox tmbox-notice editrequest");
await new Promise(function(resolve) {
if (COIRequestBoxes) {
OO.ui.confirm("Confirm in order to reply to this edit request.").done(function(confirmed) { if (confirmed) {
mw.loader.using(["oojs-ui-core", "oojs-ui-widgets", "oojs-ui-windows"]).done(function() {
resolve();
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"]);
} else {
for (var i = 0; i < COIRequestBoxes.length; i++) {
return;
var currentBox = COIRequestBoxes[i].children[0];
}});
var edReqCheck = currentBox.children[0].children[1];
});
if (edReqCheck.innerText.search("conflict") != -1) { //Check that it is a conflict edit request
//Create label box & remove quick actions
if (edReqCheck.innerText.search("The requested edits backlog is") != -1) { //For unanswered boxes
requestBox[1].innerHTML = "";
loadButtons(currentBox);
requestBox[3].remove();
} else { //For answered boxes
let statusMessage = new OO.ui.MessageWidget({
addReplyButton(currentBox);
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)){1,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);});
});
}