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

Content deleted Content added
Reduce ooui loading
Update to add user talk reply
Line 4:
var pageWatchers = "There are currently ";
var watchStatus;
var dataERT;
var commentERT;
var api = new mw.Api();
var pageNameERT = mw.config.values.wgPageName;
Line 17 ⟶ 19:
watchlist: changeWatch
};
window.___location let reloadURL = "/w/index.php?title=" + encodePageName + "&type=revision&diff=cur&oldid=prev";
if (changeWatch == "watch") {
apiParams.watchlistexpiry = watchlist;
}
if (wikitext == "") {
api.postWithEditToken(apiParams).done(function(result) {
if (typeof(commentERT) != 'undefined' && commentERT.search(/-(?=[0-9]{14}","type)/) != -1) {
window.___location = "/w/index.php?title=" + encodePageName + "&type=revision&diff=cur&oldid=prev";
OO.ui.confirm("Do you want to add an empty edit request notice to the users talk page?").done(function(confirmed) {
});
if (isSmallconfirmed) {
let commenter = commentERT.slice(commentERT.indexOf('"name"') + 10, commentERT.search(/-(?=[0-9]{14}","type)/));
let talkParams = dataERT.emptyNotice;
talkParams.title = "User talk:" + commenter;
talkParams.sectiontitle += pageNameERT;
talkParams.text = talkParams.text.replace("```", pageNameERT);
talkParams.summary = talkParams.summary.replace("```", pageNameERT);
api.postWithEditToken(apiParamstalkParams).done(function(result) {
//Do something here?
});
}
api.postWithEditToken(apiParams).done(function(result) { window.___location = reloadURL; });
});
}
} else {
api.postWithEditToken(apiParams).done(function(result) { window.___location = reloadURL; });
}
}
 
function execute(responseTable, dataERT, replyOption, inputText, answered, boxType, targets, changeWatch, watchlist) {//currentBox
OO.ui.confirm("Confirm in order to reply to this edit request.").done(function(confirmed) {
if (confirmed) {
Line 61 ⟶ 81:
action: "parse",
page: pageNameERT,
prop: "sections|wikitext|revid"
}).done(function(data) {
infoBox.setLabel("Processing request — Making changes to the edit request");
Line 71 ⟶ 91:
editTemplate += "|answered=" + answered;
let sections = data.parse.sections;
let newRev = data.parse.revid;
let secIndx = sections[0];
for (let j = 0; j < sections.length; j++) {
Line 82 ⟶ 101:
page: pageNameERT,
section: secIndx,
prop: "wikitext|revid"
}).done(function(data) {
let wikitext = data.parse.wikitext["*"];
let newRev = data.parse.revid;
wikitext = wikitext.replace(/{{ *([SETFI]PER|Edit([ -]?[A-Z]+[ -]?|[- ])Protected)\s*[^}}]*/i, editTemplate);
let editSummary = "/* " + header.replaceAll("_", " ") + " */ " + replyOption[2] + " ([[User:Terasail/Edit_Request_Tool|Edit Request Tool]])";
Line 93 ⟶ 113:
wikitext += "~~~~";
if (replyOption[1] == "Remove") {
commentERT = document.getElementById(header).dataset.mwComment;
wikitext = "";
editSummary = editSummary.replace(/[^]+\*\/ /, "");
Line 112 ⟶ 133:
}
 
function addButtons(currentBox, dataERT, replyButton) {
let boxType = currentBox.parentElement.dataset.origlevel;
boxType = boxType.replace("full", "fully");
Line 277 ⟶ 298:
toggleWLLable.$element[0].style = "white-space: nowrap;";
hzLayoutB.addItems([toggleWL, toggleWLLable]);
tst = toggleWLLable.$element[0];
let watchValue = "never";
let watchOptions = [{data: "never", 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"}];
Line 364 ⟶ 384:
let timeNow = dateObj.toLocaleTimeString('en-GB', { timeZone: 'UTC', hour: '2-digit', minute: '2-digit' });
preview += nickname + " " + timeNow + ", " + dateNow + " (UTC)";
preview = preview.replaceAll(/{{subst:/gi, "{{");
$.post(restTransform, 'wikitext=' + encodeURIComponent(preview) + '&body_only=true',
function(html) {
if (inputText.value != "" || typeof(replyOption) != "undefined") {//Stops preview appearing with empty input box
tableRow.style = "padding:8px 1em; 2px;";
tableRow.children[1].innerHTML = html;
}
Line 404 ⟶ 425:
});
var jsonERTURL = "https://en.wikipedia.org/w/index.php?title=User:Terasail/Edit_Request_Tool.json&action=raw&ctype=text/json";
$.getJSON(jsonERTURL, function(dataERTnewData) {
dataERT = newData;
mw.loader.using(["oojs-ui-core", "oojs-ui-widgets", "oojs-ui-windows"]).done(function() {
mw.loader.load(["oojs-ui-core", "oojs-ui-widgets", "oojs-ui-windows"]);
mw.loader.load(["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 (let i = 0; i < editRequestBoxes.length; i++) {
let currentBox = editRequestBoxes[i].children[0]; //The tbody tag for the box
if (typeof(currentBox.parentElement.dataset.origlevel) != "undefined") {
let isSmall = false;
let isSmall = false;
if (editRequestBoxes[i].id == "") {
isSmall = true;
}
let replyButton = new OO.ui.ButtonWidget( {
icon: "edit",
flags: ["progressive"],
label: "Respond",
invisibleLabel: isSmall,
title: "Respond to the edit request."
});
replyButton.on("click", function() {
addButtons(currentBox, dataERT, replyButton);
replyButton.setDisabled(true);
});
replyButton.$element[0].style = "margin:2px 0";
if (isSmall) {
$(currentBox.children[0].children[0]).append(replyButton.$element);
} else {
$(currentBox).append('<tr><td colspan=2><div style="display: flex; justify-content: center;"></div></td></tr>');
$(currentBox.children[1].children[0].children[0]).append(replyButton.$element);
}
}
}
let replyButton = new OO.ui.ButtonWidget( {
});
icon: "edit",
});
flags: ["progressive"],
label: "Respond",
invisibleLabel: isSmall,
title: "Respond to the edit request."
});
replyButton.on("click", function() {
addButtons(currentBox, dataERT, replyButton);
replyButton.setDisabled(true);
});
replyButton.$element[0].style = "margin:2px 0";
letif (isSmall) = false;{
$(currentBox.children[0].children[0]).append(replyButton.$element);
} else {
$(currentBox).append('<tr><td colspan=2><div style="display: flex; justify-content: center;"></div></td></tr>');
$(currentBox.children[1].children[0].children[0]).append(replyButton.$element);
}
}
}
}
//</nowiki>[[Category:Wikipedia scripts]]