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

Content deleted Content added
Fix to quick reply options & reorder and fixes to replyoption list
Changes to improve section detection & var -> let
Line 34:
"Not done: page move requests should be made at Wikipedia:Requested moves.": ["m", "tableMoveColumnAfter", "Not done - Use [[WP:RM]]"],
"Not done: Please make your request for a new image to be uploaded to Files For Upload. Once the file has been properly uploaded, feel free to reactivate this request.": ["ffu", "imageLayoutFrameless", "Not done - Use [[WP:FFU]]"],
"Not done: this is the talk page for discussing improvements to the page. If possible, please make your request at the talk page for the article concerned.": ["tp", "ongoingConversation", "Not done - Misplaced"],
"Not done: this is not the right page to request additional user rights. You may reopen this request with the specific changes to be made and someone will add them for you.": ["p", "userAdd", "Not done - Use [[WP:RFPERM]]"],
"Partially undone: This request has been partially undone.": ["pud","undo", "Partly undone"],
Line 41 ⟶ 40:
 
function postEdit(wikitext, editSummary, pageName, secIdx) {
varlet api = new mw.Api();
api.postWithEditToken({
action: 'edit',
Line 57 ⟶ 56:
if (confirmed) {
//Change buttons to label box + loading bar
varlet leftOOUI = currentBox.getElementsByClassName('mbox-image')[0].getElementsByClassName('oo-ui-widget');
if (leftOOUI.length > 1) {
leftOOUI[0].remove();
Line 63 ⟶ 62:
leftOOUI[0].remove();
currentBox.children[2].remove();
varlet infoBox = new OO.ui.MessageWidget( {
icon: 'pageSettings',
type: 'notice',
label: 'Processing request — Edit request starting, getting section data to edit.'
});
varlet firstRow = currentBox.getElementsByTagName('tr')[1].children[0];
firstRow.style = "padding-bottom:10px";
firstRow.innerHTML = "";
varlet progressBar = new OO.ui.ProgressBarWidget( {
progress: false
});
Line 79 ⟶ 78:
infoBox.$element[0].style = "margin:10px auto 0px; max-width:50em";
//Find header
varlet header = "";
varlet curElement = currentBox.parentNode;
do {
curElement = curElement.previousElementSibling;
Line 88 ⟶ 87:
}
while (header == "");
varlet pageName = mw.config.values.wgPageName;
varlet api = new mw.Api();
api.get( {
action: "parse",
Line 97 ⟶ 96:
infoBox.setLabel("Processing request — Making changes to the edit request");
boxType = replyERT[boxType];
varlet editTemplate = "{{Edit " + boxType[1] + "-protected";
if (answered) { answered = "yes"; } else { answered = "no"; }
for (varlet c3 = 0; c3 < targets.length; c3++) {
editTemplate += "|" + targets[c3];
}
editTemplate += "|answered=" + answered;
varlet sections = data.parse.sections;
varlet wikitext = data.parse.wikitext["*"];
varlet newRev = data.parse.revid;
varlet secIndx = -1sections[0], endIndx = -1;
for (varlet j = 0; j < sections.length; j++) {
varlet tempSec = sections[j];
if (tempSec.anchor == header && !isNaN(Number(tempSec.index))) {
secIndx = tempSec;
if (sections[j+1]) { endIndx = j + 1; }
} else if (tempSec.number.indexOfslice(0, secIndx.number + "."length) == 0(secIndx.number)) { //Get any subsections
if (sections[j+1]) { endIndx = j; }+ else { endIndx = -1; }
}
}
if (endIndx == -1) {
endIndx = wikitext.length;
} else {
endIndx = wikitext.lastIndexOf("==", sections[endIndx + 1].byteoffset + 5);
}
wikitext = wikitext.slice(wikitext.indexOf("==", secIndx.byteoffset - 5), endIndx);
secIndx = secIndx.index;
let headings = [...wikitext.matchAll(/==[^\n]+==/g)];
endIndxheadings[headings.length] = wikitext.length;
wikitext = wikitext.slice(wikitext.indexOf("==", headings[secIndx.byteoffset - 5)1].index, headings[endIndx].index);
wikitext = wikitext.replace(/{{ *([SETFI]PER|Edit[ -]?[A-Z]+[ -]?Protected)\s*[^}}]*/i, editTemplate);
varlet editSummary = "/* " + header.replaceAll("_", " ") + " */ " + replyOption[2] + " ([[User:Terasail/Edit_Request_Tool|Edit Request Tool]])";
if (replyOption[1] != "Close") {
varlet lastMsg = wikitext.lastIndexOf("\n", wikitext.lastIndexOf("(UTC)")) + 1;
wikitext = wikitext.trim() + "\n:";
while(lastMsg == wikitext.indexOf(":", lastMsg)) {
Line 155 ⟶ 151:
 
function addButtons(currentBox) {
varlet boxType = currentBox.parentElement.dataset.origlevel;
varlet replyList = Object.entries(replyERT);
varlet mainResponse = [[replyList[rOS + 9][1], "Unclear: X-Y", "Unclear request"], [replyList[rOS + 10][1], "WP:Reliable", "Needs reliable sources"], [replyList[rOS + 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"><div style="display: flex; justify-content: center;"></div></td></tr>');
varlet firstRow = currentBox.children[1].children[0].children[0];
//Create type change dropdown
varlet typeChange = new OO.ui.DropdownInputWidget( {
value: boxType,
options: [
Line 174 ⟶ 170:
$(currentBox.children[2].children[0]).append(typeChange.$element);
//Create target page list
varlet boxLinks = currentBox.getElementsByClassName("mbox-text")[0].getElementsByClassName("external text");
varlet pageLinks = [];
if (boxLinks.length > 0) {//Open request
for(varlet c1 = 0; c1 < boxLinks.length; c1++) {
if (boxLinks[c1].parentElement.tagName == "LI" || boxLinks[c1].parentElement.tagName == "B") {
pageLinks[pageLinks.length] = boxLinks[c1].innerHTML;
Line 184 ⟶ 180:
} else {//Closed request
boxLinks = currentBox.getElementsByClassName("mbox-text")[0].getElementsByTagName("A");
for(varlet c2 = 1; c2 < boxLinks.length; c2++) {
pageLinks[pageLinks.length] = boxLinks[c2].title;
}
Line 191 ⟶ 187:
}
}
varlet targetPages = new OO.ui.TagMultiselectWidget( {
placeholder: 'Target Pages',
allowArbitrary: true,
Line 199 ⟶ 195:
$(currentBox.children[2].children[0]).append(targetPages.$element);
//Create dropdown menu
varlet dropMenu = new OO.ui.DropdownWidget( {
label: "Select reply option - Add additional text below",
menu: {items: []}
});
for (varlet count = 9; count < replyList.length; count++) {
varlet newOption = new OO.ui.MenuOptionWidget({
label: replyList[count][0],
icon: replyList[count][1][1]
Line 213 ⟶ 209:
$(currentBox.children[2].children[0]).append(dropMenu.$element);
//Create input box
varlet inputText = new OO.ui.MultilineTextInputWidget({autosize: true, label: "Automatically signed"});
inputText.$element[0].style = "margin:auto";
$(currentBox.children[2].children[0]).append(inputText.$element);
//Create top horizontal layout
varlet hzLayoutT = new OO.ui.HorizontalLayout();
//Done
varlet doneB = new OO.ui.ButtonWidget( {
icon: "checkAll",
label: "Done",
Line 232 ⟶ 228:
execute(currentBox, replyERT.Change, "", false, typeChange.value, targetPages.getValue());
}
varlet newTargets = false;
varlet targets = targetPages.items;
if (targets.length == pageLinks.length) {
for(varlet item = 0; item < targets.length; item++) {
if (targets[item].data != pageLinks[item]) { newTargets = true; }
}
Line 260 ⟶ 256:
});
//Respond
varlet respondB = new OO.ui.ButtonWidget( {
icon: "add",
label: "More",
Line 283 ⟶ 279:
hzLayoutT.addItems([respondB]);
//Toggle answer button
varlet toggleAns = new OO.ui.CheckboxInputWidget({selected: true});
hzLayoutT.addItems([toggleAns, new OO.ui.LabelWidget({label: "Answered"})]);
//Create firstrow fieldset
varlet fieldsetT = new OO.ui.FieldsetLayout();
// Add an horizontal field layout
fieldsetT.addItems( [
Line 297 ⟶ 293:
$(firstRow).append(fieldsetT.$element);
//Close request
varlet closeB = new OO.ui.ButtonWidget( {
icon: "unFlag",
invisibleLabel: true,
Line 310 ⟶ 306:
}
//Remove request
varlet remove = new OO.ui.ButtonWidget( {
icon: "trash",
flags: ["primary", "destructive"],
Line 324 ⟶ 320:
 
function addRButton(currentBox) {
varlet boxType = replyERT[currentBox.parentElement.dataset.origlevel];
varlet openB = new OO.ui.ButtonWidget( {
icon: "edit",
flags: "progressive",
Line 335 ⟶ 331:
openB.$element.remove();
currentBox.parentElement.className = "plainlinks tmbox tmbox-notice editrequest";
varlet imgSrc = boxType[0] + "-protection-shackle.svg";
varlet origImg = currentBox.getElementsByTagName("img")[0];
varlet img = origImg.outerHTML.slice(0, origImg.outerHTML.match(/\d\//).index);
img += boxType[2] + imgSrc + "/60px-" + imgSrc + '.png" height="60" width="60" style="margin-top:5px">';
origImg.outerHTML = img;
varlet mboxText = currentBox.children[0].children[1];
mboxText.style = "font-size:120%; text-align:center;";
mboxText.innerHTML = mboxText.innerHTML.replace(/ Set.*\/b>/i, '<br/>Uncheck the "answered" checkbox and use a reply option');
Line 352 ⟶ 348:
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-content", "oojs-ui.styles.icons-editing-core", "oojs-ui.styles.icons-editing-advanced"]);
for (varlet i = 0; i < editRequestBoxes.length; i++) {
varlet currentBox = editRequestBoxes[i].children[0]; //The tbody tag for the box
if (editRequestBoxes[i].id != "") {
addButtons(currentBox);