MediaWiki:Gadget-libUtil.js

来自萌娘文库
跳转至: 导航搜索

注意:在保存之后,您可能需要清除浏览器缓存才能看到所作出的变更的影响。

  • Firefox或Safari:按住Shift的同时单击刷新,或按Ctrl-F5Ctrl-R(Mac为⌘-R
  • Google Chrome:Ctrl-Shift-R(Mac为⌘-Shift-R
  • Internet Explorer:按住Ctrl的同时单击刷新,或按Ctrl-F5
  • Opera:前往菜单 → 设置(Mac为Opera → Preferences),然后隐私和安全 → 清除浏览数据 → 缓存的图片和文件
/* <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=933a60a3ea0382fd227141260c3225a488af0ca3|shortId=933a60a|message=chore: Add track field}}';

"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 (s) {
                return s > 9 ? s : "0".concat(s);
            };
            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> */