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

Content deleted Content added
Fixed error with reopening requests
Same updates as ERT
Line 15:
 
function executeCOI(currentBox, selectedReply, inputText, answered) {
if (OO.ui.confirm("Confirm in order to reply to this edit request.").done(function(confirmed) {
if (confirmed) {
currentBox.getElementsByTagName('tr')[2].remove();
currentBox.getElementsByTagName('tr')[2].remove();
var infoBox = new OO.ui.MessageWidget( {
var infoBox = new OO.ui.MessageWidget( {
icon: 'pageSettings',
type icon: 'noticepageSettings',
type: 'notice',
label: 'Processing request — Edit request starting, getting section data to edit.'
label: 'Processing request — Edit request starting, getting section data to edit.'
});
});
var firstRow = currentBox.children[1].children[0];
var firstRowC = currentBox.children[1].children[0];
firstRow.innerHTML = "";
firstRowC.style = "padding-bottom:10px";
progressBar = new OO.ui.ProgressBarWidget( {
firstRowC.innerHTML = "";
progress: false
progressBar = new OO.ui.ProgressBarWidget( {
});
progress: false
$(firstRow).append(progressBar.$element);
});
$(firstRow).append(infoBox.$element);
$(firstRowC).append(progressBar.$element[0].style = "margin:auto");
$(firstRowC).append(infoBox.$element);
infoBox.$element[0].style = "margin:10px auto 0px; max-width:50em; text-align:left";
progressBar.$element[0].style = "margin:auto";
var header = "";
infoBox.$element[0].style = "margin:10px auto 0px; max-width:50em; text-align:left";
var curElement = currentBox.parentNode; //Table tag
var header = "";
do {
var curElement = curElementcurrentBox.previousElementSiblingparentNode; //Table tag
do {
if (curElement.getElementsByClassName("mw-headline").length == 1) {
headercurElement = curElement.getElementsByClassName("mw-headline")[0].idpreviousElementSibling;
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 (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++;
}
}
while (header == "");
infoBox.setLabel("Processing request — Getting information from section: " + sectionNum + ".");
var api = new mw.Api();
api.get( {
action: "parse",
page: mw.config.values.wgPageName,
prop: "wikitextsections",
}).done(function(data) {
section: sectionNum
infoBox.setLabel("Processing request — Making changes to the edit request");
}).done( function(data) {
var sections = data.parse.sections;
infoBox.setLabel("Processing request — Making changes to the edit request.");
var wikitextsectionNum = data.parse.wikitext["*"]-1;
var tempStroffset = ""0;
for (var j = 0; j < sections.length; j++) {
if (answered || selectedReply == "CLOSEREQ") {
if (sections[j].anchor == header) {
tempStr = "|A";
sectionNum = j + 1;
sectionNum -= offset;
}
if (sections[j].fromtitle != mw.config.values.wgPageName) {
offset++;
}
}
infoBox.setLabel("Processing request — Getting information from section: " + sectionNum + ".");
var tempType = "{{request edit";
api.get( {
if (wikitext.search(tempType) == -1) {
tempType =action: "{{Request editparse";,
page: mw.config.values.wgPageName,
}
if prop: ("wikitext.search(tempType) == -1) {",
section: sectionNum
infoBox.setLabel('Failed to find {{Request edit}} template, please report to "User talk:Terasail/COI Request Tool"');
}).done( function(data) {
infoBox.setType("error");
infoBox.setLabel("Processing request — Making changes to the edit request.");
} else {
var wikitext = data.parse.wikitext.replace(tempType, ["{{Request edit*" + tempStr)];
var editSummarytempStr = "/* " + header.replaceAll("_", " ") + " */ ";
if (answered || selectedReply == "REMOVECLOSEREQ") {
wikitexttempStr = "|A";
}
editSummary = "Removed edit request";
selectedReplyvar tempType = -1"{{request edit";
} else if (selectedReplywikitext.search(tempType) == "CLOSEREQ"-1) {
editSummarytempType += "Closed{{Request edit request";
selectedReply} = -1;
if (wikitext.search(tempType) == -1) {
infoBox.setLabel('Failed to find {{Request edit}} template, please report to "User talk:Terasail/COI Request Tool"');
infoBox.setType("error");
} else {
wikitext = wikitext.replace(tempType, "{{Request edit" + tempStr);
if (selectedReply == 0) { //Do not add response template
wikitextvar editSummary += "\n:/* " + inputTextheader.valuereplaceAll("_", " ") + " */ ";
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:{{subst:ECOI|" + COIResponse[selectedReply][0] + "}}";
if wikitext (inputText !+= "\n:") {+ inputText.value;
wikitext} +=else " " + inputText.value;{
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]])";
wikitext += " ~~~~";
if (selectedReply != -1 && infoBox.type != "error") {
editSummary += COIResponse[selectedReply][2];
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";
});
}
});
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.");
}
console.log(sectionNum);
console.log(editSummary);
console.log(wikitext);
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";
});
}
});
}
});
}
}
 
