MediaWiki:Gadget-deletion.js
注意:在保存之后,您可能需要清除浏览器缓存才能看到所作出的变更的影响。
- Firefox或Safari:按住Shift的同时单击刷新,或按Ctrl-F5或Ctrl-R(Mac为⌘-R)
- Google Chrome:按Ctrl-Shift-R(Mac为⌘-Shift-R)
- Internet Explorer:按住Ctrl的同时单击刷新,或按Ctrl-F5
- Opera:前往菜单 → 设置(Mac为Opera → Preferences),然后隐私和安全 → 清除浏览数据 → 缓存的图片和文件。
/* <pre> */ /** * ------------------------------------------------------------------------- * !!! DON'T MODIFY THIS PAGE MANUALLY, YOUR CHANGES WILL BE OVERWRITTEN !!! * ------------------------------------------------------------------------- */ var _addText = '{{GHIACode|page=GHIA:MoegirlPediaInterfaceCodes/blob/master/src/gadgets/deletion/MediaWiki:Gadget-deletion.js|user=[[U:Leranjun]]|longId=30d90e3944e72e488b45487599649e124a714e6e|shortId=30d90e3|message=fix(Gadget-deletion): fix link error}}'; "use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var __generator = (this && this.__generator) || function (thisArg, body) { var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; function verb(n) { return function (v) { return step([n, v]); }; } function step(op) { if (f) throw new TypeError("Generator is already executing."); while (_) try { if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; if (y = 0, t) op = [op[0] & 2, t.value]; switch (op[0]) { case 0: case 1: t = op; break; case 4: _.label++; return { value: op[1], done: false }; case 5: _.label++; y = op[1]; op = [0]; continue; case 7: op = _.ops.pop(); _.trys.pop(); continue; default: if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } if (t[2]) _.ops.pop(); _.trys.pop(); continue; } op = body.call(thisArg, _); } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; } }; var __read = (this && this.__read) || function (o, n) { var m = typeof Symbol === "function" && o[Symbol.iterator]; if (!m) return o; var i = m.call(o), r, ar = [], e; try { while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); } catch (error) { e = { error: error }; } finally { try { if (r && !r.done && (m = i["return"])) m.call(i); } finally { if (e) throw e.error; } } return ar; }; var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { if (ar || !(i in from)) { if (!ar) ar = Array.prototype.slice.call(from, 0, i); ar[i] = from[i]; } } return to.concat(ar || Array.prototype.slice.call(from)); }; var __values = (this && this.__values) || function(o) { var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0; if (m) return m.call(o); if (o && typeof o.length === "number") return { next: function () { if (o && i >= o.length) o = void 0; return { value: o && o[i++], done: !o }; } }; throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined."); }; $(function () { return (function () { return __awaiter(void 0, void 0, void 0, function () { var deduplicate, generatePageLinkSelector, globalDeletionLock, DELCATS, PAGENAME, api, $root, $items, $control, $portlet, $portletAnchor, pages, isDelCat, trustedUsers, candidatePages, candidatePages_1, candidatePages_1_1, _a, title, pageid, _b, user, retryTimes, html, $html, $reason, $actor, reason, actor, link, isTrusted, e_1, e_2_1; var e_2, _c; return __generator(this, function (_d) { switch (_d.label) { case 0: if (mw.config.get("wgNamespaceNumber") !== 14 || !mw.config.get("wgIsArticle") || !mw.config.get("wgUserGroups").includes("sysop") || !$(".mw-category-generated > div")[0]) { return [2]; } deduplicate = function (iterable) { return __spreadArray([], __read(new Set(iterable).values()), false); }; generatePageLinkSelector = function (title) { return deduplicate([encodeURI(title), mw.util.wikiUrlencode(title)]).map(function (selector) { return "a[href$=\"/".concat(selector, "\"]"); }).join(","); }; globalDeletionLock = false; DELCATS = { "zh.moegirl.org.cn": "即将删除的页面", "commons.moegirl.org.cn": "即将删除的页面", "en.moegirl.org.cn": "Pages awaiting deletion", "ja.moegirl.org.cn": "削除依頼中のページ", "library.moegirl.org.cn": "即将删除的页面" }; PAGENAME = mw.config.get("wgPageName"); $("body").on("click", "a", function (e) { return globalDeletionLock ? window.open(e.target.href, "_blank") && false : null; }); api = new mw.Api(); $root = $(".mw-category-generated"), $items = $root.find("li"); $control = $("<p id='batdel-control'>"); $portlet = $(mw.util.addPortletLink("p-cactions", "#", wgULS("批量删除本分类下页面", "批量刪除本分類下頁面"), "ca-batdel", wgULS("批量删除本分类下页面", "批量刪除本分類下頁面"))), $portletAnchor = $portlet.find("a"); pages = []; isDelCat = mw.config.get("wgTitle") === DELCATS[location.hostname]; if (!isDelCat) return [3, 15]; globalDeletionLock = true; $portletAnchor.text(wgULS("正在加载中……", "正在加載中……")); return [4, (function () { return __awaiter(void 0, void 0, void 0, function () { var result, eol, aufrom, _result; return __generator(this, function (_a) { switch (_a.label) { case 0: result = []; eol = Symbol(); aufrom = undefined; _a.label = 1; case 1: if (!(aufrom !== eol)) return [3, 3]; return [4, api.post({ action: "query", list: "allusers", aurights: "rollback", aulimit: "max", aufrom: aufrom })]; case 2: _result = _a.sent(); if (_result["continue"]) { aufrom = _result["continue"].aufrom; } else { aufrom = eol; } result.push.apply(result, __spreadArray([], __read(_result.query.allusers.map(function (_a) { var name = _a.name; return name; })), false)); return [3, 1]; case 3: return [2, result]; } }); }); })()]; case 1: trustedUsers = _d.sent(); return [4, (function () { return __awaiter(void 0, void 0, void 0, function () { var result, eol, gcmcontinue, _result; return __generator(this, function (_a) { switch (_a.label) { case 0: result = []; eol = Symbol(); gcmcontinue = undefined; _a.label = 1; case 1: if (!(gcmcontinue !== eol)) return [3, 3]; return [4, api.post({ action: "query", format: "json", rvprop: "user", prop: "revisions", generator: "categorymembers", gcmtitle: PAGENAME, gcmprop: "ids|title", gcmtype: "page|subcat|file", gcmlimit: "max", gcmcontinue: gcmcontinue })]; case 2: _result = _a.sent(); if (_result["continue"]) { gcmcontinue = _result["continue"].gcmcontinue; } else { gcmcontinue = eol; } result.push.apply(result, __spreadArray([], __read(Object.values(_result.query.pages)), false)); return [3, 1]; case 3: return [2, result.filter(function (_a) { var title = _a.title; return document.querySelector(generatePageLinkSelector(title)); })]; } }); }); })()]; case 2: candidatePages = _d.sent(); _d.label = 3; case 3: _d.trys.push([3, 12, 13, 14]); candidatePages_1 = __values(candidatePages), candidatePages_1_1 = candidatePages_1.next(); _d.label = 4; case 4: if (!!candidatePages_1_1.done) return [3, 11]; _a = candidatePages_1_1.value, title = _a.title, pageid = _a.pageid, _b = __read(_a.revisions, 1), user = _b[0].user; retryTimes = 0; _d.label = 5; case 5: if (!(retryTimes < 3)) return [3, 10]; _d.label = 6; case 6: _d.trys.push([6, 8, , 9]); return [4, api.post({ action: "parse", pageid: pageid, prop: "text" })]; case 7: html = (_d.sent()).parse.text["*"]; $html = $(html).children(".infoBox.will2Be2Deleted"); $reason = $html.find("#reason"), $actor = $html.find("#actor a").first(); reason = $reason.text().trim(), actor = $actor.text().trim(); link = $(generatePageLinkSelector(title)); if ($reason.length === 1 && $actor.length === 1 && reason && actor) { isTrusted = user === actor && trustedUsers.includes(user); pages.push({ title: title, user: user, isTrusted: isTrusted, reason: reason }); link.addClass("batdel-checked"); if (isTrusted) { link.after("<div>".concat(wgULS("挂删人", "掛刪人"), "\uFF1A<a href=\"/User:").concat(user, "\" class=\"mw-userlink batdel-bypass\"><bdi>").concat(user, "</bdi></a></div><div>").concat(wgULS("挂删理由", "掛刪理由"), "\uFF1A").concat(reason, "</div>")); } else { link.prop("target", "_blank").after("<div class=\"batdel-error\">".concat(wgULS("禁止删除:该次挂删不可靠,请手动检查", "禁止刪除:該次掛刪不可靠,請手動檢查"), "\uFF08").concat(user !== $actor.text() ? wgULS("最后编辑者与挂删人不符", "最後編輯者與掛刪人不符") : wgULS("最后编辑者没有巡查权限", "最後編輯者沒有巡查權限"), "\uFF09</div>")); console.warn("[BatchDelete] ".concat(title, " does not have a trusted flag")); } } else { pages.push({ title: title, user: actor, isTrusted: false, reason: reason }); link.addClass("batdel-bypass").prop("target", "_blank").after("<div class=\"batdel-error\">".concat(wgULS("禁止删除:该次挂删不可靠,请手动检查(挂删模板未给出理由或挂删人)", "禁止刪除:該次掛刪不可靠,請手動檢查(掛刪模板未給出理由或掛刪人)"), "</div>")); console.warn("[BatchDelete] ".concat(title, " has empty reason or actor")); } return [3, 10]; case 8: e_1 = _d.sent(); console.error("[BatchDelete]", e_1); return [3, 9]; case 9: retryTimes++; return [3, 5]; case 10: candidatePages_1_1 = candidatePages_1.next(); return [3, 4]; case 11: return [3, 14]; case 12: e_2_1 = _d.sent(); e_2 = { error: e_2_1 }; return [3, 14]; case 13: try { if (candidatePages_1_1 && !candidatePages_1_1.done && (_c = candidatePages_1["return"])) _c.call(candidatePages_1); } finally { if (e_2) throw e_2.error; } return [7]; case 14: $items.find("a:not(.batdel-bypass, .batdel-checked)").each(function (_, ele) { var $link = $(ele); $link.prop("target", "_blank").after("<div class=\"batdel-error\">".concat(wgULS("禁止删除:无法获取页面挂删信息", "禁止刪除:無法獲取頁面掛刪信息"), "</div>")); console.warn("[BatchDelete] ".concat($link.text(), " is not processed")); }); globalDeletionLock = false; mw.hook("wikipage.content").fire($(".mw-userlink.batdel-bypass")); $portletAnchor.text(wgULS("批量删除本分类下页面", "批量刪除本分類下頁面")); _d.label = 15; case 15: $portlet.addClass("sysop-show").on("click", function () { if ($("#batdel-control")[0] || globalDeletionLock) { return; } var selectedNum = $("<span>0</span>"), totalNum = $("<span>?</span>"); var toggleSelection = $("<button>".concat(wgULS("全选/全不选", "全選/全不選"), "</button>")), runDeletion = $("<button>提交</button>"), cancelDeletion = $("<button>取消</button>"); $control.empty().append([ "".concat(wgULS("请选择要删除的页面", "請選擇要刪除的頁面"), " ["), selectedNum, "/", totalNum, "] ", toggleSelection, runDeletion, cancelDeletion, ]).prependTo($root); $("body").addClass("batdel-body"); $items.each(function (_, ele) { return $(ele).prepend($("<input type='checkbox' class='batdel-select'>").prop("disabled", $(ele).find(".batdel-error")[0])); }).find(".stub").toggleClass("stub _stub"); var checkboxes = $items.find(".batdel-select:not(:disabled)"); totalNum.text(checkboxes.length); checkboxes.on("change", function () { return selectedNum.text(checkboxes.filter(":checked").length); }); $root.children("div").children("p").each(function (_, ele) { $("<button class=\"batdel-controlButton\">".concat(wgULS("全选/全不选本类别页面", "全選/全不選本類別頁面"), "</button>")).on("click", function (e) { return $(e.target).closest(".mw-category-generated > div").find(".batdel-select:not(:disabled)").each(function (_, ele) { return $(ele).prop("checked", !ele.checked); }).trigger("change"); }).appendTo(ele); }); toggleSelection.on("click", function () { $items.find(".batdel-select:not(:disabled)").each(function (_, ele) { return $(ele).prop("checked", !ele.checked); }).trigger("change"); }); cancelDeletion.on("click", function () { if (globalDeletionLock) { return; } $control.remove(); $(".batdel-controlButton").remove(); $root.find("._stub").toggleClass("stub _stub"); $items.find(".batdel-select").remove(); $(".batdel-disabled").removeClass("batdel-disabled"); $("body").removeClass("batdel-body"); }); runDeletion.on("click", function () { return __awaiter(void 0, void 0, void 0, function () { var _a, $spinner, $status, _loop_1, _b, _c, ele, state_1, e_3_1, e_4; var e_3, _d; return __generator(this, function (_e) { switch (_e.label) { case 0: _a = globalDeletionLock; if (_a) return [3, 2]; return [4, oouiDialog.confirm("".concat(wgULS("您确定要删除这些页面吗?", "您確定要刪除這些頁面嗎?"), "\uFF08").concat(wgULS("选中了", "選中了")).concat($items.find(".batdel-select:checked").length).concat(wgULS("个页面", "個頁面"), "\uFF09"), { title: wgULS("批量删除分类页面工具", "批量刪除分類頁面工具") })]; case 1: _a = !(_e.sent()); _e.label = 2; case 2: if (_a) { return [2]; } globalDeletionLock = true; $spinner = $('<img src="https://img.moegirl.org.cn/common/d/d1/Windows_10_loading.gif" style="height: 1em; margin-top: -.25em;">'), $status = $("<span>"); $root.find(".batdel-result").remove(); $root.find(".batdel-select").prop("disabled", true); $control.append("<br>", $spinner, $status); $root.find("a:not(.batdel-bypass)").each(function (_, ele) { var self = $(ele); if (!self.closest("li").find(".batdel-select:checked")[0]) { self.addClass("batdel-disabled"); } }); _e.label = 3; case 3: _e.trys.push([3, 12, , 13]); $status.text(wgULS("正在删除,已完成删除的页面将会被删除线划去……", "正在刪除,已完成刪除的頁面將會被刪除線划去……")); _loop_1 = function (ele) { var self_1, url, target, page, e_5; return __generator(this, function (_f) { switch (_f.label) { case 0: self_1 = $(ele); if (!self_1.text().trim()) { return [2, { value: void 0 }]; } self_1.css("margin-right", "1em"); url = new URL(new mw.Uri(self_1.prop("href"))); target = decodeURIComponent(url.searchParams.has("title") ? url.searchParams.get("title") : url.pathname.replace(/^\//, "")).replace(/_/g, " "); page = pages.filter(function (_a) { var title = _a.title; return title === target; })[0]; _f.label = 1; case 1: _f.trys.push([1, 3, , 4]); return [4, api.postWithToken("csrf", { action: "delete", format: "json", title: target, tags: "Automation tool", reason: "\u6279\u91CF\u5220\u9664\u3010".concat(PAGENAME, "\u3011\u4E0B\u7684\u9875\u9762").concat(isDelCat && page.isTrusted && page.reason && page.user ? "\uFF08[[User_talk:".concat(page.user, "|").concat(page.user, "]]\u7684\u6302\u5220\u7406\u7531\uFF1A").concat(page.reason, " \uFF09") : "") }, { timeout: 99999 })]; case 2: _f.sent(); self_1.css("text-decoration", "line-through").after("<span class=\"batdel-result batdel-success\">".concat(wgULS("删除成功", "刪除成功"), "</span>")); return [3, 4]; case 3: e_5 = _f.sent(); self_1.after("<span class=\"batdel-result batdel-error\"> ".concat(wgULS("删除失败", "刪除失敗"), "\uFF1A").concat(e_5 instanceof Error ? "".concat(e_5, " ").concat(e_5.stack.split("\n")[1].trim()) : JSON.stringify(e_5), "</span>")); return [3, 4]; case 4: return [2]; } }); }; _e.label = 4; case 4: _e.trys.push([4, 9, 10, 11]); _b = __values($root.find("a").not(".batdel-bypass, .batdel-disabled").toArray()), _c = _b.next(); _e.label = 5; case 5: if (!!_c.done) return [3, 8]; ele = _c.value; return [5, _loop_1(ele)]; case 6: state_1 = _e.sent(); if (typeof state_1 === "object") return [2, state_1.value]; _e.label = 7; case 7: _c = _b.next(); return [3, 5]; case 8: return [3, 11]; case 9: e_3_1 = _e.sent(); e_3 = { error: e_3_1 }; return [3, 11]; case 10: try { if (_c && !_c.done && (_d = _b["return"])) _d.call(_b); } finally { if (e_3) throw e_3.error; } return [7]; case 11: $spinner.remove(); $status.addClass("batdel-success").text(wgULS("删除已完成!", "刪除已完成!")); return [3, 13]; case 12: e_4 = _e.sent(); $spinner.remove(); $status.text("".concat(wgULS("发生错误", "發生錯誤"), "\uFF1A").concat(e_4 instanceof Error ? "".concat(e_4, " ").concat(e_4.stack.split("\n")[1].trim()) : JSON.stringify(e_4))); return [3, 13]; case 13: return [2]; } }); }); }); return false; }); return [2]; } }); }); })(); }); /* </pre> */