Skip to content

Commit

Permalink
better handle summary formatting in reports
Browse files Browse the repository at this point in the history
  • Loading branch information
siddharthvp committed Apr 30, 2021
1 parent 231f2bb commit f93852a
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 28 deletions.
17 changes: 16 additions & 1 deletion reports/commons.js
Expand Up @@ -178,13 +178,28 @@ async function saveWithBlacklistHandling(page, text, summary) {
});
}

/**
* Format edit summary for inclusion in a bot report
* @param {string} text
* @returns {string}
*/
function formatSummary(text) {
if (!text) { // no summary given or revdelled/suppressed summary
return '';
}
return text
.replace(/\{\{.*?\}\}/g, '<nowiki>$&</nowiki>')
.replace(/\[\[((?:Category|File|Image):.*?)\]\]/gi, '[[:$1]]');
}

module.exports = {
populateWikidataShortdescs,
normaliseShortdesc,
populateOresQualityRatings,
comparators: {promote, demote, sortAsc, sortDesc},
AfcDraftSize,
preprocessDraftForExtract,
saveWithBlacklistHandling
saveWithBlacklistHandling,
formatSummary
};

14 changes: 7 additions & 7 deletions reports/draftify-watch.js
@@ -1,11 +1,11 @@
const {bot, mwn, log, xdate, utils, emailOnError} = require('../botbase');
const TextExtractor = require('../TextExtractor')(bot);
const {bot, mwn, log, xdate, utils, emailOnError, TextExtractor} = require('../botbase');
const {formatSummary} = require('./commons');

(async () => {

await bot.getTokensAndSiteInfo();

var ts1 = new xdate().subtract(8, 'days');
var ts1 = new xdate().subtract(8, 'days');
ts1.setHours(0, 0, 0, 0);
var ts2 = new xdate().subtract(1, 'day');
ts2.setHours(0, 0, 0, 0);
Expand Down Expand Up @@ -142,13 +142,13 @@ const TextExtractor = require('../TextExtractor')(bot);
`[[${page}]] <small>(moved from [[${data.source}]])</small>`,
`<small>${data.excerpt || ''}</small>`,
`[[User:${data.user}|${user}]]`,
`<small>${data.comment || ''}</small>`,
`<small>${formatSummary(data.comment)}</small>`,
]);
}

let text = `{{/header|count=${Object.keys(tableInfo).length}|date1=${ts1.format('D MMMM YYYY')}|date2=${ts2.format('D MMMM YYYY')}|ts=~~~~~}}<includeonly><section begin=lastupdate />${new bot.date().toISOString()}<section end=lastupdate /></includeonly>` +
`\n\n` + TextExtractor.finalSanitise(maintable.getText()) +
`\n\n==Moved back or deleted==` +
`\n\n` + TextExtractor.finalSanitise(maintable.getText()) +
`\n\n==Moved back or deleted==` +
`\n` + TextExtractor.finalSanitise(footertable.getText());

await bot.save('User:SDZeroBot/Draftify Watch', text, 'Updating report');
Expand Down
24 changes: 12 additions & 12 deletions reports/prod-watch.js
@@ -1,4 +1,5 @@
const {bot, log, xdate, mwn, emailOnError} = require('../botbase');
const {formatSummary} = require('./commons');

