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

Content deleted Content added
Fix quick response linking to wrong reply
Update to match WP:ERT design
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 api = new mw.Api();
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);
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";
//Get page watchers, visitors and user watch status.
var header = "";
let watchStatus = [];
var curElement = currentBox.parentNode; //Table tag
let pageID = mw.config.get("wgArticleId");
do {
api.get({
curElement = curElement.previousElementSibling;
action: "query",
if (curElement.getElementsByClassName("mw-headline").length == 1) {
prop: "info",
header = curElement.getElementsByClassName("mw-headline")[0].id;
pageids: pageID,
}
inprop: "watchers|visitingwatchers|watched",
format: "json"
}).done(function (data) {
data = data.query.pages[pageID];
let watched = data.watched;
let expiry = data.watchlistexpiry;
if (expiry) {
watched = Math.ceil((new Date(expiry).getTime() - Date.now()) / 1000 / 60 / 60 / 24) + " days";
}
watchStatus.push(data.watchers || "less than 30", data.visitingwatchers || "0", watched);
while (header == "");
});
var conVal = mw.config.values;
//Increment through all COI requests & add respond button
var api = new mw.Api();
for (let i = 0; i < COIRequests.length; i++) {
api.get( {
let respondButton = new OO.ui.ButtonWidget({
action: "parse",
pageicon: conVal.wgPageName"edit",
proplabel: "sections|wikitextRespond",
flags: "progressive",
}).done(function(data) {
infoBox.setLabel(title: "ProcessingOpen requestthe response Makingmenu changes to thefor editthis request");
}).on("click", function() {
var sections = data.parse.sections;
loadCOIResponseBox(COIRequests[i], respondButton, watchStatus);
var wikitext = data.parse.wikitext["*"];
respondButton.setDisabled(true);
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";
});
}
}
});
respondButton.$element[0].style = "margin:5px";
$($('.response-cell')[i]).append(respondButton.$element);
}
});
}
 
