Commit d08d8d89 authored by Luís's avatar Luís 👺

Updated WikiStats to version 1.1.4

Optimized the way namespaces and extensions are verified across wikis (Gabriel)
parent 328786e3
......@@ -7,4 +7,7 @@ data/**/*.json
data/lists/*-active.json
data/lists/*-top100.json
data/lists/*-wikicap.json
\ No newline at end of file
data/lists/*-wikicap.json
package-lock.json
yarn.lock
\ No newline at end of file
This diff is collapsed.
{
"name": "wikistats",
"version": "1.1.0",
"version": "1.1.4",
"description": "OTFWiki Stats",
"main": "app.js",
"scripts": {
......
......@@ -177,9 +177,7 @@ socketio.on(selectedUser, (message) => {
document.getElementById("user-block-count").innerText = data.uBlockCount;
document.getElementById("user-delete-count").innerText = data.uDeleteCount;
// Funciona, mas o certo seria fazer isso automaticamente no futuro
// Isso permitiria que mais estatísitcas de extensões fossem facilmente adicionadas
if (selectedWiki === "tf") {
if (data.wThanks) {
document.getElementById("wiki-has-thanks").removeAttribute("class");
document.getElementById("user-thanks-given").innerText = data.uThanksGiven;
document.getElementById("user-thanks-received").innerText = data.uThanksReceived;
......
......@@ -53,6 +53,10 @@ wikis["enabled"].forEach(function (wiki) {
updateNameSpaces(wiki);
}
if (!fs.existsSync(`./data/extensions/${wiki}.json`)) {
updateExtensions(wiki);
}
if (shouldPopulateLists) {
logger.verbose(`${wiki}: Updating lists.`);
updateLists.updateLists(wiki);
......@@ -60,29 +64,65 @@ wikis["enabled"].forEach(function (wiki) {
});
function updateNameSpaces(wiki) {
if (!fs.existsSync(`./data/namespaces/${wiki}.json`)) {
logger.verbose(`${wiki}: Updating list of namespaces.`);
logger.verbose(`${wiki}: Updating list of namespaces.`);
let MWClient = new bot(`./configs/wikis/${wiki}-config.json`);
MWClient.api.call({
"action": "query",
"meta": "siteinfo",
"siprop": "namespaces"
}, (err, data) => {
if (err) {
logger.apierror(`${wiki}: namespaces returned "${err}" (updateNameSpaces)`);
return;
}
let namespaces = {
namespaces: {
}
};
for (let nm in data["namespaces"]) {
namespaces["namespaces"][nm] = data["namespaces"][nm]["*"];
}
fs.writeFile(`./data/namespaces/${wiki}.json`, JSON.stringify(namespaces, null, 2), (err) => {
if (err) {
logger.error(`${wiki}: Failed to save namespaces/${wiki}.json (updateNameSpaces): ${err}`);
return;
}
let MWClient = new bot(`./configs/wikis/${wiki}-config.json`);
logger.verbose(`${wiki}: Namespaces successfully updated!`);
});
});
}
function updateExtensions(wiki) {
logger.verbose(`${wiki}: Updating list of extensions.`);
MWClient.api.call({
"action": "query",
"meta": "siteinfo",
"siprop": "namespaces"
}, (err, data) => {
let MWClient = new bot(`./configs/wikis/${wiki}-config.json`);
MWClient.api.call({
"action": "query",
"meta": "siteinfo",
"siprop": "extensions"
}, (err, data) => {
if (err) {
logger.apierror(`${wiki}: extensions returned "${err}" (updateExtensions)`);
return;
}
let extensions = {
extensions: {
}
};
for (let ex of data["extensions"]) {
extensions["extensions"][ex["name"]] = ex["url"];
}
fs.writeFile(`./data/extensions/${wiki}.json`, JSON.stringify(extensions, null, 2), (err) => {
if (err) {
logger.apierror(`${wiki}: namespaces returned "${err}" (updateNameSpaces)`);
logger.error(`${wiki}: Failed to save extensions/${wiki}.json (updateExtensions): ${err}`);
return;
}
fs.writeFile(`./data/namespaces/${wiki}.json`, JSON.stringify(data, null, 2), (err) => {
if (err) {
logger.error(`${wiki}: Failed to save namespaces/${wiki}.json (updateNameSpaces): ${err}`);
return;
}
logger.verbose(`${wiki}: Namespaces successfully updated!`);
});
logger.verbose(`${wiki}: Extensions successfully updated!`);
});
}
});
}
......@@ -212,7 +212,7 @@ module.exports.processUser = (data) => {
}
// Name color
let bots = require(`../data/lists/${data.u_sourcewiki}-bots.json`);
const bots = require(`../data/lists/${data.u_sourcewiki}-bots.json`);
let classes = ["user-normal"];
let staffMembers = require(`../data/lists/${data.u_sourcewiki}-staff.json`);
......@@ -223,8 +223,8 @@ module.exports.processUser = (data) => {
let namespaceEdits = {};
let namespaces = require(`../data/namespaces/${data.u_sourcewiki}.json`)["namespaces"];
let userNamespaceEdits = data.u_namespaceedits[0];
const namespaces = require(`../data/namespaces/${data.u_sourcewiki}.json`)["namespaces"];
const userNamespaceEdits = data.u_namespaceedits[0];
for (let number in userNamespaceEdits) {
let namespaceData = namespaces[number];
......@@ -234,7 +234,7 @@ module.exports.processUser = (data) => {
}
if (namespaceData) {
namespaceEdits[namespaceData["*"] || "Main"] = userNamespaceEdits[number];
namespaceEdits[namespaceData || "Main"] = userNamespaceEdits[number];
}
else {
namespaceEdits["Other"] = (namespaceEdits["Other"] || 0) + userNamespaceEdits[number];
......@@ -246,8 +246,8 @@ module.exports.processUser = (data) => {
}
if (data.u_sourcewiki === "tf") {
let capUsers = require("../data/lists/tf-wikicap.json");
let valve = require("../data/lists/tf-valve.json");
const capUsers = require("../data/lists/tf-wikicap.json");
const valve = require("../data/lists/tf-valve.json");
valve["users"].includes(data.u_name) ? classes.push("user-valve") : "";
......@@ -256,12 +256,16 @@ module.exports.processUser = (data) => {
}
}
let wikiConfig = require(`../configs/wikis/${data.u_sourcewiki}-config.json`);
let wikiUrl = `https://${wikiConfig["server"]}`;
let wikiPath = `${wikiUrl}${wikiConfig["path"] === "/w" ? "/w/" : wikiConfig["path"]}`;
let oddPath = data.u_sourcewiki === "tf" || data.u_sourcewiki === "portal" ? "wiki/" : "";
let encodedUsername = encodeURIComponent(data.u_name);
let isExpensive = userEdits > 10000;
const wikiConfig = require(`../configs/wikis/${data.u_sourcewiki}-config.json`);
const wikiUrl = `https://${wikiConfig["server"]}`;
const wikiPath = `${wikiUrl}${wikiConfig["path"] === "/w" ? "/w/" : wikiConfig["path"]}`;
const oddPath = data.u_sourcewiki === "tf" || data.u_sourcewiki === "portal" ? "wiki/" : "";
const encodedUsername = encodeURIComponent(data.u_name);
const isExpensive = userEdits > 10000;
const wikiExtensions = require(`../data/extensions/${data.u_sourcewiki}.json`);
const wikiHasThanks = Object.keys(wikiExtensions["extensions"]).some((x) => x === "Thanks");
let out = {
uWiki: data.u_sourcewiki,
uName: data.u_name,
......@@ -303,6 +307,7 @@ module.exports.processUser = (data) => {
wSpecialContributions: `${wikiPath}index.php?title=Special%3AContributions&contribs=user&target=${encodedUsername}`,
wFiles: `${wikiUrl}/${oddPath}Special:ListFiles?limit=50&ilsearch=&user=${encodedUsername}&ilshowall=1`,
wLinks: `${wikiPath}index.php?title=`,
wThanks: wikiHasThanks,
};
logger.debug(`${data.u_sourcewiki}: User data for "${data.u_name}" successfully processed!`);
......
......@@ -149,6 +149,9 @@ module.exports.getUserInfo = (user, force = 0, sourceWiki = "tf") => {
list: "logevents"
};
const extensions = require(`../data/extensions/${sourceWiki}.json`)["extensions"];
const wikiHasThanks = Object.keys(extensions).some((x) => x === "Thanks");
let uBlocked = 0;
let uContribs = [];
let uDeleted = 0;
......@@ -311,7 +314,7 @@ module.exports.getUserInfo = (user, force = 0, sourceWiki = "tf") => {
}, (err) => {
if (err) {
if (err === "NOMOR") {
if (sourceWiki === "tf") {
if (wikiHasThanks) {
getUsersThanked();
} else {
updateUserModel();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment