本网站正在建设中(~ ̄▽ ̄)~
- 你好~!欢迎来到中文歌声合成个人收集站-VCPedia.cn!
- 若发现页面信息有误或投稿至本站,请联系管理员。
MediaWiki:Gadget-wikiplus-highlight.js
跳到导航
跳到搜索
注意:在发布之后,您可能需要清除浏览器缓存才能看到所作出的变更的影响。
- Firefox或Safari:按住Shift的同时单击刷新,或按Ctrl-F5或Ctrl-R(Mac为⌘-R)
- Google Chrome:按Ctrl-Shift-R(Mac为⌘-Shift-R)
- Internet Explorer或Edge:按住Ctrl的同时单击刷新,或按Ctrl-F5
- Opera:按 Ctrl-F5。
/* <pre> */ /** * ------------------------------------------------------------------------- * !!! DON'T MODIFY THIS PAGE MANUALLY, YOUR CHANGES WILL BE OVERWRITTEN !!! * ------------------------------------------------------------------------- */ var _addText = '{{GHIACode|page=GHIA:MoegirlPediaInterfaceCodes/blob/master/src/gadgets/wikiplus-highlight/MediaWiki:Gadget-wikiplus-highlight.js|user=[[U:AnnAngela]]|longId=032a2bf18458a07fe76a95ebb8296686520ffafc|shortId=032a2bf|message=auto: post Commit CI - commit from GitHub Actions}}'; "use strict"; var __assign = (this && this.__assign) || function () { __assign = Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var __generator = (this && this.__generator) || function (thisArg, body) { var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; function verb(n) { return function (v) { return step([n, v]); }; } function step(op) { if (f) throw new TypeError("Generator is already executing."); while (g && (g = 0, op[0] && (_ = 0)), _) try { if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; if (y = 0, t) op = [op[0] & 2, t.value]; switch (op[0]) { case 0: case 1: t = op; break; case 4: _.label++; return { value: op[1], done: false }; case 5: _.label++; y = op[1]; op = [0]; continue; case 7: op = _.ops.pop(); _.trys.pop(); continue; default: if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } if (t[2]) _.ops.pop(); _.trys.pop(); continue; } op = body.call(thisArg, _); } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; } }; var __values = (this && this.__values) || function(o) { var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0; if (m) return m.call(o); if (o && typeof o.length === "number") return { next: function () { if (o && i >= o.length) o = void 0; return { value: o && o[i++], done: !o }; } }; throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined."); }; var __read = (this && this.__read) || function (o, n) { var m = typeof Symbol === "function" && o[Symbol.iterator]; if (!m) return o; var i = m.call(o), r, ar = [], e; try { while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); } catch (error) { e = { error: error }; } finally { try { if (r && !r.done && (m = i["return"])) m.call(i); } finally { if (e) throw e.error; } } return ar; }; var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { if (ar || !(i in from)) { if (!ar) ar = Array.prototype.slice.call(from, 0, i); ar[i] = from[i]; } } return to.concat(ar || Array.prototype.slice.call(from)); }; (function () { return __awaiter(void 0, void 0, void 0, function () { 'use strict'; var version, newAddon, storage, getVersion, cmpVersion, msg, htmlMsg, notify, majorVersion, CDN, CM_CDN, MW_CDN, PARSER_CDN, REPO_CDN, _a, page, ns, contentmodel, server, scriptPath, userLang, skin, USING_LOCAL, ALL_SETTINGS_CACHE, SITE_ID, SITE_SETTINGS, EXPIRED, CONTENTMODEL, MODE_LIST, ADDON_LIST, options, defaultAddons, defaultIndent, addons, indent, entity, convert, escapeHTML, escapeURI, escapeHash, isPc, extraKeys, handleContextMenu, i18n, welcome, i18nLanguages, i18nLang, I18N_CDN, isLatest, setI18N, i18nPromise, getInternalScript, getExternalScript, getScript, cm, getAddonScript, intersect, initMode, updateCachedConfig, getAliases, getConfig, setPlainMode, getMwConfig, getPageMode, cmTextSelection, renderEditor, body, observer, wphlStyle, _b, _c, get, _d, set, isWikiplus, dialog, widget, searchWidget, wikiEditorWidget, lintWidget, indentWidget, field, indentField, toggleIndent, portletContainer, $portlet, handleOtherEditors; return __generator(this, function (_e) { switch (_e.label) { case 0: if (mw.libs.wphl && mw.libs.wphl.version) { return [2]; } mw.libs.wphl = mw.libs.wphl || {}; version = '2.48.7', newAddon = 0; storage = typeof mw.storage === 'object' && typeof mw.storage.getObject === 'function' ? mw.storage : { getObject: function (key) { var json = localStorage.getItem(key); if (json === false) { return false; } try { return JSON.parse(json); } catch (e) { return null; } }, setObject: function (key, value) { try { return localStorage.setItem(key, JSON.stringify(value)); } catch (e) { return false; } } }; Object.fromEntries = Object.fromEntries || (function (entries) { var e_1, _a; var obj = {}; try { for (var entries_1 = __values(entries), entries_1_1 = entries_1.next(); !entries_1_1.done; entries_1_1 = entries_1.next()) { var _b = __read(entries_1_1.value, 2), key = _b[0], value = _b[1]; obj[key] = value; } } catch (e_1_1) { e_1 = { error: e_1_1 }; } finally { try { if (entries_1_1 && !entries_1_1.done && (_a = entries_1["return"])) _a.call(entries_1); } finally { if (e_1) throw e_1.error; } } return obj; }); getVersion = function (str) { if (str === void 0) { str = version; } return str.split('.').map(Number); }; cmpVersion = function (a, b) { var _a = __read(getVersion(a), 2), a0 = _a[0], a1 = _a[1], _b = __read(getVersion(b), 2), b0 = _b[0], b1 = _b[1]; return a0 < b0 || a0 === b0 && a1 < b1; }; msg = function (key) { var args = []; for (var _i = 1; _i < arguments.length; _i++) { args[_i - 1] = arguments[_i]; } return mw.msg.apply(mw, __spreadArray(["wphl-".concat(key)], __read(args), false)); }; htmlMsg = function () { var args = []; for (var _i = 0; _i < arguments.length; _i++) { args[_i] = arguments[_i]; } return $($.parseHTML(msg.apply(void 0, __spreadArray([], __read(args), false)))); }; notify = function () { var args = []; for (var _i = 0; _i < arguments.length; _i++) { args[_i] = arguments[_i]; } return function () { var $p = $('<p>', { html: msg.apply(void 0, __spreadArray([], __read(args), false)) }); mw.notify($p, { type: 'success', autoHideSeconds: 'long', tag: 'wikiplus-highlight' }); return $p; }; }; majorVersion = getVersion().slice(0, 2).join('.'); CDN = '//fastly.jsdelivr.net', CM_CDN = 'npm/[email protected]', MW_CDN = 'gh/bhsd-harry/[email protected]', PARSER_CDN = 'gh/bhsd-harry/[email protected]', REPO_CDN = "npm/wikiplus-highlight@".concat(majorVersion); _a = mw.config.values, page = _a.wgPageName, ns = _a.wgNamespaceNumber, contentmodel = _a.wgPageContentModel, server = _a.wgServerName, scriptPath = _a.wgScriptPath, userLang = _a.wgUserLanguage, skin = _a.skin; USING_LOCAL = mw.loader.getState('ext.CodeMirror') !== null, ALL_SETTINGS_CACHE = storage.getObject('InPageEditMwConfig') || {}, SITE_ID = "".concat(server).concat(scriptPath), SITE_SETTINGS = ALL_SETTINGS_CACHE[SITE_ID] || {}, EXPIRED = !(SITE_SETTINGS.time > Date.now() - 86400 * 1000 * 30); CONTENTMODEL = { css: 'css', 'sanitized-css': 'css', javascript: 'javascript', json: 'javascript', wikitext: 'mediawiki' }; MODE_LIST = USING_LOCAL ? { lib: 'ext.CodeMirror.lib', css: 'ext.CodeMirror.lib.mode.css', javascript: 'ext.CodeMirror.lib.mode.javascript', lua: "".concat(CM_CDN, "/mode/lua/lua.min.js"), mediawiki: EXPIRED ? 'ext.CodeMirror.data' : [], htmlmixed: 'ext.CodeMirror.lib.mode.htmlmixed', xml: [] } : { lib: "".concat(CM_CDN, "/lib/codemirror.min.js"), css: "".concat(CM_CDN, "/mode/css/css.min.js"), javascript: "".concat(CM_CDN, "/mode/javascript/javascript.min.js"), lua: "".concat(CM_CDN, "/mode/lua/lua.min.js"), mediawiki: [], htmlmixed: "".concat(CM_CDN, "/mode/htmlmixed/htmlmixed.min.js"), xml: "".concat(CM_CDN, "/mode/xml/xml.min.js") }; ADDON_LIST = { searchcursor: "".concat(CM_CDN, "/addon/search/searchcursor.min.js"), search: "".concat(REPO_CDN, "/search.min.js"), markSelection: "".concat(CM_CDN, "/addon/selection/mark-selection.min.js"), activeLine: "".concat(CM_CDN, "/addon/selection/active-line.min.js"), trailingspace: "".concat(CM_CDN, "/addon/edit/trailingspace.min.js"), matchBrackets: "".concat(CM_CDN, "/addon/edit/matchbrackets.min.js"), closeBrackets: "".concat(CM_CDN, "/addon/edit/closebrackets.min.js"), matchTags: "".concat(REPO_CDN, "/matchtags.min.js"), fold: "".concat(REPO_CDN, "/fold.min.js"), wikiEditor: 'ext.wikiEditor', contextmenu: 'mediawiki.Title', lint: "".concat(CM_CDN, "/addon/lint/lint.min.js"), annotateScrollbar: "".concat(CM_CDN, "/addon/scroll/annotatescrollbar.min.js"), parser: "".concat(PARSER_CDN, "/extensions/editor.min.js"), lintWikitext: "".concat(REPO_CDN, "/lint.min.js") }; options = [ { option: 'styleSelectedText', addon: 'search', download: 'markSelection', only: true, complex: function () { return !addons.has('wikiEditor'); } }, { option: 'styleActiveLine', addon: 'activeLine' }, { option: 'showTrailingSpace', addon: 'trailingspace' }, { option: 'matchBrackets', complex: function (mode, json) { return mode === 'mediawiki' || json ? { bracketRegex: /[{}[\]]/ } : true; } }, { option: 'autoCloseBrackets', addon: 'closeBrackets', complex: function (mode, json) { return mode === 'mediawiki' || json ? '()[]{}""' : true; } }, { option: 'matchTags', addon: ['matchTags', 'fold'], modes: new Set(['mediawiki', 'widget']) }, { option: 'fold', modes: new Set(['mediawiki', 'widget']) }, ]; defaultAddons = ['search'], defaultIndent = 4, addons = new Set(storage.getObject('Wikiplus-highlight-addons') || defaultAddons); indent = storage.getObject('Wikiplus-highlight-indent') || defaultIndent; entity = { '"': 'quot', "'": 'apos', '<': 'lt', '>': 'gt', '&': 'amp', ' ': 'nbsp' }, convert = function (func) { return function (doc) { doc.replaceSelection(doc.getSelection().split('\n').map(func).join('\n'), 'around'); }; }, escapeHTML = convert(function (str) { return __spreadArray([], __read(str), false).map(function (c) { if (c in entity) { return "&".concat(entity[c], ";"); } var code = c.codePointAt(); return code < 256 ? "&#".concat(code, ";") : "&#x".concat(code.toString(16), ";"); }).join(''); }), escapeURI = convert(function (str) { if (str.includes('%')) { try { return decodeURIComponent(str); } catch (e) { } } return encodeURIComponent(str); }), escapeHash = convert(function (str) { try { return decodeURIComponent(str.replace(/\.([\da-f]{2})/gi, '%$1')); } catch (e) { return str; } }), isPc = function (_a) { var keyMap = _a.keyMap; return keyMap["default"] === keyMap.pcDefault; }, extraKeys = function (CM) { var _a; var ctrl = isPc(CM) ? 'Ctrl' : 'Cmd'; return _a = {}, _a["".concat(ctrl, "-/")] = escapeHTML, _a["".concat(ctrl, "-\\")] = escapeURI, _a["Shift-".concat(ctrl, "-\\")] = escapeHash, _a; }; handleContextMenu = function (doc, mode) { if (mode !== 'mediawiki' && mode !== 'widget' || !addons.has('contextmenu')) { return; } var $wrapper = $(doc.getWrapperElement()).addClass('CodeMirror-contextmenu'), _a = __read((mw.config.get('extCodeMirrorConfig') || { functionSynonyms: [{ invoke: 'invoke', 调用: 'invoke', widget: 'widget', 小工具: 'widget' }] }).functionSynonyms, 1), synonyms = _a[0]; var getSysnonyms = function (str) { return new Set(Object.keys(synonyms).filter(function (key) { return synonyms[key] === str; }) .map(function (key) { return key.startsWith('#') ? key : "#".concat(key); })); }; var invoke = getSysnonyms('invoke'), widget = getSysnonyms('widget'); $wrapper.contextmenu(function (_a) { var pageX = _a.pageX, pageY = _a.pageY; var pos = doc.coordsChar({ left: pageX, top: pageY }), line = pos.line, ch = pos.ch, curType = doc.getTokenTypeAt(pos); if (!/\bmw-(?:template-name|parserfunction)\b/.test(curType)) { return undefined; } var tokens = doc.getLineTokens(line); for (var i = tokens.length - 1; i > 0; i--) { var _b = tokens[i], type = _b.type, end = _b.end, string = _b.string; if (tokens[i - 1].type === type) { tokens[i - 1].end = end; tokens[i - 1].string += string; tokens.splice(i, 1); } } var index = tokens.findIndex(function (_a) { var start = _a.start, end = _a.end; return start < ch && end >= ch; }), text = tokens[index].string.replace(/\u200E/g, '').replace(/_/g, ' ').trim(); if (/\bmw-template-name\b/.test(curType)) { var title = new mw.Title(text); if (title.namespace !== 0 || text.startsWith(':')) { open(title.getUrl(), '_blank'); } else { open(mw.util.getUrl("Template:".concat(text)), '_blank'); } return false; } else if (index < 2 || !/\bmw-parserfunction-delimiter\b/.test(tokens[index - 1].type) || !/\bmw-parserfunction-name\b/.test(tokens[index - 2].type)) { return undefined; } var parserFunction = tokens[index - 2].string.trim().toLowerCase(); if (invoke.has(parserFunction)) { open(mw.util.getUrl("Module:".concat(text)), '_blank'); } else if (widget.has(parserFunction)) { open(mw.util.getUrl("Widget:".concat(text), { action: 'edit' }), '_blank'); } else { return undefined; } return false; }); }; i18n = storage.getObject('Wikiplus-highlight-i18n') || {}; if (!i18n['wphl-version']) { welcome = notify('welcome'); } else if (cmpVersion(i18n['wphl-version'], version)) { welcome = notify("welcome-".concat(newAddon ? 'new-addon' : 'upgrade'), version, newAddon); } i18nLanguages = { zh: 'zh-hans', 'zh-hans': 'zh-hans', 'zh-cn': 'zh-hans', 'zh-my': 'zh-hans', 'zh-sg': 'zh-hans', 'zh-hant': 'zh-hant', 'zh-tw': 'zh-hant', 'zh-hk': 'zh-hant', 'zh-mo': 'zh-hant', ka: 'ka' }, i18nLang = i18nLanguages[userLang] || 'en', I18N_CDN = "".concat(CDN, "/").concat(REPO_CDN, "/i18n/").concat(i18nLang, ".json"), isLatest = i18n['wphl-version'] === majorVersion; setI18N = function () { return __awaiter(void 0, void 0, void 0, function () { var _a, _b, _c; return __generator(this, function (_d) { switch (_d.label) { case 0: if (!(!isLatest || i18n['wphl-lang'] !== i18nLang)) return [3, 2]; _b = (_a = Object).assign; _c = [i18n]; return [4, $.ajax("".concat(I18N_CDN), { dataType: 'json', cache: true })]; case 1: _b.apply(_a, _c.concat([_d.sent()])); storage.setObject('Wikiplus-highlight-i18n', i18n); _d.label = 2; case 2: mw.messages.set(i18n); return [2]; } }); }); }; i18nPromise = Promise.all([ mw.loader.using('mediawiki.util'), setI18N(), ]); getInternalScript = function (exts) { return exts.length > 0 ? mw.loader.using(exts) : Promise.resolve(); }; getExternalScript = function (urls) { return urls.length > 0 ? $.ajax("".concat(CDN, "/").concat(urls.length > 1 ? 'combine/' : '').concat(urls.join()), { dataType: 'script', cache: true }) : Promise.resolve(); }; getScript = function (urls, local) { return __awaiter(void 0, void 0, void 0, function () { var internal, external; return __generator(this, function (_a) { switch (_a.label) { case 0: internal = urls.filter(function (url) { return !url.includes('/'); }), external = urls.filter(function (url) { return url.includes('/'); }); if (!(local === true)) return [3, 2]; return [4, getInternalScript(internal)]; case 1: _a.sent(); return [2, getExternalScript(external)]; case 2: if (!(local === false)) return [3, 4]; return [4, getExternalScript(external)]; case 3: _a.sent(); return [2, getInternalScript(internal)]; case 4: return [2, Promise.all([getInternalScript(internal), getExternalScript(external)])]; } }); }); }; getAddonScript = function (CM, other) { var e_2, _a; if (other === void 0) { other = false; } var addonScript = []; try { for (var options_1 = __values(options), options_1_1 = options_1.next(); !options_1_1.done; options_1_1 = options_1.next()) { var _b = options_1_1.value, option = _b.option, _c = _b.addon, addon = _c === void 0 ? option : _c, _d = _b.download, download = _d === void 0 ? Array.isArray(addon) ? option : addon : _d, only = _b.only; if (!(only && other) && !(option in CM.optionHandlers) && intersect(addon, addons)) { addonScript.push(ADDON_LIST[download]); } } } catch (e_2_1) { e_2 = { error: e_2_1 }; } finally { try { if (options_1_1 && !options_1_1.done && (_a = options_1["return"])) _a.call(options_1); } finally { if (e_2) throw e_2.error; } } return addonScript; }; intersect = function (arr, set) { return Array.isArray(arr) ? arr.some(function (ele) { return set.has(ele); }) : set.has(arr); }; initMode = function (type) { var e_3, _a; var scripts = []; var loaded = typeof window.CodeMirror === 'function'; var CM = loaded ? window.CodeMirror : { modes: {}, prototype: {}, commands: {}, optionHandlers: {}, helpers: {} }; if (!loaded) { scripts.push(MODE_LIST.lib); if (!USING_LOCAL) { mw.loader.load("".concat(CDN, "/").concat(CM_CDN, "/lib/codemirror.min.css"), 'text/css'); } } if (type === 'mediawiki' && SITE_SETTINGS.config && SITE_SETTINGS.config.tags.html) { type = 'html'; } if ((type === 'mediawiki' || type === 'widget') && !CM.modes.mediawiki) { mw.loader.load("".concat(CDN, "/").concat(MW_CDN, "/mediawiki.min.css"), 'text/css'); scripts.push("".concat(MW_CDN, "/mediawiki.min.js")); } if (type === 'widget' || type === 'html') { try { for (var _b = __values(['css', 'javascript', 'mediawiki', 'htmlmixed', 'xml']), _c = _b.next(); !_c.done; _c = _b.next()) { var lang = _c.value; if (!CM.modes[lang]) { scripts = scripts.concat(MODE_LIST[lang]); } } } catch (e_3_1) { e_3 = { error: e_3_1 }; } finally { try { if (_c && !_c.done && (_a = _b["return"])) _a.call(_b); } finally { if (e_3) throw e_3.error; } } } else { scripts = scripts.concat(MODE_LIST[type]); } if (!CM.prototype.getSearchCursor && addons.has('search') && !addons.has('wikiEditor')) { scripts.push(ADDON_LIST.searchcursor); } if (!CM.prototype.annotateScrollbar && type === 'mediawiki' && addons.has('lint')) { scripts.push(ADDON_LIST.annotateScrollbar); } if (!CM.commands.find && addons.has('search') && !addons.has('wikiEditor')) { scripts.push(ADDON_LIST.search); } if (!window.wikiparse && type === 'mediawiki' && addons.has('lint')) { scripts.push(ADDON_LIST.parser); } if (!CM.optionHandlers.lint && type === 'mediawiki' && addons.has('lint')) { mw.loader.load("".concat(CDN, "/").concat(CM_CDN, "/addon/lint/lint.min.css"), 'text/css'); scripts.push(ADDON_LIST.lint); } if (!(CM.helpers.lint && CM.helpers.lint.mediawiki) && type === 'mediawiki' && addons.has('lint')) { scripts.push(ADDON_LIST.lintWikitext); } if (addons.has('wikiEditor')) { var state = mw.loader.getState('ext.wikiEditor'); if (!state) { addons["delete"]('wikiEditor'); } else if (state !== 'ready') { scripts.push(ADDON_LIST.wikiEditor); } } if (mw.loader.getState('mediawiki.Title') !== 'ready' && addons.has('contextmenu')) { scripts.push(ADDON_LIST.contextmenu); } scripts.push.apply(scripts, __spreadArray([], __read(getAddonScript(CM)), false)); return getScript(scripts, loaded ? undefined : USING_LOCAL); }; updateCachedConfig = function (config) { ALL_SETTINGS_CACHE[SITE_ID] = { config: config, time: Date.now() }; storage.setObject('InPageEditMwConfig', ALL_SETTINGS_CACHE); }; getAliases = function (words) { return words.flatMap(function (_a) { var aliases = _a.aliases, name = _a.name; return aliases.map(function (alias) { return ({ alias: alias, name: name }); }); }); }; getConfig = function (aliases) { return Object.fromEntries(aliases.map(function (_a) { var alias = _a.alias, name = _a.name; return [alias.replace(/:$/, ''), name]; })); }; setPlainMode = function (config) { var e_4, _a; var tags = ['indicator', 'poem', 'ref', 'tabs', 'tab', 'poll']; try { for (var tags_1 = __values(tags), tags_1_1 = tags_1.next(); !tags_1_1.done; tags_1_1 = tags_1.next()) { var tag = tags_1_1.value; if (config.tags[tag]) { config.tagModes[tag] = 'text/mediawiki'; } } } catch (e_4_1) { e_4 = { error: e_4_1 }; } finally { try { if (tags_1_1 && !tags_1_1.done && (_a = tags_1["return"])) _a.call(tags_1); } finally { if (e_4) throw e_4.error; } } }; getMwConfig = function (type, initModePromise) { return __awaiter(void 0, void 0, void 0, function () { var config, _a, magicwords, extensiontags, functionhooks, variables, otherMagicwords, _b, insensitive, aliases, aliases_1, aliases_1_1, _c, alias, name_1, realMagicwords_1, allMagicwords, sensitive, insensitive; var e_5, _d; return __generator(this, function (_e) { switch (_e.label) { case 0: if (type !== 'mediawiki' && type !== 'widget') { return [2, undefined]; } if (!(USING_LOCAL && EXPIRED)) return [3, 2]; return [4, initModePromise]; case 1: _e.sent(); _e.label = 2; case 2: config = mw.config.get('extCodeMirrorConfig'); if (!config && !EXPIRED && isLatest) { (config = SITE_SETTINGS.config); setPlainMode(config); mw.config.set('extCodeMirrorConfig', config); } if (config && config.redirect && config.img) { return [2, config]; } return [4, new mw.Api().get({ meta: 'siteinfo', siprop: config ? 'magicwords' : 'magicwords|extensiontags|functionhooks|variables', formatversion: 2 })]; case 3: _a = (_e.sent()).query, magicwords = _a.magicwords, extensiontags = _a.extensiontags, functionhooks = _a.functionhooks, variables = _a.variables; otherMagicwords = new Set(['msg', 'raw', 'msgnw', 'subst', 'safesubst']); if (config) { _b = __read(config.functionSynonyms, 1), insensitive = _b[0]; if (!insensitive.subst) { aliases = getAliases(magicwords.filter(function (_a) { var name = _a.name; return otherMagicwords.has(name); })); try { for (aliases_1 = __values(aliases), aliases_1_1 = aliases_1.next(); !aliases_1_1.done; aliases_1_1 = aliases_1.next()) { _c = aliases_1_1.value, alias = _c.alias, name_1 = _c.name; insensitive[alias.replace(/:$/, '')] = name_1; } } catch (e_5_1) { e_5 = { error: e_5_1 }; } finally { try { if (aliases_1_1 && !aliases_1_1.done && (_d = aliases_1["return"])) _d.call(aliases_1); } finally { if (e_5) throw e_5.error; } } } } else { config = { tagModes: { pre: 'mw-tag-pre', nowiki: 'mw-tag-nowiki', ref: 'text/mediawiki' }, tags: Object.fromEntries(extensiontags.map(function (tag) { return [tag.slice(1, -1), true]; })), urlProtocols: mw.config.get('wgUrlProtocols') }; realMagicwords_1 = new Set(__spreadArray(__spreadArray(__spreadArray([], __read(functionhooks), false), __read(variables), false), __read(otherMagicwords), false)), allMagicwords = magicwords.filter(function (_a) { var name = _a.name, aliases = _a.aliases; return aliases.some(function (alias) { return /^__.+__$/.test(alias); }) || realMagicwords_1.has(name); }), sensitive = getAliases(allMagicwords.filter(function (word) { return word['case-sensitive']; })), insensitive = getAliases(allMagicwords.filter(function (word) { return !word['case-sensitive']; })).map(function (_a) { var alias = _a.alias, name = _a.name; return ({ alias: alias.toLowerCase(), name: name }); }); config.doubleUnderscore = [ getConfig(insensitive.filter(function (_a) { var alias = _a.alias; return /^__.+__$/.test(alias); })), getConfig(sensitive.filter(function (_a) { var alias = _a.alias; return /^__.+__$/.test(alias); })), ]; config.functionSynonyms = [ getConfig(insensitive.filter(function (_a) { var alias = _a.alias; return !/^__.+__|^#$/.test(alias); })), getConfig(sensitive.filter(function (_a) { var alias = _a.alias; return !/^__.+__|^#$/.test(alias); })), ]; } config.redirect = magicwords.find(function (_a) { var name = _a.name; return name === 'redirect'; }).aliases; config.img = getConfig(getAliases(magicwords.filter(function (_a) { var name = _a.name; return name.startsWith('img_'); }))); setPlainMode(config); mw.config.set('extCodeMirrorConfig', config); updateCachedConfig(config); return [2, config]; } }); }); }; getPageMode = function () { return __awaiter(void 0, void 0, void 0, function () { var pageMode, bool; return __generator(this, function (_a) { switch (_a.label) { case 0: if (page.endsWith('/doc')) { return [2, 'mediawiki']; } else if (ns !== 274 && ns !== 828) { return [2, CONTENTMODEL[contentmodel]]; } pageMode = ns === 274 ? 'Widget' : 'Lua'; return [4, mw.loader.using(['oojs-ui-windows', 'oojs-ui.styles.icons-content'])]; case 1: _a.sent(); return [4, OO.ui.confirm(msg('contentmodel'), { actions: [{ label: pageMode }, { label: 'Wikitext', action: 'accept' }] })]; case 2: bool = _a.sent(); return [2, bool ? 'mediawiki' : pageMode.toLowerCase()]; } }); }); }; cmTextSelection = { getContents: function () { return cm.getValue(); }, setContents: function (content) { cm.setValue(content); return this; }, getSelection: function () { return cm.getSelection(); }, setSelection: function (option) { cm.setSelection(cm.posFromIndex(option.start), 'end' in option ? cm.posFromIndex(option.end) : undefined); cm.focus(); return this; }, replaceSelection: function (value) { cm.replaceSelection(value); return this; }, getCaretPosition: function (option) { var caretPos = cm.indexFromPos(cm.getCursor('from')), endPos = cm.indexFromPos(cm.getCursor('to')); return option.startAndEnd ? [caretPos, endPos] : caretPos; }, scrollToCaretPosition: function () { cm.scrollIntoView(); return this; } }; renderEditor = function ($target, setting) { return __awaiter(void 0, void 0, void 0, function () { var mode, initModePromise, _a, mwConfig, _b, config, height, json, ctrl, context_1, Wikiplus, escToExitQuickEdit, submit, submitMinor; var _c, _d; return __generator(this, function (_e) { switch (_e.label) { case 0: if (!setting) return [3, 1]; _b = 'javascript'; return [3, 3]; case 1: return [4, getPageMode()]; case 2: _b = _e.sent(); _e.label = 3; case 3: mode = _b, initModePromise = initMode(mode); return [4, Promise.all([ getMwConfig(mode, initModePromise), initModePromise, ])]; case 4: _a = __read.apply(void 0, [_e.sent(), 1]), mwConfig = _a[0]; if (!setting && addons.has('wikiEditor')) { try { if (typeof mw.addWikiEditor === 'function') { mw.addWikiEditor($target); } else { config = $.wikiEditor.modules.dialogs.config; $target.wikiEditor('addModule', __assign(__assign({}, $.wikiEditor.modules.toolbar.config.getDefaultConfig()), config.getDefaultConfig())); config.replaceIcons($target); } } catch (e) { addons["delete"]('wikiEditor'); mw.notify('WikiEditor工具栏加载失败。', { type: 'error' }); console.error(e); } } if (!(mode === 'mediawiki' && mwConfig.tags.html)) return [3, 6]; mwConfig.tagModes.html = 'htmlmixed'; return [4, initMode('html')]; case 5: _e.sent(); return [3, 7]; case 6: if (mode === 'widget' && !CodeMirror.mimeModes.widget) { CodeMirror.defineMIME('widget', { name: 'htmlmixed', tags: { noinclude: [[null, null, 'mediawiki']] } }); } _e.label = 7; case 7: height = $target.height(); if (cm) { cm.toTextArea(); } json = setting || contentmodel === 'json'; cm = CodeMirror.fromTextArea($target[0], $.extend({ inputStyle: 'contenteditable', lineNumbers: !/Android\b/.test(navigator.userAgent), lineWrapping: true, mode: mode, mwConfig: mwConfig, json: json }, Object.fromEntries(options.map(function (_a) { var option = _a.option, _b = _a.addon, addon = _b === void 0 ? option : _b, modes = _a.modes, _c = _a.complex, complex = _c === void 0 ? function (mod) { return !modes || modes.has(mod); } : _c; var mainAddon = Array.isArray(addon) ? addon[0] : addon; return [option, addons.has(mainAddon) && complex(mode, json)]; })), mode === 'mediawiki' ? { extraKeys: addons.has('escape') && extraKeys(CodeMirror) } : { indentUnit: addons.has('indentWithSpace') ? indent : defaultIndent, indentWithTabs: !addons.has('indentWithSpace') })); cm.setSize(null, height); cm.getWrapperElement().id = 'Wikiplus-CodeMirror'; if ($.fn.textSelection) { $target.textSelection('register', cmTextSelection); } ctrl = isPc(CodeMirror) ? 'Ctrl' : 'Cmd'; if (addons.has('wikiEditor')) { context_1 = $target.data('wikiEditorContext'); cm.addKeyMap((_c = {}, _c["".concat(ctrl, "-F")] = function () { $.wikiEditor.modules.dialogs.api.openDialog(context_1, 'search-and-replace'); }, _c)); } handleContextMenu(cm, mode); $('#Wikiplus-Quickedit-Jump').children('a').attr('href', '#Wikiplus-CodeMirror'); if (!setting) { Wikiplus = typeof window.Wikiplus === 'object' ? window.Wikiplus : { getSetting: function (key) { var settings = storage.getObject('Wikiplus_Settings'); return settings && settings[key]; } }, escToExitQuickEdit = Wikiplus.getSetting('esc_to_exit_quickedit'), submit = function () { $('#Wikiplus-Quickedit-Submit').triggerHandler('click'); }, submitMinor = function () { $('#Wikiplus-Quickedit-MinorEdit').click(); $('#Wikiplus-Quickedit-Submit').triggerHandler('click'); }; cm.addKeyMap($.extend((_d = {}, _d["".concat(ctrl, "-S")] = submit, _d["Shift-".concat(ctrl, "-S")] = submitMinor, _d), escToExitQuickEdit === true || escToExitQuickEdit === 'true' ? { Esc: function () { $('#Wikiplus-Quickedit-Back').triggerHandler('click'); } } : {})); } cm.refresh(); mw.hook('wiki-codemirror').fire(cm); return [2]; } }); }); }; body = document.body; observer = new MutationObserver(function (records) { var $editArea = $(records.flatMap(function (_a) { var addedNodes = _a.addedNodes; return __spreadArray([], __read(addedNodes), false); })) .find('#Wikiplus-Quickedit, #Wikiplus-Setting-Input'); if ($editArea.length > 0) { renderEditor($editArea, $editArea.attr('id') === 'Wikiplus-Setting-Input'); } }); observer.observe(body, { childList: true }); $(body).on('keydown.wphl', '.ui-dialog', function (e) { if (e.key === 'Escape') { var context = $(this).children('.ui-dialog-content').data('context'); if (context && context.$textarea && context.$textarea.attr('id') === 'Wikiplus-Quickedit') { e.stopPropagation(); } } }); wphlStyle = document.querySelector('#wphl-style') || mw.loader.addStyleTag('#Wikiplus-CodeMirror{border:1px solid #c8ccd1;line-height:1.3;clear:both;' + '-moz-user-select:auto;-webkit-user-select:auto;user-select:auto}' + '#Wikiplus-CodeMirror .CodeMirror-gutter-wrapper{' + '-moz-user-select:none;-webkit-user-select:none;user-select:none}' + 'div.Wikiplus-InterBox{font-size:14px;z-index:100}' + '.skin-minerva .Wikiplus-InterBox{font-size:16px}' + '.cm-trailingspace{text-decoration:underline wavy red}' + 'div.CodeMirror span.CodeMirror-matchingbracket{box-shadow:0 0 0 2px #9aef98}' + 'div.CodeMirror span.CodeMirror-nonmatchingbracket{box-shadow:0 0 0 2px #eace64}' + '#Wikiplus-highlight-dialog .oo-ui-messageDialog-title{margin-bottom:0.28571429em}' + '#Wikiplus-highlight-dialog .oo-ui-flaggedElement-notice{font-weight:normal;margin:0}' + '.CodeMirror-contextmenu .cm-mw-template-name{cursor:pointer}' + '.skin-moeskin #ca-more-actions li>a{display:inline-block;padding:0.4rem 0.8rem;line-height:1.5}' + '.skin-moeskin .oo-ui-windowManager-modal>.oo-ui-dialog{z-index:101}'); wphlStyle.id = 'wphl-style'; _b = $.valHooks.textarea || {}, _c = _b.get, get = _c === void 0 ? function (elem) { return elem.value; } : _c, _d = _b.set, set = _d === void 0 ? function (elem, value) { elem.value = value; } : _d; isWikiplus = function (elem) { return elem.id === 'Wikiplus-Quickedit' || elem.id === 'Wikiplus-Setting-Input'; }; $.valHooks.textarea = { get: function (elem) { return isWikiplus(elem) && cm ? cm.getValue() : get(elem); }, set: function (elem, value) { if (isWikiplus(elem) && cm) { cm.setValue(value); } else { set(elem, value); } } }; return [4, i18nPromise]; case 1: _e.sent(); toggleIndent = function (value) { if (value === void 0) { value = __spreadArray([], __read(addons), false); } indentField.toggle(value.includes('indentWithSpace')); }; portletContainer = { minerva: 'page-actions-overflow', citizen: 'p-actions', moeskin: 'ca-more-actions' }; $portlet = $(mw.util.addPortletLink(portletContainer[skin] || 'p-cactions', '#', msg('portlet'), 'wphl-settings')).click(function (e) { return __awaiter(void 0, void 0, void 0, function () { var windowManager, checkboxMultiselectWidget, wikiplusLoaded, data, value, value_1, value_1_1, addon; var e_6, _a; return __generator(this, function (_b) { switch (_b.label) { case 0: e.preventDefault(); if (!dialog) return [3, 1]; widget.setValue(__spreadArray([], __read(addons), false)); indentWidget.setValue(indent); return [3, 3]; case 1: return [4, mw.loader.using(['oojs-ui-windows', 'oojs-ui.styles.icons-content'])]; case 2: _b.sent(); dialog = new OO.ui.MessageDialog({ id: 'Wikiplus-highlight-dialog' }); windowManager = new OO.ui.WindowManager(); windowManager.$element.appendTo(body); windowManager.addWindows([dialog]); widget = new OO.ui.CheckboxMultiselectInputWidget({ options: __spreadArray(__spreadArray([], __read(options.map(function (_a) { var option = _a.option, _b = _a.addon, addon = _b === void 0 ? option : _b; var mainAddon = Array.isArray(addon) ? addon[0] : addon; return { data: mainAddon, label: htmlMsg("addon-".concat(mainAddon.toLowerCase())) }; })), false), __read(['wikiEditor', 'escape', 'contextmenu', 'lint', 'indentWithSpace', 'otherEditors'] .map(function (addon) { return ({ data: addon, label: htmlMsg("addon-".concat(addon.toLowerCase())) }); })), false), value: __spreadArray([], __read(addons), false) }).on('change', toggleIndent); checkboxMultiselectWidget = widget.checkboxMultiselectWidget; searchWidget = checkboxMultiselectWidget.findItemFromData('search'); wikiEditorWidget = checkboxMultiselectWidget.findItemFromData('wikiEditor'); lintWidget = checkboxMultiselectWidget.findItemFromData('lint'); indentWidget = new OO.ui.NumberInputWidget({ min: 0, value: indent }); field = new OO.ui.FieldLayout(widget, { label: msg('addon-label'), notices: [msg('addon-notice')], align: 'top' }); indentField = new OO.ui.FieldLayout(indentWidget, { label: msg('addon-indent') }); toggleIndent(); Object.assign(mw.libs.wphl, { widget: widget, indentWidget: indentWidget }); _b.label = 3; case 3: wikiplusLoaded = typeof window.Wikiplus === 'object' || typeof window.Pages === 'object'; searchWidget.setDisabled(!wikiplusLoaded); wikiEditorWidget.setDisabled(!wikiplusLoaded || !mw.loader.getState('ext.wikiEditor')); lintWidget.setDisabled(!wikiplusLoaded); return [4, dialog.open({ title: msg('addon-title'), message: field.$element.add(indentField.$element).add($('<p>', { html: msg('feedback') })), actions: [ { action: 'reject', label: mw.msg('ooui-dialog-message-reject') }, { action: 'accept', label: mw.msg('ooui-dialog-message-accept'), flags: 'progressive' }, ], size: i18nLang === 'en' || skin === 'minerva' ? 'medium' : 'small' }).closing]; case 4: data = _b.sent(); field.$element.detach(); indentField.$element.detach(); if (typeof data === 'object' && data.action === 'accept') { value = widget.getValue(); addons.clear(); try { for (value_1 = __values(value), value_1_1 = value_1.next(); !value_1_1.done; value_1_1 = value_1.next()) { addon = value_1_1.value; addons.add(addon); } } catch (e_6_1) { e_6 = { error: e_6_1 }; } finally { try { if (value_1_1 && !value_1_1.done && (_a = value_1["return"])) _a.call(value_1); } finally { if (e_6) throw e_6.error; } } indent = Number(indentWidget.getValue()); storage.setObject('Wikiplus-highlight-addons', value); storage.setObject('Wikiplus-highlight-indent', indent); } return [2]; } }); }); }); if (skin === 'minerva') { $portlet.find('.mw-ui-icon').addClass('mw-ui-icon-minerva-settings'); } if (typeof welcome === 'function') { welcome().find('#wphl-settings-notify').click(function (e) { e.preventDefault(); $('#wphl-settings').triggerHandler('click'); }); } handleOtherEditors = function (doc) { return __awaiter(void 0, void 0, void 0, function () { var mode, addonScript, json, _loop_1, _a, _b, _c, option, _d, addon, modes, _e, complex; var e_7, _f; return __generator(this, function (_g) { switch (_g.label) { case 0: if (!addons.has('otherEditors')) { return [2]; } mode = doc.getOption('mode'); mode = mode === 'text/mediawiki' ? 'mediawiki' : mode; addonScript = getAddonScript(CodeMirror, true), json = doc.getOption('json'); return [4, getScript(addonScript)]; case 1: _g.sent(); _loop_1 = function (option, addon, modes, complex) { var mainAddon = Array.isArray(addon) ? addon[0] : addon; if (doc.getOption(option) === undefined && addons.has(mainAddon)) { doc.setOption(option, complex(mode, json)); } }; try { for (_a = __values(options.filter(function (_a) { var only = _a.only; return !only; })), _b = _a.next(); !_b.done; _b = _a.next()) { _c = _b.value, option = _c.option, _d = _c.addon, addon = _d === void 0 ? option : _d, modes = _c.modes, _e = _c.complex, complex = _e === void 0 ? function (mod) { return !modes || modes.has(mod); } : _e; _loop_1(option, addon, modes, complex); } } catch (e_7_1) { e_7 = { error: e_7_1 }; } finally { try { if (_b && !_b.done && (_f = _a["return"])) _f.call(_a); } finally { if (e_7) throw e_7.error; } } if (mode === 'mediawiki' && addons.has('escape')) { doc.addKeyMap(extraKeys(CodeMirror), true); } else if (mode !== 'mediawiki' && addons.has('indentWithSpace')) { doc.setOption('indentUnit', indent); doc.setOption('indentWithTabs', false); } handleContextMenu(doc, mode); return [2]; } }); }); }; mw.hook('InPageEdit.quickEdit.codemirror').add(function (_a) { var doc = _a.cm; return handleOtherEditors(doc); }); mw.hook('inspector').add(function (doc) { return handleOtherEditors(doc); }); mw.hook('wiki-codemirror').add(function (doc) { if (!doc.getTextArea || !isWikiplus(doc.getTextArea())) { handleOtherEditors(doc); } }); Object.assign(mw.libs.wphl, { version: version, options: options, addons: addons, i18n: i18n, i18nLang: i18nLang, wphlStyle: wphlStyle, $portlet: $portlet, USING_LOCAL: USING_LOCAL, MODE_LIST: MODE_LIST, ADDON_LIST: ADDON_LIST, msg: msg, htmlMsg: htmlMsg, escapeHTML: escapeHTML, handleContextMenu: handleContextMenu, setI18N: setI18N, getAddonScript: getAddonScript, updateCachedConfig: updateCachedConfig, getMwConfig: getMwConfig, renderEditor: renderEditor, handleOtherEditors: handleOtherEditors, isPc: isPc }); return [2]; } }); }); })(); /* </pre> */