MediaWiki:Gadget-libUtil.js:修订间差异
跳到导航
跳到搜索
test>Lih 小 (已保护“MediaWiki:Gadget-libUtil.js”:MW页面([编辑=仅允许管理员](无限期)[移动=仅允许管理员](无限期))) |
小 (导入1个版本) |
2024年1月2日 (二) 23:17的版本
/* <pre> */ /** * ------------------------------------------------------------------------- * !!! DON'T MODIFY THIS PAGE MANUALLY, YOUR CHANGES WILL BE OVERWRITTEN !!! * ------------------------------------------------------------------------- */ var _addText = '{{GHIACode|page=GHIA:MoegirlPediaInterfaceCodes/blob/master/src/gadgets/libUtil/MediaWiki:Gadget-libUtil.js|user=[[U:AnnAngela]]|longId=a61697334268d06b666d2ac2b15ded8cc135a53f|shortId=a616973|message=refactor: Use `padStart` to pad zero}}'; "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) { } } } } }); })(); /* </pre> */