function loadButtons(currentBox) {
$(currentBox).append('<tr><td colspan=2 style="padding-bottom:10px"><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 firstRowfirstRowC = currentBox.children[1].children[0].children[0];
//Create dropdown menu
var dropMenu = new OO.ui.DropdownWidget( {
Line 142:
$(currentBox.children[2].children[0]).append(dropMenu.$element);
//Create input box
var inputText = new OO.ui.MultilineTextInputWidget({autosize: true, label: "'~~" + "~~" + "' is automatically added"});
inputText.$element[0].style = "margin:auto";
$(currentBox.children[2].children[0]).append(inputText.$element);
//Create horizontal layout
var hzCLayout = new OO.ui.HorizontalLayout();
//Toggle answer button
var answerBanswerCB = new OO.ui.ToggleButtonWidgetCheckboxInputWidget( {selected: true});
icon: "close",
label: "Close",
value: false
});
answerB.on("click", function() {
if (answerB.value == true) {
answerB.setIcon("check");
} else {
answerB.setIcon("close");
}
});
//Done button
var doneBdoneCB = new OO.ui.ButtonWidget( {
icon: "checkAll",
flags: ["primary", "progressive"],
label: "Done",
title: "Mark as done"
});
doneBdoneCB.on("click", function() {
if (doneBdoneCB.getLabel() == "Submit") {
for (var k = 0; k < COIResponse.length; k++) {
dropMenu = dropMenu.getLabel();
for if (COIResponse[k][3] == 0; k < COIResponsedropMenu.length; k++getLabel()) {
executeCOI(currentBox, k, inputText, answerCB.selected);
if (COIResponse[k][3] == dropMenu) {
executeCOI(currentBox, k, inputText, answerB.value);
}
}
} else {
executeCOI(currentBox, 1, inputText, answerBanswerCB.valueselected);
}
});
hzCLayout.addItems([doneCB]);
$(firstRow.children[0]).append(doneB.$element);
//Go ahead button
var gaB = new OO.ui.ButtonWidget( {
icon: "edit",
label: "Go ahead",
title: "Approve to make change themselves"
});
hzCLayout.addItems([gaB]);
$(firstRow.children[0]).append(gaB.$element);
gaB.on("click", function() {
executeCOI(currentBox, 5, inputText, answerBanswerCB.valueselected);
});
//Consensus button
var conB = new OO.ui.ButtonWidget( {
icon: "userGroup",
label: "WP:Consensus",
title: "Change needs consensus"
});
hzCLayout.addItems([conB]);
$(firstRow.children[0]).append(conB.$element);
conB.on("click", function() {
executeCOI(currentBox, 9, inputText, answerBanswerCB.valueselected);
});
//Responses button
var responseBrespondCB = new OO.ui.ButtonWidget( {
icon: "add",
label: "OtherMore",
title: "Extra reply options"
});
hzCLayout.addItems([respondCB]);
$(firstRow.children[0]).append(responseB.$element);
responseBrespondCB.on("click", function() {
if (currentBox.children[2].style.display == "") {
responseBrespondCB.setIcon("add");
respondCB.setLabel("More");
currentBox.children[2].style = "display:none";
doneBdoneCB.setLabel("Done");
doneCB.setTitle("Mark as done");
} else {
responseBrespondCB.setIcon("subtract");
respondCB.setLabel("Less");
currentBox.children[2].style = "";
doneBdoneCB.setLabel("Submit");
doneCB.setTitle("Submit response");
}
});
hzCLayout.addItems([answerCB, new OO.ui.LabelWidget({label: "Close"})]);
$(firstRow.children[0]).append(answerB.$element);
//Create first row fieldset
var fieldsetC = new OO.ui.FieldsetLayout();
// Add an horizontal field layout
fieldsetC.addItems([
new OO.ui.FieldLayout(
new OO.ui.Widget({
content: [hzCLayout]
}),
)
]);
$(firstRowC).append(fieldsetC.$element);
//Close request
var closeB = new OO.ui.ButtonWidget( {
icon: "unFlag",
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", "", answerBanswerCB.valueselected)
});
//Remove request
Line 227 ⟶ 237:
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", "", answerBanswerCB.valueselected);
});
}
Line 259 ⟶ 270:
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];