置顶公告:【置顶】关于临时开启评论区所有功能的公告(2022.10.22) | 【置顶】关于本站Widget恢复使用的公告
  • 你好~!欢迎来到萌娘百科镜像站!如需查看或编辑,请联系本站管理员注册账号。
  • 本镜像站和其他萌娘百科的镜像站无关,请注意分别。

MediaWiki:Gadget-registerToDelete.js:修订间差异

贴贴♀百科,万娘皆可贴的百科全书!转载请标注来源页面的网页链接,并声明引自贴贴百科。内容不可商用。
跳到导航 跳到搜索
(已保护“MediaWiki:Gadget-registerToDelete.js”:​MW页面([编辑=仅允许管理员](无限期)[移动=仅允许管理员](无限期)))
无编辑摘要
第97行: 第97行:
$(function () {
$(function () {
    try {
    try {
      if ($(".noarticletext")[0] || $(".will2Be2Deleted")[0] || mw.config.get("wgRevisionId") === 0 || !mw.config.get("wgUserGroups").includes("patroller") && !(new URL(location.href).searchParams.get("AnnTools-debug") || "").split("|").includes("registerToDelete")) {
      if ($(".noarticletext")[0] || $(".will2Be2Deleted")[0] || mw.config.get("wgRevisionId") === 0 || !mw.config.get("wgUserGroups").includes("patroller", "sysop") {
        return;
        return;
      }
      }

2025年1月25日 (六) 14:13的版本

预览加载中...
  1. /* <pre> */
  2. /**
  3. * -------------------------------------------------------------------------
  4. * !!! DON'T MODIFY THIS PAGE MANUALLY, YOUR CHANGES WILL BE OVERWRITTEN !!!
  5. * -------------------------------------------------------------------------
  6. */
  7. var _addText = '{{GHIACode|page=GHIA:MoegirlPediaInterfaceCodes/blob/master/src/gadgets/registerToDelete/MediaWiki:Gadget-registerToDelete.js|user=[[U:AnnAngela]]|longId=6f8a23f9951f134b52ac3f0427df1d3f9d4e8490|shortId=6f8a23f|message=refactor: Use `Reflect.has` instead of `in` operator}}';
  8. "use strict";
  9. var __extends = (this && this.__extends) || (function () {
  10. var extendStatics = function (d, b) {
  11. extendStatics = Object.setPrototypeOf ||
  12. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  13. function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
  14. return extendStatics(d, b);
  15. };
  16. return function (d, b) {
  17. if (typeof b !== "function" && b !== null)
  18. throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
  19. extendStatics(d, b);
  20. function __() { this.constructor = d; }
  21. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  22. };
  23. })();
  24. var __assign = (this && this.__assign) || function () {
  25. __assign = Object.assign || function(t) {
  26. for (var s, i = 1, n = arguments.length; i < n; i++) {
  27. s = arguments[i];
  28. for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
  29. t[p] = s[p];
  30. }
  31. return t;
  32. };
  33. return __assign.apply(this, arguments);
  34. };
  35. var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
  36. function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
  37. return new (P || (P = Promise))(function (resolve, reject) {
  38. function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
  39. function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
  40. function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
  41. step((generator = generator.apply(thisArg, _arguments || [])).next());
  42. });
  43. };
  44. var __generator = (this && this.__generator) || function (thisArg, body) {
  45. var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
  46. return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
  47. function verb(n) { return function (v) { return step([n, v]); }; }
  48. function step(op) {
  49. if (f) throw new TypeError("Generator is already executing.");
  50. while (_) try {
  51. 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;
  52. if (y = 0, t) op = [op[0] & 2, t.value];
  53. switch (op[0]) {
  54. case 0: case 1: t = op; break;
  55. case 4: _.label++; return { value: op[1], done: false };
  56. case 5: _.label++; y = op[1]; op = [0]; continue;
  57. case 7: op = _.ops.pop(); _.trys.pop(); continue;
  58. default:
  59. if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
  60. if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
  61. if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
  62. if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
  63. if (t[2]) _.ops.pop();
  64. _.trys.pop(); continue;
  65. }
  66. op = body.call(thisArg, _);
  67. } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
  68. if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
  69. }
  70. };
  71. var __read = (this && this.__read) || function (o, n) {
  72. var m = typeof Symbol === "function" && o[Symbol.iterator];
  73. if (!m) return o;
  74. var i = m.call(o), r, ar = [], e;
  75. try {
  76. while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
  77. }
  78. catch (error) { e = { error: error }; }
  79. finally {
  80. try {
  81. if (r && !r.done && (m = i["return"])) m.call(i);
  82. }
  83. finally { if (e) throw e.error; }
  84. }
  85. return ar;
  86. };
  87. var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
  88. if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
  89. if (ar || !(i in from)) {
  90. if (!ar) ar = Array.prototype.slice.call(from, 0, i);
  91. ar[i] = from[i];
  92. }
  93. }
  94. return to.concat(ar || Array.prototype.slice.call(from));
  95. };
  96. $(function () {
  97. try {
  98. if ($(".noarticletext")[0] || $(".will2Be2Deleted")[0] || mw.config.get("wgRevisionId") === 0 || !mw.config.get("wgUserGroups").includes("patroller", "sysop") {
  99. return;
  100. }
  101. var $body_1 = $("body");
  102. $("#mw-notification-area").appendTo($body_1);
  103. var loadReason_1 = false;
  104. var FFDWindow = (function (_super) {
  105. __extends(FFDWindow, _super);
  106. function FFDWindow(config) {
  107. var _this = _super.call(this, config) || this;
  108. _this.storage = config.data.storage;
  109. return _this;
  110. }
  111. FFDWindow.prototype.initialize = function () {
  112. _super.prototype.initialize.call(this);
  113. this.panelLayout = new OO.ui.PanelLayout({
  114. scrollable: false,
  115. expanded: false,
  116. padded: true
  117. });
  118. this.reasonsDropdown = new OO.ui.DropdownInputWidget({
  119. options: [{
  120. data: "",
  121. label: "其他(请自行说明理由)"
  122. }, {
  123. data: "",
  124. disabled: true,
  125. label: "加载中……"
  126. }]
  127. });
  128. this.detailsText = new OO.ui.TextInputWidget();
  129. this.dbCheckbox = new OO.ui.CheckboxInputWidget();
  130. this.enterCheckbox = new OO.ui.CheckboxInputWidget({
  131. selected: this.storage.getItem("enterToSubmit")
  132. });
  133. this.reasonsDropdownMenu = this.reasonsDropdown.dropdownWidget.getMenu();
  134. var reasonsField = new OO.ui.FieldLayout(this.reasonsDropdown, {
  135. label: wgULS("挂删理由", "掛删緣由"),
  136. align: "top"
  137. });
  138. var detailsField = new OO.ui.FieldLayout(this.detailsText, {
  139. label: wgULS("详情", "詳情"),
  140. align: "top"
  141. });
  142. var dbField = new OO.ui.FieldLayout(this.dbCheckbox, {
  143. label: wgULS("讨论版申请", "討論版申請"),
  144. align: "inline"
  145. });
  146. var enterField = new OO.ui.FieldLayout(this.enterCheckbox, {
  147. label: wgULS("理由详情按回车提交(浏览器级设置)", "緣由詳情按回車鍵提交(瀏覽器級設置)"),
  148. align: "inline"
  149. });
  150. this.panelLayout.$element.append(reasonsField.$element, detailsField.$element, dbField.$element, enterField.$element);
  151. this.reasonsDropdownMenu.connect(this, { toggle: "dropdownToggle" });
  152. this.detailsText.connect(this, { enter: "onEnter" });
  153. this.enterCheckbox.connect(this, { change: "setStorage" });
  154. this.$body.append(this.panelLayout.$element);
  155. };
  156. FFDWindow.prototype.updateReasons = function (reasons) {
  157. this.reasonsDropdown.setOptions(__spreadArray([{
  158. data: "",
  159. label: "其他(请自行说明理由)"
  160. }], __read(reasons), false));
  161. };
  162. FFDWindow.prototype.setStorage = function (selected) {
  163. this.storage.setItem("enterToSubmit", selected);
  164. };
  165. FFDWindow.prototype.onEnter = function () {
  166. if (this.enterCheckbox.isSelected()) {
  167. this.executeAction("submit");
  168. }
  169. };
  170. FFDWindow.prototype.dropdownToggle = function (visible) {
  171. var _this = this;
  172. if (visible) {
  173. var newHeight_1 = parseFloat(this.$frame.css("height")) + 300;
  174. this.withoutSizeTransitions(function () {
  175. _this.$frame.css("height", newHeight_1);
  176. _this.reasonsDropdownMenu.clip();
  177. });
  178. }
  179. else {
  180. this.updateSize();
  181. }
  182. };
  183. FFDWindow.prototype.getBodyHeight = function () {
  184. return this.panelLayout.$element.outerHeight(true);
  185. };
  186. FFDWindow.prototype.getReadyProcess = function (data) {
  187. var _this = this;
  188. return _super.prototype.getReadyProcess.call(this, data).next(function () {
  189. _this.reasonsDropdown.focus();
  190. }, this);
  191. };
  192. FFDWindow.prototype.getActionProcess = function (action) {
  193. var _this = this;
  194. if (action === "cancel") {
  195. return new OO.ui.Process(function () {
  196. _this.close({ action: action });
  197. }, this);
  198. }
  199. else if (action === "submit") {
  200. return new OO.ui.Process($.when((function () { return __awaiter(_this, void 0, void 0, function () {
  201. var e_1;
  202. return __generator(this, function (_b) {
  203. switch (_b.label) {
  204. case 0:
  205. this.reason = this.reasonsDropdown.getValue();
  206. this.detail = this.detailsText.getValue();
  207. if (!this.reason && !this.detail) {
  208. throw new OO.ui.Error("请填写理由或详情");
  209. }
  210. this.reason = "".concat(this.dbCheckbox.isSelected() ? "讨论版申请:" : "").concat(this.reason ? "".concat(this.reason).concat(this.detail ? "\uFF1A".concat(this.detail) : "") : this.detail);
  211. _b.label = 1;
  212. case 1:
  213. _b.trys.push([1, 3, , 4]);
  214. return [4, this.flagTemplate()];
  215. case 2:
  216. _b.sent();
  217. this.close({ action: action });
  218. mw.notify(wgULS("即将刷新……", "即將刷新……"), {
  219. title: wgULS("挂删成功", "掛删成功"),
  220. type: "success",
  221. tag: "lr-ffd"
  222. });
  223. setTimeout(function () { return location.reload(); }, 730);
  224. return [3, 4];
  225. case 3:
  226. e_1 = _b.sent();
  227. console.error("[FlagForDeletion] Error:", e_1);
  228. throw new OO.ui.Error(e_1);
  229. case 4: return [2];
  230. }
  231. });
  232. }); })()).promise(), this);
  233. }
  234. return _super.prototype.getActionProcess.call(this, action);
  235. };
  236. FFDWindow.prototype.flagTemplate = function () {
  237. return __awaiter(this, void 0, void 0, function () {
  238. var api, template, d;
  239. return __generator(this, function (_b) {
  240. switch (_b.label) {
  241. case 0:
  242. api = new mw.Api();
  243. template = /^en/.test(location.hostname) ? "Awaiting_deletion" : "即将删除";
  244. return [4, api.postWithToken("csrf", {
  245. action: "edit",
  246. format: "json",
  247. title: mw.config.get("wgPageName"),
  248. text: "<noinclude>{{".concat(template, "|1=").concat(this.reason, "|user=").concat(mw.config.get("wgUserName"), "}}</noinclude>"),
  249. summary: "\u6302\u5220\uFF1A".concat(this.reason),
  250. nocreate: true,
  251. watchlist: "nochange",
  252. tags: "Automation tool"
  253. })];
  254. case 1:
  255. d = _b.sent();
  256. if (d.error) {
  257. throw d.error.code;
  258. }
  259. return [2];
  260. }
  261. });
  262. });
  263. };
  264. FFDWindow.static = __assign(__assign({}, _super.static), { name: "lr-ffd", title: wgULS("挂删", "掛删"), actions: [
  265. {
  266. action: "cancel",
  267. label: "取消",
  268. flags: ["safe", "close", "destructive"]
  269. },
  270. {
  271. action: "submit",
  272. label: wgULS("确认", "確認"),
  273. flags: ["primary", "progressive"]
  274. },
  275. ] });
  276. return FFDWindow;
  277. }(OO.ui.ProcessDialog));
  278. var storage = new LocalObjectStorage("AnnTools-registerToDelete");
  279. var windowManager_1 = new OO.ui.WindowManager();
  280. $body_1.append(windowManager_1.$element);
  281. var ffdDialog_1 = new FFDWindow({
  282. size: "medium",
  283. data: { storage: storage }
  284. });
  285. windowManager_1.addWindows([ffdDialog_1]);
  286. $(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 () {
  287. var html, container, result_1, getReason_1;
  288. return __generator(this, function (_b) {
  289. switch (_b.label) {
  290. case 0:
  291. e.preventDefault();
  292. windowManager_1.openWindow(ffdDialog_1);
  293. $body_1.css("overflow", "auto");
  294. if (!(loadReason_1 === false)) return [3, 2];
  295. loadReason_1 = true;
  296. return [4, new mw.Api().post({
  297. action: "parse",
  298. page: mw.config.get("wgNamespaceNumber") === mw.config.get("wgNamespaceIds").file ? "MediaWiki:Filedelete-reason-dropdown" : "MediaWiki:Deletereason-dropdown",
  299. prop: "text"
  300. })];
  301. case 1:
  302. html = (_b.sent()).parse.text["*"];
  303. container = $("<div>");
  304. container.html(html);
  305. result_1 = [];
  306. getReason_1 = function (ele) {
  307. result_1.push({
  308. data: ele.innerText.trim(),
  309. label: ele.innerText.trim()
  310. });
  311. };
  312. container.children(".mw-parser-output").children("ul").children("li").each(function (_, ele) {
  313. var $ele = $(ele);
  314. if ($ele.children("ul").length > 0) {
  315. result_1.push({
  316. optgroup: $ele.clone().find("*").remove().end().text().trim()
  317. });
  318. $ele.children("ul").children("li").each(function (_, e) { return getReason_1(e); });
  319. }
  320. else {
  321. getReason_1(ele);
  322. }
  323. });
  324. ffdDialog_1.updateReasons(result_1);
  325. _b.label = 2;
  326. case 2: return [2];
  327. }
  328. });
  329. }); });
  330. }
  331. catch (e) {
  332. var parseError = function (errLike, space) {
  333. if (space === void 0) {
  334. space = 4;
  335. }
  336. return JSON.stringify(errLike, function (_, v) {
  337. if (v instanceof Error) {
  338. var stack = [];
  339. if (v.stack) {
  340. stack.push.apply(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; }));
  341. }
  342. var keys = Object.keys(v).filter(function (key) { return !(Reflect.has(Error.prototype, key)); });
  343. if (keys.length) {
  344. stack.push(JSON.stringify(Object.fromEntries(keys.map(function (key) { return [key, v[key]]; })), null, space));
  345. }
  346. return stack.join("\n").trim() || "";
  347. }
  348. return v;
  349. }, space).replace(/^"(.*)"$/, "$1");
  350. };
  351. oouiDialog.alert("错误信息:<br>" + oouiDialog.sanitize(parseError(e)), {
  352. title: "挂删工具发生错误"
  353. });
  354. console.error("[FlagForDeletion] Setup error:", e);
  355. }
  356. });
  357. /* </pre> */