2023年政策修订增补工作正在进行中,欢迎参与!
MediaWiki:Gadget-registerToDelete.js
跳转到导航
跳转到搜索
注意:在保存之后,您可能需要清除浏览器缓存才能看到所作出的变更的影响。
- Firefox/Safari:按住“Shift”的同时单击“刷新”,或按“Ctrl-F5”或“Ctrl-R”(Mac为“⌘-R”)
- Google Chrome:按“Ctrl-Shift-R”(Mac为“⌘-Shift-R”)
- Internet Explorer:按住“Ctrl”的同时单击“刷新”,或按“Ctrl-F5”
- Opera:在“工具→首选项”中清除缓存
- 如果您已登录但该页面出现未登录状态,请尝试在地址栏的地址最后添加代码
?_=1
来访问最新页面。 - 添加代码后的本页地址如下:
-{R|https://moegirl.icu/MediaWiki:Gadget-registerToDelete.js?_=1}-
萌娘百科界面管理员团队提醒您
本页面由萌娘百科界面管理员团队在其 GitHub 库内进行维护,通过机器人自动生成可被 MediaWiki Gadget 扩展接受的版本并保存到此处。
- 本页面的内容为自动生成,手动修改可能会被覆盖,源码可在此处查看;
- 最新修订由 U:BearBin 做出,相关 commit 为:96adf950 - feat(registerToDelete): 不使用的判定条件;顺带补充文档
/**
* -------------------------------------------------------------------------
* !!! DON'T MODIFY THIS PAGE MANUALLY, YOUR CHANGES WILL BE OVERWRITTEN !!!
* -------------------------------------------------------------------------
*/
var _addText = '{{GHIACode|page=GHIA:MoegirlPediaInterfaceCodes/blob/master/src/gadgets/registerToDelete/MediaWiki:Gadget-registerToDelete.js|user=[[U:BearBin]]|co-authors=|longId=96adf950f2eea1a4926fe47c31d51f322ac04376|shortId=96adf950|summary=feat(registerToDelete): 不使用的判定条件;顺带补充文档}}';
/* <pre> */
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
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 (g && (g = 0, op[0] && (_ = 0)), _) 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));
};
$(function () {
try {
if ($(".will2Be2Deleted")[0]
|| mw.config.get("wgRevisionId") === 0 && mw.config.get("wgArticleId") === 0
|| !mw.config.get("wgUserGroups").includes("patroller") && !(new URL(location.href).searchParams.get("AnnTools-debug") || "").split("|").includes("registerToDelete")) {
return;
}
var $body_1 = $("body");
$("#mw-notification-area").appendTo($body_1);
var loadReason_1 = false;
var FFDWindow = (function (_super) {
__extends(FFDWindow, _super);
function FFDWindow(config) {
var _this = _super.call(this, config) || this;
_this.storage = config.data.storage;
return _this;
}
FFDWindow.prototype.initialize = function () {
_super.prototype.initialize.call(this);
this.panelLayout = new OO.ui.PanelLayout({
scrollable: false,
expanded: false,
padded: true
});
this.reasonsDropdown = new OO.ui.DropdownInputWidget({
options: [{
data: "",
label: "其他(请自行说明理由)"
}, {
data: "",
disabled: true,
label: "加载中……"
}]
});
this.detailsText = new OO.ui.TextInputWidget();
this.dbCheckbox = new OO.ui.CheckboxInputWidget();
this.enterCheckbox = new OO.ui.CheckboxInputWidget({
selected: this.storage.getItem("enterToSubmit")
});
this.reasonsDropdownMenu = this.reasonsDropdown.dropdownWidget.getMenu();
var reasonsField = new OO.ui.FieldLayout(this.reasonsDropdown, {
label: wgULS("挂删理由", "掛删緣由"),
align: "top"
});
var detailsField = new OO.ui.FieldLayout(this.detailsText, {
label: wgULS("详情", "詳情"),
align: "top"
});
var dbField = new OO.ui.FieldLayout(this.dbCheckbox, {
label: wgULS("讨论版申请", "討論版申請"),
align: "inline"
});
var enterField = new OO.ui.FieldLayout(this.enterCheckbox, {
label: wgULS("理由详情按回车提交(浏览器级设置)", "緣由詳情按回車鍵提交(瀏覽器級設置)"),
align: "inline"
});
this.panelLayout.$element.append(reasonsField.$element, detailsField.$element, dbField.$element, enterField.$element);
this.reasonsDropdownMenu.connect(this, { toggle: "dropdownToggle" });
this.detailsText.connect(this, { enter: "onEnter" });
this.enterCheckbox.connect(this, { change: "setStorage" });
this.$body.append(this.panelLayout.$element);
};
FFDWindow.prototype.updateReasons = function (reasons) {
this.reasonsDropdown.setOptions(__spreadArray([{
data: "",
label: "其他(请自行说明理由)"
}], __read(reasons), false));
};
FFDWindow.prototype.setStorage = function (selected) {
this.storage.setItem("enterToSubmit", selected);
};
FFDWindow.prototype.onEnter = function () {
if (this.enterCheckbox.isSelected()) {
this.executeAction("submit");
}
};
FFDWindow.prototype.dropdownToggle = function (visible) {
var _this = this;
if (visible) {
var newHeight_1 = parseFloat(this.$frame.css("height")) + 300;
this.withoutSizeTransitions(function () {
_this.$frame.css("height", newHeight_1);
_this.reasonsDropdownMenu.clip();
$(_this.$frame).animate({
height: newHeight_1
}, 700);
});
}
else {
this.updateSize();
}
};
FFDWindow.prototype.getBodyHeight = function () {
return this.panelLayout.$element.outerHeight(true);
};
FFDWindow.prototype.getReadyProcess = function (data) {
var _this = this;
return _super.prototype.getReadyProcess.call(this, data).next(function () {
_this.reasonsDropdown.focus();
}, this);
};
FFDWindow.prototype.getActionProcess = function (action) {
var _this = this;
if (action === "cancel") {
return new OO.ui.Process(function () {
_this.close({ action: action });
}, this);
}
else if (action === "submit") {
return new OO.ui.Process($.when((function () { return __awaiter(_this, void 0, void 0, function () {
var e_1;
return __generator(this, function (_b) {
switch (_b.label) {
case 0:
this.reason = this.reasonsDropdown.getValue();
this.detail = this.detailsText.getValue();
if (!this.reason && !this.detail) {
throw new OO.ui.Error("请填写理由或详情");
}
this.reason = "".concat(this.dbCheckbox.isSelected() ? "讨论版申请:" : "").concat(this.reason ? "".concat(this.reason).concat(this.detail ? "\uFF1A".concat(this.detail) : "") : this.detail);
_b.label = 1;
case 1:
_b.trys.push([1, 3, , 4]);
return [4, this.flagTemplate()];
case 2:
_b.sent();
this.close({ action: action });
mw.notify(wgULS("即将刷新……", "即將刷新……"), {
title: wgULS("挂删成功", "掛删成功"),
type: "success",
tag: "lr-ffd"
});
setTimeout(function () { return location.reload(); }, 730);
return [3, 4];
case 3:
e_1 = _b.sent();
console.error("[FlagForDeletion] Error:", e_1);
throw new OO.ui.Error(e_1);
case 4: return [2];
}
});
}); })()).promise(), this);
}
return _super.prototype.getActionProcess.call(this, action);
};
FFDWindow.prototype.flagTemplate = function () {
return __awaiter(this, void 0, void 0, function () {
var api, template, d;
return __generator(this, function (_b) {
switch (_b.label) {
case 0:
api = new mw.Api();
template = /^en/.test(location.hostname) ? "Awaiting_deletion" : "即将删除";
return [4, api.postWithToken("csrf", {
action: "edit",
assertuser: mw.config.get("wgUserName"),
format: "json",
title: mw.config.get("wgPageName"),
text: "<noinclude>{{".concat(template, "|1=").concat(this.reason, "|user=").concat(mw.config.get("wgUserName"), "}}</noinclude>"),
summary: "\u6302\u5220\uFF1A".concat(this.reason),
nocreate: true,
watchlist: "nochange",
tags: "Automation tool",
contentmodel: "wikitext"
})];
case 1:
d = _b.sent();
if (d.error) {
throw d.error.code;
}
return [2];
}
});
});
};
FFDWindow.static = __assign(__assign({}, _super.static), { tagName: "div", name: "lr-ffd", title: wgULS("挂删", "掛删"), actions: [
{
action: "cancel",
label: "取消",
flags: ["safe", "close", "destructive"]
},
{
action: "submit",
label: wgULS("确认", "確認"),
flags: ["primary", "progressive"]
},
] });
return FFDWindow;
}(OO.ui.ProcessDialog));
var storage = new LocalObjectStorage("AnnTools-registerToDelete");
var windowManager_1 = new OO.ui.WindowManager();
$body_1.append(windowManager_1.$element);
var ffdDialog_1 = new FFDWindow({
size: "medium",
data: { storage: storage }
});
windowManager_1.addWindows([ffdDialog_1]);
$(mw.util.addPortletLink("p-cactions", "#", wgULS("挂删", "掛删"), "ca-lr-ffd", "".concat(wgULS("挂删本页", "掛删本頁"), "[alt-shift-d]")), "d").on("click", function (e) { return __awaiter(void 0, void 0, void 0, function () {
var html, container, result_1, getReason_1;
return __generator(this, function (_b) {
switch (_b.label) {
case 0:
e.preventDefault();
windowManager_1.openWindow(ffdDialog_1);
$body_1.css("overflow", "auto");
if (!(loadReason_1 === false)) return [3, 2];
loadReason_1 = true;
return [4, 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"
})];
case 1:
html = (_b.sent()).parse.text["*"];
container = $("<div>");
container.html(html);
result_1 = [];
getReason_1 = function (ele) {
result_1.push({
data: ele.innerText.trim(),
label: ele.innerText.trim()
});
};
container.children(".mw-parser-output").children("ul").children("li").each(function (_, ele) {
var $ele = $(ele);
if ($ele.children("ul").length > 0) {
result_1.push({
optgroup: $ele.clone().find("*").remove().end().text().trim()
});
$ele.children("ul").children("li").each(function (_, e) { return getReason_1(e); });
}
else {
getReason_1(ele);
}
});
ffdDialog_1.updateReasons(result_1);
_b.label = 2;
case 2: return [2];
}
});
}); });
}
catch (e) {
var parseError = function (errLike, _space) {
var space = _space;
if (_space === void 0) {
space = 4;
}
return JSON.stringify(errLike, function (_, v) {
if (v instanceof Error) {
var stack = [];
if (v.stack) {
Reflect.apply(stack.push, stack, v.stack.split("\n").map(function (n) {
return n.trim();
}).filter(function (n) {
var _a;
return ((_a = n === null || n === void 0 ? void 0 : n.length) !== null && _a !== void 0 ? _a : -1) > 0;
}));
}
var keys = Object.keys(v).filter(function (key) {
return !Reflect.has(Error.prototype, key);
});
if (keys.length) {
stack.push(JSON.stringify(Object.fromEntries(keys.map(function (key) {
return [key, v[key]];
})), null, space));
}
return stack.join("\n").trim() || "";
}
return v;
}, space).replace(/^"(.*)"$/, "$1");
};
oouiDialog.alert("错误信息:<br>" + oouiDialog.sanitize(parseError(e)), {
title: "挂删工具发生错误"
});
console.error("[FlagForDeletion] Setup error:", e);
}
});
/* </pre> */