function loadCOIResponseBox(COIRequest, respondButton, watchStatus) {
function loadButtons(currentBox) {
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 replyListC = Object.entries(replyCOIT);
$(responseBoxHTML).insertAfter(COIRequest, respondButton);
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 responseBox = COIRequest.nextElementSibling;
$(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>');
let responseQuick = $(responseBox).find('.response-quick')[0];
var firstRowC = currentBox.children[1].children[0].children[0];
let responseCustom = $(responseBox).find('.response-custom')[0];
//Create dropdown menu
let responsePreview = $(responseBox).find('.response-preview')[0];
var dropMenu = new OO.ui.DropdownWidget( {
let responseControls = $(responseBox).find('.response-controls')[0];
label: "Select reply option - Add additional text below",
//Quick Responses
menu: {items: []}
//Create a HorizontalLayout & Fieldset for quick responses
});
let quickLayout = new OO.ui.HorizontalLayout();
for (var count = 2; count < replyListC.length; count++) {
var let newOptionquickFieldset = new OO.ui.MenuOptionWidgetFieldsetLayout({);
quickFieldset.addItems([new OO.ui.FieldLayout(new OO.ui.Widget({content: [quickLayout]}), {align: 'top'})]);
label: replyListC[count][0],
$(responseQuick).append(quickFieldset.$element);
icon: replyListC[count][1][1]
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 () {
executeCOIResponse([COIRequest, responseQuick, responsePreview, responseControls], nonResponseCOI[tempVal], "", "nochange", undefined);
});
dropMenu.menuquickLayout.addItems([newOptiontempButton]);
}
let quickResponses = [0, 5, 8, 10];//Done, Go ahead, Consensus, Unclear
dropMenu.$element[0].style = "text-align:left; margin:0px";
for (let i = 0; i < quickResponses.length; i++) {
$(currentBox.children[2].children[0]).append(dropMenu.$element);
let tempVal = quickResponses[i];
//Create input box
let tempButton = new OO.ui.ButtonWidget({
var inputText = new OO.ui.MultilineTextInputWidget({autosize: true, label: "Automatically signed"});
flags: responseCOI[tempVal].flags,
inputText.$element[0].style = "margin:auto";
label: responseCOI[tempVal].label,
$(currentBox.children[2].children[0]).append(inputText.$element);
title: responseCOI[tempVal].title
//Create horizontal layout
}).on("click", function () {
var hzCLayout = new OO.ui.HorizontalLayout();
executeCOIResponse([COIRequest, responseQuick, responsePreview, responseControls], responseCOI[tempVal], "", "nochange", undefined);
//Toggle answer button
var answerCB = new OO.ui.CheckboxInputWidget({selected: true});
//Done button
var doneCB = new OO.ui.ButtonWidget( {
icon: "checkAll",
flags: ["primary", "progressive"],
label: "Done",
title: "Mark as done"
});
doneCB.on("click", function() {
if (doneCB.getLabel() == "Submit") {
executeCOI(currentBox, replyCOIT[dropMenu.getLabel()], inputText.value, answerCB.selected);
} else {
executeCOI(currentBox, replyListC[3][1], inputText.value, answerCB.selected);
}
});
hzCLayout.addItems([doneCB]);
//Quick access buttons
mainResponseC.forEach(function(item) {
item[3] = new OO.ui.ButtonWidget({
label: item[1],
title: item[2]
});
quickLayout.addItems([tempButton]);
item[3].on("click", function() {
}
executeCOI(currentBox, item[0], "", answerCB.selected);
//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);
peviewCOIResponse(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]
});
hzCLayoutresponseDropdown.menu.addItems([item[3]tempWidget]);
});
responseDropdown.$element[0].style = "margin:auto; text-align:left;";
//Responses button
$(responseCustom).append(responseDropdown.$element);
var respondCB = new OO.ui.ButtonWidget( {
//Response text
icon: "add",
var responseText = new OO.ui.MultilineTextInputWidget({
label: "More",
autosize: true, rows: 4, label: "Additional text"
title: "Extra reply options"
}).on("change", function () {
});
if (responseDropdown.menu.findSelectedItem()) {
hzCLayout.addItems([respondCB]);
peviewCOIResponse(responseDropdown.menu.findSelectedItem().getData(), responseText.value, responsePreview);
respondCB.on("click", function() {
if (currentBox.children[2].style.display == "") {
respondCB.setIcon("add");
respondCB.setLabel("More");
currentBox.children[2].style = "display:none";
doneCB.setLabel("Done");
doneCB.setTitle("Mark as done");
} else {
respondCB.setIcon("subtract");
respondCB.setLabel("Less");
currentBox.children[2].style = "";
doneCB.setLabel("Submit");
doneCB.setTitle("Submit response");
}
});
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]);
hzCLayout.addItems([answerCB, new OO.ui.LabelWidget({label: "Close"})]);
//Watchlist dropdown
//Create first row fieldset
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"}];
var fieldsetC = new OO.ui.FieldsetLayout();
let watchValue = "infinite";
// Add an horizontal field layout
if (!!watchStatus[2]) {
fieldsetC.addItems([
watchOptions.unshift({data: "nochange", label: watchStatus[2]});
new OO.ui.FieldLayout(
watchValue = "nochange";
new OO.ui.Widget({
}
content: [hzCLayout]
let watchlistLayout = new OO.ui.HorizontalLayout();
}),
let watchlistDropdown = new OO.ui.DropdownInputWidget({
)
value: watchValue,
]);
options: watchOptions,
$(firstRowC).append(fieldsetC.$element);
disabled: (watchStatus[2] == undefined)
//Close request
});
var closeB = new OO.ui.ButtonWidget( {
watchlistLayout.addItems([watchlistDropdown]);
icon: "unFlag",
//Watchlist checkbox & label
invisibleLabel: true,
let watchlistCheckbox = new OO.ui.CheckboxInputWidget({
title: "Mark as answered"
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) {
closeB.$element[0].style = "margin:10px 10px 0px";
 
$(currentBox.children[0].children[0]).append(closeB.$element);
closeB.on("click", function() {
executeCOI(currentBox, replyCOIT.Close, "", true)
});
//RemoveSubmit requestButton
varlet removeBsubmitButton = new OO.ui.ButtonWidget( {
icon: "trashcheckAll",
flags: ["primary", "destructiveprogressive"],
label: "Submit",
invisibleLabel: true,
title: "RemoveSubmit entirethe section!response",
disabled: true
}).on("click", function () {
executeCOIResponse([COIRequest, responseQuick, responsePreview, responseControls], responseDropdown.menu.findSelectedItem().getData(), responseText.value, watchlistCheckbox.selected, watchlistDropdown.value);
});
controlsLayout.addItems([cancelButton, watchlistCheckbox, watchlistLabel, watchlistLayout, submitButton]);
removeB.$element[0].style = "margin:10px";
removeB.on("click", function() {
executeCOI(currentBox, replyCOIT.Remove, "", false);
});
$(currentBox.children[0].children[0]).append(removeB.$element);
}
 
function addReplyButtonpeviewCOIResponse(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;";
}
}
 
function executeCOIResponse(requestBox, responseOption, responseText, watchPage, watchValue) {
var COIRequestBoxes = document.getElementsByClassName("plainlinks tmbox tmbox-notice editrequest");
OO.ui.confirm("Confirm in order to reply to this edit request.").done(function(confirmed) { if (confirmed) {
if (COIRequestBoxes) {
//Create label box & remove quick actions
mw.loader.using(["oojs-ui-core", "oojs-ui-widgets", "oojs-ui-windows"]).done(function() {
requestBox[1].innerHTML = "";
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"]);
requestBox[3].remove();
for (var i = 0; i < COIRequestBoxes.length; i++) {
let statusMessage = new OO.ui.MessageWidget({
var currentBox = COIRequestBoxes[i].children[0];
icon: 'pageSettings',
var edReqCheck = currentBox.children[0].children[1];
type: 'notice',
if (edReqCheck.innerText.search("conflict") != -1) { //Check that it is a conflict edit request
label: 'Processing request — Edit request starting, getting section data to edit.'
if (edReqCheck.innerText.search("The requested edits backlog is") != -1) { //For unanswered boxes
});
loadButtons(currentBox);
statusMessage.$element[0].style = "margin:5px 0; max-width:50em";
} else { //For answered boxes
$(requestBox[1]).append(statusMessage.$element);
addReplyButton(currentBox);
//Create progress bar
let progressBar = new OO.ui.ProgressBarWidget({
progress: false
});
$(requestBox[1]).append(progressBar.$element);
//Set preview for output
peviewCOIResponse(responseOption, responseText, requestBox[2]);
//Find header
let header = "";
let tempElement = requestBox[0];
do {
tempElement = tempElement.previousElementSibling;
if (tempElement.getElementsByClassName("mw-headline").length == 1) {
header = tempElement.getElementsByClassName("mw-headline")[0].id;
}
}
while (header == "");
let editSummary = "/* " + header.replaceAll("_", " ") + " */ " + responseOption.summary + " ([[User:Terasail/COI_Request_Tool|COI Request Tool]])";
api.get({
action: "parse",
page: mw.config.get("wgPageName"),
prop: "sections"
}).done(function (data) {
let sections = data.parse.sections;
let sectionIndex = 0;
statusMessage.setLabel("Processing request — Making changes to the edit request");
for (let i = 0; i < sections.length; i++) {
if (sections[i].anchor == header) {
sectionIndex = parseInt(sections[i].index);
}
}
api.get({
action: "parse",
page: mw.config.get("wgPageName"),
section: sectionIndex,
prop: "wikitext|revid"
}).done(function (data) {
let wikitext = data.parse.wikitext["*"];
let latestRevision = data.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) {
postCOIResponse(wikitext, editSummary, sectionIndex, watchPage, watchValue);
} else {
OO.ui.confirm("There has been a new revision to the page, do you wish to continue?").done(function (revisionConfirm) {
if (revisionConfirm) {
postCOIResponse(wikitext, editSummary, sectionIndex, watchPage, watchValue);
}
});
}
});
});
}});
}
 
function postCOIResponse(wikitext, editSummary, sectionIndex, watchPage, watchValue) {
if (watchPage) {
if (watchValue == "nochange") {
watchPage = "nochange";
} else {
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";
api.postWithEditToken(apiParams).done(function () {
window.___location = reloadURL;
});
}
//</nowiki>[[Category:Wikipedia scripts]]