Skip to content

Commit

Permalink
feat: assertuser (#384)
Browse files Browse the repository at this point in the history
* feat: assert

* feat: assert

* revert: 未登录可用

---------

Co-authored-by: AnnAngela <[email protected]>
  • Loading branch information
lovelyCARDINAL and AnnAngela authored Dec 26, 2023
1 parent 5a3ee11 commit 7da2042
Show file tree
Hide file tree
Showing 29 changed files with 95 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ $(() => {
}
const toclist = Object.fromEntries((await api.post({
action: "parse",
assertuser: mw.config.get("wgUserName"),
format: "json",
pageid: mw.config.get("wgArticleId"),
prop: "sections",
Expand Down Expand Up @@ -204,6 +205,7 @@ $(() => {
async markAsResolved({ section }) {
const d = await api.postWithToken("csrf", {
action: "edit",
assertuser: mw.config.get("wgUserName"),
pageid: mw.config.get("wgArticleId"),
section,
summary: `标记讨论串「/* ${this.sectionTitle} */」状态为【${this.statusLabel}】`,
Expand Down
2 changes: 2 additions & 0 deletions src/gadgets/MarkAsResolved/MediaWiki:Gadget-MarkAsResolved.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ $(() => {
}
const toclist = Object.fromEntries((await api.post({
action: "parse",
assertuser: mw.config.get("wgUserName"),
format: "json",
pageid: mw.config.get("wgArticleId"),
prop: "sections",
Expand Down Expand Up @@ -213,6 +214,7 @@ $(() => {
async markAsResolved({ section }) {
const d = await api.postWithToken("csrf", {
action: "edit",
assertuser: mw.config.get("wgUserName"),
pageid: mw.config.get("wgArticleId"),
section,
summary: `标记讨论串「/* ${this.sectionTitle} */」状态为【${this.statusLabel}】`,
Expand Down
2 changes: 2 additions & 0 deletions src/gadgets/Navbox-link/MediaWiki:Gadget-Navbox-link.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ $(() => {
}
const pageNonExist = wgULS("(页面不存在)", "(頁面不存在)");
const wgPageName = mw.config.get("wgPageName");
const wgUserName = mw.config.get("wgUserName");
const api = new mw.Api();
const targetLoc = $("<div>", {
id: "not-listed-articles",
Expand Down Expand Up @@ -36,6 +37,7 @@ $(() => {
e.stopPropagation();
const result = await api.post({
action: "query",
assertuser: wgUserName,
redirects: "true",
generator: "links",
gplnamespace: "0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ $(() => {
welcomeAsk.innerText = wgULS("正在通信中……");
const response = await api.postWithToken("csrf", {
action: "edit",
assertuser: mw.config.get("wgUserName"),
format: "json",
title: userName,
summary: "欢迎来到萌娘百科",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@
const api = new mw.Api();
const wgPageName = mw.config.get("wgPageName");
const wgRevisionId = mw.config.get("wgRevisionId");
const wgUserName = mw.config.get("wgUserName");
const noticeHTML = {
loading: `<div class="mw-_addText-preview-loading"><div class="quotebox" style="margin: auto; width: 50%; padding: 6px; border: 1px solid #aaa; font-size: 88%; background-color: #F9F9F9;"><div class="mw-_addText-preview-loading-content" style="background-color: #F9F9F9; color: black; text-align: center; font-size: larger;"><img src="https://img.moegirl.org.cn/common/d/d1/Windows_10_loading.gif" decoding="async" data-file-width="64" data-file-height="64" style="width: 32px; height: 32px;"> ${wgULS("预览加载中...", "預覽載入中...")} </div></div></div>`,
fail: `<img src="https://img.moegirl.org.cn/common/5/5f/Ambox_warning_orange.svg" decoding="async" data-file-width="48" data-file-height="48" width="32" height="32">${wgULS("预览加载失败", "預覽載入失敗")}`,
Expand Down Expand Up @@ -193,6 +194,7 @@
}
const params = {
action: "parse",
assertuser: wgUserName,
uselang: getLanguage(),
useskin: mw.config.get("skin"),
title: pagename,
Expand Down Expand Up @@ -235,6 +237,7 @@
}
const params = {
action: "parse",
assertuser: wgUserName,
uselang: getLanguage(),
useskin: mw.config.get("skin"),
format: "json",
Expand Down Expand Up @@ -280,6 +283,7 @@
try {
const data = await api.post({
action: "parse",
assertuser: wgUserName,
oldid: wgRevisionId,
prop: "wikitext",
});
Expand All @@ -303,6 +307,7 @@
try {
const data = await api.post({
action: "parse", //get the original wikitext content of a page
assertuser: wgUserName,
uselang: getLanguage(),
useskin: mw.config.get("skin"),
title: `${pagename}${subPagename}`,
Expand Down Expand Up @@ -425,6 +430,7 @@
const wikitext = `<div class="special-wikitext-preview-testcase-container">${wikitextPackage}</div>`;
const params = {
action: "parse",
assertuser: wgUserName,
text: wikitext,
contentmodel: "wikitext",
prop: "text",
Expand Down
6 changes: 6 additions & 0 deletions src/gadgets/UserMessages/MediaWiki:Gadget-UserMessages.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
const User = this.oldValue = this.callingObject.umCleanFileAndUser(val);
const query = {
action: "query",
assertuser: mw.config.get("wgUserName"),
list: "allusers",
aufrom: User,
auto: User,
Expand Down Expand Up @@ -411,6 +412,7 @@
umSeekUsers: (request, pCallback) => {
const query = {
action: "query",
assertuser: mw.config.get("wgUserName"),
list: "allusers",
auprefix: request.term.replace(/^(?:User):/, ""),
};
Expand All @@ -431,6 +433,7 @@
umSeekFiles: (request, pCallback) => {
const query = {
action: "query",
assertuser: mw.config.get("wgUserName"),
list: "allimages",
aiprefix: request.term.replace(/^(?:File|Image):/, ""),
};
Expand Down Expand Up @@ -558,6 +561,7 @@
umsg.umPendingParser++;
const action = {
action: "parse",
assertuser: mw.config.get("wgUserName"),
uselang: mw.config.get("wgUserLanguage"),
redirects: true,
prop: "text",
Expand Down Expand Up @@ -595,6 +599,7 @@
}
const query = {
action: "query",
assertuser: mw.config.get("wgUserName"),
prop: "info",
intoken: "edit",
titles: "FAQ", // Random title
Expand Down Expand Up @@ -634,6 +639,7 @@
savePage: (page, summary, callback) => {
const edit = {
action: "edit",
assertuser: mw.config.get("wgUserName"),
summary: summary,
tags: "UserMessages",
watchlist: page.watchlist || "preferences",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ $(() => (async () => {
try {
const __details = (await api.post({
action: "query",
assertuser: mw.config.get("wgUserName"),
list: "abuselog",
afluser: user_name,
afltitle: article_prefixedtext,
Expand All @@ -42,6 +43,7 @@ $(() => (async () => {
progress.text(2);
const _rules = (await api.post({
action: "query",
assertuser: mw.config.get("wgUserName"),
list: "abusefilters",
abfstartid: +filter,
abfendid: +filter,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ $(() => {
type: "POST",
data: {
action: "query",
assertuser: mw.config.get("wgUserName"),
titles: pageName,
format: "json",
converttitles: " zh-cn",
Expand Down Expand Up @@ -82,4 +83,4 @@ $(() => {
});
});
$("#mw-abusefilter-edit-warn-actions").remove();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@
try {
const data = await api.post({
action: "query",
assertuser: mw.config.get("wgUserName"),
format: "json",
meta: "allmessages",
amfilter: filter,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ $(() => (async () => {
const sleep = (ms = 1000) => new Promise((res) => setTimeout(res, ms));
const hasHighLimit = (await mw.user.getRights()).includes("apihighlimits");
const pageid = mw.config.get("wgArticleId");
const username = mw.config.get("wgUserName");
let result = {};

const $body = $("body");
Expand Down Expand Up @@ -113,12 +114,14 @@ $(() => (async () => {
this.addStep(wgULS("正在获取忽略用户名单...", "正在獲取忽略使用者名單...", null, null, "正在獲取忽略用戶名單 ..."));
const bots = (await api.get({
action: "query",
assertuser: username,
list: "allusers",
augroup: "bot",
aulimit: "max",
})).query.allusers.map((u) => u.name);
const MGUsers = JSON.parse((await api.get({
action: "parse",
assertuser: username,
page: "Module:UserGroup/data",
prop: "wikitext",
})).parse.wikitext["*"]);
Expand All @@ -129,6 +132,7 @@ $(() => (async () => {
this.addStep(wgULS("正在获取发言用户名单...", "正在獲取發言使用者名稱單..."));
let contributorsResult = await api.get({
action: "query",
assertuser: username,
prop: "contributors",
pageids: pageid,
pclimit: "max",
Expand All @@ -137,6 +141,7 @@ $(() => (async () => {
while (contributorsResult.continue) {
contributorsResult = await api.get({
action: "query",
assertuser: username,
prop: "contributors",
pageids: pageid,
pclimit: "max",
Expand All @@ -150,6 +155,7 @@ $(() => (async () => {
this.addStep(wgULS(`正在复核用户条件...(第${i + 1}批)`, `正在複核使用者條件...(第${i + 1}批)`));
const prelimRes = (await api.get({
action: "query",
assertuser: username,
list: "users",
ususers: chunk.join("|"),
usprop: "implicitgroups|blockinfo|registration",
Expand All @@ -161,6 +167,7 @@ $(() => (async () => {
u,
lastEdit: (await api.get({
action: "query",
assertuser: username,
list: "usercontribs",
ucuser: u,
ucnamespace: "0|10|14|12|4",
Expand Down
4 changes: 4 additions & 0 deletions src/gadgets/backlog/MediaWiki:Gadget-backlog.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,12 @@ $(() => (async () => {
const userRights = await autoRetryAsyncFunction(async () => await mw.user.getRights());
const hasSuppressionlogRight = userRights.includes("suppressionlog");
const hasDeletelogentryRight = userRights.includes("deletelogentry");
const wgUserName = mw.config.get("wgUserName");
let scrollFlag = false;
const api = new mw.Api();
const blockLogResult = await autoRetryAsyncFunction(async () => await api.post({
action: "query",
assertuser: wgUserName,
format: "json",
list: "logevents",
leprop: "ids|title|type|user|timestamp|details|parsedcomment|tags",
Expand Down Expand Up @@ -203,6 +205,7 @@ $(() => (async () => {
}
const abuseLogResult = await autoRetryAsyncFunction(async () => await api.post({
action: "query",
assertuser: wgUserName,
format: "json",
list: "abuselog",
afllimit: "500",
Expand Down Expand Up @@ -332,6 +335,7 @@ $(() => (async () => {
let cmcontinue = undefined;
const f = async () => await api2.get({
action: "query",
assertuser: wgUserName,
format: "json",
list: "categorymembers",
cmtitle,
Expand Down
1 change: 1 addition & 0 deletions src/gadgets/blockEnhance/MediaWiki:Gadget-blockEnhance.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@
timeout: 5000,
}).post({
action: "query",
assertuser: mw.config.get("wgUserName"),
list: "allusers",
aurights: "block|unblockself",
aulimit: "max",
Expand Down
5 changes: 5 additions & 0 deletions src/gadgets/deletion/MediaWiki:Gadget-deletion.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ $(() => (async () => {
"library.moegirl.org.cn": "即将删除的页面",
};
const PAGENAME = mw.config.get("wgPageName");
const USERNAME = mw.config.get("wgUserName");
// Make sure that all links open in a new tab when locked
$("body").on("click", "a", (e) => globalDeletionLock ? window.open(e.target.href, "_blank") && false : null);

Expand All @@ -43,6 +44,7 @@ $(() => (async () => {
while (aufrom !== eol) {
const _result = await api.post({
action: "query",
assertuser: USERNAME,
list: "allusers",
aurights: "rollback",
aulimit: "max",
Expand All @@ -66,6 +68,7 @@ $(() => (async () => {
while (gcmcontinue !== eol) {
const _result = await api.post({
action: "query",
assertuser: USERNAME,
format: "json",
rvprop: "user",
prop: "revisions",
Expand All @@ -91,6 +94,7 @@ $(() => (async () => {
try {
const html = (await api.post({
action: "parse",
assertuser: USERNAME,
pageid,
prop: "text",
})).parse.text["*"];
Expand Down Expand Up @@ -249,6 +253,7 @@ $(() => (async () => {
try {
await api.postWithToken("csrf", {
action: "delete",
assertuser: USERNAME,
format: "json",
title: target,
tags: "Automation tool",
Expand Down
1 change: 1 addition & 0 deletions src/gadgets/flagBlocked/MediaWiki:Gadget-flagBlocked.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ $(() => {
});
const data = (await api.get({
action: "query",
assertuser: mw.config.get("wgUserName"),
list: "logevents",
letype: "block",
leprop: "timestamp|details|comment",
Expand Down
5 changes: 5 additions & 0 deletions src/gadgets/flagEditWar/MediaWiki:Gadget-flagEditWar.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ $(() => {
$("#mw-notification-area").appendTo("body");

const pagename = mw.config.get("wgPageName");
const username = mw.config.get("wgUserName");
const api = new mw.Api();
try {
mw.notify("正在查询日志……", {
Expand All @@ -24,6 +25,7 @@ $(() => {
});
const data = (await api.get({
action: "query",
assertuser: username,
list: "logevents",
letype: "protect",
leprop: "user|details",
Expand All @@ -47,6 +49,7 @@ $(() => {
});
let text = (await api.get({
action: "parse",
assertuser: username,
prop: "wikitext",
page: pagename,
section: 0,
Expand All @@ -60,6 +63,7 @@ $(() => {
});
await api.postWithToken("csrf", {
action: "edit",
assertuser: username,
title: pagename,
section: 0,
text,
Expand All @@ -75,6 +79,7 @@ $(() => {
});
await api.postWithToken("csrf", {
action: "edit",
assertuser: username,
title: pagename,
section: 0,
prependtext: template,
Expand Down
Loading

0 comments on commit 7da2042

Please sign in to comment.