MediaWiki:Gadget-HotCat.js
注意:在发布之后,您可能需要清除浏览器缓存才能看到所作出的更改的影响。
- Firefox或Safari:按住Shift的同时单击刷新,或按Ctrl-F5或Ctrl-R(Mac为⌘-R)
- Google Chrome:按Ctrl-Shift-R(Mac为⌘-Shift-R)
- Edge:按住Ctrl的同时单击刷新,或按Ctrl-F5。
/**
* SPDX-License-Identifier: CC-BY-SA-4.0
* _addText: '{{Gadget Header|title=HotCat|license=CC-BY-SA-4.0}}'
*
* @base {@link https://commons.wikimedia.org/wiki/MediaWiki:Gadget-HotCat.js}
* @base {@link https://commons.wikimedia.org/wiki/MediaWiki:Gadget-HotCat.js/zh-hans}
* @base {@link https://zh.wikipedia.org/wiki/MediaWiki:Gadget-HotCat.js/local_defaults}
* @source {@link https://git.qiuwen.net.cn/InterfaceAdmin/QiuwenGadgets/src/branch/master/src/HotCat}
* @license CC-BY-SA-4.0 {@link https://www.qiuwenbaike.cn/wiki/H:CC-BY-SA-4.0}
*/
/**
* SPDX-License-Identifier: CC-BY-SA-4.0
* _addText: '{{Gadget Header|title=CheckCategories HotCat Extension|license=CC-BY-SA-4.0}}'
*
* @base {@link https://commons.wikimedia.org/wiki/MediaWiki:Gadget-Hotcatcheck.js}
* @source {@link https://git.qiuwen.net.cn/InterfaceAdmin/QiuwenGadgets/src/branch/master/src/HotCat/HotCat-check.js}
* @license CC-BY-SA-4.0 {@link https://www.qiuwenbaike.cn/wiki/H:CC-BY-SA-4.0}
*/
/**
* SPDX-License-Identifier: CC-BY-SA-3.0 + GFDL-1.3-no-invariants-or-later
*
* P no
*
* @base {@link https://www.qiuwenbaike.cn/wiki/File:P_no.svg}
* @source {@link https://git.qiuwen.net.cn/InterfaceAdmin/QiuwenGadgets/src/branch/master/src/HotCat/images}
* @license CC-BY-SA-3.0 + GFDL-1.3-no-invariants-or-later {@link https://www.qiuwenbaike.cn/wiki/H:CC-BY-SA-3.0}
*/
/**
* SPDX-License-Identifier: CC-BY-SA-3.0 + GFDL-1.3-no-invariants-or-later
*
* P yes
*
* @base {@link https://www.qiuwenbaike.cn/wiki/File:P_yes.svg}
* @source {@link https://git.qiuwen.net.cn/InterfaceAdmin/QiuwenGadgets/src/branch/master/src/HotCat/images}
* @license CC-BY-SA-3.0 + GFDL-1.3-no-invariants-or-later {@link https://www.qiuwenbaike.cn/wiki/H:CC-BY-SA-3.0}
*/
/**
* +------------------------------------------------------------+
* | === WARNING: GLOBAL GADGET FILE === |
* +------------------------------------------------------------+
* | All changes should be made in the repository, |
* | otherwise they will be lost. |
* +------------------------------------------------------------+
* | Changes to this page may affect many users. |
* | Please discuss changes by opening an issue before editing. |
* +------------------------------------------------------------+
*/
/* <nowiki> */
(() => {
"use strict";
// dist/HotCat/HotCat.js
//! src/HotCat/modules/check.module.less
var _templateObject;
var _templateObject2;
var _templateObject3;
var _templateObject4;
var _templateObject5;
var _templateObject6;
var _templateObject7;
var _templateObject8;
var _templateObject9;
function _createForOfIteratorHelper(r, e) {
var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
if (!t) {
if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) {
t && (r = t);
var n = 0, F = function() {
};
return { s: F, n: function() {
return n >= r.length ? { done: true } : { done: false, value: r[n++] };
}, e: function(r2) {
throw r2;
}, f: F };
}
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
var o, a = true, u = false;
return { s: function() {
t = t.call(r);
}, n: function() {
var r2 = t.next();
return a = r2.done, r2;
}, e: function(r2) {
u = true, o = r2;
}, f: function() {
try {
a || null == t.return || t.return();
} finally {
if (u) throw o;
}
} };
}
function _unsupportedIterableToArray(r, a) {
if (r) {
if ("string" == typeof r) return _arrayLikeToArray(r, a);
var t = {}.toString.call(r).slice(8, -1);
return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
}
}
function _arrayLikeToArray(r, a) {
(null == a || a > r.length) && (a = r.length);
for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
return n;
}
function _taggedTemplateLiteral(e, t) {
return t || (t = e.slice(0)), Object.freeze(Object.defineProperties(e, { raw: { value: Object.freeze(t) } }));
}
var catcheckInlineIcon = "check-module__catcheckInlineIcon_mJ5NDq__4100";
//! src/HotCat/modules/api.ts
var import_ext_gadget = require("ext.gadget.Util");
var mwApi = (userAgent) => {
return (0, import_ext_gadget.initMwApi)(userAgent);
};
//! src/HotCat/modules/check.ts
(function hotCatCheck() {
if (mw.config.get("wgNamespaceNumber") !== 6 || window.HotCatAutoRemoveCheckCatOptOut || !document.querySelector(".checkcategories")) {
return;
}
const api = mwApi("hotCatCheck/2.0");
const checkCategoriesRegExp = /{{[Cc]heck[ _]categories[^{}]*}}/g;
const selfName = "([[MediaWiki:Gadget-HotCat-check.js|Script]]): ";
const storageItemName = "checkCat";
const storageItem = mw.storage.get(storageItemName);
const createjIcon = (iconClass) => {
return $("<span>").attr("class", "ui-icon ".concat(iconClass, " ").concat(catcheckInlineIcon)).text(" ");
};
const createNotifyArea = (textNode, icon, state) => {
return $("<div>").addClass("ui-widget").append($("<div>").attr("class", "".concat(state, " ui-corner-all")).css({
"margin-top": "20px",
padding: "0.7em"
}).append($("<p>").append(createjIcon(icon).css("marginRight", "0.3em"), textNode)));
};
$("body").one("submit.checkCatListener", "#hotcatCommitForm", function(e) {
var _self$wpTextbox1$valu;
if (storageItem === "disabled") {
return true;
}
const self = this;
const newVal = (_self$wpTextbox1$valu = self.wpTextbox1.value) === null || _self$wpTextbox1$valu === void 0 ? void 0 : _self$wpTextbox1$valu.replace(checkCategoriesRegExp, "");
const dlgButtons = {};
let $dialogCheckStorage;
let $permaSaveHint;
let $textHintNode;
let $dialog;
const doRemove = () => {
self.wpSummary.value = "Removing [[Template:Check categories|{{Check categories}}]] ".concat(self.wpSummary.value);
self.wpTextbox1.value = newVal;
};
const writeStorage = (val) => {
mw.storage.set(storageItemName, val, 60 * 60 * 24 * 7);
};
dlgButtons["Yes, Remove"] = function() {
var _$dialogCheckStorage$;
doRemove();
if ((_$dialogCheckStorage$ = $dialogCheckStorage[0]) !== null && _$dialogCheckStorage$ !== void 0 && _$dialogCheckStorage$.checked) {
writeStorage("auto");
}
$(this).dialog("close");
};
dlgButtons["No, keep it"] = function() {
var _$dialogCheckStorage$2;
if ((_$dialogCheckStorage$2 = $dialogCheckStorage[0]) !== null && _$dialogCheckStorage$2 !== void 0 && _$dialogCheckStorage$2.checked) {
writeStorage("disabled");
}
$(this).dialog("close");
};
const _addToJS = function(_e) {
_e.preventDefault();
if ($permaSaveHint.hasClass("ui-state-disabled")) {
return;
}
const $el = $(this);
$el.off("click").text("Please wait.");
$permaSaveHint.addClass("ui-state-disabled");
const params = {
action: "edit",
format: "json",
title: "User:".concat(mw.config.get("wgUserName"), "/common.js"),
summary: "".concat(selfName, "Saving HotCat configuration."),
appendtext: $el.data("addText")
};
const editDone = (editStat) => {
if (!editStat) {
return;
}
if (editStat.error) {
void mw.notify("Unable to save to your common.js using the API\n".concat(editStat.error.code, "\n").concat(editStat.error.info), {
tag: "hotCatCheck",
type: "error"
});
$el.text("Edit-Error!");
} else {
$el.text("Done.");
$permaSaveHint.fadeOut();
}
};
void api.postWithToken("csrf", params).then(editDone);
};
const prompt = () => {
$dialogCheckStorage = $("<input>").attr({
type: "checkbox",
id: "hotCatAutoRemoveCheckCatStorage"
}).on("change", function() {
if (this.checked) {
$permaSaveHint.fadeIn();
} else {
$permaSaveHint.fadeOut();
}
});
$textHintNode = $("<ul>");
$("<li>").append($("<a>").attr("href", "#").text("Disable this feature.").data("addText", "\nwindow.HotCatAutoRemoveCheckCatOptOut = true;").on("click", _addToJS)).appendTo($textHintNode);
$("<li>").append($("<a>").attr("href", "#").text("Remove {{check categories}} when editing using HotCat without prompting.").data("addText", "\nwindow.HotCatAutoRemoveCheckCat = true;").on("click", _addToJS)).appendTo($textHintNode);
$permaSaveHint = createNotifyArea($("<span>").text("Save these setting in your common.js: ").append($textHintNode), "ui-icon-info", "ui-state-highlight");
$dialog = $("<div>").append($("<span>").css({
"font-size": "2em",
"line-height": "1.8em"
}).append($("<span>").text(" {{check categories}} ").css({
"background-color": "#F8CCB0",
"text-decoration": "line-through !important",
display: "inline-block"
}), $("<span>").text(" ?"))).append("<br>", $dialogCheckStorage, $("<label>").attr("for", "hotCatAutoRemoveCheckCatStorage").text("Don't ask again"), "<br>").append(mw.user.isAnon() ? "" : $permaSaveHint.hide());
$dialog.dialog({
modal: true,
closeOnEscape: true,
title: "{{check categories}} (−)?",
width: 450,
buttons: dlgButtons,
close: () => {
const $body = $("body");
$body.find("#hotcatCommitForm").trigger("submit");
},
open() {
const $buttons = $(this).parent().find(".ui-dialog-buttonpane button");
$buttons.eq(0).button({
icons: {
primary: "ui-icon-circle-check"
}
});
$buttons.eq(1).button({
icons: {
primary: "ui-icon-cancel"
}
});
}
});
};
if (newVal !== self.wpTextbox1.value) {
if (window.HotCatAutoRemoveCheckCat || storageItem === "auto") {
doRemove();
return true;
}
e.preventDefault();
prompt();
}
return true;
});
const $okLink = $("<a>").attr({
href: "#",
title: "Categories are OK! Immediately remove the template."
}).append("<s>").text("{{Check categories}}");
$okLink.on("click", function(e) {
e.preventDefault();
const $el = $(this);
$el.off("click");
const doEdit = (result) => {
if (!result) {
return;
}
$el.text("Doing.");
const text = result.replace(checkCategoriesRegExp, "");
if (text === result) {
$el.text("Template not found!");
return;
}
const params = {
text,
action: "edit",
format: "json",
title: mw.config.get("wgPageName"),
summary: "".concat(selfName, "Categories are checked and OK. You can help [[Category:Media needing category review|reviewing]]!"),
nocreate: true
};
const editDone = (editStat) => {
if (!editStat) {
return;
}
if (editStat.error) {
void mw.notify('Unable to remove "Check categories" with the API\n'.concat(editStat.error.code, "\n").concat(editStat.error.info), {
tag: "hotCatCheck",
type: "error"
});
$el.text("Edit-Error!");
} else {
$el.text("Edit Done.");
}
const $body = $("body");
$body.find(".checkcategories").fadeOut();
};
$el.text("Doing..");
void api.postWithToken("csrf", params).then(editDone);
};
$el.text("Doing");
void $.ajax({
url: mw.config.get("wgScript"),
data: {
action: "raw",
title: mw.config.get("wgPageName").replace(/ /g, "_")
},
dataType: "text",
error: () => {
$el.text("Error!");
},
success: doEdit,
type: "GET",
cache: false
});
});
$(function loadHotCatCheck() {
const $body = $("body");
$body.find("#catlinks").find("ul:first").append($("<li>").append($okLink));
});
})();
//! src/HotCat/HotCat.js
var import_ext_gadget2 = require("ext.gadget.Util");
//! src/HotCat/modules/getMessage.ts
var getMessage = (key, ...args) => {
key = "hotcat-".concat(key);
return mw.message(key, ...args).plain();
};
//! src/HotCat/modules/messages.ts
var hotCatMessages = () => {
const {
wgUserLanguage
} = mw.config.get();
if (["zh-hant", "zh-hk", "zh-mo", "zh-tw"].includes(wgUserLanguage)) {
mw.messages.set({
"hotcat-messages-cat_removed": "已移除[[Category:$1]]",
"hotcat-messages-template_removed": "已移除{{[[Category:$1]]}}",
"hotcat-messages-cat_added": "已添加[[Category:$1]]",
// $2 is the new key
"hotcat-messages-cat_keychange": '已設置[[Category:$1]]的新排序字:"$2"',
"hotcat-messages-cat_notFound": "分類“$1”沒有找到",
"hotcat-messages-cat_exists": "分類“$1”已經存在,沒有添加。",
"hotcat-messages-cat_resolved": "(重定向[[Category:$1]]已處理)",
"hotcat-messages-uncat_removed": "已移除{{uncategorized}}",
// Some text to prefix to the edit summary.
"hotcat-messages-prefix": "使用[[Help:HotCat|HotCat]]",
// Some text to append to the edit summary. Named 'using' for historical reasons. If you prefer
// to have a marker at the front, use prefix and set this to the empty string.
"hotcat-messages-using": "",
"hotcat-messages-multi_change": "$1個分類",
// Any category in this category is deemed a disambiguation category; i.e., a category that should not contain
// any items, but that contains links to other categories where stuff should be categorized. If you don't have
// that concept on your wiki, set it to blank string. Use blanks, not underscores.
"hotcat-disambig_category": "",
// Any category in this category is deemed a (soft) redirect to some other category defined by a link
// to another non-blacklisted category. If your wiki doesn't have soft category redirects, set this to null.
// If a soft-redirected category contains more than one link to another non-blacklisted category, it's considered
// a disambiguation category instead.
"hotcat-redir_category": "已重定向的分类",
"hotcat-messages-separator": "; ",
// $1 is replaced by a number. If your language has several plural forms (c.f. [[:enwiki:Dual (grammatical form)]]),
// you can set this to an array of strings suitable for passing to mw.language.configPlural().
// If that function doesn't exist, HotCat will simply fall back to using the last
// entry in the array.
// Defaults to '[[' + category_canonical + ':$1]]'. Can be overridden if in the short edit summaries
// not the standard category name should be used but, say, a shorter namespace alias. $1 is replaced
// by a category name.
"hotcat-messages-short_catchange": "$1",
// Button text. Localize to wgContentLanguage here; localize to wgUserLanguage in a subpage,
// see localization hook below.
"hotcat-messages-commit": "儲存",
// Button text. Localize to wgContentLanguage here; localize to wgUserLanguage in a subpage,
// see localization hook below.
"hotcat-messages-ok": "確定",
// Button text. Localize to wgContentLanguage here; localize to wgUserLanguage in a subpage,
// see localization hook below.
"hotcat-messages-cancel": "取消",
// Localize to wgContentLanguage here; localize to wgUserLanguage in a subpage,
// see localization hook below.
"hotcat-messages-multi_error": "無法從伺服器取得頁面文字。因此,您的分類變更無法儲存。我們為此不便表示抱歉。",
// Plural of category_canonical.
"hotcat-categories": "分類",
// Names for the search engines
"hotcat-engine_names-searchindex": "搜尋索引",
"hotcat-engine_names-pagelist": "頁面列表",
"hotcat-engine_names-combined": "合併搜尋",
"hotcat-engine_names-subcat": "子分類",
"hotcat-engine_names-parentcat": "上層分類",
// The tooltips for the above links
"hotcat-tooltips-change": "修改",
"hotcat-tooltips-remove": "移除",
"hotcat-tooltips-add": "增加一個新分類",
"hotcat-tooltips-restore": "復原變更",
"hotcat-tooltips-undo": "復原變更",
"hotcat-tooltips-down": "打開以修改並顯示子分類",
"hotcat-tooltips-up": "打開以修改並顯示上層分類",
// Tooltip for the "enter multi-mode" link
"hotcat-multi_tooltip": "修改多個分類"
});
} else {
mw.messages.set({
"hotcat-messages-cat_removed": "已移除[[Category:$1]]",
"hotcat-messages-template_removed": "已移除{{[[Category:$1]]}}",
"hotcat-messages-cat_added": "已添加[[Category:$1]]",
// $2 is the new key
"hotcat-messages-cat_keychange": '已设置[[Category:$1]]的新排序字:"$2"',
"hotcat-messages-cat_notFound": "分类“$1”没有找到",
"hotcat-messages-cat_exists": "分类“$1”已经存在,没有添加。",
"hotcat-messages-cat_resolved": "(重定向[[Category:$1]]已处理)",
"hotcat-messages-uncat_removed": "已移除{{uncategorized}}",
// Some text to prefix to the edit summary.
"hotcat-messages-prefix": "使用[[Help:HotCat|HotCat]]",
// Some text to append to the edit summary. Named 'using' for historical reasons. If you prefer
// to have a marker at the front, use prefix and set this to the empty string.
"hotcat-messages-using": "",
"hotcat-messages-multi_change": "$1个分类",
// Any category in this category is deemed a disambiguation category; i.e., a category that should not contain
// any items, but that contains links to other categories where stuff should be categorized. If you don't have
// that concept on your wiki, set it to blank string. Use blanks, not underscores.
"hotcat-disambig_category": "",
// Any category in this category is deemed a (soft) redirect to some other category defined by a link
// to another non-blacklisted category. If your wiki doesn't have soft category redirects, set this to null.
// If a soft-redirected category contains more than one link to another non-blacklisted category, it's considered
// a disambiguation category instead. 'hotcat-redir_category': '已重定向的分类',
"hotcat-messages-separator": "; ",
// $1 is replaced by a number. If your language has several plural forms (c.f. [[:enwiki:Dual (grammatical form)]]),
// you can set this to an array of strings suitable for passing to mw.language.configPlural().
// If that function doesn't exist, HotCat will simply fall back to using the last
// entry in the array.
// Defaults to '[[' + category_canonical + ':$1]]'. Can be overridden if in the short edit summaries
// not the standard category name should be used but, say, a shorter namespace alias. $1 is replaced
// by a category name.
"hotcat-messages-short_catchange": "$1",
// Button text. Localize to wgContentLanguage here; localize to wgUserLanguage in a subpage,
// see localization hook below.
"hotcat-messages-commit": "保存",
// Button text. Localize to wgContentLanguage here; localize to wgUserLanguage in a subpage,
// see localization hook below.
"hotcat-messages-ok": "确定",
// Button text. Localize to wgContentLanguage here; localize to wgUserLanguage in a subpage,
// see localization hook below.
"hotcat-messages-cancel": "取消",
// Localize to wgContentLanguage here; localize to wgUserLanguage in a subpage,
// see localization hook below.
"hotcat-messages-multi_error": "无法从服务器取得页面文字。因此,您的分类更改无法保存。我们为此不便表示抱歉。",
// Plural of category_canonical.
"hotcat-categories": "分类",
// Names for the search engines
"hotcat-engine_names-searchindex": "搜索索引",
"hotcat-engine_names-pagelist": "页面列表",
"hotcat-engine_names-combined": "合并搜索",
"hotcat-engine_names-subcat": "子分类",
"hotcat-engine_names-parentcat": "上层分类",
// The tooltips for the above links
"hotcat-tooltips-change": "修改",
"hotcat-tooltips-remove": "移除",
"hotcat-tooltips-add": "增加一个新分类",
"hotcat-tooltips-restore": "撤销更改",
"hotcat-tooltips-undo": "撤销更改",
"hotcat-tooltips-down": "打开以修改并显示子分类",
"hotcat-tooltips-up": "打开以修改并显示上层分类",
// Tooltip for the "enter multi-mode" link
"hotcat-multi_tooltip": "修改多个分类"
});
}
};
//! src/HotCat/images/P_no.png
var P_no_default = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAASCAYAAABb0P4QAAAABmJLR0QA/wD/AP+gvaeTAAADOUlEQVQ4jY2SXUzbZRjFf/9/y1fsKEGQQaDbmEKZzrmL6Qg6RzQQso9ELcm6i043zURJTPy40IQF9WqJmZpdaEIWIyH76EzwZsZEs6spc2TSJgjFhQEZUrqh2RAK9P++7+ONLbVs6pOcq+e853lzzrH4n3PtmhTny0qZyRMzOVk43dxsqbvxrH8XcRot0YcEaw9QnbVaBC4JcrKurvDCfwqOjCw/ZIucxKI1d6e1Jh6/QWVlNS6XG4GzKafw5W3brEUAO/dBNLoQPHGia/hYd2frTHwGpSWDocggzc/U8WxLA/1fn8ZRBq3lgMu19IWIWGsEoz8vhMTQt6Vhe374/Ck6OwPM/zmPUoapqet0vPYcN2/OEHjhMMXFpcTjv6GUQTmmPRJJ7v+H4ODgnccdI6eUFnvX0/tob3+FkdEhurpeZSWlePe9I9y+/Tu7d++j6ck2Nmz0U3p/Zeb3xuijGQ/DYXH5fPPDgD99wBhNR8ceotEB/P7HiMUi1NRsprPzQ2pqaqmtbch1a27nTm+5DVBdfed5rcWvtZCGiM3x42eoqKgmFovgdrsJBI7i8ZTg89WTzf0b6wDcAI6jg3cLvKiomKqqjSQS04hAMrnIpk0Po7UAkkv/I+Oh0jRlp5nGwMD3DA1dwuPxImLo7f2I8euja3hKC46WH1cFlSlVypANx1H09HwAQEtrkJbWIEtLi7zf/RK3biXI5SutzmQEtTbzuZ5cvNjP+Pgw6ys3sPWRJg4efIfGxjbm5uJ88vGbOI5a5SsZvvzDA/0ZQUeZwdyL5859CsCOHS0UFHrweit46+3P8fnquXLlO8ZiEZQyaGUcY9SL3d2WWf2hWJ9l+zExEWNqcpSiIg8NW56grNyHNmC78uk6dpqSknJmE9OkHGWUMof37q26mk7GAhAR6/xX8TCWBABSqWVm4xNMTP5CibeMrY8+hW27MnGurCQZG7uarHtw+5FQqP5sdtSZrvT2zt7nLnB6wAqmi+04KWzbRV5efk5DrG8dWX7j0IHNv+Z2Z035+vputAm8jmV2gbUuizoF8o3Y1pehYM1Pue/uKZiecFhcC3qmCqPy3LogEQqtX7wXN3v+ApHw44zjlQ7KAAAAAElFTkSuQmCC";
//! src/HotCat/images/P_yes.png
var P_yes_default = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAASCAYAAABb0P4QAAAABmJLR0QA/wD/AP+gvaeTAAADAElEQVQ4jY2S32vbZRSHnzffdMvWJVmWtJamnUXWbnZgHKuTMSnOm1GcCJ3iil0qcyBDUIbzYl5N8K43SileFDc60h/0RlR0/gE6JkVpIQy0DLo4pavbsEvTtP2+7zlezKRZ2joPnJv3fM7DOef9GP5nzMxoZIuuJKRGZXY2dPvoUWM30pn/hviHjbo+xbwMNFWUCsAPig60tYW+fSzwxo3l1oDqAIZjj5tcYXzVD51JpUwBIFgtyGaXToqTIYEdGwHy+QUyI4P8cfsWZ89eIJlsOel5RU9V3zDG6CPA6V8W09aXy0BgI9jdu3OcfvsYudxNUqnnmZ+fIxpNEAptf31qamkE+KrcODm5cMgX/cI6DVinVOfKqs8H53vJ5W6yZ89+envfxzoIeFuwThFx75RXnphQz7kHwyDrTlCKwcGPmZ6+TjS6i1OnzrFzZ4K9ew8gYhARgOfKwKamhW7n2LcZbGrqGpnMZwB0d58hGo3T2vosqgbntCQLl4G+73o2c5Dvr9Lffw5VpaPjRdraDtDS0o4xQayVSun9MtA6joCuVe7PE4vVYYxhdHSA2dlfqa2N0NXVSzzRSDiSwK5NBoDCNfj3N62VXdYKvu/45uth+tKHGBn5lHv3/mJs7OGqnZ2vsm17hGSyFWtlfTo7VgY6Jw+cU5aXV7h6NcPSUp7Llz6hL91BsbhILFbPwYMv0dDwFMYEcU4fTavZ6z/Wf1kG+lYmrRUCgRoufHSJaDQOQLG4CMCRF14htC1MPN64bjJnxRexb128aGRtQjWfl/wWiT7B+Q+HCAQeWjQUquXp9sPU17fgxFT7U6yV08ePN/5cuqUHMD7a/1s2m98vqu0iSiLRhOcFsb7PM6lOdjfvY/eT7agaRLSUeXWSPnEiOV75OWWvXLkyVxvc6g+B6Sm9zd/JUSj8zY5wjLq65sq279WT9958rXmm2mbrzJfJ/N6l8C5GOsGEK6S3QL/TgBlO9zT/VN23KbAUExPqLbo/GxFbE3Rb76TTDYXNtJXxD+yujTqqNmcnAAAAAElFTkSuQmCC";
//! src/HotCat/HotCat.js
hotCatMessages();
(function hotCat() {
const conf = mw.config.values;
if (window.HotCat && !window.HotCat.nodeName || conf.wgAction === "edit") {
return;
}
const api = mwApi("HotCat/3.0");
window.HotCat = {
// The little modification links displayed after category names. U+2212 is a minus sign; U+2193 and U+2191 are
// downward and upward pointing arrows. Do not use ↓ and ↑ in the code!
links: {
change: "(±)",
remove: "(−)",
add: "(+)",
restore: "(×)",
undo: "(×)",
down: "(↓)",
up: "(↑)"
},
changeTag: "HotCat",
// The HTML content of the "enter multi-mode" link at the front.
addmulti: "<span>+<sup>+</sup></span>",
// Return true to disable HotCat.
disable: () => {
const ns = conf.wgNamespaceNumber;
const nsIds = conf.wgNamespaceIds;
return ns < 0 || // Special pages; Special:Upload is handled differently
ns === 10 || // Templates
ns === 828 || // Module (Lua)
ns === 8 || // MediaWiki
ns === 6 && !conf.wgArticleId || // Non-existing file pages
ns === 2 && /\.(js|css)$/.test(conf.wgTitle) || // User scripts
nsIds && (ns === nsIds.creator || ns === nsIds.timedtext || ns === nsIds.institution);
},
// A regexp matching a templates used to mark uncategorized pages, if your wiki does have that.
// If not, set it to null.
uncat_regexp: /{{\s*[Uu]ncategorized\s*[^}]*}}\s*(<!--.*?-->\s*)?/g,
// The images used for the little indication icon. Should not need changing.
existsYes: P_yes_default,
existsNo: P_no_default,
// a list of categories which can be removed by removing a template
// key: the category without namespace
// value: A regexp matching the template name, again without namespace
// If you don't have this at your wiki, or don't want this, set it to an empty object {}.
template_categories: {},
// Override the decision of whether HotCat should help users by automatically
// capitalising the title in the user input text if the wiki has case-sensitive page names.
// Basically, this will make an API query to check the MediaWiki configuration and HotCat then sets
// this to true for most wikis, and to false on Wiktionary.
//
// You can set this directly if there is a problem with it. For example, Georgian Wikipedia (kawiki),
// is known to have different capitalisation logic between MediaWiki PHP and JavaScript. As such, automatic
// case changes in JavaScript by HotCat would be wrong.
capitalizePageNames: null,
// If upload_disabled is true, HotCat will not be used on the Upload form.
upload_disabled: false,
// Single regular expression matching blacklisted categories that cannot be changed or
// added using HotCat. For instance /\bstubs?$/ (any category ending with the word "stub"
// or "stubs"), or /(\bstubs?$)|\bmaintenance\b/ (stub categories and any category with the
// word "maintenance" in its title.
blacklist: null,
// Stuff changeable by users:
// Background for changed categories in multi-edit mode. Default is a very light salmon pink.
bg_changed: "#FCA",
// If true, HotCat will never automatically submit changes. HotCat will only open an edit page with
// the changes; users must always save explicitly.
no_autocommit: false,
// If true, the "category deletion" link "(-)" will never save automatically but always show an
// edit page where the user has to save the edit manually. Is false by default because that's the
// traditional behavior. This setting overrides no_autocommit for "(-)" links.
del_needs_diff: false,
// Time, in milliseconds, that HotCat waits after a keystroke before making a request to the
// server to get suggestions.
suggest_delay: 1e3,
// Default width, in characters, of the text input field.
editbox_width: 40,
// One of the engine_names above, to be used as the default suggestion engine.
suggestions: "combined",
// If true, always use the default engine, and never display a selector.
fixed_search: false,
// If false, do not display the "up" and "down" links
use_up_down: true,
// Default list size
listSize: 10,
// If true, single category changes are marked as minor edits. If false, they're not.
single_minor: true,
// If true, never add a page to the user's watchlist. If false, pages get added to the watchlist if
// the user has the "Add pages I edit to my watchlist" or the "Add pages I create to my watchlist"
// options in his or her preferences set.
dont_add_to_watchlist: false,
shortcuts: null,
addShortcuts: (map) => {
var _window$HotCat;
if (!map) {
return;
}
(_window$HotCat = window.HotCat).shortcuts || (_window$HotCat.shortcuts = {});
for (let k in map) {
if (!Object.hasOwn(map, k) || typeof k !== "string") {
continue;
}
let v = map[k];
if (typeof v !== "string") {
continue;
}
k = k.trim();
v = v.trim();
if (k.length === 0 || v.length === 0) {
continue;
}
window.HotCat.shortcuts[k] = v;
}
}
};
const HC = window.HotCat;
const ua = navigator.userAgent.toLowerCase();
const is_webkit = /applewebkit\/\d+/.test(ua) && !ua.includes("spoofer");
let cat_prefix = null;
let noSuggestions = false;
const wikiTextBlank = String.raw(_templateObject || (_templateObject = _taggedTemplateLiteral(["[ _ - \u2028\u2029 ]+"], ["[\\t _\\xA0\\u1680\\u180E\\u2000-\\u200A\\u2028\\u2029\\u202F\\u205F\\u3000]+"])));
const wikiTextBlankRE = new RegExp(wikiTextBlank, "g");
const wikiTextBlankOrBidi = String.raw(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["[ _ -\u2028- ]*"], ["[\\t _\\xA0\\u1680\\u180E\\u2000-\\u200B\\u200E\\u200F\\u2028-\\u202F\\u205F\\u3000]*"])));
const formattedNamespaces = conf.wgFormattedNamespaces;
const namespaceIds = conf.wgNamespaceIds;
const autoLocalize = (namespaceNumber, fallback) => {
const createRegexpStr = (name) => {
if (!name || name.length === 0) {
return;
}
let regex_name = "";
for (let i = 0; i < name.length; i++) {
const initial = name.charAt(i);
const ll = initial.toLowerCase();
const ul = initial.toUpperCase();
regex_name += ll === ul ? initial : "[".concat(ll).concat(ul, "]");
}
return regex_name.replace(/([$()*+.?\\^])/g, String.raw(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["$1"], ["\\$1"])))).replace(wikiTextBlankRE, wikiTextBlank);
};
fallback = fallback.toLowerCase();
const canonical = formattedNamespaces[String(namespaceNumber)].toLowerCase();
let regexp = createRegexpStr(canonical);
if (fallback && canonical !== fallback) {
regexp += "|".concat(createRegexpStr(fallback));
}
if (namespaceIds) {
for (const cat_name in namespaceIds) {
if (typeof cat_name === "string" && cat_name.toLowerCase() !== canonical && cat_name.toLowerCase() !== fallback && namespaceIds[cat_name] === namespaceNumber) {
regexp += "|".concat(createRegexpStr(cat_name));
}
}
}
return regexp;
};
HC.category_canonical = formattedNamespaces["14"];
HC.category_regexp = autoLocalize(14, "category");
if (formattedNamespaces["10"]) {
HC.template_regexp = autoLocalize(10, "template");
}
const make = (arg, literal) => {
if (!arg) {
return null;
}
return literal ? document.createTextNode(arg) : document.createElement(arg);
};
const param = (name, uri) => {
uri || (uri = document.location.href);
const re = new RegExp("[&?]".concat(name, "=([^&#]*)"));
const m = re.exec(uri);
if (m && m.length > 1) {
return decodeURIComponent(m[1]);
}
return null;
};
const title = (href) => {
if (!href) {
return null;
}
const script = "".concat(conf.wgScript, "?");
if (href.indexOf(script) === 0 || href.indexOf(conf.wgServer + script) === 0 || conf.wgServer.slice(0, 2) === "//" && href.indexOf(document.location.protocol + conf.wgServer + script) === 0) {
return param("title", href);
}
let prefix = conf.wgArticlePath.replace("$1", "");
if (href.indexOf(prefix)) {
prefix = conf.wgServer + prefix;
}
if (href.indexOf(prefix) && prefix.slice(0, 2) === "//") {
prefix = document.location.protocol + prefix;
}
if (href.indexOf(prefix) === 0) {
return decodeURIComponent(href.slice(prefix.length));
}
return null;
};
const hasClass = ({
className
}, name) => {
return " ".concat(className, " ").includes(" ".concat(name, " "));
};
const capitalize = (str) => {
if (!str || str.length === 0) {
return str;
}
return str.slice(0, 1).toUpperCase() + str.slice(1);
};
const wikiPagePath = (pageName) => {
return conf.wgArticlePath.replace("$1", encodeURIComponent(pageName).replace(/%3A/g, ":").replace(/%2F/g, "/"));
};
const escapeRE = (str) => {
return str.replace(/([$()*+.?[\\\]^])/g, String.raw(_templateObject4 || (_templateObject4 = _taggedTemplateLiteral(["$1"], ["\\$1"]))));
};
const substituteFactory = (options) => {
options || (options = {});
const lead = options.indicator || "$";
const indicator = escapeRE(lead);
const lbrace = escapeRE(options.lbrace || "{");
const rbrace = escapeRE(options.rbrace || "}");
const re = new RegExp(
// $$
"(?:".concat(indicator, "(").concat(indicator, "))|(?:").concat(indicator, "(\\d+))|(?:").concat(indicator, "(?:").concat(lbrace, "([^").concat(lbrace).concat(rbrace, "]+)").concat(rbrace, "))|(?:").concat(indicator, "(?!(?:[").concat(indicator).concat(lbrace, "]|\\d))(\\S+?)\\b)"),
"g"
);
return (str, map) => {
if (!map) {
return str;
}
return str.replace(re, (match, prefix, idx, key, alpha) => {
if (prefix === lead) {
return lead;
}
const k = alpha || key || idx;
const replacement = typeof map[k] === "function" ? map[k](match, k) : map[k];
return typeof replacement === "string" ? replacement : replacement || match;
});
};
};
const replaceShortcuts = (() => {
const replaceHash = substituteFactory({
indicator: "#",
lbrace: "[",
rbrace: "]"
});
return (str, map) => {
const s = replaceHash(str, map);
return HC.capitalizePageNames ? capitalize(s) : s;
};
})();
const findCatsRE = new RegExp("\\[\\[".concat(wikiTextBlankOrBidi, "(?:").concat(HC.category_regexp, ")").concat(wikiTextBlankOrBidi, ":[^\\]]+\\]\\]"), "g");
const replaceByBlanks = (match) => {
return match.replace(/(\s|\S)/g, " ");
};
const find_category = (wikitext, category, once) => {
let cat_regex = null;
if (HC.template_categories[category]) {
cat_regex = new RegExp("\\{\\{".concat(wikiTextBlankOrBidi, "(").concat(HC.template_regexp, "(?=").concat(wikiTextBlankOrBidi, ":))?").concat(wikiTextBlankOrBidi, "(?:").concat(HC.template_categories[category], ")").concat(wikiTextBlankOrBidi, "(\\|.*?)?\\}\\}"), "g");
} else {
const cat_name = escapeRE(category);
const initial = cat_name.slice(0, 1);
cat_regex = new RegExp("\\[\\[".concat(wikiTextBlankOrBidi, "(").concat(HC.category_regexp, ")").concat(wikiTextBlankOrBidi, ":").concat(wikiTextBlankOrBidi).concat(initial === "\\" || !HC.capitalizePageNames ? initial : "[".concat(initial.toUpperCase()).concat(initial.toLowerCase(), "]")).concat(cat_name.slice(1).replace(wikiTextBlankRE, wikiTextBlank)).concat(wikiTextBlankOrBidi, "(\\|.*?)?\\]\\]"), "g");
}
if (once) {
return cat_regex.exec(wikitext);
}
const nowikiRegex = new RegExp("<no".concat("wiki>", String.raw(_templateObject5 || (_templateObject5 = _taggedTemplateLiteral(["(s|S)*?</no"], ["(\\s|\\S)*?</no"]))), "wiki", ">"), "g");
const copiedtext = wikitext.replace(/<!--(\s|\S)*?-->/g, replaceByBlanks).replace(nowikiRegex, replaceByBlanks);
const result = [];
let curr_match = null;
while ((curr_match = cat_regex.exec(copiedtext)) !== null) {
result[result.length] = {
match: curr_match
};
}
result.re = cat_regex;
return result;
};
let interlanguageRE = null;
const change_category = (wikitext, toRemove, toAdd, key, is_hidden) => {
const find_insertionpoint = (_wikitext) => {
const nowikiRegex = new RegExp("<no".concat("wiki>", String.raw(_templateObject6 || (_templateObject6 = _taggedTemplateLiteral(["(s|S)*?</no"], ["(\\s|\\S)*?</no"]))), "wiki", ">"), "g");
const copiedtext = _wikitext.replace(/<!--(\s|\S)*?-->/g, replaceByBlanks).replace(nowikiRegex, replaceByBlanks);
let index = -1;
findCatsRE.lastIndex = 0;
while (findCatsRE.exec(copiedtext) !== null) {
index = findCatsRE.lastIndex;
}
if (index < 0) {
let match = null;
if (interlanguageRE) {
match = interlanguageRE.exec(copiedtext);
} else {
match = /((^|\n\r?)(\[\[\s*(([a-z]{2,3}(-[a-z]+)*)|simple|tokipona)\s*:[^\]]+]]\s*))+$/.exec(copiedtext);
}
if (match) {
({
index
} = match);
}
return {
idx: index,
onCat: false
};
}
return {
idx: index,
onCat: index >= 0
};
};
const summary = [];
const nameSpace = HC.category_canonical;
const keyChange = toRemove && toAdd && toRemove === toAdd && toAdd.length > 0;
let matches;
let cat_point = -1;
key && (key = "|".concat(key));
if (toRemove && toRemove.length > 0) {
matches = find_category(wikitext, toRemove);
if (!matches || matches.length === 0) {
return {
text: wikitext,
summary,
error: getMessage("messages-cat_notFound", toRemove)
};
}
let before = wikitext.slice(0, Math.max(0, matches[0].match.index));
let after = wikitext.slice(Math.max(0, matches[0].match.index + matches[0].match[0].length));
if (matches.length > 1) {
matches.re.lastIndex = 0;
after = after.replace(matches.re, "");
}
if (toAdd && // nameSpace = matches[ 0 ].match[ 1 ] || nameSpace; Canonical namespace should be always preferred
key === null) {
[, , key] = matches[0].match;
}
let i = before.length - 1;
while (i >= 0 && before.charAt(i) !== "\n" && before.slice(i, i + 1).search(/\s/) >= 0) {
i--;
}
let j = 0;
while (j < after.length && after.charAt(j) !== "\n" && after.slice(j, j + 1).search(/\s/) >= 0) {
j++;
}
if (i >= 0 && before.charAt(i) === "\n" && (after.length === 0 || j < after.length && after.charAt(j) === "\n")) {
i--;
}
before = i >= 0 ? before.slice(0, Math.max(0, i + 1)) : "";
after = j < after.length ? after.slice(Math.max(0, j)) : "";
if (before.length > 0 && before.slice(Math.max(0, before.length - 1)).search(/\S/) >= 0 && after.length > 0 && after.slice(0, 1).search(/\S/) >= 0) {
before += " ";
}
cat_point = before.length;
if (cat_point === 0 && after.length > 0 && after.slice(0, 1) === "\n") {
after = after.slice(1);
}
wikitext = before + after;
if (!keyChange) {
if (HC.template_categories[toRemove]) {
summary[summary.length] = getMessage("messages-template_removed", toRemove);
} else {
summary[summary.length] = getMessage("messages-cat_removed", toRemove);
}
}
}
if (toAdd && toAdd.length > 0) {
matches = find_category(wikitext, toAdd);
if (matches && matches.length > 0) {
return {
text: wikitext,
summary,
error: getMessage("messages-cat_exists", toAdd)
};
}
let onCat = false;
if (cat_point < 0) {
const point = find_insertionpoint(wikitext);
cat_point = point.idx;
({
onCat
} = point);
} else {
onCat = true;
}
const newcatstring = "[[".concat(nameSpace, ":").concat(toAdd).concat(key || "", "]]");
if (cat_point >= 0) {
const suffix = wikitext.slice(Math.max(0, cat_point));
wikitext = wikitext.slice(0, Math.max(0, cat_point)) + (cat_point > 0 ? "\n" : "") + newcatstring + (onCat ? "" : "\n");
wikitext += suffix.length > 0 && suffix.slice(0, 1) !== "\n" ? "\n".concat(suffix) : suffix;
} else {
if (wikitext.length > 0 && wikitext.slice(-1, wikitext.length - 1 + 1) !== "\n") {
wikitext += "\n";
}
wikitext += (wikitext.length > 0 ? "\n" : "") + newcatstring;
}
if (keyChange) {
let k = key || "";
if (k.length > 0) {
k = k.slice(1);
}
summary[summary.length] = getMessage("messages-cat_keychange", toAdd, k);
} else {
summary[summary.length] = getMessage("messages-cat_added", toAdd);
}
if (HC.uncat_regexp && !is_hidden) {
const txt = wikitext.replace(HC.uncat_regexp, "");
if (txt.length !== wikitext.length) {
wikitext = txt;
summary[summary.length] = getMessage("messages-uncat_removed");
}
}
}
return {
text: wikitext,
summary,
error: null
};
};
const evtKeys = ({
ctrlKey,
metaKey,
shiftKey
}) => {
let code = 0;
if (ctrlKey) {
if (ctrlKey || metaKey) {
code || (code = 1);
}
if (shiftKey) {
code || (code = 2);
}
}
return code;
};
const evtKill = (e) => {
if (e.preventDefault) {
e.preventDefault();
e.stopPropagation();
} else {
e.cancelBubble = true;
}
return false;
};
let catLine = null;
let onUpload = false;
let editors = [];
let commitButton = null;
let commitForm = null;
let multiSpan = null;
let pageText = null;
let pageTime = null;
let pageWatched = false;
let watchCreate = false;
let watchEdit = false;
let minorEdits = false;
let editToken = null;
let is_rtl = false;
let serverTime = null;
let lastRevId = null;
let pageTextRevId = null;
let conflictingUser = null;
let newDOM = false;
const UNCHANGED = 0;
const OPEN = 1;
const CHANGE_PENDING = 2;
const CHANGED = 3;
const DELETED = 4;
const setPage = (data) => {
let startTime = null;
if (data && data.query) {
if (data.query.pages) {
const [page] = data.query.pages;
if (page) {
if (page.revisions && page.revisions.length > 0) {
pageText = page.revisions[0].slots.main.content;
if (page.revisions[0].timestamp) {
pageTime = page.revisions[0].timestamp.replace(/\D/g, "");
}
if (page.revisions[0].revid) {
pageTextRevId = page.revisions[0].revid;
}
if (page.revisions.length > 1) {
conflictingUser = page.revisions[1].user;
}
}
if (page.lastrevid) {
lastRevId = page.lastrevid;
}
if (page.starttimestamp) {
startTime = page.starttimestamp.replace(/\D/g, "");
}
pageWatched = typeof page.watched === "string";
if (data.query.tokens) {
editToken = data.query.tokens.csrftoken;
}
if (page.langlinks && (!data["query-continue"] || !data["query-continue"].langlinks)) {
let re = "";
for (let i = 0; i < page.langlinks.length; i++) {
re += (i > 0 ? "|" : "") + page.langlinks[i].lang.replace(/([$()*+.?\\^])/g, String.raw(_templateObject7 || (_templateObject7 = _taggedTemplateLiteral(["$1"], ["\\$1"]))));
}
if (re.length > 0) {
interlanguageRE = new RegExp("((^|\\n\\r?)(\\[\\[\\s*(".concat(re, ")\\s*:[^\\]]+\\]\\]\\s*))+$"));
}
}
}
}
if (data.query.general) {
if (data.query.general.time && !startTime) {
startTime = data.query.general.time.replace(/\D/g, "");
}
if (HC.capitalizePageNames === null) {
HC.capitalizePageNames = data.query.general.case === "first-letter";
}
}
serverTime = startTime;
if (data.query.userinfo && data.query.userinfo.options) {
watchCreate = !HC.dont_add_to_watchlist && data.query.userinfo.options.watchcreations === "1";
watchEdit = !HC.dont_add_to_watchlist && data.query.userinfo.options.watchdefault === "1";
minorEdits = data.query.userinfo.options.minordefault === 1;
if (minorEdits) {
HC.single_minor = true;
}
}
}
};
let saveInProgress = false;
const initiateEdit = (doEdit, failure) => {
if (saveInProgress) {
return;
}
saveInProgress = true;
let oldButtonState;
if (commitButton) {
oldButtonState = commitButton.disabled;
commitButton.disabled = true;
}
const fail = function(...args) {
saveInProgress = false;
if (commitButton) {
commitButton.disabled = oldButtonState;
}
failure.apply(this, args);
};
const params = {
action: "query",
format: "json",
formatversion: "2",
rawcontinue: "",
titles: conf.wgPageName,
prop: ["info", "revisions", "langlinks"],
inprop: "watched",
rvprop: ["content", "timestamp", "ids", "user"],
rvslots: "main",
rvlimit: "2",
rvdir: "newer",
rvstartid: conf.wgCurRevisionId,
lllimit: "500",
meta: ["siteinfo", "userinfo", "tokens"],
type: "csrf",
uiprop: ["options"]
};
api.get(params).done((data) => {
setPage(data);
doEdit(fail);
}).fail(({
status,
statusText
}) => {
fail("".concat(status, " ").concat(statusText));
});
};
const multiChangeMsg = (count) => {
return getMessage("messages-multi_change", String(count));
};
const currentTimestamp = () => {
const now = /* @__PURE__ */ new Date();
let ts = String(now.getUTCFullYear());
const two = (s) => {
return s.slice(-2);
};
ts += two("0".concat(now.getUTCMonth() + 1)) + two("0".concat(now.getUTCDate())) + two("00".concat(now.getUTCHours())) + two("00".concat(now.getUTCMinutes())) + two("00".concat(now.getUTCSeconds()));
return ts;
};
const performChanges = (failure, singleEditor) => {
if (pageText === null) {
failure(getMessage("messages-multi_error"));
return;
}
let action;
const selfEditConflict = (lastRevId !== null && lastRevId !== conf.wgCurRevisionId || pageTextRevId !== null && pageTextRevId !== conf.wgCurRevisionId) && conflictingUser && conflictingUser === conf.wgUserName;
if (singleEditor && !singleEditor.noCommit && !HC.no_autocommit && editToken && !selfEditConflict) {
commitForm.wpEditToken.value = editToken;
action = commitForm.wpDiff;
if (action) {
action.value = "wpSave";
action.name = action.value;
}
} else {
action = commitForm.wpSave;
if (action) {
action.value = "wpDiff";
action.name = action.value;
}
}
let result = {
text: pageText
};
const changed = [];
const added = [];
const deleted = [];
const toEdit = singleEditor ? [singleEditor] : editors;
let edit;
let i;
let error = null;
let changes = 0;
for (i = 0; i < toEdit.length; i++) {
edit = toEdit[i];
if (edit.state === CHANGED) {
result = change_category(result.text, edit.originalCategory, edit.currentCategory, edit.currentKey, edit.currentHidden);
if (!result.error) {
changes++;
if (!edit.originalCategory || edit.originalCategory.length === 0) {
added[added.length] = edit.currentCategory;
} else {
changed[changed.length] = {
from: edit.originalCategory,
to: edit.currentCategory
};
}
} else if (error === null) {
({
error
} = result);
}
} else if (edit.state === DELETED && edit.originalCategory && edit.originalCategory.length > 0) {
result = change_category(result.text, edit.originalCategory, null, null, false);
if (!result.error) {
changes++;
deleted[deleted.length] = edit.originalCategory;
} else if (error === null) {
({
error
} = result);
}
}
}
if (error !== null) {
action = commitForm.wpSave;
if (action) {
action.value = "wpDiff";
action.name = action.value;
}
}
commitForm.wpMinoredit.checked = minorEdits;
commitForm.wpWatchthis.checked = !conf.wgArticleId && watchCreate || watchEdit || pageWatched;
if (conf.wgArticleId || !!singleEditor) {
if (action && action.value === "wpSave") {
if (HC.changeTag) {
commitForm.wpChangeTags.value = HC.changeTag;
}
} else {
commitForm.wpAutoSummary.value = HC.changeTag;
}
if (changes === 1) {
if (result.summary && result.summary.length > 0) {
commitForm.wpSummary.value = (HC.changeTag ? "" : getMessage("messages-prefix")) + result.summary.join(getMessage("messages-separator")) + (HC.changeTag ? "" : getMessage("messages-using"));
}
commitForm.wpMinoredit.checked = HC.single_minor || minorEdits;
} else if (changes) {
let summary = [];
const shortSummary = [];
for (i = 0; i < deleted.length; i++) {
summary[summary.length] = "−".concat(getMessage("messages-short_catchange", deleted[i]));
}
if (deleted.length === 1) {
shortSummary[shortSummary.length] = "−".concat(getMessage("messages-short_catchange", deleted[0]));
} else if (deleted.length > 0) {
shortSummary[shortSummary.length] = "− ".concat(multiChangeMsg(deleted.length));
}
for (i = 0; i < added.length; i++) {
summary[summary.length] = "+".concat(getMessage("messages-short_catchange", added[i]));
}
if (added.length === 1) {
shortSummary[shortSummary.length] = "+".concat(getMessage("messages-short_catchange", added[0]));
} else if (added.length > 0) {
shortSummary[shortSummary.length] = "+ ".concat(multiChangeMsg(added.length));
}
const arrow = is_rtl ? "←" : "→";
for (i = 0; i < changed.length; i++) {
if (changed[i].from === changed[i].to) {
summary[summary.length] = "±".concat(getMessage("messages-short_catchange", changed[i].from));
} else {
summary[summary.length] = "±".concat(getMessage("messages-short_catchange", changed[i].from)).concat(arrow).concat(getMessage("messages-short_catchange", changed[i].to));
}
}
if (changed.length === 1) {
if (changed[0].from === changed[0].to) {
shortSummary[shortSummary.length] = "±".concat(getMessage("messages-short_catchange", changed[0].from));
} else {
shortSummary[shortSummary.length] = "±".concat(getMessage("messages-short_catchange", changed[0].from)).concat(arrow).concat(getMessage("messages-short_catchange", changed[0].to));
}
} else if (changed.length > 0) {
shortSummary[shortSummary.length] = "± ".concat(multiChangeMsg(changed.length));
}
if (summary.length > 0) {
summary = summary.join(getMessage("messages-separator"));
if (summary.length > 200 - (HC.changeTag ? "" : getMessage("messages-prefix")).length - (HC.changeTag ? "" : getMessage("messages-using")).length) {
summary = shortSummary.join(getMessage("messages-separator"));
}
commitForm.wpSummary.value = (HC.changeTag ? "" : getMessage("messages-prefix")) + summary + (HC.changeTag ? "" : getMessage("messages-using"));
}
}
}
commitForm.wpTextbox1.value = result.text;
commitForm.wpStarttime.value = serverTime || currentTimestamp();
commitForm.wpEdittime.value = pageTime || commitForm.wpStarttime.value;
if (selfEditConflict) {
commitForm.oldid.value = String(pageTextRevId || conf.wgCurRevisionId);
}
commitForm.hcCommit.click();
};
const resolveOne = (page, toResolve) => {
const cats = page.categories;
const {
links
} = page;
let is_dab = false;
let is_redir = typeof page.redirect === "string";
let i;
const is_hidden = page.categoryinfo && typeof page.categoryinfo.hidden === "string";
const is_missing = typeof page.missing === "string";
for (i = 0; i < toResolve.length; i++) {
if (i && toResolve[i].dabInputCleaned !== page.title.slice(Math.max(0, page.title.indexOf(":") + 1))) {
continue;
}
toResolve[i].currentHidden = is_hidden;
toResolve[i].inputExists = !is_missing;
toResolve[i].icon.src = is_missing ? HC.existsNo : HC.existsYes;
}
if (is_missing) {
return;
}
if (!is_redir && cats && (getMessage("disambig_category") || getMessage("redir_category"))) {
var _iterator = _createForOfIteratorHelper(cats), _step;
try {
for (_iterator.s(); !(_step = _iterator.n()).done; ) {
const cat_ = _step.value;
let cat = cat_.title;
if (cat) {
cat = cat.slice(Math.max(0, cat.indexOf(":") + 1)).replace(/_/g, " ");
if (cat === getMessage("disambig_category")) {
is_dab = true;
break;
} else if (cat === getMessage("redir_category")) {
is_redir = true;
break;
}
}
}
} catch (err) {
_iterator.e(err);
} finally {
_iterator.f();
}
}
if (!is_redir && !is_dab) {
return;
}
if (!links || links.length === 0) {
return;
}
const titles = [];
for (i = 0; i < links.length; i++) {
if (
// Category namespace -- always true since we ask only for the category links
links[i].ns === 14 && // Name not empty
links[i].title && links[i].title.length > 0
) {
let match = links[i].title;
match = match.slice(Math.max(0, match.indexOf(":") + 1));
if (!HC.blacklist || !HC.blacklist.test(match)) {
titles[titles.length] = match;
}
}
}
if (titles.length === 0) {
return;
}
for (i = 0; i < toResolve.length; i++) {
if (i && toResolve[i].dabInputCleaned !== page.title.slice(Math.max(0, page.title.indexOf(":") + 1))) {
continue;
}
toResolve[i].inputExists = true;
toResolve[i].icon.src = HC.existsYes;
if (titles.length > 1) {
toResolve[i].dab = titles;
} else {
toResolve[i].text.value = titles[0] + (toResolve[i].currentKey === null ? "" : "|".concat(toResolve[i].currentKey));
}
}
};
const resolveRedirects = (toResolve, params) => {
if (!params || !params.query || !params.query.pages) {
return;
}
for (const p in params.query.pages) {
if (!Object.hasOwn(params.query.pages, p)) {
continue;
}
resolveOne(params.query.pages[p], toResolve);
}
};
const resolveMulti = (toResolve, callback) => {
let i;
for (i = 0; i < toResolve.length; i++) {
toResolve[i].dab = null;
toResolve[i].dabInput = toResolve[i].lastInput;
}
if (noSuggestions) {
callback(toResolve);
return;
}
const params = {
action: "query",
format: "json",
prop: "info|links|categories|categoryinfo",
plnamespace: "14",
pllimit: toResolve.length * 10,
cllimit: toResolve.length * 10
};
const titles = [];
for (i = 0; i < toResolve.length; i++) {
let v = toResolve[i].dabInput;
v = replaceShortcuts(v, HC.shortcuts);
toResolve[i].dabInputCleaned = v;
titles[titles.length] = "Category:".concat(v);
}
params.titles = titles.join("|");
api.get(params).done((json) => {
resolveRedirects(toResolve, json);
callback(toResolve);
}).fail((req) => {
if (!req) {
noSuggestions = true;
}
callback(toResolve);
});
};
const makeActive = (which) => {
if (which.is_active) {
return;
}
for (var _i = 0, _editors = editors; _i < _editors.length; _i++) {
const editor = _editors[_i];
if (editor !== which) {
editor.inactivate();
}
}
which.is_active = true;
if (which.dab) {
showDab(which);
} else {
const expectedInput = which.lastRealInput || which.lastInput || "";
const actualValue = which.text.value || "";
if (expectedInput.length === 0 && actualValue.length > 0 || expectedInput.length > 0 && actualValue.indexOf(expectedInput)) {
which.showsList = false;
const v = actualValue.split("|");
[which.lastInput] = v;
which.lastRealInput = which.lastInput;
if (v.length > 1) {
[, which.currentKey] = v;
}
which.lastSelection && (which.lastSelection = {
start: v[0].length,
end: v[0].length
});
}
if (which.showsList) {
which.displayList();
}
if (which.lastSelection) {
setTimeout(() => {
which.setSelection(which.lastSelection.start, which.lastSelection.end);
}, 0);
}
}
};
const showDab = (which) => {
if (which.is_active) {
which.showSuggestions(which.dab, false, null, null);
which.dab = null;
} else {
makeActive(which);
}
};
const multiSubmit = () => {
const toResolve = [];
for (var _i2 = 0, _editors2 = editors; _i2 < _editors2.length; _i2++) {
const editor = _editors2[_i2];
if (editor.state === CHANGE_PENDING || editor.state === OPEN) {
toResolve[toResolve.length] = editor;
}
}
if (toResolve.length === 0) {
initiateEdit((failure) => {
performChanges(failure);
}, (msg) => {
void mw.notify(msg, {
tag: "hotCat"
});
});
return;
}
resolveMulti(toResolve, (resolved) => {
let firstDab = null;
let dontChange = false;
var _iterator2 = _createForOfIteratorHelper(resolved), _step2;
try {
for (_iterator2.s(); !(_step2 = _iterator2.n()).done; ) {
const element = _step2.value;
if (element.lastInput === element.dabInput) {
if (element.dab) {
firstDab || (firstDab = element);
} else if (element.acceptCheck(true)) {
element.commit();
}
} else {
dontChange = true;
}
}
} catch (err) {
_iterator2.e(err);
} finally {
_iterator2.f();
}
if (firstDab) {
showDab(firstDab);
} else if (!dontChange) {
initiateEdit((failure) => {
performChanges(failure);
}, (msg) => {
void mw.notify(msg, {
tag: "hotCat"
});
});
}
});
};
const setMultiInput = () => {
if (commitButton || onUpload) {
return;
}
commitButton = make("input");
commitButton.type = "button";
commitButton.value = getMessage("messages-commit");
commitButton.addEventListener("click", multiSubmit);
if (multiSpan) {
multiSpan.replaceWith(commitButton);
} else {
catLine.append(commitButton);
}
};
const checkMultiInput = () => {
if (!commitButton) {
return;
}
let hasChanges = false;
for (var _i3 = 0, _editors3 = editors; _i3 < _editors3.length; _i3++) {
const editor = _editors3[_i3];
if (editor.state !== UNCHANGED) {
hasChanges = true;
break;
}
}
commitButton.disabled = !hasChanges;
};
const suggestionEngines = {
opensearch: {
uri: "".concat(mw.config.get("wgScriptPath"), "/api.php?format=json&action=opensearch&namespace=14&limit=30&search=Category:$1"),
// $1 = search term
// Function to convert result of uri into an array of category names
handler: (queryResult, queryKey) => {
if (queryResult && queryResult.length >= 2) {
const key = queryResult[0].slice(Math.max(0, queryResult[0].indexOf(":") + 1));
const [, titles] = queryResult;
let exists = false;
cat_prefix || (cat_prefix = new RegExp("^(".concat(HC.category_regexp, "):")));
for (let i = 0; i < titles.length; i++) {
cat_prefix.lastIndex = 0;
const m = cat_prefix.exec(titles[i]);
if (m && m.length > 1) {
titles[i] = titles[i].slice(Math.max(0, titles[i].indexOf(":") + 1));
if (key === titles[i]) {
exists = true;
}
} else {
titles.splice(i, 1);
i--;
}
}
titles.exists = exists;
if (queryKey !== key) {
titles.normalized = key;
}
return titles;
}
return null;
}
},
internalsearch: {
uri: "".concat(mw.config.get("wgScriptPath"), "/api.php?format=json&action=query&list=allpages&apnamespace=14&aplimit=30&apfrom=$1&apprefix=$1"),
handler: (queryResult) => {
if (queryResult && queryResult.query && queryResult.query.allpages) {
const titles = queryResult.query.allpages;
for (let i = 0; i < titles.length; i++) {
titles[i] = titles[i].title.slice(Math.max(0, titles[i].title.indexOf(":") + 1));
}
return titles;
}
return null;
}
},
exists: {
uri: "".concat(mw.config.get("wgScriptPath"), "/api.php?format=json&action=query&prop=info&titles=Category:$1"),
handler: (queryResult, queryKey) => {
if (queryResult && queryResult.query && queryResult.query.pages && !queryResult.query.pages[-1]) {
for (const p in queryResult.query.pages) {
if (!Object.hasOwn(queryResult.query.pages, p)) {
continue;
}
let _title = queryResult.query.pages[p].title;
_title = _title.slice(Math.max(0, _title.indexOf(":") + 1));
const titles = [_title];
titles.exists = true;
if (queryKey !== _title) {
titles.normalized = _title;
}
return titles;
}
}
return null;
}
},
subcategories: {
uri: "".concat(mw.config.get("wgScriptPath"), "/api.php?format=json&action=query&list=categorymembers&cmtype=subcat&cmlimit=max&cmtitle=Category:$1"),
handler: (queryResult) => {
if (queryResult && queryResult.query && queryResult.query.categorymembers) {
const titles = queryResult.query.categorymembers;
for (let i = 0; i < titles.length; i++) {
titles[i] = titles[i].title.slice(Math.max(0, titles[i].title.indexOf(":") + 1));
}
return titles;
}
return null;
}
},
parentcategories: {
uri: "".concat(mw.config.get("wgScriptPath"), "/api.php?format=json&action=query&prop=categories&titles=Category:$1&cllimit=max"),
handler: (queryResult) => {
if (queryResult && queryResult.query && queryResult.query.pages) {
for (const p in queryResult.query.pages) {
if (queryResult.query.pages[p].categories) {
const titles = queryResult.query.pages[p].categories;
for (let i = 0; i < titles.length; i++) {
titles[i] = titles[i].title.slice(Math.max(0, titles[i].title.indexOf(":") + 1));
}
return titles;
}
}
}
return null;
}
}
};
const suggestionConfigs = {
searchindex: {
name: "Search index",
engines: ["opensearch"],
cache: {},
show: true,
temp: false,
noCompletion: false
},
pagelist: {
name: "Page list",
engines: ["internalsearch", "exists"],
cache: {},
show: true,
temp: false,
noCompletion: false
},
combined: {
name: "Combined search",
engines: ["opensearch", "internalsearch"],
cache: {},
show: true,
temp: false,
noCompletion: false
},
subcat: {
name: "Subcategories",
engines: ["subcategories"],
cache: {},
show: true,
temp: true,
noCompletion: true
},
parentcat: {
name: "Parent categories",
engines: ["parentcategories"],
cache: {},
show: true,
temp: true,
noCompletion: true
}
};
const BS = 8;
const TAB = 9;
const RET = 13;
const ESC = 27;
const SPACE = 32;
const PGUP = 33;
const PGDOWN = 34;
const UP = 38;
const DOWN = 40;
const DEL = 46;
const IME = 229;
class CategoryEditor {
constructor(...args) {
this.isCompositionStart = false;
this.callbackObj = null;
this.initialize(...args);
}
initialize(line, span, after, key, is_hidden) {
if (span) {
if (is_rtl) {
span.dir = "rtl";
}
this.isAddCategory = false;
this.catLink = span.firstChild;
this.originalCategory = after;
this.originalKey = key && key.length > 1 ? key.slice(1) : null;
this.originalExists = !hasClass(this.catLink, "new");
this.makeLinkSpan();
if (!this.originalExists && this.upDownLinks) {
this.upDownLinks.style.display = "none";
}
span.append(this.linkSpan);
} else {
this.isAddCategory = true;
this.originalCategory = "";
this.originalKey = null;
this.originalExists = false;
if (!newDOM) {
span = make("span");
span.className = "noprint";
if (key) {
span.append(make(" | ", true));
if (after) {
after.parentNode.insertBefore(span, after.nextSibling);
after = after.nextSibling;
} else if (line) {
line.append(span);
}
} else if (line && line.firstChild) {
span.append(make(" ", true));
line.append(span);
}
}
this.linkSpan = make("span");
this.linkSpan.className = "noprint nopopups hotcatlink";
const link = make("a");
link.href = "#catlinks";
link.addEventListener("click", this.open.bind(this));
link.append(make(HC.links.add, true));
link.title = getMessage("tooltips-add");
this.linkSpan.append(link);
span = make(newDOM ? "li" : "span");
span.className = "noprint";
if (is_rtl) {
span.dir = "rtl";
}
span.append(this.linkSpan);
if (after) {
after.parentNode.insertBefore(span, after.nextSibling);
} else if (line) {
line.append(span);
}
this.normalLinks = null;
this.undelLink = null;
this.catLink = null;
}
this.originalHidden = is_hidden;
this.line = line;
this.engine = HC.suggestions;
this.span = span;
this.currentCategory = this.originalCategory;
this.currentExists = this.originalExists;
this.currentHidden = this.originalHidden;
this.currentKey = this.originalKey;
this.state = UNCHANGED;
this.lastSavedState = UNCHANGED;
this.lastSavedCategory = this.originalCategory;
this.lastSavedKey = this.originalKey;
this.lastSavedExists = this.originalExists;
this.lastSavedHidden = this.originalHidden;
if (this.catLink && this.currentKey) {
this.catLink.title = this.currentKey;
}
editors[editors.length] = this;
}
makeLinkSpan() {
this.normalLinks = make("span");
let link = null;
if (this.originalCategory && this.originalCategory.length > 0) {
link = make("a");
link.href = "#catlinks";
link.addEventListener("click", this.remove.bind(this));
link.append(make(HC.links.remove, true));
link.title = getMessage("tooltips-remove");
this.normalLinks.append(make(" ", true));
this.normalLinks.append(link);
}
if (!HC.template_categories[this.originalCategory]) {
link = make("a");
link.href = "#catlinks";
link.addEventListener("click", this.open.bind(this));
link.append(make(HC.links.change, true));
link.title = getMessage("tooltips-change");
this.normalLinks.append(make(" ", true));
this.normalLinks.append(link);
if (!noSuggestions && HC.use_up_down) {
this.upDownLinks = make("span");
link = make("a");
link.href = "#catlinks";
link.addEventListener("click", this.down.bind(this));
link.append(make(HC.links.down, true));
link.title = getMessage("tooltips-down");
this.upDownLinks.append(make(" ", true));
this.upDownLinks.append(link);
link = make("a");
link.href = "#catlinks";
link.addEventListener("click", this.up.bind(this));
link.append(make(HC.links.up, true));
link.title = getMessage("tooltips-up");
this.upDownLinks.append(make(" ", true));
this.upDownLinks.append(link);
this.normalLinks.append(this.upDownLinks);
}
}
this.linkSpan = make("span");
this.linkSpan.className = "noprint nopopups hotcatlink";
this.linkSpan.append(this.normalLinks);
this.undelLink = make("span");
this.undelLink.className = "nopopups hotcatlink";
this.undelLink.style.display = "none";
link = make("a");
link.href = "#catlinks";
link.addEventListener("click", this.restore.bind(this));
link.append(make(HC.links.restore, true));
link.title = getMessage("tooltips-restore");
this.undelLink.append(make(" ", true));
this.undelLink.append(link);
this.linkSpan.append(this.undelLink);
}
invokeSuggestions(dont_autocomplete) {
if (this.engine && suggestionConfigs[this.engine] && suggestionConfigs[this.engine].temp && !dont_autocomplete) {
this.engine = HC.suggestions;
}
this.state = CHANGE_PENDING;
const self = this;
setTimeout(() => {
self.textchange(dont_autocomplete);
}, HC.suggest_delay);
}
makeForm() {
const form = make("form");
form.method = "POST";
form.addEventListener("submit", this.accept.bind(this));
this.form = form;
const self = this;
const text = make("input");
text.type = "text";
text.size = HC.editbox_width;
if (!noSuggestions) {
text.addEventListener("keyup", (event) => {
const key = event.key || 0;
if (self.ime && self.lastKey === IME && !self.usesComposition && (key === TAB || key === RET || key === ESC || key === SPACE)) {
self.ime = false;
}
if (self.ime) {
return true;
}
if (key === UP || key === DOWN || key === PGUP || key === PGDOWN) {
if (self.keyCount === 0) {
return self.processKey(event);
}
} else {
if (key === ESC && self.lastKey !== IME && !self.resetKeySelection()) {
self.cancel();
return;
}
if (self.isCompositionStart) {
return;
}
self.invokeSuggestions(key === BS || key === DEL || key === ESC);
}
return true;
});
text.addEventListener("keydown", (event) => {
const key = event.key || 0;
self.lastKey = key;
self.keyCount = 0;
if (!self.ime && key === IME && !self.usesComposition) {
self.ime = true;
} else if (self.ime && key !== IME && !(key >= 16 && key <= 20 || key >= 91 && key <= 93 || key === 144)) {
self.ime = false;
}
if (self.ime) {
return true;
}
if (key === RET) {
return self.accept(event);
}
return key === ESC ? evtKill(event) : true;
});
text.addEventListener("keypress", (event) => {
self.keyCount++;
return self.processKey(event);
});
text.addEventListener("focus", () => {
makeActive(self);
});
$(text).on("blur", this.saveView.bind(this));
try {
$(text).on("compositionstart", () => {
self.lastKey = IME;
self.usesComposition = true;
self.ime = true;
self.isCompositionStart = true;
});
$(text).on("compositionend", () => {
self.lastKey = IME;
self.usesComposition = true;
self.ime = false;
self.isCompositionStart = false;
});
$(text).on("textInput", () => {
self.ime = false;
if (self.isCompositionStart) {
return;
}
self.invokeSuggestions(false);
});
} catch (e) {
}
$(text).on("blur", () => {
self.usesComposition = false;
self.ime = false;
});
}
this.text = text;
this.icon = make("img");
let list = null;
if (!noSuggestions) {
list = make("select");
list.addEventListener("click", () => {
if (self.highlightSuggestion(0)) {
self.textchange(false, true);
}
});
list.addEventListener("dblclick", (e) => {
if (self.highlightSuggestion(0)) {
self.accept(e);
}
});
list.addEventListener("change", () => {
self.highlightSuggestion(0);
self.text.focus();
});
list.addEventListener("keyup", (event) => {
if (event.key === ESC) {
self.resetKeySelection();
self.text.focus();
setTimeout(() => {
self.textchange(true);
}, HC.suggest_delay);
} else if (event.key === RET) {
self.accept(event);
}
});
if (!HC.fixed_search) {
const engineSelector = make("select");
for (const key in suggestionConfigs) {
if (suggestionConfigs[key].show) {
const opt = make("option");
opt.value = key;
if (key === this.engine) {
opt.selected = true;
}
opt.append(make(suggestionConfigs[key].name, true));
engineSelector.append(opt);
}
}
engineSelector.addEventListener("change", () => {
self.engine = self.engineSelector.options[self.engineSelector.selectedIndex].value;
self.text.focus();
self.textchange(true, true);
});
this.engineSelector = engineSelector;
}
}
this.list = list;
const button_label = (_id, defaultText) => {
const label = null;
if (!label || !label.data) {
return defaultText;
}
return label.data;
};
const OK = make("input");
OK.type = "button";
OK.value = button_label("wpOkUploadLbl", getMessage("messages-ok"));
OK.addEventListener("click", this.accept.bind(this));
this.ok = OK;
const cancel = make("input");
cancel.type = "button";
cancel.value = button_label("wpCancelUploadLbl", getMessage("messages-cancel"));
cancel.addEventListener("click", this.cancel.bind(this));
this.cancelButton = cancel;
const span = make("span");
span.className = "hotcatinput";
span.style.position = "relative";
span.append(text);
span.style.whiteSpace = "nowrap";
if (list) {
span.append(list);
}
if (this.engineSelector) {
span.append(this.engineSelector);
}
if (!noSuggestions) {
span.append(this.icon);
}
span.append(OK);
span.append(cancel);
form.append(span);
form.style.display = "none";
this.span.append(form);
}
display(event) {
if (this.isAddCategory && !onUpload && this.line) {
new CategoryEditor(this.line, null, this.span, true);
}
if (!commitButton && !onUpload) {
for (var _i4 = 0, _editors4 = editors; _i4 < _editors4.length; _i4++) {
const editor = _editors4[_i4];
if (editor.state !== UNCHANGED) {
setMultiInput();
break;
}
}
}
if (!this.form) {
this.makeForm();
}
if (this.list) {
this.list.style.display = "none";
}
if (this.engineSelector) {
this.engineSelector.style.display = "none";
}
this.currentCategory = this.lastSavedCategory;
this.currentExists = this.lastSavedExists;
this.currentHidden = this.lastSavedHidden;
this.currentKey = this.lastSavedKey;
this.icon.src = this.currentExists ? HC.existsYes : HC.existsNo;
this.text.value = this.currentCategory + (this.currentKey === null ? "" : "|".concat(this.currentKey));
this.originalState = this.state;
this.lastInput = this.currentCategory;
this.inputExists = this.currentExists;
this.state = this.state === UNCHANGED ? OPEN : CHANGE_PENDING;
this.lastSelection = {
start: this.currentCategory.length,
end: this.currentCategory.length
};
this.showsList = false;
if (this.catLink) {
this.catLink.style.display = "none";
}
this.linkSpan.style.display = "none";
this.form.style.display = "inline";
this.ok.disabled = false;
const result = evtKill(event);
this.text.focus();
this.text.readOnly = false;
checkMultiInput();
return result;
}
show(event, engine, readOnly) {
const result = this.display(event);
const v = this.lastSavedCategory;
if (v.length === 0) {
return result;
}
this.text.readOnly = !!readOnly;
this.engine = engine;
this.textchange(false, true);
return result;
}
open(event) {
return this.show(event, this.engine && suggestionConfigs[this.engine].temp ? HC.suggestions : this.engine);
}
down(event) {
return this.show(event, "subcat", true);
}
up(event) {
return this.show(event, "parentcat");
}
cancel() {
if (this.isAddCategory && !onUpload) {
this.removeEditor();
return;
}
this.inactivate();
this.form.style.display = "none";
if (this.catLink) {
this.catLink.style.display = "";
}
this.linkSpan.style.display = "";
this.state = this.originalState;
this.currentCategory = this.lastSavedCategory;
this.currentKey = this.lastSavedKey;
this.currentExists = this.lastSavedExists;
this.currentHidden = this.lastSavedHidden;
if (this.catLink) {
this.catLink.title = this.currentKey && this.currentKey.length > 0 ? this.currentKey : "";
}
if (this.state === UNCHANGED) {
if (this.catLink) {
this.catLink.style.backgroundColor = "transparent";
}
} else if (!onUpload) {
try {
this.catLink.style.backgroundColor = HC.bg_changed;
} catch (e) {
}
}
checkMultiInput();
}
removeEditor() {
if (!newDOM) {
const next = this.span.nextSibling;
if (next) {
next.remove();
}
}
if (this.span && this.span.parentNode) {
this.span.remove();
}
for (let i = 0; i < editors.length; i++) {
if (editors[i] === this) {
editors.splice(i, 1);
break;
}
}
checkMultiInput();
}
rollback(event) {
this.undoLink.remove();
this.undoLink = null;
this.currentCategory = this.originalCategory;
this.currentKey = this.originalKey;
this.currentExists = this.originalExists;
this.currentHidden = this.originalHidden;
this.lastSavedCategory = this.originalCategory;
this.lastSavedKey = this.originalKey;
this.lastSavedExists = this.originalExists;
this.lastSavedHidden = this.originalHidden;
this.state = UNCHANGED;
if (!this.currentCategory || this.currentCategory.length === 0) {
this.removeEditor();
} else {
this.catLink.firstChild.remove();
this.catLink.append(make(this.currentCategory, true));
this.catLink.href = wikiPagePath("".concat(HC.category_canonical, ":").concat(this.currentCategory));
this.catLink.title = this.currentKey || "";
this.catLink.className = this.currentExists ? "" : "new";
this.catLink.style.backgroundColor = "transparent";
if (this.upDownLinks) {
this.upDownLinks.style.display = this.currentExists ? "" : "none";
}
checkMultiInput();
}
return evtKill(event);
}
inactivate() {
if (this.list) {
this.list.style.display = "none";
}
if (this.engineSelector) {
this.engineSelector.style.display = "none";
}
this.is_active = false;
}
acceptCheck(dontCheck) {
this.sanitizeInput();
const value = this.text.value.split("|");
let key = null;
if (value.length > 1) {
[, key] = value;
}
let v = value[0].replace(/_/g, " ").trim();
if (HC.capitalizePageNames) {
v = capitalize(v);
}
this.lastInput = v;
v = replaceShortcuts(v, HC.shortcuts);
if (v.length === 0) {
this.cancel();
return false;
}
if (!dontCheck && (conf.wgNamespaceNumber === 14 && v === conf.wgTitle || HC.blacklist && HC.blacklist.test(v))) {
this.cancel();
return false;
}
this.currentCategory = v;
this.currentKey = key;
this.currentExists = this.inputExists;
return true;
}
accept(event) {
this.noCommit = evtKeys(event) === 1;
const result = evtKill(event);
if (this.acceptCheck()) {
const toResolve = [this];
const original = this.currentCategory;
resolveMulti(toResolve, (resolved) => {
if (resolved[0].dab) {
showDab(resolved[0]);
} else if (resolved[0].acceptCheck(true)) {
resolved[0].commit(resolved[0].currentCategory === original ? null : getMessage("messages-cat_resolved", original));
}
});
}
return result;
}
close() {
if (!this.catLink) {
this.catLink = make("a");
this.catLink.append(make("foo", true));
this.catLink.style.display = "none";
this.span.insertBefore(this.catLink, this.span.firstChild.nextSibling);
}
this.catLink.firstChild.remove();
this.catLink.append(make(this.currentCategory, true));
this.catLink.href = wikiPagePath("".concat(HC.category_canonical, ":").concat(this.currentCategory));
this.catLink.className = this.currentExists ? "" : "new";
this.lastSavedCategory = this.currentCategory;
this.lastSavedKey = this.currentKey;
this.lastSavedExists = this.currentExists;
this.lastSavedHidden = this.currentHidden;
this.inactivate();
this.form.style.display = "none";
this.catLink.title = this.currentKey || "";
this.catLink.style.display = "";
if (this.isAddCategory) {
if (onUpload && this.line) {
new CategoryEditor(this.line, null, this.span, true);
}
this.isAddCategory = false;
this.linkSpan.remove();
this.makeLinkSpan();
this.span.append(this.linkSpan);
}
if (!this.undoLink) {
const span = make("span");
const link = make("a");
link.href = "#catlinks";
link.addEventListener("click", this.rollback.bind(this));
link.append(make(HC.links.undo, true));
link.title = getMessage("tooltips-undo");
span.append(make(" ", true));
span.append(link);
this.normalLinks.append(span);
this.undoLink = span;
if (!onUpload) {
try {
this.catLink.style.backgroundColor = HC.bg_changed;
} catch (e) {
}
}
}
if (this.upDownLinks) {
this.upDownLinks.style.display = this.lastSavedExists ? "" : "none";
}
this.linkSpan.style.display = "";
this.state = CHANGED;
checkMultiInput();
}
commit() {
if (this.currentCategory === this.originalCategory && (this.currentKey === this.originalKey || this.currentKey === null && this.originalKey.length === 0) || conf.wgNamespaceNumber === 14 && this.currentCategory === conf.wgTitle || HC.blacklist && HC.blacklist.test(this.currentCategory)) {
this.cancel();
return;
}
this.close();
if (!commitButton && !onUpload) {
const self = this;
initiateEdit((failure) => {
performChanges(failure, self);
}, (msg) => {
void mw.notify(msg, {
tag: "hotCat"
});
});
}
}
remove(event) {
this.doRemove(evtKeys(event) === 1);
return evtKill(event);
}
doRemove(noCommit) {
if (this.isAddCategory) {
this.cancel();
return;
}
if (!commitButton && !onUpload) {
for (var _i5 = 0, _editors5 = editors; _i5 < _editors5.length; _i5++) {
const editor = _editors5[_i5];
if (editor.state !== UNCHANGED) {
setMultiInput();
break;
}
}
}
if (commitButton) {
this.catLink.title = "";
this.catLink.style.cssText += "; text-decoration : line-through !important;";
try {
this.catLink.style.backgroundColor = HC.bg_changed;
} catch (e) {
}
this.originalState = this.state;
this.state = DELETED;
this.normalLinks.style.display = "none";
this.undelLink.style.display = "";
checkMultiInput();
} else if (onUpload) {
this.removeEditor();
} else {
this.originalState = this.state;
this.state = DELETED;
this.noCommit = noCommit || HC.del_needs_diff;
const self = this;
initiateEdit((failure) => {
performChanges(failure, self);
}, (msg) => {
self.state = self.originalState;
void mw.notify(msg, {
tag: "hotCat"
});
});
}
}
restore(event) {
this.catLink.title = this.currentKey || "";
this.catLink.style.textDecoration = "";
this.state = this.originalState;
if (this.state === UNCHANGED) {
this.catLink.style.backgroundColor = "transparent";
} else {
try {
this.catLink.style.backgroundColor = HC.bg_changed;
} catch (e) {
}
}
this.normalLinks.style.display = "";
this.undelLink.style.display = "none";
checkMultiInput();
return evtKill(event);
}
// Internal operations
selectEngine(engineName) {
if (!this.engineSelector) {
return;
}
for (let i = 0; i < this.engineSelector.options.length; i++) {
this.engineSelector.options[i].selected = this.engineSelector.options[i].value === engineName;
}
}
sanitizeInput() {
let v = this.text.value || "";
v = v.replace(/^(\s|_)+/, "");
const re = new RegExp("^(".concat(HC.category_regexp, "):"));
if (re.test(v)) {
v = v.slice(Math.max(0, v.indexOf(":") + 1)).replace(/^(\s|_)+/, "");
}
v = v.replace(/\u200E$/, "");
if (HC.capitalizePageNames) {
v = capitalize(v);
}
if (this.text.value !== null && this.text.value !== v) {
this.text.value = v;
}
}
makeCall(url, callbackObj, engine, queryKey, cleanKey) {
let cb = callbackObj;
const e = engine;
const v = queryKey;
const z = cleanKey;
const self = this;
const done = () => {
cb.callsMade++;
if (cb.callsMade === cb.nofCalls) {
if (cb.exists) {
cb.allTitles.exists = true;
}
if (cb.normalized) {
cb.allTitles.normalized = cb.normalized;
}
if (!cb.dontCache && !suggestionConfigs[cb.engineName].cache[z]) {
suggestionConfigs[cb.engineName].cache[z] = cb.allTitles;
}
self.text.readOnly = false;
if (!cb.cancelled) {
self.showSuggestions(cb.allTitles, cb.noCompletion, v, cb.engineName);
}
if (cb === self.callbackObj) {
self.callbackObj = null;
}
cb = void 0;
}
};
$.getJSON(url, (json) => {
const titles = e.handler(json, z);
if (titles && titles.length > 0) {
cb.allTitles = cb.allTitles === null ? titles : [...cb.allTitles, ...(0, import_ext_gadget2.generateArray)(titles)];
if (titles.exists) {
cb.exists = true;
}
if (titles.normalized) {
cb.normalized = titles.normalized;
}
}
done();
}).fail((req) => {
if (!req) {
noSuggestions = true;
}
cb.dontCache = true;
done();
});
}
textchange(dont_autocomplete, force) {
makeActive(this);
this.sanitizeInput();
let v = this.text.value;
const pipe = v.indexOf("|");
if (pipe === -1) {
this.currentKey = null;
} else {
this.currentKey = v.slice(Math.max(0, pipe + 1));
v = v.slice(0, Math.max(0, pipe));
}
if (this.lastInput === v && !force) {
return;
}
if (this.lastInput !== v) {
checkMultiInput();
}
this.lastInput = v;
this.lastRealInput = v;
this.ok.disabled = v.length > 0 && HC.blacklist && HC.blacklist.test(v);
if (noSuggestions) {
if (this.list) {
this.list.style.display = "none";
}
if (this.engineSelector) {
this.engineSelector.style.display = "none";
}
if (this.icon) {
this.icon.style.display = "none";
}
return;
}
if (v.length === 0) {
this.showSuggestions([]);
return;
}
let cleanKey = v.replace(/[\u200E\u200F\u202A-\u202E]/g, "").replace(wikiTextBlankRE, " ");
cleanKey = replaceShortcuts(cleanKey, HC.shortcuts);
cleanKey = cleanKey.trim();
if (cleanKey.length === 0) {
this.showSuggestions([]);
return;
}
if (this.callbackObj) {
this.callbackObj.cancelled = true;
}
const engineName = suggestionConfigs[this.engine] ? this.engine : "combined";
dont_autocomplete || (dont_autocomplete = suggestionConfigs[engineName].noCompletion);
if (suggestionConfigs[engineName].cache[cleanKey]) {
this.showSuggestions(suggestionConfigs[engineName].cache[cleanKey], dont_autocomplete, v, engineName);
return;
}
const {
engines
} = suggestionConfigs[engineName];
this.callbackObj = {
allTitles: null,
callsMade: 0,
nofCalls: engines.length,
noCompletion: dont_autocomplete,
engineName
};
this.makeCalls(engines, this.callbackObj, v, cleanKey);
}
makeCalls(engines, cb, v, cleanKey) {
var _iterator3 = _createForOfIteratorHelper(engines), _step3;
try {
for (_iterator3.s(); !(_step3 = _iterator3.n()).done; ) {
const engine_ = _step3.value;
const engine = suggestionEngines[engine_];
const url = conf.wgScriptPath + engine.uri.replace(/\$1/g, encodeURIComponent(cleanKey));
this.makeCall(url, cb, engine, v, cleanKey);
}
} catch (err) {
_iterator3.e(err);
} finally {
_iterator3.f();
}
}
showSuggestions(titles, dontAutocomplete, queryKey, engineName) {
this.text.readOnly = false;
this.dab = null;
this.showsList = false;
if (!this.list) {
return;
}
if (noSuggestions) {
if (this.list) {
this.list.style.display = "none";
}
if (this.engineSelector) {
this.engineSelector.style.display = "none";
}
if (this.icon) {
this.icon.style.display = "none";
}
this.inputExists = true;
return;
}
this.engineName = engineName;
if (engineName) {
if (!this.engineSelector) {
this.engineName = null;
}
} else if (this.engineSelector) {
this.engineSelector.style.display = "none";
}
if (queryKey) {
if (this.lastInput.indexOf(queryKey)) {
return;
}
if (this.lastQuery && this.lastInput.indexOf(this.lastQuery) === 0 && this.lastQuery.length > queryKey.length) {
return;
}
}
this.lastQuery = queryKey;
let v = this.text.value.split("|");
const key = v.length > 1 ? "|".concat(v[1]) : "";
v = HC.capitalizePageNames ? capitalize(v[0]) : v[0];
let vNormalized = v;
const knownToExist = titles && titles.exists;
let i;
if (titles) {
if (titles.normalized && v.indexOf(queryKey) === 0) {
vNormalized = titles.normalized + v.slice(queryKey.length);
}
const vLow = vNormalized.toLowerCase();
if (HC.blacklist) {
for (i = 0; i < titles.length; i++) {
if (HC.blacklist.test(titles[i])) {
titles.splice(i, 1);
i--;
}
}
}
titles.sort((a, b) => {
if (a === b) {
return 0;
}
if (a.indexOf(b) === 0) {
return 1;
}
if (b.indexOf(a) === 0) {
return -1;
}
let prefixMatchA = a.indexOf(vNormalized) === 0 ? 1 : 0;
let prefixMatchB = b.indexOf(vNormalized) === 0 ? 1 : 0;
if (prefixMatchA !== prefixMatchB) {
return prefixMatchB - prefixMatchA;
}
const aLow = a.toLowerCase();
const bLow = b.toLowerCase();
prefixMatchA = aLow.indexOf(vLow) === 0 ? 1 : 0;
prefixMatchB = bLow.indexOf(vLow) === 0 ? 1 : 0;
if (prefixMatchA !== prefixMatchB) {
return prefixMatchB - prefixMatchA;
}
if (a < b) {
return -1;
}
if (b < a) {
return 1;
}
return 0;
});
for (i = 0; i < titles.length; i++) {
if (i + 1 < titles.length && titles[i] === titles[i + 1] || conf.wgNamespaceNumber === 14 && titles[i] === conf.wgTitle) {
titles.splice(i, 1);
i--;
}
}
}
if (!titles || titles.length === 0) {
if (this.list) {
this.list.style.display = "none";
}
if (this.engineSelector) {
this.engineSelector.style.display = "none";
}
if (engineName && suggestionConfigs[engineName] && !suggestionConfigs[engineName].temp) {
if (this.icon) {
this.icon.src = HC.existsNo;
}
this.inputExists = false;
}
return;
}
const [firstTitle] = titles;
const completed = this.autoComplete(firstTitle, v, vNormalized, key, dontAutocomplete);
const existing = completed || knownToExist || firstTitle === replaceShortcuts(v, HC.shortcuts);
if (engineName && suggestionConfigs[engineName] && !suggestionConfigs[engineName].temp) {
this.icon.src = existing ? HC.existsYes : HC.existsNo;
this.inputExists = existing;
}
if (completed) {
this.lastInput = firstTitle;
if (titles.length === 1) {
this.list.style.display = "none";
if (this.engineSelector) {
this.engineSelector.style.display = "none";
}
return;
}
}
while (this.list.firstChild) {
this.list.firstChild.remove();
}
for (i = 0; i < titles.length; i++) {
const opt = make("option");
opt.append(make(titles[i], true));
opt.selected = completed && i === 0;
this.list.append(opt);
}
this.displayList();
}
displayList() {
this.showsList = true;
if (!this.is_active) {
this.list.style.display = "none";
if (this.engineSelector) {
this.engineSelector.style.display = "none";
}
return;
}
let nofItems = Math.min(this.list.options.length, HC.listSize);
if (nofItems <= 1) {
nofItems = 2;
}
this.list.size = nofItems;
this.list.style.align = is_rtl ? "right" : "left";
this.list.style.zIndex = 5;
this.list.style.position = "absolute";
const anchor = is_rtl ? "right" : "left";
let listh = 0;
if (this.list.style.display === "none") {
this.list.style.top = "".concat(this.text.offsetTop, "px");
this.list.style[anchor] = "-10000px";
this.list.style.display = "";
listh = this.list.offsetHeight;
this.list.style.display = "none";
} else {
listh = this.list.offsetHeight;
}
let maxListHeight = listh;
if (nofItems < HC.listSize) {
maxListHeight = listh / nofItems * HC.listSize;
}
const viewport = (what) => {
const s = "client".concat(what);
return document.documentElement ? document.documentElement[s] : 0;
};
const scroll_offset = (what) => {
const s = "scroll".concat(what);
let result = document.documentElement ? document.documentElement[s] : 0;
if (is_rtl && what === "Left") {
if (result < 0) {
result = -result;
}
if (!is_webkit) {
result = scroll_offset("Width") - viewport("Width") - result;
}
}
return result;
};
const position = (node) => {
if (node.getBoundingClientRect) {
const box = node.getBoundingClientRect();
return {
x: Math.round(box.left + scroll_offset("Left")),
y: Math.round(box.top + scroll_offset("Top"))
};
}
let t = 0;
let l = 0;
do {
t += node.offsetTop || 0;
l += node.offsetLeft || 0;
node = node.offsetParent;
} while (node);
return {
x: l,
y: t
};
};
const textPos = position(this.text);
const nl = 0;
let nt = 0;
let offset = 0;
const textBoxWidth = this.text.offsetWidth || this.text.clientWidth;
if (this.engineName) {
this.engineSelector.style.zIndex = 5;
this.engineSelector.style.position = "absolute";
this.engineSelector.style.width = "".concat(textBoxWidth, "px");
if (this.engineSelector.style.display === "none") {
this.engineSelector.style[anchor] = "-10000px";
this.engineSelector.style.top = "0";
this.engineSelector.style.display = "";
offset = this.engineSelector.offsetHeight;
this.engineSelector.style.display = "none";
} else {
offset = this.engineSelector.offsetHeight;
}
this.engineSelector.style[anchor] = "".concat(nl, "px");
}
if (textPos.y < maxListHeight + offset + 1) {
nt = this.text.offsetHeight + offset + 1;
if (this.engineName) {
this.engineSelector.style.top = "".concat(this.text.offsetHeight, "px");
}
} else {
nt = -listh - offset - 1;
if (this.engineName) {
this.engineSelector.style.top = "".concat(-(offset + 1), "px");
}
}
this.list.style.top = "".concat(nt, "px");
this.list.style.width = "";
this.list.style[anchor] = "".concat(nl, "px");
if (this.engineName) {
this.selectEngine(this.engineName);
this.engineSelector.style.display = "";
}
this.list.style.display = "block";
if (this.list.offsetWidth < textBoxWidth) {
this.list.style.width = "".concat(textBoxWidth, "px");
return;
}
const scroll = scroll_offset("Left");
const view_w = viewport("Width");
let w = this.list.offsetWidth;
const l_pos = position(this.list);
let left = l_pos.x;
let right = left + w;
if (left < scroll || right > scroll + view_w) {
if (w > view_w) {
w = view_w;
this.list.style.width = "".concat(w, "px");
if (is_rtl) {
left = right - w;
} else {
right = left + w;
}
}
let relative_offset = 0;
if (left < scroll) {
relative_offset = scroll - left;
} else if (right > scroll + view_w) {
relative_offset = -(right - scroll - view_w);
}
if (is_rtl) {
relative_offset = -relative_offset;
}
if (relative_offset) {
this.list.style[anchor] = "".concat(nl + relative_offset, "px");
}
}
}
autoComplete(newVal, actVal, normalizedActVal, key, dontModify) {
if (newVal === actVal) {
return true;
}
if (dontModify || this.ime || !this.canSelect()) {
return false;
}
if (newVal.indexOf(actVal)) {
if (normalizedActVal && newVal.indexOf(normalizedActVal) === 0) {
if (this.lastRealInput === actVal) {
this.lastRealInput = normalizedActVal;
}
actVal = normalizedActVal;
} else {
return false;
}
}
this.text.focus();
this.text.value = newVal + key;
this.setSelection(actVal.length, newVal.length);
return true;
}
canSelect() {
return this.text.setSelectionRange || this.text.selectionStart !== void 0 && this.text.selectionEnd !== void 0;
}
setSelection(from, to) {
if (!this.text.value) {
return;
}
if (this.text.setSelectionRange) {
this.text.setSelectionRange(from, to);
} else if (this.text.selectionStart !== void 0) {
if (from > this.text.selectionStart) {
this.text.selectionEnd = to;
this.text.selectionStart = from;
} else {
this.text.selectionStart = from;
this.text.selectionEnd = to;
}
}
}
getSelection() {
let from = 0;
let to = 0;
if (!this.text.value) {
} else if (this.text.selectionStart !== void 0) {
from = this.text.selectionStart;
to = this.text.selectionEnd;
}
return {
start: from,
end: to
};
}
saveView() {
this.lastSelection = this.getSelection();
}
processKey(event) {
let dir = 0;
switch (this.lastKey) {
case UP:
dir = -1;
break;
case DOWN:
dir = 1;
break;
case PGUP:
dir = -HC.listSize;
break;
case PGDOWN:
dir = HC.listSize;
break;
case ESC:
return evtKill(event);
}
if (dir) {
if (this.list.style.display !== "none") {
this.highlightSuggestion(dir);
return evtKill(event);
} else if (this.keyCount <= 1 && (!this.callbackObj || this.callbackObj.callsMade === this.callbackObj.nofCalls)) {
this.textchange();
}
}
return true;
}
highlightSuggestion(dir) {
if (noSuggestions || !this.list || this.list.style.display === "none") {
return false;
}
const curr = this.list.selectedIndex;
let tgt = -1;
if (dir === 0) {
if (curr < 0 || curr >= this.list.options.length) {
return false;
}
tgt = curr;
} else {
tgt = curr < 0 ? 0 : curr + dir;
tgt = Math.max(tgt, 0);
if (tgt >= this.list.options.length) {
tgt = this.list.options.length - 1;
}
}
if (tgt !== curr || dir === 0) {
if (curr >= 0 && curr < this.list.options.length && dir !== 0) {
this.list.options[curr].selected = false;
}
this.list.options[tgt].selected = true;
const v = this.text.value.split("|");
const key = v.length > 1 ? "|".concat(v[1]) : "";
const completed = this.autoComplete(this.list.options[tgt].text, this.lastRealInput, null, key, false);
if (!completed || this.list.options[tgt].text === this.lastRealInput) {
this.text.value = this.list.options[tgt].text + key;
if (this.canSelect()) {
this.setSelection(this.list.options[tgt].text.length, this.list.options[tgt].text.length);
}
}
this.lastInput = this.list.options[tgt].text;
this.inputExists = true;
if (this.icon) {
this.icon.src = HC.existsYes;
}
this.state = CHANGE_PENDING;
}
return true;
}
resetKeySelection() {
if (noSuggestions || !this.list || this.list.style.display === "none") {
return false;
}
const curr = this.list.selectedIndex;
if (curr >= 0 && curr < this.list.options.length) {
this.list.options[curr].selected = false;
const v = this.text.value.split("|");
const key = v.length > 1 ? "|".concat(v[1]) : "";
let result = v[0] !== this.lastInput;
if (v[0] !== this.lastRealInput) {
this.text.value = this.lastRealInput + key;
result = true;
}
this.lastInput = this.lastRealInput;
return result;
}
return false;
}
}
const initialize = () => {
const config = {};
HC.dont_add_to_watchlist = window.hotcat_dont_add_to_watchlist === void 0 ? config.HotCatDontAddToWatchlist === void 0 ? HC.dont_add_to_watchlist : config.HotCatDontAddToWatchlist : !!window.hotcat_dont_add_to_watchlist;
HC.no_autocommit = window.hotcat_no_autocommit === void 0 ? config.HotCatNoAutoCommit === void 0 ? conf.wgNamespaceNumber % 2 ? true : HC.no_autocommit : config.HotCatNoAutoCommit : !!window.hotcat_no_autocommit;
HC.del_needs_diff = window.hotcat_del_needs_diff === void 0 ? config.HotCatDelNeedsDiff === void 0 ? HC.del_needs_diff : config.HotCatDelNeedsDiff : !!window.hotcat_del_needs_diff;
HC.suggest_delay = window.hotcat_suggestion_delay || config.HotCatSuggestionDelay || HC.suggest_delay;
HC.editbox_width = window.hotcat_editbox_width || config.HotCatEditBoxWidth || HC.editbox_width;
HC.suggestions = window.hotcat_suggestions || config.HotCatSuggestions || HC.suggestions;
if (typeof HC.suggestions !== "string" || !suggestionConfigs[HC.suggestions]) {
HC.suggestions = "combined";
}
HC.fixed_search = window.hotcat_suggestions_fixed === void 0 ? config.HotCatFixedSuggestions === void 0 ? HC.fixed_search : config.HotCatFixedSuggestions : !!window.hotcat_suggestions_fixed;
HC.single_minor = window.hotcat_single_changes_are_minor === void 0 ? config.HotCatMinorSingleChanges === void 0 ? HC.single_minor : config.HotCatMinorSingleChanges : !!window.hotcat_single_changes_are_minor;
HC.bg_changed = window.hotcat_changed_background || config.HotCatChangedBackground || HC.bg_changed;
HC.use_up_down = window.hotcat_use_category_links === void 0 ? config.HotCatUseCategoryLinks === void 0 ? HC.use_up_down : config.HotCatUseCategoryLinks : !!window.hotcat_use_category_links;
HC.listSize = window.hotcat_list_size || config.HotCatListSize || HC.listSize;
HC.changeTag = config.HotCatChangeTag || "";
if (HC.changeTag) {
const eForm = document.editform;
const catRegExp = new RegExp("^\\[\\[(".concat(HC.category_regexp, "):"));
let oldTxt;
const isMinorChange = () => {
let newTxt = eForm.wpTextbox1;
if (!newTxt) {
return;
}
newTxt = newTxt.value;
const oldLines = oldTxt.match(/^.*$/gm);
const newLines = newTxt.match(/^.*$/gm);
let cArr;
const except = (aArr, bArr) => {
const result = [];
let lArr;
let sArr;
if (aArr.length < bArr.length) {
lArr = bArr;
sArr = aArr;
} else {
lArr = aArr;
sArr = bArr;
}
var _iterator4 = _createForOfIteratorHelper(lArr), _step4;
try {
for (_iterator4.s(); !(_step4 = _iterator4.n()).done; ) {
const item = _step4.value;
const ind = sArr.indexOf(item);
if (ind === -1) {
result[result.length] = item;
} else {
sArr.splice(ind, 1);
}
}
} catch (err) {
_iterator4.e(err);
} finally {
_iterator4.f();
}
return [...result, ...sArr];
};
cArr = except(oldLines, newLines);
if (cArr.length > 0) {
cArr = cArr.filter((c) => {
c = c.trim();
return c && !catRegExp.test(c);
});
}
if (cArr.length === 0) {
oldTxt = newTxt;
return true;
}
};
if (conf.wgAction === "submit" && conf.wgArticleId && eForm && eForm.wpSummary && document.querySelector("#wikiDiff")) {
const sum = eForm.wpSummary;
const sumA = eForm.wpAutoSummary;
if (sum.value && sumA.value === HC.changeTag) {
sumA.value = sumA.value.replace(HC.changeTag, "d41d8cd98f00b204e9800998ecf8427e");
const $ct = $("<input>").attr({
type: "hidden",
name: "wpChangeTags"
}).val(HC.changeTag);
$(eForm).append($ct);
oldTxt = eForm.wpTextbox1.value;
const $body = $("body");
$body.find("input[name=wpSave]").one("click", () => {
if ($ct.val()) {
sum.value = sum.value.replace(getMessage("messages-using") || getMessage("messages-prefix"), "");
}
});
const removeChangeTag = () => {
$(eForm.wpTextbox1).add(sum).one("input", () => {
setTimeout(() => {
if (isMinorChange()) {
removeChangeTag();
} else {
$ct.val("");
}
}, 500);
});
};
removeChangeTag();
}
}
}
HC.listSize = Number.parseInt(HC.listSize, 10);
if (Number.isNaN(HC.listSize) || HC.listSize < 5) {
HC.listSize = 5;
}
HC.listSize = Math.min(HC.listSize, 30);
for (var _i6 = 0, _Object$entries = Object.entries(suggestionConfigs); _i6 < _Object$entries.length; _i6++) {
const [key, suggestionConfig] = _Object$entries[_i6];
try {
if (key && getMessage("engine_names-".concat(key))) {
suggestionConfig.name = getMessage("engine_names-".concat(key));
}
} catch (e) {
continue;
}
}
is_rtl = hasClass(document.querySelector("body"), "rtl");
if (!is_rtl) {
if (document.defaultView && document.defaultView.getComputedStyle) {
is_rtl = document.defaultView.getComputedStyle(document.querySelector("body"), null).getPropertyValue("direction");
} else {
is_rtl = $("body")[0].style.direction;
}
is_rtl = is_rtl === "rtl";
}
};
const can_edit = () => {
return document.querySelector("#ca-edit") !== null;
};
const closeForm = function() {
for (var _i7 = 0, _editors6 = editors; _i7 < _editors6.length; _i7++) {
const edit = _editors6[_i7];
if (edit.state === OPEN) {
edit.cancel();
} else if (edit.state === CHANGE_PENDING) {
edit.sanitizeInput();
const value = edit.text.value.split("|");
let key = null;
if (value.length > 1) {
[, key] = value;
}
const v = value[0].replace(/_/g, " ").trim();
if (v.length === 0) {
edit.cancel();
} else {
edit.currentCategory = v;
edit.currentKey = key;
edit.currentExists = this.inputExists;
edit.close();
}
}
}
};
const setup_upload = () => {
onUpload = true;
let ip = document.querySelector("#mw-htmlform-description") || document.querySelector("input[name=wpDestFile]");
if (!ip) {
ip = document.querySelector("input[name=wpDestFile]");
while (ip && ip.nodeName.toLowerCase() !== "table") {
ip = ip.parentNode;
}
}
if (!ip) {
return;
}
const reupload = document.querySelector("input[name=wpForReUpload]");
const destFile = document.querySelector("input[name=wpDestFile]");
if (reupload && !!reupload.value || destFile && (destFile.disabled || destFile.readOnly)) {
return;
}
const labelCell = make("td");
const lineCell = make("td");
catLine = make("div");
catLine.className = "catlinks";
catLine.id = "catlinks";
catLine.style.textAlign = is_rtl ? "right" : "left";
catLine.style.margin = "0";
catLine.style.border = "none";
lineCell.append(catLine);
const label = null;
if (label) {
labelCell.id = "hotcatLabelTranslated";
labelCell.append(label);
} else {
labelCell.id = "hotcatLabel";
labelCell.append(make(getMessage("categories"), true));
}
labelCell.className = "mw-label";
labelCell.style.textAlign = "right";
labelCell.style.verticalAlign = "middle";
const form = document.querySelector("#upload") || document.querySelector("#mw-upload-form");
if (form) {
const newRow = ip.insertRow(-1);
newRow.append(labelCell);
newRow.append(lineCell);
form.addEventListener("submit", (oldSubmit, ...args) => {
return (() => {
let do_submit = true;
if (oldSubmit) {
if (typeof oldSubmit === "string") {
do_submit = window.eval(oldSubmit);
} else if (oldSubmit instanceof Function) {
do_submit = oldSubmit.apply(form, [oldSubmit, ...args]);
}
}
if (!do_submit) {
return false;
}
closeForm();
const eb = document.querySelector("textarea[name=wpUploadDescription]") || document.querySelector("#wpDesc");
let addedOne = false;
for (var _i8 = 0, _editors7 = editors; _i8 < _editors7.length; _i8++) {
const editor = _editors7[_i8];
const t = editor.currentCategory;
if (!t) {
continue;
}
const key = editor.currentKey;
const new_cat = "[[".concat(HC.category_canonical, ":").concat(t).concat(key ? "|".concat(key) : "", "]]");
const nowikiRegex = new RegExp("<no".concat("wiki>", String.raw(_templateObject8 || (_templateObject8 = _taggedTemplateLiteral(["(s|S)*?</no"], ["(\\s|\\S)*?</no"]))), "wiki", ">"), "g");
const _cleanedText = eb.value.replace(/<!--(\s|\S)*?-->/g, "").replace(nowikiRegex);
if (!find_category(_cleanedText, t, true)) {
eb.value += "\n".concat(new_cat);
addedOne = true;
}
}
if (addedOne) {
const regex = new RegExp("{{$".concat("subst:").concat("unc}}"), "g");
eb.value = eb.value.replace(regex, "");
}
return true;
})(form.onsubmit);
});
}
};
let cleanedText = null;
const isOnPage = ({
firstChild
}) => {
if (firstChild.nodeType !== Node.ELEMENT_NODE) {
return null;
}
let catTitle = title(firstChild.getAttribute("href"));
if (!catTitle) {
return null;
}
catTitle = catTitle.slice(catTitle.indexOf(":") + 1).replace(/_/g, " ");
if (HC.blacklist && HC.blacklist.test(catTitle)) {
return null;
}
const result = {
title: catTitle,
match: ["", "", ""]
};
if (pageText === null) {
return result;
}
if (cleanedText === null) {
const nowikiRegex = new RegExp("<no".concat("wiki>", String.raw(_templateObject9 || (_templateObject9 = _taggedTemplateLiteral(["(s|S)*?</no"], ["(\\s|\\S)*?</no"]))), "wiki", ">"), "g");
cleanedText = pageText.replace(/<!--(\s|\S)*?-->/g, "").replace(nowikiRegex, "");
}
result.match = find_category(cleanedText, catTitle, true);
return result;
};
let initialized = false;
let setupTimeout = null;
const findByClass = (scope, tag, className) => {
const result = $(scope).find("".concat(tag, ".").concat(className));
return result && result.length > 0 ? result[0] : null;
};
const setup = (additionalWork) => {
if (initialized) {
return;
}
initialized = true;
if (setupTimeout) {
window.clearTimeout(setupTimeout);
setupTimeout = null;
}
catLine || (catLine = document.querySelector("#mw-normal-catlinks"));
const hiddenCats = document.querySelector("#mw-hidden-catlinks");
if (!catLine) {
let footer = null;
if (!hiddenCats) {
footer = findByClass(document, "div", "printfooter");
if (!footer) {
return;
}
}
catLine = make("div");
catLine.id = "mw-normal-catlinks";
catLine.style.textAlign = is_rtl ? "right" : "left";
const label = make("a");
label.href = conf.wgArticlePath.replace("$1", "Special:Categories");
label.title = getMessage("categories");
label.append(make(getMessage("categories"), true));
catLine.append(label);
catLine.append(make(":", true));
let container = hiddenCats ? hiddenCats.parentNode : document.querySelector("#catlinks");
if (!container) {
container = make("div");
container.id = "catlinks";
footer.parentNode.insertBefore(container, footer.nextSibling);
}
container.className = "catlinks noprint";
container.style.display = "";
if (hiddenCats) {
hiddenCats.before(catLine);
} else {
container.append(catLine);
}
}
if (is_rtl) {
catLine.dir = "rtl";
}
const createEditors = (line, is_hidden) => {
let i;
let cats = line.querySelectorAll("li");
if (cats.length > 0) {
newDOM = true;
line = cats[0].parentNode;
} else {
cats = line.querySelectorAll("span");
}
const copyCats = Array.from({
length: cats.length
});
for (i = 0; i < cats.length; i++) {
copyCats[i] = cats[i];
}
for (i = 0; i < copyCats.length; i++) {
const test = isOnPage(copyCats[i]);
if (test !== null && test.match !== null && line) {
new CategoryEditor(line, copyCats[i], test.title, test.match[2], is_hidden);
}
}
return copyCats.length > 0 ? copyCats.at(-1) : null;
};
const lastSpan = createEditors(catLine, false);
new CategoryEditor(newDOM ? catLine.querySelectorAll("ul")[0] : catLine, null, null, lastSpan !== null, false);
if (!onUpload) {
if (pageText !== null && hiddenCats) {
if (is_rtl) {
hiddenCats.dir = "rtl";
}
createEditors(hiddenCats, true);
}
const enableMulti = make("span");
enableMulti.className = "noprint";
if (is_rtl) {
enableMulti.dir = "rtl";
}
catLine.insertBefore(enableMulti, catLine.firstChild.nextSibling);
enableMulti.append(make(" ", true));
multiSpan = make("span");
enableMulti.append(multiSpan);
multiSpan.innerHTML = "(<a>".concat(HC.addmulti, "</a>)");
const [link] = multiSpan.querySelectorAll("a");
link.addEventListener("click", (event) => {
setMultiInput();
checkMultiInput();
return evtKill(event);
});
link.title = getMessage("multi_tooltip");
link.style.cursor = "pointer";
}
cleanedText = null;
if (additionalWork instanceof Function) {
additionalWork();
}
mw.hook("hotcat.ready").fire();
$("body").trigger("hotcatSetupCompleted");
};
const createCommitForm = () => {
if (commitForm) {
return;
}
const formContainer = make("div");
formContainer.style.display = "none";
document.querySelector("body").append(formContainer);
formContainer.innerHTML = '<form id="hotcatCommitForm" method="post" enctype="multipart/form-data" action="'.concat(conf.wgScript, "?title=").concat(encodeURIComponent(conf.wgPageName), '&action=submit">\n <input type="hidden" name="wpTextbox1">\n <input type="hidden" name="model" value="').concat(conf.wgPageContentModel, '">\n <input type="hidden" name="format" value="text/x-wiki">\n <input type="hidden" name="wpSummary" value="">\n <input type="checkbox" name="wpMinoredit" title="wpMinoredit" value="1">\n <input type="checkbox" name="wpWatchthis" title="wpWatchthis" value="1">\n <input type="hidden" name="wpAutoSummary" value="d41d8cd98f00b204e9800998ecf8427e">\n <input type="hidden" name="wpEdittime">\n <input type="hidden" name="wpStarttime">\n <input type="hidden" name="wpDiff" value="wpDiff">\n <input type="hidden" name="oldid" value="0">\n <input type="submit" name="hcCommit" value="hcCommit">\n <input type="hidden" name="wpEditToken">\n <input type="hidden" name="wpUltimateParam" value="1">\n <input type="hidden" name="wpChangeTags">\n <input type="hidden" value="ℳ𝒲♥𝓊𝓃𝒾𝒸ℴ𝒹ℯ" name="wpUnicodeCheck">\n </form>');
commitForm = document.querySelector("#hotcatCommitForm");
};
const getPage = () => {
if (conf.wgArticleId) {
const params = {
action: "query",
format: "json",
formatversion: "2",
rawcontinue: "",
titles: conf.wgPageName,
prop: ["info", "revisions"],
rvprop: ["content", "timestamp", "ids"],
rvlimit: "1",
rvstartid: conf.wgCurRevisionId,
rvslots: "main",
meta: ["siteinfo"]
};
HC.start = (data) => {
setPage(data);
setup(createCommitForm);
};
api.get(params).then((data) => {
HC.start(data);
});
setupTimeout = setTimeout(() => {
setup(createCommitForm);
}, 4e3);
} else {
if (conf.wgNamespaceNumber === 2) {
return;
}
pageText = "";
pageTime = null;
setup(createCommitForm);
}
};
const setState = (state) => {
const cats = state.split("\n");
if (cats.length === 0) {
return null;
}
if (initialized && editors.length === 1 && editors[0].isAddCategory) {
const newSpans = [];
const before = editors.length === 1 ? editors[0].span : null;
let i;
for (i = 0; i < cats.length; i++) {
if (cats[i].length === 0) {
continue;
}
let cat = cats[i].split("|");
const key = cat.length > 1 ? cat[1] : null;
[cat] = cat;
const link = make("a");
link.href = wikiPagePath("".concat(HC.category_canonical, ":").concat(cat));
link.append(make(cat, true));
link.title = cat;
const span = make("span");
span.append(link);
if (!i) {
catLine.insertBefore(make(" ", true), before);
}
before.before(span);
if (before && i + 1 < cats.length) {
parent.insertBefore(make(" | ", true), before);
}
newSpans[newSpans.length] = {
element: span,
title: cat,
key
};
}
if (before) {
before.parentNode.insertBefore(make(" | ", true), before);
}
for (i = 0; i < newSpans.length; i++) {
new CategoryEditor(catLine, newSpans[i].element, newSpans[i].title, newSpans[i].key);
}
}
return null;
};
const getState = () => {
let result = null;
for (var _i9 = 0, _editors8 = editors; _i9 < _editors8.length; _i9++) {
const editor = _editors8[_i9];
let text = editor.currentCategory;
const key = editor.currentKey;
if (text && text.length > 0) {
if (key !== null) {
text += "|".concat(key);
}
if (result === null) {
result = text;
} else {
result += "\n".concat(text);
}
}
}
return result;
};
const really_run = () => {
initialize();
if (!HC.upload_disabled && conf.wgNamespaceNumber === -1 && conf.wgCanonicalSpecialPageName === "Upload" && conf.wgUserName) {
setup_upload();
setup(() => {
if (window.UploadForm && UploadForm.previous_hotcat_state) {
UploadForm.previous_hotcat_state = setState(UploadForm.previous_hotcat_state);
}
});
} else {
if (!conf.wgIsArticle || conf.wgAction !== "view" || param("diff") !== null || param("oldid") !== null || !can_edit() || HC.disable()) {
return;
}
getPage();
}
};
const run = () => {
if (HC.started) {
return;
}
HC.started = true;
really_run();
};
window.hotcat_get_state = () => {
return getState();
};
window.hotcat_set_state = (state) => {
return setState(state);
};
window.hotcat_close_form = () => {
closeForm();
};
HC.runWhenReady = (callback) => {
mw.hook("hotcat.ready").add(callback);
};
if (conf.wgCanonicalSpecialPageName !== "Upload") {
mw.hook("postEdit").add(() => {
if (document.querySelector("#catlinks .hotcatlink")) {
return;
}
catLine = null;
editors = [];
initialized = false;
HC.started = false;
run();
});
}
$(run);
})();
})();
/* </nowiki> */