(async function() {

Expand All @@ -9,8 +10,8 @@ const {bot, log, xdate, mwn, emailOnError} = require('../botbase');
return `[[User:${user}|${user}]]`;
}

var small = function(comment) {
return `<small>${comment}</small>`;
var formatComment = function(comment) {
return `<small>${formatSummary(comment)}</small>`;
}

async function main(date, subpage) {
Expand Down Expand Up @@ -78,7 +79,7 @@ const {bot, log, xdate, mwn, emailOnError} = require('../botbase');

if (!redirectRgx.test(rev.content)) { // not a redirect

pages[page].note = `Redirected to [[${pages[page].redirecttarget}]] by ${userlink(prevuser)}: ${small(prevcomment)}`;
pages[page].note = `Redirected to [[${pages[page].redirecttarget}]] by ${userlink(prevuser)}: ${formatComment(prevcomment)}`;
others.add(page);
return; // TODO: also find out who de-prodded it, if different

Expand Down Expand Up @@ -115,14 +116,13 @@ const {bot, log, xdate, mwn, emailOnError} = require('../botbase');
let firstrev = revs[revs.length-1];
if (logs.length && new Date(logs[0].timestamp) < new Date(firstrev.timestamp)) {
// yes
pages[page].note = `Deleted by ${userlink(logs[0].user)}: ${small(logs[0].comment)}\n\n` +
`Recreated as redirect by ${userlink(firstrev.user)}: ${small(firstrev.comment)}`;
pages[page].note = `Deleted by ${userlink(logs[0].user)}: ${formatComment(logs[0].comment)}\n\n` +
`Recreated as redirect by ${userlink(firstrev.user)}: ${formatComment(firstrev.comment)}`;
others.add(page);

} else {
pages[page].note = `[Could not determine status]`;
others.add(page);
return;
}
});

Expand All @@ -134,7 +134,7 @@ const {bot, log, xdate, mwn, emailOnError} = require('../botbase');
if (prodRgx.test(rev.content)) {
pages[page].deproder = prevuser;
pages[page].comment = prevcomment;
pages[page].note = `De-prodded by ${userlink(pages[page].deproder)} with comment: <small>${pages[page].comment || ''}</small>`;
pages[page].note = `De-prodded by ${userlink(pages[page].deproder)} with comment: ${formatComment(pages[page].comment)}`;

// check if it was AFD'd later after de-prodding
return bot.search('prefix:Wikipedia:Articles for deletion/' + page, 5, '', {
Expand Down Expand Up @@ -177,8 +177,8 @@ const {bot, log, xdate, mwn, emailOnError} = require('../botbase');
var firstrev = revs[revs.length-1];
if (logs.length && new Date(logs[0].timestamp) < new Date(firstrev.timestamp)) {
// yes
pages[page].note = `Deleted by ${logs[0].user}: ${small(logs[0].comment)}\n\n` +
`Recreated by ${userlink(firstrev.user)}: ${small(firstrev.comment)}`;
pages[page].note = `Deleted by ${logs[0].user}: ${formatComment(logs[0].comment)}\n\n` +
`Recreated by ${userlink(firstrev.user)}: ${formatComment(firstrev.comment)}`;
others.add(page);

} else {
Expand All @@ -202,7 +202,7 @@ const {bot, log, xdate, mwn, emailOnError} = require('../botbase');

let afd_comment_rgx = /^\[\[Wikipedia:Articles for deletion\//;
let isAfd = afd_comment_rgx.test(logs[0].comment);
pages[page].note = `Deleted by ${userlink(logs[0].user)}: ${small(logs[0].comment)}`;
pages[page].note = `Deleted by ${userlink(logs[0].user)}: ${formatComment(logs[0].comment)}`;
if (isAfd) {
afddeleted.add(page);
} else {
Expand All @@ -219,14 +219,14 @@ const {bot, log, xdate, mwn, emailOnError} = require('../botbase');
} else {
let move = movelogs[0];
if (move.params.target_title === 'Draft:' + page) {
pages[page].note = `Draftified to [[${move.params.target_title}]] by ${userlink(move.user)}: ${small(move.comment)}`;
pages[page].note = `Draftified to [[${move.params.target_title}]] by ${userlink(move.user)}: ${formatComment(move.comment)}`;
others.add(page);
} else {
let target = move.params.target_title;

// non-mainspace target, don't follow
if (bot.title.newFromText(target).namespace !== 0) {
pages[page].note = `Moved to [[${target}]] by ${userlink(move.user)}: ${small(move.comment)}`;
pages[page].note = `Moved to [[${target}]] by ${userlink(move.user)}: ${formatComment(move.comment)}`;
others.add(page);
return;
}
Expand Down
10 changes: 2 additions & 8 deletions reports/redirectify-watch.js
@@ -1,5 +1,5 @@
const {mwn, bot, log, emailOnError} = require('../botbase');
const TextExtractor = require('../TextExtractor')(bot);
const {mwn, bot, log, emailOnError, TextExtractor} = require('../botbase');
const {formatSummary} = require('./commons');

(async function() {

Expand Down Expand Up @@ -45,12 +45,6 @@ const isRedirect = function(text) {
return /^#?redirect\s*\[\[/i.test(text);
};

const formatSummary = function(text) {
return text
.replace(/\{\{.*?\}\}/g, '<nowiki>$&</nowiki>')
.replace(/\[\[((?:Category|File|Image):.*?)\]\]/gi, '[[:$1]]');
}

let count = 0;

for (let edit of actions) {
Expand Down

0 comments on commit f93852a

Please sign in to comment.