Skip to content

Commit

Permalink
feat: assert
Browse files Browse the repository at this point in the history
  • Loading branch information
lovelyCARDINAL committed Dec 25, 2023
1 parent 592d5ea commit 1977f55
Show file tree
Hide file tree
Showing 12 changed files with 33 additions and 3 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
1 change: 1 addition & 0 deletions src/gadgets/Purgecache/MediaWiki:Gadget-Purgecache.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ $(() => {
const api = new mw.Api(),
opt = {
action: "purge",
assertuser: mw.config.get("wgUserName"),
format: "json",
forcelinkupdate: true,
titles: mw.config.get("wgPageName"),
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 @@ -12,6 +12,7 @@
// };
$(() => (async () => {
const pagename = mw.config.get("wgPageName");
const username = mw.config.get("wgUserName");
if (mw.config.get("wgNamespaceNumber") !== 8 || pagename.includes(".js") || pagename.includes(".css")) {
return;
}
Expand Down Expand Up @@ -44,6 +45,7 @@ $(() => (async () => {
try {
prepopContent = lr_aivc.autoPopulate ? (await api.get({
action: "parse",
assertuser: username,
pageid,
prop: "wikitext",
})).parse.wikitext["*"] : "";
Expand Down Expand Up @@ -355,6 +357,7 @@ $(() => (async () => {
const text = `{{NoteTA|${this.config.noteTAStr}}}<pre id="converted">-{}-${replaced}</pre>`;
const parsed = $($.parseHTML((await zhAPI.post({
action: "parse",
assertuser: username,
text,
contentmodel: "wikitext",
prop: "text",
Expand Down Expand Up @@ -384,6 +387,7 @@ $(() => (async () => {
const text = this.textInputs[variant].getValue();
return api.postWithToken("csrf", {
action: "edit",
assertuser: username,
title: variantPage(variant),
text,
summary: `自动转换自[[${pagename}]]`,
Expand All @@ -394,6 +398,7 @@ $(() => (async () => {
const text = this.textInputs[parent/* as string*/].getValue();
return api.postWithToken("csrf", {
action: "edit",
assertuser: username,
title: variantPage(variant),
text,
summary: `自动转换自[[${pagename}]](同步${parent})`,
Expand Down
5 changes: 3 additions & 2 deletions src/gadgets/noteTA/MediaWiki:Gadget-noteTA.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ mw.hook("wikipage.content").add(() => {
try {
const results = await api.post({
action: "parse",
assertuser: mw.config.get("wgUserName"),
title: "Template:CGroup/____SAND_BOX____",
text: wikitext_1,
prop: "text",
Expand Down Expand Up @@ -95,6 +96,7 @@ mw.hook("wikipage.content").add(() => {
try {
const results = await api.post({
action: "parse",
assertuser: mw.config.get("wgUserName"),
title: actualTitle_1,
text: `{{noteTA/multititle|${actualTitle_1}}}`,
prop: "text",
Expand Down Expand Up @@ -189,7 +191,6 @@ mw.hook("wikipage.content").add(() => {
if (typeof wgUserId === "number" && wgUserId > 0 && mw.config.get("wgAction") === "view" && localStorage.getItem("AnnTools-noteTA-alert") !== "true" && !document.querySelector("#noteTA-lang") && !/^\/zh-[a-z]+\//.test(location.pathname)) {
const url = new mw.Uri();
const wgUserVariant = mw.config.get("wgUserVariant");
const wgUserName = mw.config.get("wgUserName");
if (!(Reflect.has(url.query, "variant") || Reflect.has(url.query, "uselang")) && !url.path.startsWith("/index.php") && name.includes(wgUserVariant)) {
$("body").append(`<div id="noteTA-lang" style="background: #3366CC; color: white; text-align: center; padding: .5rem; position: fixed; top: 0; left: 0; right: 0; z-index: 9999;"><p>检测到您当前使用的<b>内容</b>语言变体 ${wgUserVariant}${map[wgUserVariant]}会导致繁简转换无法正常工作,我们建议您切换到以下三种<b>内容</b>语言变体之一:</p><p><span class="noteTA-lang-changer mw-ui-button" data-lang="zh-cn">zh-cn(中国大陆)</span> <span class="noteTA-lang-changer mw-ui-button" data-lang="zh-hk">zh-hk(中国香港)</span> <span class="noteTA-lang-changer mw-ui-button" data-lang="zh-tw">zh-tw(台湾地区)</span> | <span id="noteTA-lang-explainer" class="mw-ui-button">了解更多</span> <span id="noteTA-lang-disable" class="mw-ui-button mw-ui-destructive">不再提示</span></div>`);
const container = $("#noteTA-lang");
Expand All @@ -201,7 +202,7 @@ mw.hook("wikipage.content").add(() => {
try {
const result = await api.postWithToken("csrf", {
action: "options",
assertuser: wgUserName,
assertuser: mw.config.get("wgUserName"),
optionname: "variant",
optionvalue: lang,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ $(() => {
const template = /^en/.test(location.hostname) ? "Awaiting_deletion" : "即将删除";
const d = await api.postWithToken("csrf", {
action: "edit",
assertuser: mw.config.get("wgUserName"),
format: "json",
title: mw.config.get("wgPageName"),
text: `<noinclude>{{${template}|1=${this.reason}|user=${mw.config.get("wgUserName")}}}</noinclude>`,
Expand Down Expand Up @@ -204,6 +205,7 @@ $(() => {
loadReason = true;
const { parse: { text: { ["*"]: html } } } = await new mw.Api().post({
action: "parse",
assertuser: mw.config.get("wgUserName"),
page: mw.config.get("wgNamespaceNumber") === mw.config.get("wgNamespaceIds").file ? "MediaWiki:Filedelete-reason-dropdown" : "MediaWiki:Deletereason-dropdown",
prop: "text",
});
Expand Down
1 change: 1 addition & 0 deletions src/gadgets/report/MediaWiki:Gadget-report.js
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,7 @@ $(() => {
const sectiontitle = `【页面反馈】${this.primaryType}${this.secondaryType !== "none" ? ` - ${this.secondaryType}` : ""} @ ${this.wgPageName}`;
await api.postWithToken("csrf", {
action: "edit",
assertuser: mw.config.get("wgUserName"),
title: "萌娘百科_talk:讨论版/提问求助",
section: "new",
sectiontitle,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,12 @@ $(() => {
if (uri.query.from) {
try {
await api.post({
action: "rollback",
assertuser: mw.config.get("wgUserName"),
title: uri.query.title,
user: uri.query.from,
summary,
token: uri.query.token,
action: "rollback",
format: "json",
});
rbing.css("color", "green").html(`成功!${wgULS("将在", "將在")}<span id="rbcount">3</span>秒${wgULS("内刷新", "內重新整理")}`);
Expand Down
2 changes: 2 additions & 0 deletions src/gadgets/temp-editcheck/MediaWiki:Gadget-temp-editcheck.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ $(() => {
const wgCurRevisionId = mw.config.get("wgCurRevisionId");
const wgArticleId = mw.config.get("wgArticleId");
const wgPageName = mw.config.get("wgPageName");
const wgUserName = mw.config.get("wgUserName");
const UNDEFINED = Symbol("UNDEFINED");
const sleep = (ms) => new Promise((res) => setTimeout(res, ms));
let unloading = false;
Expand Down Expand Up @@ -101,6 +102,7 @@ $(() => {
try {
_apiResult = await api.post({
action: "query",
assertuser: wgUserName,
format: "json",
prop: "revisions",
titles: wgPageName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ $(() => {
const api = new mw.Api();
const d = await api.postWithToken("csrf", {
action: "edit",
assertuser: mw.config.get("wgUserName"),
format: "json",
title: mw.config.get("wgPageName"),
text: "<noinclude>{{ns2d}}</noinclude>",
Expand Down

0 comments on commit 1977f55

Please sign in to comment.