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

Content deleted Content added
Fix close template error
Account for {{COI edit}}
 
(16 intermediate revisions by the same user not shown)
Line 1:
//*<nowiki>
COI Request Tool
var COIResponse = [
Created by: Terasail
["ntmp", "speechBubbleAdd", "Comment", "Comment (No template)", ""],
*/
["d", "checkAll", "Done", "Done", "|A"],
var nonResponseCOI = [
["pd", "check", "Partly done", "Partly done:", "|P"],
{label: "Close", title: "Close request", summary: "Closed edit request", parameter: "answered=yes", response: "", icon: "unFlag", flags: "", text: ""},
["a", "clock", "Already Done", "Already Done", "|A"],
{label: "Open", title: "Reopen request", summary: "Reopened edit request", parameter: "answered=no", response: "", icon: "flag", flags: "", text: ""},
["q", "helpNotice", "Question", "Question:", ""],
{label: "Remove", title: "Remove entire section", summary: "Removed COI request", parameter: "", response: "", icon: "trash", flags: ["primary", "destructive"], text: ""}
["g", "edit", "Go ahead", "Go ahead: I have reviewed these proposed changes and suggest that you go ahead and make the proposed changes to the page.", "|G"],
];
["note", "ellipsis", "Note", "Note:", ""],
var responseCOI = [
["n", "notice", "Not done", "Not done:", "|D"],
{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"},
["nfn", "notice", "Not done for now", "Not done for now:", "|D"],
{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:"},
["c", "userGroup", "Not done – Needs consensus", "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.", "|D|C"],
{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:"},
["udp","undo", "Partly undone", "Undone: This request has been partially undone.", "|D|The requested edit has been partially undone"],
{label: "Note", title: "Add a note", summary: "Added a note", parameter: "", response: "note", icon: "ellipsis", flags: "", text: "Note:"},
["ud", "undo", "Undone", "Undone: This request has been undone.", "|D|The requested edit has been undone"]];
{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) {
function executeCOI(currentBox, selectedReply, inputText, answered) {
mw.loader.using(["oojs-ui-core", "oojs-ui-widgets", "oojs-ui-windows"]).done(function() {
OO.ui.confirm("Confirm in order to reply to this edit request.").done(function(confirmed) {
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"]);
if (confirmed) {
loadCOITool();
currentBox.getElementsByTagName('tr')[2].remove();
currentBox.children[0].children[0].children[1].remove();
currentBox.children[0].children[0].children[1].remove();
var infoBox = new OO.ui.MessageWidget( {
icon: 'pageSettings',
type: 'notice',
label: 'Processing request — Edit request starting, getting section data to edit.'
});
var firstRowC = currentBox.children[1].children[0];
firstRowC.style = "padding-bottom:10px";
firstRowC.innerHTML = "";
progressBar = new OO.ui.ProgressBarWidget( {
progress: false
});
$(firstRowC).append(progressBar.$element);
$(firstRowC).append(infoBox.$element);
progressBar.$element[0].style = "margin:auto";
infoBox.$element[0].style = "margin:10px auto 0px; max-width:50em; text-align:left";
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 api = new mw.Api();
api.get( {
action: "parse",
page: mw.config.values.wgPageName,
prop: "sections",
}).done(function(data) {
infoBox.setLabel("Processing request — Making changes to the edit request");
var sections = data.parse.sections;
var sectionNum = -1;
var offset = 0;
for (var j = 0; j < sections.length; j++) {
if (sections[j].anchor == header) {
sectionNum = j + 1;
sectionNum -= offset;
}
if (sections[j].fromtitle != mw.config.values.wgPageName) {
offset++;
}
}
infoBox.setLabel("Processing request — Getting information from section: " + sectionNum + ".");
api.get( {
action: "parse",
page: mw.config.values.wgPageName,
prop: "wikitext",
section: sectionNum
}).done( function(data) {
infoBox.setLabel("Processing request — Making changes to the edit request.");
var wikitext = data.parse.wikitext["*"];
var tempStr = "";
if (selectedReply == "CLOSEREQ") {
tempStr = "|A";
} else {
tempStr = COIResponse[selectedReply][4];
}
var tempType = "{{request edit";
var upperWT = wikitext.toUpperCase();
var templateLoc = upperWT.indexOf("{{REQ");
if (templateLoc == -1) {
templateLoc = upperWT.indexOf("{{EDIT");
}
if (templateLoc == -1) {
templateLoc = upperWT.indexOf("{{COI");
}
if (templateLoc == -1) {
infoBox.setLabel('Failed to find {{Request edit}} template, please report to "User talk:Terasail/COI Request Tool"');
infoBox.setType("error");
} else {
var templateEnd = upperWT.indexOf("}}", templateLoc) + 2;
if (tempStr != "" || answered == false) {
if (answered == false) {
tempStr = "";
}
wikitext = wikitext.slice(0, templateLoc) + "{{Request edit" + tempStr + "}}" + wikitext.slice(templateEnd);
}
var editSummary = "/* " + header.replaceAll("_", " ") + " */ ";
if (selectedReply == "REMOVE") {
wikitext = "";
editSummary = "Removed edit request";
selectedReply = -1;
} else if (selectedReply == "CLOSEREQ") {
editSummary += "Closed edit request";
selectedReply = -1;
} else {
if (selectedReply == 0) { //Do not add response template
wikitext += "\n:" + inputText.value;
} else {
wikitext += "\n:{{subst:ECOI|" + COIResponse[selectedReply][0] + "}}";
if (inputText != "") {
wikitext += " " + inputText.value;
}
}
wikitext += " ~~~~";
editSummary += COIResponse[selectedReply][2];
}
editSummary += " ([[User:Terasail/COI_Request_Tool|COI Request Tool]])";
if (selectedReply != -1 && infoBox.type != "error") {
infoBox.setType("success");
infoBox.setLabel("Processing '" + COIResponse[selectedReply][2] + "' request — Saving changes to the talk page. (This may take a few seconds)");
}
api.postWithEditToken({
action: 'edit',
title: mw.config.values.wgPageName,
text: wikitext,
section: sectionNum,
summary: editSummary
}).done(function(result) {
window.___location = "https" + "://en.wikipedia.org/w/index.php?title=" + mw.config.values.wgPageName + "&type=revision&diff=cur&oldid=prev";
});
}
});
});
}
});
}
 
async function loadButtonsloadCOITool(currentBox) {
// Get page watchers, visitors and user watch status.
$(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 watchStatus = [];
var firstRowC = currentBox.children[1].children[0].children[0];
let watchQuery = await ApiGetCOI({
//Create dropdown menu
action: "query",
var dropMenu = new OO.ui.DropdownWidget( {
prop: "info",
label: "Select reply option - Add additional text below",
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";
}
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";
$($('.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><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>';
$(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++) {
COIResponse.forEach(function(item) {
varlet newOptiontempWidget = new OO.ui.MenuOptionWidget({
label: itemresponseCOI[3i].text,
icon: itemresponseCOI[1i].icon,
data: responseCOI[i]
});
dropMenuresponseDropdown.menu.addItems(newOption[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]);
dropMenu.$element[0].style = "text-align:left; margin:0px";
//Watchlist dropdown
$(currentBox.children[2].children[0]).append(dropMenu.$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"}];
//Create input box
let watchValue = "infinite";
var inputText = new OO.ui.MultilineTextInputWidget({autosize: true, label: "'~~~~' is automatically added"});
if (!!watchStatus[2]) {
inputText.$element[0].style = "margin:auto";
watchOptions.unshift({data: "nochange", label: watchStatus[2]});
$(currentBox.children[2].children[0]).append(inputText.$element);
watchValue = "nochange";
//Create horizontal layout
}
var hzCLayout = new OO.ui.HorizontalLayout();
let watchlistLayout = new OO.ui.HorizontalLayout();
//Toggle answer button
varlet answerCBwatchlistDropdown = new OO.ui.CheckboxInputWidgetDropdownInputWidget({selected: true});
value: watchValue,
//Done button
options: watchOptions,
var doneCB = new OO.ui.ButtonWidget( {
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"});
//Submit Button
let submitButton = new OO.ui.ButtonWidget({
icon: "checkAll",
flags: ["primary", "progressive"],
label: "DoneSubmit",
title: "MarkSubmit asthe doneresponse",
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]);
doneCB.on("click", function() {
}
if (doneCB.getLabel() == "Submit") {
 
for (var k = 0; k < COIResponse.length; k++) {
function previewCOI(responseOption, responseText, tableCell) {
if (COIResponse[k][3] == dropMenu.getLabel()) {
let restTransform = "https://en.wikipedia.org/api/rest_v1/transform/wikitext/to/html/" + encodeURI(mw.config.get("wgPageName"));
executeCOI(currentBox, k, inputText, answerCB.selected);
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;
executeCOI(currentBox, 1, inputText, answerCB.selected);
}});
});
//Create label box & remove quick actions
hzCLayout.addItems([doneCB]);
requestBox[1].innerHTML = "";
//Go ahead button
requestBox[3].remove();
var gaB = new OO.ui.ButtonWidget( {
let statusMessage = new OO.ui.MessageWidget({
icon: "edit",
labelicon: "Go ahead"'pageSettings',
type: 'notice',
title: "Approve to make change themselves"
label: 'Processing request — Edit request starting, getting section data to edit.'
});
statusMessage.$element[0].style = "margin:5px 0; max-width:50em";
hzCLayout.addItems([gaB]);
$(requestBox[1]).append(statusMessage.$element);
gaB.on("click", function() {
//Create progress bar
executeCOI(currentBox, 5, inputText, answerCB.selected);
let progressBar = new OO.ui.ProgressBarWidget({
progress: false
});
$(requestBox[1]).append(progressBar.$element);
//Consensus button
//Set preview for output
var conB = new OO.ui.ButtonWidget( {
previewCOI(responseOption, responseText, requestBox[2]);
icon: "userGroup",
// Find header
label: "WP:Consensus",
let header = "";
title: "Change needs consensus"
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;
hzCLayout.addItems([conB]);
do {
conB.on("click", function() {
tempElement = tempElement.previousElementSibling;
executeCOI(currentBox, 9, inputText, answerCB.selected);
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["*"];
//Responses button
let latestRevision = wikitextQuery.parse.revid;
var respondCB = new OO.ui.ButtonWidget( {
if (responseOption.parameter != "") {
icon: "add",
let template = "{{Edit COI|" + responseOption.parameter + "}}";
label: "More",
wikitext = wikitext.replace(/{{ *(Edit[ _])?COI(-protected|([ _](edit|request)){1,2})?( *\| *([=A-Z])*)* *}}/i, template);
title: "Extra reply options"
});
if (responseOption.response != "") {
hzCLayout.addItems([respondCB]);
wikitext += "\n:{{subst:ECOI|" + responseOption.response + "}}";
respondCB.on("click", function() {
wikitext += responseText.replaceAll(/\s*~~~~\s*/g, "") + " ~~~~";
if (currentBox.children[2].style.display == "") {
}
respondCB.setIcon("add");
if (responseOption.label == "Remove") {
respondCB.setLabel("More");
wikitext = "";
currentBox.children[2].style = "display:none";
editSummary = editSummary.replace(/[^]+\*\/ /, "");
doneCB.setLabel("Done");
}
doneCB.setTitle("Mark as done");
statusMessage.setType("success");
} else {
statusMessage.setLabel("Processing request — Saving changes to the talk page.");
respondCB.setIcon("subtract");
if (latestRevision != mw.config.values.wgRevisionId) {
respondCB.setLabel("Less");
await new Promise(function(resolve) {
currentBox.children[2].style = "";
OO.ui.confirm("There has been a new revision to the page, do you wish to continue?").done(function(confirmed) { if (confirmed) {
doneCB.setLabel("Submit");
resolve();
doneCB.setTitle("Submit response");
} else {
return;
}});
});
}
if (watchPage) {
if (watchPage != "nochange") {
watchPage = "watch";
}
}); else {
watchPage = "unwatch";
hzCLayout.addItems([answerCB, new OO.ui.LabelWidget({label: "Close"})]);
}
//Create first row fieldset
let apiParams = {
var fieldsetC = new OO.ui.FieldsetLayout();
action: 'edit',
// Add an horizontal field layout
title: mw.config.get("wgPageName"),
fieldsetC.addItems([
text: wikitext,
new OO.ui.FieldLayout(
section: sectionIndex,
new OO.ui.Widget({
summary: editSummary,
content: [hzCLayout]
watchlist: watchPage
}),
};
)
if (watchPage == "watch") {
]);
apiParams.watchlistexpiry = watchValue;
$(firstRowC).append(fieldsetC.$element);
}
//Close request
let reloadURL = "/w/index.php?title=" + encodeURI(mw.config.get("wgPageName")) + "&type=revision&diff=cur&oldid=prev";
var closeB = new OO.ui.ButtonWidget( {
new mw.Api().postWithEditToken(apiParams).done(function () {
icon: "unFlag",
window.___location = reloadURL;
invisibleLabel: true,
title: "Mark as answered"
});
closeB.$element[0].style = "margin:10px 10px 0px";
$(currentBox.children[0].children[0]).append(closeB.$element);
closeB.on("click", function() {
executeCOI(currentBox, "CLOSEREQ", "", answerCB.selected)
});
//Remove request
var removeB = new OO.ui.ButtonWidget( {
icon: "trash",
flags: ["primary", "destructive"],
invisibleLabel: true,
title: "Remove entire section!"
});
removeB.$element[0].style = "margin:10px";
$(currentBox.children[0].children[0]).append(removeB.$element);
removeB.on("click", function() {
executeCOI(currentBox, "REMOVE", "", answerCB.selected);
});
}
 
function addReplyButtonApiGetCOI(currentBox, boxTypeparams) {
return new Promise(function(resolve) {
var replyB = new OO.ui.ButtonWidget( {
new mw.Api().get(params)
icon: "edit",
.done(function (data) {resolve(data);})
flags: "progressive",
.fail(function (data) {console.error(data);});
invisibleLabel: true
});
replyB.$element[0].style = "margin:5px 0px";
$(currentBox.children[0].children[0]).append(replyB.$element);
replyB.on("click", function() {
currentBox.parentElement.setAttribute("class", "plainlinks tmbox tmbox-notice editrequest");
var img = currentBox.children[0].children[0].children[0]
img.width = 53;
img.height = 53;
img.src = "//upload.wikimedia.org/wikipedia/commons/f/f4/Info_talk.png"
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);
});
}
 
var COIRequestBoxes = document.getElementsByClassName("plainlinks tmbox tmbox-notice editrequest");
if (COIRequestBoxes) {
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-user", "oojs-ui.styles.icons-editing-core"]);
for (var i = 0; i < COIRequestBoxes.length; i++) {
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
if (edReqCheck.innerText.search("The requested edits backlog is") != -1) { //For unanswered boxes
loadButtons(currentBox);
} else { //For answered boxes
addReplyButton(currentBox);
}
}
}
});
}