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

Content deleted Content added
Make pageName variable unique
Add option to control watchlist. (I wonder what I broke).
Line 3:
var editRequestBoxes = document.getElementsByClassName("plainlinks tmbox tmbox-notice editrequest");
var pageWatchers = "There are currently ";
var watchStatus;
var api = new mw.Api();
var pageNameERT = mw.config.values.wgPageName;
var encodePageName = encodeURIComponent(pageNameERT);
 
function postEdit(wikitext, editSummary, secIndx, changeWatch, watchlist) {
let apiParams = {
api.postWithEditToken({
action: 'edit',
title: pageNameERT,
text: wikitext,
section: secIndx,
summary: editSummary,
watchlist: changeWatch
}).done(function(result) {
};
if (changeWatch == "watch") {
apiParams.watchlistexpiry = watchlist;
}
api.postWithEditToken(apiParams).done(function(result) {
window.___location = "/w/index.php?title=" + encodePageName + "&type=revision&diff=cur&oldid=prev";
});
}
 
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 99 ⟶ 105:
infoBox.setLabel("Processing request — Saving changes to the talk page.");
if (newRev == mw.config.values.wgRevisionId) {
postEdit(wikitext, editSummary, secIndx, changeWatch, watchlist);
} else {
OO.ui.confirm("There has been a new revision to the page, do you wish to continue?").done(function(revCon) {
if (revCon) { postEdit(wikitext, editSummary, secIndx, changeWatch, watchlist); }
});
}
Line 115 ⟶ 121:
boxType = boxType.replace("full", "fully");
let tableElem = currentBox.parentElement;
$('<table style="border:1px solid #A2A9B1; border-radius:2px; padding:12px 16px; margin:auto; max-width:55em; clear:both;"><tr><td style="color:#808080"><div style="font-style:italic; margin-left:1em;">' + pageWatchers + '</div><div>Quick options:</div></td></tr><tr style="display: flex; justify-content: center;"><td></td></tr><tr><td style="color:#808080">Custom response:</td></tr><tr style="text-align:center;"><td></td></tr><tr style="background:#F6F6F6;"><td style="display:none;"><div style="color:#808080">Preview:</div><div></div></td></tr><tr style="margin-top:5px; display: flex; justify-content: right;"><td></td></tr></table>').insertAfter(tableElem);
let responseTable = tableElem.nextElementSibling.children[0];
let firstRow = responseTable.children[1].children[0];
Line 207 ⟶ 213:
});
remove.on("click", function() {
execute(responseTable, dataERT, nonResponses.Remove, "", null, typeChange.defaultValue, targetPages.getValue(), "nochange", "");
});
hzLayoutT.addItems([remove]);
Line 218 ⟶ 224:
});
closeB.on("click", function() {
execute(responseTable, dataERT, nonResponses.Close, "", true, typeChange.defaultValue, targetPages.getValue(), "nochange", "");
});
hzLayoutT.addItems([closeB]);
Line 228 ⟶ 234:
});
openB.on("click", function() {
execute(responseTable, dataERT, nonResponses.Open, "", false, typeChange.defaultValue, targetPages.getValue(), "nochange", "");
});
hzLayoutT.addItems([openB]);
Line 240 ⟶ 246:
});
newButton.on("click", function() {
execute(responseTable, dataERT, responses[quickResponses[i][0]], "", toggleAns.selected, typeChange.defaultValue, targetPages.getValue(), "nochange", "");
});
hzLayoutT.addItems([newButton]);
Line 247 ⟶ 253:
let toggleAns = new OO.ui.CheckboxInputWidget({selected: true});
hzLayoutT.addItems([toggleAns, new OO.ui.LabelWidget({label: "Answered"})]);
//Create lastrow horizontal layout
let hzLayoutB = new OO.ui.HorizontalLayout();
//hzLayoutB.$element[0].style = "display: flex;";
//Create lastrow fieldset
let fieldsetB = new OO.ui.FieldsetLayout();
fieldsetB.addItems([new OO.ui.FieldLayout(new OO.ui.Widget({content:[hzLayoutB]}))]);
$(fourthRow).append(fieldsetB.$element);
//Cancel response button
let cancelB = new OO.ui.ButtonWidget( {
Line 259 ⟶ 272:
responseTable.parentElement.remove();
});
$(fourthRow)hzLayoutB.appendaddItems([cancelB.$element]);
let isWatched = (typeof(watchStatus[0]) != "undefined");
//Watch list//Toggle answer button
let toggleWL = new OO.ui.CheckboxInputWidget({selected: isWatched});
let toggleWLLable = new OO.ui.LabelWidget({label: "Watch this page"});
toggleWL.on("change", function(newStatus) {
watchDropdown.setDisabled(!newStatus);
});
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 week", label: "1 week"}, {data: "1 month", label: "1 month"}, {data: "3 months", label: "3 months"}, {data: "6 months", label: "6 months"}];
let wlExpiry = watchStatus[1];
if (typeof(wlExpiry) != "undefined") {
let daysDif = Math.ceil((new Date(wlExpiry).getTime() - Date.now())/1000/60/60/24);
watchOptions.unshift({data: "nochange", label: daysDif + " days"});
watchValue = wlExpiry;
}
//Create WLDropdown horizontal layout
let hzLayoutWLD = new OO.ui.HorizontalLayout();
hzLayoutB.addItems([hzLayoutWLD]);
//Watchlist dropdown
let watchDropdown = new OO.ui.DropdownInputWidget( {
value: watchValue,
options: watchOptions,
disabled: !isWatched
});
hzLayoutWLD.addItems([watchDropdown]);
//Submit response button
let submitB = new OO.ui.ButtonWidget( {
Line 276 ⟶ 317:
let targets = targetPages.items;
let targetChange = false;
let wlChange = toggleWL.selected;
let wlVals = watchDropdown.value;
if (wlChange) {
wlChange = "watch";
if (wlVals == "nochange") {
wlChange = "nochange";
}
} else {
wlChange = "unwatch";
}
if (typeof(newResponse) != "undefined") {
execute(responseTable, dataERT, newResponse, newText, isAns, newType, newTargets, wlChange, wlVals);
} else if (typeChange.value != typeChange.defaultValue) {
execute(responseTable, dataERT, nonResponses.ChangeLevel, "", isAns, newType, newTargets, wlChange, wlVals);
}
if (targets.length == pageLinks.length) {
Line 289 ⟶ 341:
}
if (targetChange) {
execute(responseTable, dataERT, nonResponses.ChangeTarget, "", isAns, newType, newTargets, wlChange, wlVals);
}
});
$(fourthRow)hzLayoutB.appendaddItems([submitB.$element]);
}
 
Line 335 ⟶ 387:
prop: "info",
pageids: pageID,
inprop: "watchers|visitingwatchers|watched",
format: "json"
}).done(function(data) {
Line 341 ⟶ 393:
let watchers = data.watchers;
let visiting = data.visitingwatchers;
watchStatus = [data.watched, data.watchlistexpiry];
if (typeof(watchers) == "undefined") {
pageWatchers += "less than 30";