Content deleted Content added
Be more accurate |
Account for {{COI edit}} |
||
(9 intermediate revisions by the same user not shown) | |||
Line 9:
];
var responseCOI = [
{label: "Done", title: "Mark request as done", summary: "Marked COI request as done", parameter: "answered=yes", response: "d", icon: "checkAll", flags: ["primary", "progressive"], text: "Done
{label: "Partly done", title: "Mark request as partly done", summary: "Marked COI request as partly done", parameter: "P", response: "pd", icon: "check", flags: "", text: "Partly done:"},
{label: "Already done", title: "Mark request as already done", summary: "Marked COI request as already done", parameter: "answered=yes", response: "a", icon: "clock", flags: "", text: "Already done:"},
Line 29:
{label: "Undo", title: "Undo request", summary: "COI request has been undone", parameter: "D|The requested edit has been undone", response: "ud", icon: "undo", flags: "", text: "Undone: This request has been undone."}
];
var editRequests = $('.editrequest');
var COIRequests = [];
Line 38 ⟶ 37:
}
}
if (COIRequests.length > 0) {
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-editing-core", "oojs-ui.styles.icons-editing-advanced", "oojs-ui.styles.icons-user"]);
loadCOITool();
});
}
async function loadCOITool() {
// Get page watchers, visitors and user watch status.
let watchStatus = [];
let watchQuery = await ApiGetCOI({
action: "query",
prop: "info",
pageids: mw.config.get("wgArticleId"),
inprop: "watchers|visitingwatchers|watched",
format: "json"
});
let watchData = watchQuery.query.pages[mw.config.get("wgArticleId")];
let watched = watchData.watched;
let expiry = watchData.watchlistexpiry;
if (expiry) {
watched = Math.ceil((new Date(expiry).getTime() - Date.now()) / 1000 / 60 / 60 / 24) + " days";
}
if (watched == undefined && typeof(autoWatchRequests) != "undefined" && autoWatchRequests == true) {
watched = '';
}
watchStatus.push(watchData.watchers || "less than 30", watchData.visitingwatchers || "<30", watched);
//Increment through all COI requests & add respond button
for (let i = 0; i < COIRequests.length; i++) {
let respondButton = new OO.ui.ButtonWidget({
icon: "edit",
label: "Respond",
flags: "progressive",
title: "Open the response menu for this request"
}).on("click", function() {
loadCOIResponse(COIRequests[i], respondButton, watchStatus);
respondButton.setDisabled(true);
});
respondButton.$element[0].style = "margin:5px";
$($('.response-cell')[i]).append(respondButton.$element);
}
}
function loadCOIResponse(COIRequest, respondButton, watchStatus) {
let responseBoxHTML = '<table class="response-box" style="border:1px solid #A2A9B1; border-radius:2px; padding:10px 16px 0; margin:auto; max-width:55em; width:100%; clear:both;"><tr><td><div style="font-style:italic; margin-left:1em;">There are currently ' + watchStatus[0] + ' users watching this page (' + watchStatus[1] + ' have viewed recent edits).</div><div>Quick options:</div></td></tr><tr style="display: flex; justify-content: center;"><td class="response-quick"></td></tr><tr><td>Custom response:</td></tr><tr style="text-align:center;"><td class="response-custom"></td></tr><tr style="background:#F6F6F6;"><td class="response-preview" style="display:none;"><div>Preview:</div><div></div></td></tr><tr style="display: flex; justify-content: right;"><td class="response-controls"></td></tr></table>';
$(responseBoxHTML).insertAfter(COIRequest, respondButton);
let responseBox = COIRequest.nextElementSibling;
Line 104 ⟶ 109:
invisibleLabel: true
}).on("click", function () {
});
quickLayout.addItems([tempButton]);
Line 116 ⟶ 121:
title: responseCOI[tempVal].title
}).on("click", function () {
});
quickLayout.addItems([tempButton]);
Line 123 ⟶ 128:
//Response dropdown
let responseDropdown = new OO.ui.DropdownWidget({
for (let i = 0; i < responseCOI.length; i++) {
let tempWidget = new OO.ui.MenuOptionWidget({
Line 144 ⟶ 149:
}).on("change", function () {
if (responseDropdown.menu.findSelectedItem()) {
}
responseText.$element[0].style = "margin:5px auto;";
$(responseCustom).append(responseText.$element);
Line 175 ⟶ 180:
}
let watchlistLayout = new OO.ui.HorizontalLayout();
value: watchValue,
watchlistLayout.addItems([watchlistDropdown]);
//Watchlist checkbox & label
Line 187 ⟶ 192:
watchlistDropdown.setDisabled(!newStatus);
});
let watchlistLabel = new OO.ui.LabelWidget({label: "Watch this page"})
//Submit Button
let submitButton = new OO.ui.ButtonWidget({
Line 198 ⟶ 201:
disabled: true
}).on("click", function () {
});
controlsLayout.addItems([cancelButton, watchlistCheckbox, watchlistLabel, watchlistLayout, submitButton]);
}
function
let restTransform = "https://en.wikipedia.org/api/rest_v1/transform/wikitext/to/html/" + encodeURI(mw.config.get("wgPageName"));
if (responseOption.response != "") {
Line 211 ⟶ 214:
let nickname = " " + mw.user.options.values.nickname;
if (nickname == " ") {//Create default signature if no nickname
}
let dateObj = new Date();
responseText = responseText + nickname + " " + timeNow + ", " + dateNow + " (UTC)";
responseText = responseText.replaceAll(/{{subst:/gi, "{{");
responseText = responseText.replaceAll(/\s*~~~~\s*/g, "");
$.post(restTransform, 'wikitext=' + encodeURIComponent(responseText) + '&body_only=true',
}
);
} else {
}
}
async function
await new Promise(function(resolve) {
OO.ui.confirm("Confirm in order to reply to this edit request.").done(function(confirmed) { if (confirmed) { resolve();
} else {
return;
}});
});
//Create label box & remove quick actions
requestBox[1].innerHTML = "";
requestBox[3].remove();
icon: 'pageSettings',
type: 'notice',
label: 'Processing request — Edit request starting, getting section data to edit.'
});
statusMessage.$element[0].style = "margin:5px 0; max-width:50em";
//Create progress bar
let progressBar = new OO.ui.ProgressBarWidget({
progress: false
});
//Set preview for output
previewCOI(responseOption, responseText, requestBox[2]);
// Find header
let header = "";
let sectionIndex = 0;
let tempElement = requestBox[0];
let sectionQuery = await ApiGetCOI({
action: "parse",
page: mw.config.get("wgPageName"),
});
let sections = sectionQuery.parse.sections;
do {
tempElement = tempElement.previousElementSibling;
if (tempElement.classList.contains("mw-heading")) {
if (tempElement.parentElement.tagName == "SECTION") { //Need to support both while new parser is being implemented
header = $(tempElement).find("h1,h2,h3,h4,h5,h6")[0].id;
sectionIndex = parseInt(tempElement.parentElement.dataset.mwSectionId);
} else {
if (tempElement.getElementsByClassName("mw-headline").length > 0) { //Vector 2022
header = tempElement.getElementsByClassName("mw-headline")[0].id;
} else { //Vector Legacy
header = $(tempElement).find("h1,h2,h3,h4,h5,h6")[0].id;
}
for (let i = 0; i < sections.length; i++) {
if (sections[i].anchor == header) {
sectionIndex = parseInt(sections[i].index);
}
}
}
}
}
while (header == "");
statusMessage.setLabel("Processing request — Making changes to the edit request");
let editSummary = "/* " + header.replaceAll("_", " ") + " */ " + responseOption.summary + " ([[User:Terasail/COI_Request_Tool|COI Request Tool]])";
let wikitextQuery = await ApiGetCOI({
action: "parse",
page: mw.config.get("wgPageName"),
section: sectionIndex,
prop: "wikitext|revid"
});
let wikitext = wikitextQuery.parse.wikitext["*"];
let latestRevision = wikitextQuery.parse.revid;
if (responseOption.parameter != "") {
let template = "{{Edit COI|" + responseOption.parameter + "}}";
wikitext = wikitext.replace(/{{ *(Edit[ _])?COI(-protected|([ _](edit|request)){1,2})?( *\| *([=A-Z])*)* *}}/i, template);
}
if (responseOption.response != "") {
wikitext += "\n:{{subst:ECOI|" + responseOption.response + "}}";
wikitext += responseText.replaceAll(/\s*~~~~\s*/g, "") + " ~~~~";
}
if (responseOption.label == "Remove") {
wikitext = "";
editSummary = editSummary.replace(/[^]+\*\/ /, "");
}
statusMessage.setType("success");
statusMessage.setLabel("Processing request — Saving changes to the talk page.");
if (latestRevision != mw.config.values.wgRevisionId) {
await new Promise(function(resolve) {
OO.ui.confirm("There has been a new revision to the page, do you wish to continue?").done(function(confirmed) { if (confirmed) {
resolve();
} else {
return;
}});
});
}
if (watchPage) {
if (
watchPage = "watch";
}
Line 326 ⟶ 336:
}
let apiParams = {
}
new
}
function ApiGetCOI(params) {
return new Promise(function(resolve) {
new mw.Api().get(params)
.done(function (data) {resolve(data);})
.fail(function (data) {console.error(data);});
});
}
//</nowiki>[[Category:Wikipedia scripts]]
|