MediaWiki:Gadget-libUtil.js:修订间差异
跳到导航
跳到搜索
test>Lih 小 (已保护“MediaWiki:Gadget-libUtil.js”:MW页面([编辑=仅允许管理员](无限期)[移动=仅允许管理员](无限期))) |
无编辑摘要 |
||
(未显示同一用户的1个中间版本) | |||
第1行: | 第1行: | ||
"use strict"; | "use strict"; | ||
(function () { | (function () { | ||
第112行: | 第104行: | ||
}); | }); | ||
})(); | })(); | ||
2024年1月2日 (二) 23:27的最新版本
"use strict"; (function () { if (!mw.libs.commons) { mw.libs.commons = {}; } var lc = mw.libs.commons; $.extend(mw.libs.commons, { guessUser: function () { var user = mw.config.get("wgRelevantUserName"); var title, target; if (user) { return user; } switch (mw.config.get("wgNamespaceNumber")) { case 3: case 2: { return mw.config.get("wgPageName").match(/.*?:(.*?)(\/.*)*$/)[1]; } case -1: { try { switch (mw.config.get("wgCanonicalSpecialPageName")) { case "CentralAuth": target = mw.util.getParamValue("target"); if (target) { return target; } title = mw.util.getParamValue("title"); if (title) { title = title.match(/Special:(?:CentralAuth)\/(.*)$/); if (title) { return title[1]; } } if (/Special:(?:CentralAuth)\//.test(location.href)) { return decodeURIComponent(location.href.match(/Special:(?:CentralAuth)\/(.*?)(?:[?&].*)?$/)[1]); } break; case "Log": if (mw.util.getParamValue("page") && /User:+./.test(mw.util.getParamValue("page"))) { return mw.util.getParamValue("page") .replace("User:", ""); } break; } } catch (_a) { } break; } } }, monthNamesInSiteLang: ["", "一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"], formatDate: function (fmt, _date, fallbackDate) { var pad0 = function (n) { return "".concat(n).padStart(2, "0"); }; var date = _date || fallbackDate || new Date(); var month = date.getUTCMonth() + 1; var str = fmt.replace(/YYYY/g, date.getUTCFullYear()); str = str.replace(/MM/g, pad0(month)); date = date.getUTCDate(); str = str.replace(/DD/g, pad0(date)); str = str.replace(/MON/g, lc.monthNamesInSiteLang[month]); str = str.replace(/DAY/g, date); return str; }, getTalkPageFromTitle: function (_title) { var rens = /^(.+):/; var pref = _title.match(rens), nsid = -1; var title = _title; if (pref) { pref = pref[1].toLowerCase().replace(/ /g, "_"); } else { pref = ""; } nsid = mw.config.get("wgNamespaceIds")[pref]; if (0 === nsid % 2) { nsid++; } var newPref = "".concat(mw.config.get("wgFormattedNamespaces")[nsid], ":"); if (pref) { title = title.replace(/^.+:/, newPref); } else { title = newPref + title; } return title; }, titleFromImgSrc: function (src) { mw.log.warn(".titleFromImgSrc() is deprecated. Use mw.Title.newFromImg() instead."); try { return decodeURIComponent(src).match(/\/[a-f0-9]\/[a-f0-9]{2}\/(\S+\.\S{2,5})\//)[1].replace(/_/g, " "); } catch (_a) { try { return decodeURIComponent(src).match(/thumb\.php.*(?:\?|&)f=(\S+\.\S{2,5})(?:&.+)?$/)[1].replace(/_/g, " "); } catch (_b) { try { return decodeURIComponent(src).match(/\/[a-f0-9]\/[a-f0-9]{2}\/(\S+\.\S{2,5})$/)[1].replace(/_/g, " "); } catch (_c) { } } } } }); })();