MediaWiki:Gadget-QueryContributors.js
外观
注意:在发布之后,您可能需要清除浏览器缓存才能看到所作出的更改的影响。
- Firefox或Safari:按住Shift的同时单击刷新,或按Ctrl-F5或Ctrl-R(Mac为⌘-R)
- Google Chrome:按Ctrl-Shift-R(Mac为⌘-Shift-R)
- Edge:按住Ctrl的同时单击刷新,或按Ctrl-F5。
/**
* SPDX-License-Identifier: CC-BY-SA-4.0
* _addText: '{{Gadget Header|license=CC-BY-SA-4.0|license2=Qiuwen Public Licence}}'
*
* @source {@link https://git.qiuwen.net.cn/InterfaceAdmin/QiuwenGadgets/src/branch/master/src/QueryContributors}
* @author WaitSpring <me@waitspring.com>
* @license CC-BY-SA-4.0 {@link https://www.qiuwenbaike.cn/wiki/H:CC-BY-SA-4.0}
* @license Qiuwen Public License {@link https://www.qiuwenbaike.cn/wiki/QW:QWL}
*/
/**
* Copyright 2024 WaitSpring <me@waitspring.com>
* Licensed under the "Qiuwen Public Licence"
* (the "License", formerly the "Qiuwen Licence"),
* either version 1.0 of the Licence, or any
* later version.
* You may obtain a copy of the License at
*
* http://www.qiuwenbaike.cn/wiki/QW:QWL
*
* See the License for details.
*/
/**
* +------------------------------------------------------------+
* | === WARNING: GLOBAL GADGET FILE === |
* +------------------------------------------------------------+
* | All changes should be made in the repository, |
* | otherwise they will be lost. |
* +------------------------------------------------------------+
* | Changes to this page may affect many users. |
* | Please discuss changes by opening an issue before editing. |
* +------------------------------------------------------------+
*/
/* <nowiki> */
(() => {
"use strict";
// dist/QueryContributors/QueryContributors.js
function asyncGeneratorStep(n, t, e, r, o, a, c) {
try {
var i = n[a](c), u = i.value;
} catch (n2) {
return void e(n2);
}
i.done ? t(u) : Promise.resolve(u).then(r, o);
}
function _asyncToGenerator(n) {
return function() {
var t = this, e = arguments;
return new Promise(function(r, o) {
var a = n.apply(t, e);
function _next(n2) {
asyncGeneratorStep(a, r, o, _next, _throw, "next", n2);
}
function _throw(n2) {
asyncGeneratorStep(a, r, o, _next, _throw, "throw", n2);
}
_next(void 0);
});
};
}
function _createForOfIteratorHelper(r, e) {
var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
if (!t) {
if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) {
t && (r = t);
var n = 0, F = function() {
};
return { s: F, n: function() {
return n >= r.length ? { done: true } : { done: false, value: r[n++] };
}, e: function(r2) {
throw r2;
}, f: F };
}
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
var o, a = true, u = false;
return { s: function() {
t = t.call(r);
}, n: function() {
var r2 = t.next();
return a = r2.done, r2;
}, e: function(r2) {
u = true, o = r2;
}, f: function() {
try {
a || null == t.return || t.return();
} finally {
if (u) throw o;
}
} };
}
function _unsupportedIterableToArray(r, a) {
if (r) {
if ("string" == typeof r) return _arrayLikeToArray(r, a);
var t = {}.toString.call(r).slice(8, -1);
return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
}
}
function _arrayLikeToArray(r, a) {
(null == a || a > r.length) && (a = r.length);
for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
return n;
}
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
var _iterator = _createForOfIteratorHelper(__getOwnPropNames(from)), _step;
try {
for (_iterator.s(); !(_step = _iterator.n()).done; ) {
let key = _step.value;
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
get: () => from[key],
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
});
}
} catch (err) {
_iterator.e(err);
} finally {
_iterator.f();
}
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
value: mod,
enumerable: true
}) : target,
mod
));
//! src/QueryContributors/options.json
var elementId = "gadget-query_contributors";
var mountPointSelector = "#footer-info,.page-info";
var version = "1.0";
//! src/QueryContributors/modules/components/react.tsx
var import_ext_gadget2 = __toESM(require("ext.gadget.JSX"), 1);
//! src/QueryContributors/modules/i18n.ts
var import_ext_gadget = require("ext.gadget.i18n");
var getI18nMessages = () => {
return {
"Based on contributions of": (0, import_ext_gadget.localize)({
en: "Based on contributions of ",
"zh-hans": "基于下列用户的贡献:",
"zh-hant": "基于下列使用者的貢獻:"
}),
Seperator: (0, import_ext_gadget.localize)({
en: ", ",
"zh-hans": "、",
"zh-hant": "、"
}),
Period: (0, import_ext_gadget.localize)({
en: ".",
zh: "。"
}),
"Other $1 anonymous contributors": (0, import_ext_gadget.localize)({
en: "other $1 anonymous contributor(s)",
"zh-hans": "其他$1位匿名贡献者",
"zh-hant": "其他$1位匿名貢獻者"
})
};
};
var i18nMessages = getI18nMessages();
var getMessage = (key) => {
return i18nMessages[key] || key;
};
//! src/QueryContributors/modules/util/sanitize.ts
var sanitize = (string) => {
return string.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/'/g, "'").replace(/"/g, """);
};
//! src/QueryContributors/modules/components/react.tsx
var FooterNotice = ({
children = /* @__PURE__ */ import_ext_gadget2.default.createElement(import_ext_gadget2.default.Fragment, null)
}) => {
const {
skin
} = mw.config.get();
const id = elementId;
const className = elementId;
if (skin === "citizen") {
return /* @__PURE__ */ import_ext_gadget2.default.createElement("section", {
id,
className: [className, "page-info__item", "citizen-footer__pageinfo-item", "noprint"]
}, children);
} else if (["gongbi", "vector", "vector-2022"].includes(skin) || document.querySelector("ul#footer-info")) {
return /* @__PURE__ */ import_ext_gadget2.default.createElement("li", {
id,
className: [className, "noprint"]
}, children);
}
return /* @__PURE__ */ import_ext_gadget2.default.createElement("div", {
id,
className: [className, "noprint"]
}, children);
};
var UserList = ({
userNames
}) => /* @__PURE__ */ import_ext_gadget2.default.createElement(import_ext_gadget2.default.Fragment, null, /* @__PURE__ */ import_ext_gadget2.default.createElement(import_ext_gadget2.default.Fragment, null, getMessage("Based on contributions of")), userNames.map((userName, index) => /* @__PURE__ */ import_ext_gadget2.default.createElement(import_ext_gadget2.default.Fragment, null, typeof userName === "number" ? /* @__PURE__ */ import_ext_gadget2.default.createElement("span", {
key: "".concat(userName)
}, getMessage("Other $1 anonymous contributors").replace("$1", "".concat(userName))) : /* @__PURE__ */ import_ext_gadget2.default.createElement("a", {
href: /(>|>)/.test(userName) ? mw.util.getUrl("Special:GoToInterWiki/".concat(sanitize(userName.replace(/(>|>)/, ":User:").replace(/(>|>)/g, ">")))) : mw.util.getUrl("User:".concat(sanitize(userName))),
rel: "noopener noreferrer",
target: "_blank",
key: userName
}, userName), /* @__PURE__ */ import_ext_gadget2.default.createElement(import_ext_gadget2.default.Fragment, null, index < userNames.length - 1 ? getMessage("Seperator") : getMessage("Period")))));
var FooterUserList = ({
userNames
}) => /* @__PURE__ */ import_ext_gadget2.default.createElement(FooterNotice, null, /* @__PURE__ */ import_ext_gadget2.default.createElement(UserList, {
userNames
}));
//! src/QueryContributors/modules/appendElement.tsx
var import_ext_gadget3 = __toESM(require("ext.gadget.JSX"), 1);
var appendElement = (userNames) => {
if (!userNames || !userNames.length) {
return;
}
const mountPoint = document.querySelector(mountPointSelector);
if (!mountPoint) {
return;
}
mountPoint.prepend(/* @__PURE__ */ import_ext_gadget3.default.createElement(FooterUserList, {
userNames
}));
};
//! src/QueryContributors/modules/api.ts
var import_ext_gadget4 = require("ext.gadget.Util");
var api = (0, import_ext_gadget4.initMwApi)("QueryContributors/".concat(version));
//! src/QueryContributors/modules/queryContributors.ts
var queryContributors = /* @__PURE__ */ (function() {
var _ref = _asyncToGenerator(function* (titles, pccontinue) {
const params = {
action: "query",
format: "json",
formatversion: "2",
prop: "contributors",
pcexcludegroup: ["bot"],
pclimit: 5e3,
titles,
smaxage: 600,
maxage: 600
};
if (pccontinue) {
params.pccontinue = pccontinue;
}
const response = yield api.get(params);
return response;
});
return function queryContributors2(_x, _x2) {
return _ref.apply(this, arguments);
};
})();
//! src/QueryContributors/modules/util/getContributors.ts
var import_ext_gadget5 = require("ext.gadget.Util");
var getContributors = /* @__PURE__ */ (function() {
var _ref2 = _asyncToGenerator(function* (title) {
let pclist = [];
let pccontinue;
const CACHE_KEY_PREFIX = "ext.gadget.QueryContributors_getContributors-";
if (mw.storage.getObject(CACHE_KEY_PREFIX + title)) {
pclist = mw.storage.getObject(CACHE_KEY_PREFIX + title);
return (0, import_ext_gadget5.uniqueArray)(pclist);
}
while (true) {
const data = yield queryContributors(title, pccontinue);
try {
var _data$query, _data$continue;
if ((_data$query = data["query"]) !== null && _data$query !== void 0 && _data$query.pages) {
var _iterator2 = _createForOfIteratorHelper(data["query"].pages), _step2;
try {
for (_iterator2.s(); !(_step2 = _iterator2.n()).done; ) {
const page = _step2.value;
if (page !== null && page !== void 0 && page.contributors) {
var _iterator3 = _createForOfIteratorHelper(page.contributors), _step3;
try {
for (_iterator3.s(); !(_step3 = _iterator3.n()).done; ) {
const contributor = _step3.value;
if (contributor !== null && contributor !== void 0 && contributor.name) {
pclist[pclist.length] = contributor.name;
}
}
} catch (err) {
_iterator3.e(err);
} finally {
_iterator3.f();
}
}
if (page !== null && page !== void 0 && page.anoncontributors) {
pclist[pclist.length] = page.anoncontributors;
}
}
} catch (err) {
_iterator2.e(err);
} finally {
_iterator2.f();
}
} else {
break;
}
if ((_data$continue = data["continue"]) !== null && _data$continue !== void 0 && _data$continue.pccontinue) {
({
pccontinue
} = data["continue"]);
} else {
break;
}
} catch {
break;
}
}
mw.storage.setObject(CACHE_KEY_PREFIX + title, pclist, 10 * 60);
return (0, import_ext_gadget5.uniqueArray)(pclist);
});
return function getContributors2(_x3) {
return _ref2.apply(this, arguments);
};
})();
//! src/QueryContributors/QueryContributors.ts
(function() {
var _queryContributos = _asyncToGenerator(function* () {
const {
wgAction,
wgArticleId,
wgCurRevisionId,
wgPageName,
wgRevisionId
} = mw.config.get();
if (wgAction !== "view" || !wgArticleId || !wgPageName) {
return;
}
if (wgCurRevisionId > wgRevisionId) {
return;
}
const contributors = yield getContributors(wgPageName);
appendElement(contributors);
});
function queryContributos() {
return _queryContributos.apply(this, arguments);
}
return queryContributos;
})()();
})();
/* </nowiki> */