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

Content deleted Content added
Fix template edit request targets & Don't link to edit request when removing request.
Update from test version - Fix answered checkbox not working & cropping error
Line 35:
"Undone: This request has been undone.": ["ud", "undo", "Undone"]
};
 
function postEdit(wikitext, editSummary, pageName, secIdx) {
api.postWithEditToken({
action: 'edit',
title: pageName,
text: wikitext,
section: sectionIndx[0]secIdx,
summary: editSummary
}).done(function(result) {
window.___location = "https" + "://en.wikipedia.org/w/index.php?title=" + mw.config.values.wgPageNamepageName + "&type=revision&diff=cur&oldid=prev";
});
}
 
function execute(currentBox, replyOption, inputText, answered, boxType, targets) {
Line 71 ⟶ 83:
}
while (header == "");
var pagenamepageName = mw.config.values.wgPageName;
var api = new mw.Api();
api.get( {
action: "parse",
page: pagenamepageName,
prop: "sections|wikitext|revid"
}).done(function(data) {
infoBox.setLabel("Processing request — Making changes to the edit request");
boxType = replyERT[boxType];
var editTemplate = "{{Edit " + boxType[1] + "-protected|answered=";
if (answered) { answered = "yes"; } else { answered = "no"; }
editTemplate += "yes";
} else {
answered += "no";
}
for (var c3 = 0; c3 < targets.length; c3++) {
editTemplate += "|" + targets[c3];
}
editTemplate += "yes|answered=" + answered;
var sections = data.parse.sections;
var wikitext = data.parse.wikitext["*"];
var sectionIndxnewRev = [-1, -1, -1]data.parse.revid;
var secIndx = -1, endIndx = -1;
for (var j = 0; j < sections.length; j++) {
var tempSec = sections[j];
if (tempSec.anchor == header && !isNaN(Number(tempSec.index))) {
sectionIndx[1]secIndx = tempSec.number;
sectionIndxif (sections[0j+1]) { endIndx = tempSec.indexj; }
} else if (tempSec.number.indexOf(sectionIndx[1]secIndx.number + ".") == 0) {
sectionIndx[2] = sectionIndx[0];
if (sections[j+1]) { endIndx = j; } else { endIndx = -1; }
} else if (tempSec.number.indexOf(sectionIndx[1]) == 0) {
sectionIndx[2] = tempSec.index;
}
}
if (endIndx == -1) {
var offset = sections[sectionIndx[0] - 1].byteoffset;
offset endIndx = wikitext.indexOf("==", offset)length;
if (sectionIndx[2] < sections.length) {
wikitext = wikitext.slice(offset, sections[sectionIndx[2]].byteoffset);
} else {
wikitextendIndx = wikitext.slicelastIndexOf(offset"==", wikitextsections[endIndx + 1].lengthbyteoffset + 5);
}
wikitext = wikitext.slice(offsetwikitext.indexOf("==", sections[sectionIndx[2]]secIndx.byteoffset - 5), endIndx);
secIndx = secIndx.index;
wikitext = wikitext.replace(/{{ *([SETFI]PER|Edit[ -]?[A-Z]+[ -]?Protected)\s*[^}}]*/i, editTemplate);
var editSummary = "/* " + header.replaceAll("_", " ") + " */ " + replyOption[2] + " ([[User:Terasail/Edit_Request_Tool|Edit Request Tool]])";
Line 128 ⟶ 137:
infoBox.setType("success");
infoBox.setLabel("Processing '" + replyOption[2] + "' request — Saving changes to the talk page.");
title:if (newRev == mw.config.values.wgPageName,wgRevisionId) {
api.postWithEditToken({
postEdit(wikitext, editSummary, pageName, secIndx);
action: 'edit',
} else {
title: mw.config.values.wgPageName,
OO.ui.confirm("There has been a new revision to the page, do you wish to continue?").done(function(revCon) {
text: wikitext,
if (revCon) { postEdit(wikitext, editSummary, pageName, secIndx); }
section: sectionIndx[0],
});
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";
});
});
}