Skip to content

Commit

Permalink
migrate class name mwn -> Mwn
Browse files Browse the repository at this point in the history
  • Loading branch information
siddharthvp committed Jun 22, 2023
1 parent dde89a3 commit 394a9d1
Show file tree
Hide file tree
Showing 33 changed files with 91 additions and 91 deletions.
10 changes: 5 additions & 5 deletions afd-notifications/notifier.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import {bot, log, emailOnError, mwn, argv} from '../botbase';
import {bot, log, emailOnError, Mwn, argv} from '../botbase';

const PercentDefault = 0.25;
const ByteDefault = 1000;

class Notifier {
table: InstanceType<typeof mwn.table>
table: InstanceType<typeof Mwn.table>
notificationScheme: Map<string, Array<string>>
afds: { [afdtitle: string]: string }
config: {
Expand All @@ -22,7 +22,7 @@ class Notifier {

await notifier.getAfDs();

notifier.table = new mwn.table();
notifier.table = new Mwn.table();
notifier.table.addHeaders([
`! scope="col" style="width: 14em" | AfD`,
`! scope="col" style="width: 14em" | Article`,
Expand Down Expand Up @@ -348,7 +348,7 @@ class Notifier {
return Promise.reject('nobots');
}

let rgx = new RegExp(`== ?Nomination of \\[\\[:?${mwn.util.escapeRegExp(article)}\\]\\] for deletion ?==`);
let rgx = new RegExp(`== ?Nomination of \\[\\[:?${Mwn.util.escapeRegExp(article)}\\]\\] for deletion ?==`);
if (rgx.test(text)) {
log(`[C] ${username} was already notified of ${article}`);
return Promise.reject('already-notified');
Expand All @@ -360,7 +360,7 @@ class Notifier {
}
}

if (!mwn.util.isIPAddress(username)) { // IP blocks can't be looked up this way, TODO: handle this
if (!Mwn.util.isIPAddress(username)) { // IP blocks can't be looked up this way, TODO: handle this
let blockinfo = await user.info('blockinfo');
if (blockinfo.blockid) { // blocked
if (blockinfo.blockexpiry === 'infinite') {
Expand Down
4 changes: 2 additions & 2 deletions bot-monitor/Alert.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { argv, bot, log, mwn } from "../botbase";
import { argv, bot, log, Mwn } from "../botbase";
import {Rule, RuleError, Monitor} from "./index";

export class Alert {
Expand Down Expand Up @@ -39,7 +39,7 @@ export class Alert {
}

getMessage() {
return mwn.template('subst:Wikipedia:Bot activity monitor/Notification', {
return Mwn.template('subst:Wikipedia:Bot activity monitor/Notification', {
bot: this.rule.bot,
task: this.rule.task,
action: this.rule.action === 'edit' ? 'edit' : `"${this.rule.action}" action`,
Expand Down
6 changes: 3 additions & 3 deletions bot-monitor/Rule.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {argv, bot, mwn, path} from "../botbase";
import {argv, bot, Mwn, path} from "../botbase";
import {MwnTitle, MwnDate} from "../../mwn";
import {getFromDate} from "./index";
import {readFile} from "../utils";
Expand Down Expand Up @@ -88,9 +88,9 @@ export function parseRule(rule: RawRule): Rule {
namespace: rule.namespace && rule.namespace.match(/\d+/g).map(num => parseInt(num)),
duration: rule.duration,
fromDate,
titleRegex: (rule.title && new RegExp('^' + mwn.util.escapeRegExp(rule.title) + '$')) ||
titleRegex: (rule.title && new RegExp('^' + Mwn.util.escapeRegExp(rule.title) + '$')) ||
(rule.title_regex && new RegExp('^' + rule.title_regex + '$')),
summaryRegex: (rule.summary && new RegExp('^' + mwn.util.escapeRegExp(rule.summary) + '$')) ||
summaryRegex: (rule.summary && new RegExp('^' + Mwn.util.escapeRegExp(rule.summary) + '$')) ||
(rule.summary_regex && new RegExp('^' + rule.summary_regex + '$')),
minEdits: rule.min_edits ? parseInt(rule.min_edits) : 1,
alertPage
Expand Down
10 changes: 5 additions & 5 deletions bot-monitor/Tabulator.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { bot, mwn, log, argv, enwikidb } from "../botbase";
import { bot, Mwn, log, argv, enwikidb } from "../botbase";
import {Monitor} from './index';

import * as moment from "moment";

export class Tabulator {
static rootpage = 'Wikipedia:Bot activity monitor' + (argv.fake ? '/sandbox' : '');

static table: InstanceType<typeof mwn.table>;
static table: InstanceType<typeof Mwn.table>;
static invalidRules: { task: string, reason: string }[] = []

static init() {
this.table = new mwn.table();
this.table = new Mwn.table();
this.table.addHeaders([
{label: 'Bot'},
{label: 'Task'},
Expand Down Expand Up @@ -52,7 +52,7 @@ export class Tabulator {
static async whineAboutRuleErrors() {
let msg;
if (this.invalidRules.length) {
let table = new mwn.table();
let table = new Mwn.table();
table.addHeaders([
'Bot and task',
'Configuration error'
Expand All @@ -73,7 +73,7 @@ export class Tabulator {
} catch (e) {}
let text = '== Current status report ==' +
(replagHours > 6 ? `Database replication lag is ${replagHours} hours; as a result some bots may not be working` : '') +
'<noinclude>' + mwn.template('/header', {
'<noinclude>' + Mwn.template('/header', {
errcount: this.invalidRules.length ? String(this.invalidRules.length) : null
}) + '</noinclude>\n' + Tabulator.table.getText();
if (argv.dry) {
Expand Down
8 changes: 4 additions & 4 deletions botbase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ process.on('uncaughtException', function(err) {
}
});

import {mwn} from '../mwn';
export {mwn};
import {Mwn} from '../mwn';
export {Mwn};

/** Colorised and dated console logging. */
export const log = mwn.log;
export const log = Mwn.log;

/** Parsed console arguments */
export const argv = require('minimist')(process.argv.slice(2));
Expand All @@ -68,7 +68,7 @@ export class AuthManager {
}
}

export const bot = new mwn({
export const bot = new Mwn({
apiUrl: 'https://en.wikipedia.org/w/api.php',
...AuthManager.get('SDZeroBot:oauth2'),
...AuthManager.get('SDZeroBot:bp1'),
Expand Down
4 changes: 2 additions & 2 deletions check-webservice.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { emailOnError, mwn } from './botbase';
import { emailOnError, Mwn } from './botbase';

process.chdir(__dirname + '/webservice');

new mwn().rawRequest({
new Mwn().rawRequest({
url: 'https://sdzerobot.toolforge.org/ping'
}).then(response => {
let data = response?.data;
Expand Down
8 changes: 4 additions & 4 deletions db-tabulator/app.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { argv, bot, emailOnError, log, mwn, TextExtractor } from "../botbase";
import { argv, bot, emailOnError, log, Mwn, TextExtractor } from "../botbase";
import { enwikidb, SQLError } from "../db";
import { Template } from "../../mwn/build/wikitext";
import { arrayChunk, createLogStream, lowerFirst, readFile, writeFile } from "../utils";
Expand Down Expand Up @@ -458,10 +458,10 @@ export class Query {
const header_template = this.getTemplateValue('header_template');
const skip_table = this.getTemplateValue('skip_table');

let table: InstanceType<typeof mwn.table>;
let table: InstanceType<typeof Mwn.table>;
let tableText = '';
if (!skip_table) {
table = new mwn.table({
table = new Mwn.table({
style: this.getTemplateValue('table_style') || 'overflow-wrap: anywhere'
});
if (header_template) {
Expand Down Expand Up @@ -516,7 +516,7 @@ export class Query {
db.makeReplagMessage(2) +
tableText + '\n' +
'----\n' +
mwn.template('Database report/footer', {
Mwn.template('Database report/footer', {
count: result.length,
page: pageNumber && String(pageNumber),
num_pages: pageNumber && String(this.numPages),
Expand Down
8 changes: 4 additions & 4 deletions experiments/rich-statistics/num-active-editors.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const {bot, mwn, log} = require('../../botbase');
const {bot, Mwn, log} = require('../../botbase');

(async function() {

Expand Down Expand Up @@ -28,7 +28,7 @@ for (let i = userswithcount.length - 1; i >= 0; i--) {
userswithcount[i] = orz(userswithcount[i+1]) + orz(userswithcount[i]);
}

let table = new mwn.table();
let table = new Mwn.table();
table.addHeaders([
{label: 'Statistic', style: 'width: 40em;'},
{label: 'Value', style: 'width: 20em'}
Expand All @@ -43,7 +43,7 @@ table.addRow([ 'Users with 500+ actions in the last 30 days', orz(userswithcount
table.addRow([ 'Users with 1000+ actions in the last 30 days', orz(userswithcount[1000]) ]);
table.addRow([ 'Users with 5000+ actions in the last 30 days', orz(userswithcount[5000]) ]);

let wikitext =
let wikitext =
`{{hatnote|Last updated by [[User:SDZeroBot|SDZeroBot]] at ~~~~~}}
${table.getText()}
Expand All @@ -56,4 +56,4 @@ await bot.save('User:SDZeroBot/Number of active editors', wikitext, 'Updating');

log(`[i] Finished`);

})();
})();
4 changes: 2 additions & 2 deletions most-gans/gans-lister.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { argv, bot, log, mwn } from '../botbase';
import { argv, bot, log, Mwn } from '../botbase';
import { TOOLS_DB_HOST, toolsdb } from '../db';
import { closeTunnels, createLocalSSHTunnel, withIndices } from "../utils";
import { TABLE } from "./model";
Expand All @@ -17,7 +17,7 @@ import { TABLE } from "./model";
db.end();
log(`[S] Got query result`);

let wikitable = new mwn.table();
let wikitable = new Mwn.table();
wikitable.addHeaders(['Rank', 'User', 'Count']);

let rank500Count;
Expand Down
8 changes: 4 additions & 4 deletions one-time/books.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { argv, bot, log, mwn } from '../botbase';
import { argv, bot, log, Mwn } from '../botbase';
import { enwikidb, ENWIKI_DB_HOST } from "../db";
import { createLocalSSHTunnel, readFile, saveObject, writeFile } from "../utils";

Expand Down Expand Up @@ -93,7 +93,7 @@ import { createLocalSSHTunnel, readFile, saveObject, writeFile } from "../utils"
// })
// }

let wikitable = new mwn.table({
let wikitable = new Mwn.table({
classes: ['plainlinks']
});
wikitable.addHeaders([
Expand All @@ -106,9 +106,9 @@ import { createLocalSSHTunnel, readFile, saveObject, writeFile } from "../utils"
title = 'Book:' + title.replace(/_/g, ' ');
wikitable.addRow([
`[[${title}]]`,
`[https://en.wikipedia.org/w/index.php?title=${mwn.util.wikiUrlencode(title)}&action=history ${num_revisions}]`,
`[https://en.wikipedia.org/w/index.php?title=${Mwn.util.wikiUrlencode(title)}&action=history ${num_revisions}]`,
num_editors,
`[https://en.wikipedia.org/w/index.php?title=${mwn.util.wikiUrlencode(title)}&action=info ${pageviews}]`
`[https://en.wikipedia.org/w/index.php?title=${Mwn.util.wikiUrlencode(title)}&action=info ${pageviews}]`
]);
}

Expand Down
4 changes: 2 additions & 2 deletions one-time/feature-historian.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {bot, fs, log, mwn} from '../botbase.js';
import {bot, fs, log, Mwn} from '../botbase.js';

(async function () {

Expand Down Expand Up @@ -90,7 +90,7 @@ for await (let pg of reader) {

}

let mwntable = new mwn.table({
let mwntable = new Mwn.table({
style: 'overflow-wrap: anywhere;'
});
mwntable.addHeaders([
Expand Down
8 changes: 4 additions & 4 deletions reports/afc-sorting/afc-sorting.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const {fs, mwn, bot, enwikidb, utils, argv, log, emailOnError} = require('../../botbase');
const {fs, Mwn, bot, enwikidb, utils, argv, log, emailOnError} = require('../../botbase');
const OresUtils = require('../OresUtils');
const {createLocalSSHTunnel, closeTunnels} = require("../../utils");
const {ENWIKI_DB_HOST} = require("../../db");
Expand Down Expand Up @@ -86,7 +86,7 @@ process.chdir(__dirname);

var entriesFound = 0;
var getCopyioPercent = function(title) {
var re = new RegExp(`${mwn.util.escapeRegExp(title).replace(/ /g, '_')}(?:\\s|\\S)*?tools\\.wmflabs\\.org\\/copyvios\\/.*? (.*?)\\]%`).exec(UserSQLReport);
var re = new RegExp(`${Mwn.util.escapeRegExp(title).replace(/ /g, '_')}(?:\\s|\\S)*?tools\\.wmflabs\\.org\\/copyvios\\/.*? (.*?)\\]%`).exec(UserSQLReport);
if (!re || !re[1]) {
return null;
}
Expand Down Expand Up @@ -280,7 +280,7 @@ process.chdir(__dirname);
}
content += `{{Wikipedia:AfC sorting/header|count=${sorter[topic].length}|date=${accessdate}|ts=~~~~~}}\n${replagMessage}`;

var table = new mwn.table();
var table = new Mwn.table();
table.addHeaders([
`scope="col" style="width: 17em;" | Page`,
`Class`,
Expand All @@ -307,7 +307,7 @@ process.chdir(__dirname);
editorString = `[[Special:Contribs/${tabledata.creator}|${tabledata.creator}]] (${tabledata.creatorEdits})`;
} else {
// lowercase IPv6 address and split to 2 lines to reduce column width
if (mwn.util.isIPv6Address(tabledata.creator)) {
if (Mwn.util.isIPv6Address(tabledata.creator)) {
var ip = tabledata.creator.toLowerCase();
var idx = Math.round(ip.length / 2);
ip = ip.slice(0, idx) + '<br>' + ip.slice(idx);
Expand Down
4 changes: 2 additions & 2 deletions reports/afd-sorting/afd-sorting-beta.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const {mwn, bot, log, argv, utils, emailOnError} = require('../../botbase');
const {Mwn, bot, log, argv, utils, emailOnError} = require('../../botbase');
const OresUtils = require('../OresUtils');

process.chdir(__dirname);
Expand Down Expand Up @@ -171,7 +171,7 @@ process.chdir(__dirname);
if (isStarred(topic)) {
pagetitle = meta(topic);
}
var table = new mwn.table({ sortable: true, multiline: true });
var table = new Mwn.table({ sortable: true, multiline: true });
table.addHeaders([
`scope="col" style="width: 5em;" | AfD date`,
`scope="col" style="width: 19em;" | Article`,
Expand Down
4 changes: 2 additions & 2 deletions reports/afd-sorting/afd-sorting.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const {mwn, bot, log, argv, utils, emailOnError} = require('../../botbase');
const {Mwn, bot, log, argv, utils, emailOnError} = require('../../botbase');
const OresUtils = require('../OresUtils');
const {normaliseShortdesc, populateWikidataShortdescs, escapeForTableCell, saveWithBlacklistHandling } = require('../commons');

Expand Down Expand Up @@ -169,7 +169,7 @@ process.chdir(__dirname);
if (isStarred(topic)) {
pagetitle = meta(topic);
}
var table = new mwn.table({
var table = new Mwn.table({
style: 'overflow-wrap: anywhere'
});
table.addHeaders([
Expand Down
4 changes: 2 additions & 2 deletions reports/commons.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const {bot, mwn, log, emailOnError} = require('../botbase');
const {bot, Mwn, log, emailOnError} = require('../botbase');
const OresUtils = require('./OresUtils');

/**
Expand All @@ -7,7 +7,7 @@ const OresUtils = require('./OresUtils');
*/
async function populateWikidataShortdescs(tableInfo) {
/* GET WIKIDATA SHORTDESCS */
const wdbot = new mwn({
const wdbot = new Mwn({
...bot.options,
apiUrl: 'https://www.wikidata.org/w/api.php'
});
Expand Down
4 changes: 2 additions & 2 deletions reports/declined-afcs.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const {argv, bot, log, TextExtractor, emailOnError, mwn, utils} = require('../botbase');
const {argv, bot, log, TextExtractor, emailOnError, Mwn, utils} = require('../botbase');
const {AfcDraftSize, populateWikidataShortdescs, populateOresQualityRatings, comparators,
preprocessDraftForExtract, saveWithBlacklistHandling} = require('./commons');
const {enwikidb} = require("../db");
Expand Down Expand Up @@ -104,7 +104,7 @@ await populateOresQualityRatings(tableInfo);
// Wikidata short descriptions
await populateWikidataShortdescs(tableInfo);

let table = new mwn.table({
let table = new Mwn.table({
style: 'overflow-wrap: anywhere'
});
table.addHeaders([
Expand Down
6 changes: 3 additions & 3 deletions reports/draftify-watch.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const {bot, mwn, log, utils, emailOnError, TextExtractor} = require('../botbase');
const {bot, Mwn, log, utils, emailOnError, TextExtractor} = require('../botbase');
const {formatSummary, saveWithBlacklistHandling} = require('./commons');

(async () => {
Expand Down Expand Up @@ -117,10 +117,10 @@ const {formatSummary, saveWithBlacklistHandling} = require('./commons');
{ label: `Move summary` },
];

var maintable = new mwn.table();
var maintable = new Mwn.table();
maintable.addHeaders(tableHeaders);

let footertable = new mwn.table();
let footertable = new Mwn.table();
footertable.addHeaders(tableHeaders);

for (let [page, data] of Object.entries(tableInfo)) {
Expand Down
4 changes: 2 additions & 2 deletions reports/g13-1week.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { argv, bot, emailOnError, log, mwn, TextExtractor } from "../botbase";
import { argv, bot, emailOnError, log, Mwn, TextExtractor } from "../botbase";
import { ApiRevision, MwnDate} from "../../mwn";
import {
AfcDraftSize,
Expand Down Expand Up @@ -125,7 +125,7 @@ async function runForDate(date: MwnDate) {
// Wikidata short descriptions
await populateWikidataShortdescs(tableInfo);

let table = new mwn.table({
let table = new Mwn.table({
style: 'overflow-wrap: anywhere'
});
table.addHeaders([
Expand Down
Loading

0 comments on commit 394a9d1

Please sign in to comment.