Content deleted Content added
Fix regression with handling large numbers of edits by spacing them out [Factotum] |
Fix major bug where it used undefined for RFD nominations due to inocrrect format of titles object [Factotum] |
||
Line 1:
// <nowiki>
// todo: make counter inline, remove progresss and progressElement from editPAge(), more dynamic reatelimit wait.
Line 6 ⟶ 5:
// Function to wipe the text content of the page inside #bodyContent
// update normalise function for CfD - use mw.Title()
function capitalise(s) {
return s[0].toUpperCase() + s.slice(1);
Line 73:
"userNotificationTemplate": 'Rfd mass notice',
"baseDiscussionPage": 'Wikipedia:Redirects for discussion/Log/',
"normaliseFunction": (title) => { return new mw.Title(title).getPrefixedText() }
"actions":
{
Line 310:
}
function createErrorMessage(text) {
var errorMessage = new OO.ui.MessageWidget({
type: 'error',
Line 392:
const currentDate = new Date();
// now
let date2
// Parse the dates
const parseDate = (dateString) => {
Line 414:
function deepCopy(obj) {
if (obj === null || typeof obj !== 'object') {
return obj;
}
if (obj instanceof OO.ui.Element) {
return obj;
}
if (Array.isArray(obj)) {
const copy = [];
for (let i = 0; i < obj.length; i++) {
copy[i] = deepCopy(obj[i]);
}
return copy;
}
const copy = {};
for (const key in obj) {
if (obj.hasOwnProperty(key)) {
copy[key] = deepCopy(obj[key]);
}
}
return copy;
function parseHTML(html) {
Line 635:
format: 'json'
}).then(function (data) {
return data.query;
}).catch(function (error) {
console.error('Error occurred while fetching page author:', error);
Line 748:
nonredirects.push(...Object.values(data.pages).map(p => p.title))
}
})
.catch(error => {
Line 782:
const requestData = {
action: 'edit',
title: window.debuggingMode ? 'User:Qwerfjkl/sandbox/51' : localOptions.title,
summary: localOptions.summary,
format: 'json'
Line 917:
wipePageContent();
if (!window.debuggingMode) { // annoying when reloading for debugging
onbeforeunload = function () {
return "Closing this tab will cause you to lose all progress.";
};
}
elementsToDisable = [];
Line 1,068:
if (XFD === 'RFD') {
const date = discussionLinkInputField.getValue().trim().match(/^Wikipedia:Redirects for discussion\/Log\/(\d\d\d\d \w+ \d\d?)#.+$/)[1]
if (/(\| *days *= *)\d+/.test(text)) { // already has days=, update
text = text.replace(/(\| *days *= *)\d+/, '$1' + getDateDifference(date))
text = replaceOccurence(text, oldSectionName, sectionName);
} else {
text = replaceOccurence(text, oldSectionName, sectionName + '|days=' + getDateDifference(date));
}
} else text = replaceOccurence(text, oldSectionName, sectionName);
Line 1,320:
return allTitles.concat(Object.keys(obj.titles));
}, []);
if (XFD === 'RFD') {
Line 1,334:
var [redirectTargets, nonredirects] = await createRedirectTargetsList(allTitles);
// window.batches=batches
batches[0].titles =
.filter(x => !nonredirects.includes(x) .reduce((acc, curr) => {
acc[curr] = [];
▲ }, {});
console.log(batches)
if (!Object.keys(redirectTargets).length) {
Line 1,347 ⟶ 1,352:
if (nonredirects.length) {
let nonredirectsWarningMessage = createWarningMessage();
nonredirectsWarningMessage.$element.css({ 'max-height': '20em', 'overflow-y': 'auto' }) // normally shouldn't be needed
let nonRedirectsHTML = $('<div>').append($('<span>').text('The following pages were ignored because they are not redirects:'))
let $listElement = $('<ul>')
Line 1,364 ⟶ 1,369:
console.log(redirectTargets);
let fetchingAuthorsElement = createDoingElement();
fetchingAuthorsElement.setLabel('Fetching authors...')
Line 1,388 ⟶ 1,393:
return Object.keys(object).find(key => object[key] === value);
}
console.log(options);
console.log(options.titles);
if (!Array.isArray(options.titles)) {
options.titlesDict = options.titles;
Line 1,398 ⟶ 1,403:
options.titlesDict = {};
}
const fieldset = createFieldset(options.headingLabel);
bodyContent.append(fieldset.$element);
options.progressElement = createProgressElement();
fieldset.addItems([options.progressElement]);
options.ratelimitMessage = createWarningMessage();
options.ratelimitMessage.toggle(false);
fieldset.addItems([options.ratelimitMessage]);
const progressObj = createProgressBar(`(0 / ${options.titles.length}, 0 errors)`);
options.progress = progressObj.progressBar;
Line 1,415 ⟶ 1,420:
options.progress.pushPending();
fieldset.addItems([progressContainer]);
let resolvedCount = 0;
let rejectedCount = 0;
function updateCounter() {
progressContainer.setLabel(`(${resolvedCount} / ${options.titles.length}, ${rejectedCount} errors)`);
}
function updateProgress() {
const percentage = (resolvedCount + rejectedCount) / options.titles.length * 100;
options.progress.setProgress(percentage);
}
function trackPromise(promise) {
return new Promise((resolve) => {
Line 1,445 ⟶ 1,450:
});
}
const promises = [];
for (const title of options.titles) {
Line 1,454 ⟶ 1,459:
data.type = 'text';
}
if (data.id === 'rfd-notify-target') {
data.textToModify = data.textToModify.replace('${redirectTitle}', getKeyByValue(redirectTargets, new mw.Title(title).getSubjectPage().getPrefixedText()));
}
data.title = title;
console.log('Data:', data);
const promise = editPage(data);
promises.push(trackPromise(promise));
if (!window.abortEdits) await sleep(100); // space out calls - not needed if they're being rejected
await massXFDratelimitPromise; // stop if ratelimit reached (global variable)
}
await Promise.allSettled(promises);
options.progress.toggle(false);
if (window.abortEdits) {
const abortMessage = createAbortMessage();
Line 1,486 ⟶ 1,491:
}
}
const date = new Date();
Line 1,617 ⟶ 1,622:
});
}
}
|