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

Content deleted Content added
Fix close template error
Casual overhaul of script...
Line 1:
//<nowiki>
var COIResponsereplyCOIT = [{
["ntmpClose",: ["speechBubbleAdd", "CommentClose", "CommentClosed (Noedit template)request", "|A"],
["dRemove",: ["checkAll", "DoneRemove", "DoneRemoved edit request", "|A"],
["pdComment (No template)",: ["check", "Partly donespeechBubbleAdd", "Partly done:Comment", "|P"],
["aDone:",: ["clockd", "Already DonecheckAll", "Already Done", "|A"],
["qPartly done:",: ["helpNoticepd", "Questioncheck", "Question:Partly done", "|P"],
"Already Done:": ["a", "clock", "Already Done", "|A"],
["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:": ["note", "ellipsis", "Note", "Note:", ""],
["nQuestion:",: ["noticeq", "Not donehelpNotice", "Not done:Question", "|D"],
"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"],
["nfn", "notice", "Not done for now", "Not done for now:", "|D"],
"Not done:": ["n", "notice", "Not done", "|D"],
["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"],
"Not done for now:": ["nfn", "notice", "Not done for now", "|D"],
["udp","undo", "Partly undone", "Undone: This request has been partially undone.", "|D|The requested edit has been partially undone"],
"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"],
["ud", "undo", "Undone", "Undone: This request has been undone.", "|D|The requested edit has been undone"]];
"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"],
 
"Undone: This request has been partially undone.": ["udp","undo", "Partly undone", "|D|The requested edit has been partially undone"],
function executeCOI(currentBox, selectedReply, inputText, answered) {
"Undone: This request has been undone.": ["ud", "undo", "Undone", "|D|The requested edit has been undone"]
};
var COIResponse = [];
//selectedReply
function executeCOI(currentBox, replyOption, inputText, answered) {
OO.ui.confirm("Confirm in order to reply to this edit request.").done(function(confirmed) {
if (confirmed) {
Line 48 ⟶ 53:
action: "parse",
page: mw.config.values.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 sectionNum = -1;
var offset = 0;
Line 63 ⟶ 69:
}
}
offset = sections[sectionNum - 1].byteoffset;
infoBox.setLabel("Processing request — Getting information from section: " + sectionNum + ".");
wikitext = wikitext.slice(offset);
api.get( {
if (sectionNum < sections.length) {
action: "parse",
offset = sections[sectionNum].byteoffset - offset;
page: mw.config.values.wgPageName,
prop:wikitext = "wikitext".slice(0, offset);
}
section: sectionNum
var templateR = replyOption[3];
}).done( function(data) {
var tempType = "{{request edit";
infoBox.setLabel("Processing request — Making changes to the edit request.");
var wikitextwikitextU = datawikitext.parse.wikitext["*"]toUpperCase();
var tempStrtemplateS = wikitextU.indexOf("{{REQ");
if (selectedReplytemplateS == "CLOSEREQ"-1) {
tempStrtemplateS = wikitextU.indexOf("|A{{EDIT");
} else {
if (templateS == -1) {
tempStr = COIResponse[selectedReply][4];
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) {
var tempType = "{{request edit";
wikitext = wikitext.slice(0, templateS) + "{{Request edit" + templateR + "}}" + wikitext.slice(templateE);
var upperWT = wikitext.toUpperCase();
var templateLoc = upperWT.indexOf("{{REQ");
if (templateLoc == -1) {
templateLoc = upperWT.indexOf("{{EDIT");
}
var editSummary = "/* " + header.replaceAll("_", " ") + " */ " + replyOption[2] + " ([[User:Terasail/COI_Request_Tool|COI Request Tool]])";
if (templateLoc == -1) {
if (replyOption[1] != "Close") {
templateLoc = upperWT.indexOf("{{COI");
wikitext = wikitext.trim() + "\n:";
}
if (templateLocreplyOption[0] =!= -1"") {
wikitext += "{{subst:ECOI|" + replyOption[0] + "}}";
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 editSummaryinputText = "/* " + headerinputText.replaceAll("_~~~~", " ") + " */ ";
if (selectedReplywikitext =+= "REMOVE ") {+ inputText;
wikitext = wikitext.trim() + " ~~~~";
if (replyOption[1] == "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)");
}
}
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',
Line 130 ⟶ 119:
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";
});
}
});
});
}
Line 140 ⟶ 129:
 
function loadButtons(currentBox) {
var replyListC = Object.entries(replyCOIT);
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"]];
$(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>');
var firstRowC = currentBox.children[1].children[0].children[0];
Line 147 ⟶ 138:
menu: {items: []}
});
for (var count = 2; count < replyListC.length; count++) {
COIResponse.forEach(function(item) {
var newOption = new OO.ui.MenuOptionWidget({
label: itemreplyListC[3count][0],
icon: itemreplyListC[count][1][1]
});
dropMenu.menu.addItems(newOption);
});
dropMenu.$element[0].style = "text-align:left; margin:0px";
$(currentBox.children[2].children[0]).append(dropMenu.$element);
Line 173 ⟶ 164:
doneCB.on("click", function() {
if (doneCB.getLabel() == "Submit") {
executeCOI(currentBox, replyCOIT[dropMenu.getLabel()], inputText.value, answerCB.selected);
for (var k = 0; k < COIResponse.length; k++) {
if (COIResponse[k][3] == dropMenu.getLabel()) {
executeCOI(currentBox, k, inputText, answerCB.selected);
}
}
} else {
executeCOI(currentBox, replyListC[3][1], inputText.value, answerCB.selected);
}
});
hzCLayout.addItems([doneCB]);
//GoQuick aheadaccess buttonbuttons
mainResponseC.forEach(function(item) {
var gaB = new OO.ui.ButtonWidget( {
item[3] = new OO.ui.ButtonWidget({
icon: "edit",
label: "Go ahead"item[1],
title: item[2]
title: "Approve to make change themselves"
});
item[3].on("click", function() {
hzCLayout.addItems([gaB]);
executeCOI(currentBox, item[0], "", answerCB.selected);
gaB.on("click", function() {
});
executeCOI(currentBox, 5, inputText, answerCB.selected);
hzCLayout.addItems([item[3]]);
});
//Consensus button
var conB = new OO.ui.ButtonWidget( {
icon: "userGroup",
label: "WP:Consensus",
title: "Change needs consensus"
});
hzCLayout.addItems([conB]);
conB.on("click", function() {
executeCOI(currentBox, 9, inputText, answerCB.selected);
});
//Responses button
Line 246 ⟶ 224:
$(currentBox.children[0].children[0]).append(closeB.$element);
closeB.on("click", function() {
executeCOI(currentBox, "CLOSEREQ"replyCOIT.Close, "", answerCB.selectedtrue)
});
//Remove request
Line 256 ⟶ 234:
});
removeB.$element[0].style = "margin:10px";
$(currentBox.children[0].children[0]).append(removeB.$element);
removeB.on("click", function() {
executeCOI(currentBox, "REMOVE"replyCOIT.Remove, "", answerCB.selectedfalse);
});
$(currentBox.children[0].children[0]).append(removeB.$element);
}