;
×
创建新页面
在此填写您的页面标题:
我们当前在Undertale社区维基上拥有211个页面。请在上方输入您的页面名称或点击以下任意标题来开始编写页面!



Undertale社区维基
欢迎来到Undertale社区维基(*`∀´*)ノ亻,如果想要参与条目创建或编辑,请先登录

可在模块:赋值/doc创建此模块的帮助文档

local p = {}
local b = require("Module:Basic")

function p.ref(text, mode)
    local ref_list = b.str_split(text, ";")
    local result = ""
    for _, value in ipairs(ref_list) do
        if b.empty(value) then
            if mode == "source" then
                if mw.ustring.find(text, "<ref") or mw.ustring.find(text, "{{#tag:ref|") then
                    result = result .. value
                else
                    result = result .. "{{#tag:ref|" .. value .. "}}"
                end
            elseif mode == "note" then
                if mw.ustring.find(text, "<ref group='注'") or mw.ustring.find(text, "<ref group=\"\"") or mw.ustring.find(text, "group=注") or mw.ustring.find(text, "group=\"\"|") or mw.ustring.find(text, "group='注'}}") then
                    result = result .. value
                else
                    result = result .. "{{#tag:ref|" .. value .. "|group=注}}"
                end
            end
        end
    end
    return result
end

function p.id2link_person(args)
    local be_id2link_dict = {
        bilibili={ "bilibili",    {"space.bilibili.com/" .. (args.bilibili or "")} },
        twitter={ "twitter",     {"twitter.com/" .. (args.twitter or "")} },
        tumblr={ "tumblr",      {(args.tumblr or "") .. ".tumblr.com", "tumblr.com/" .. (args.tumblr or "") } },
        gamejolt={ "gamejolt",    {"gamejolt.com/@" .. (args.gamejolt or "")} },
        deviantart={ "deviantart",  {"deviantart.com/" .. (args.deviantart or "")} },
        utcwiki={ "utcwiki",     {"utcwiki.com/User:" .. (args.utcwiki or "")} },
        soundcloud={ "soundcloud",  {"soundcloud.com/" .. (args.soundcloud or "")} },
        youtube={ "youtube",     {"www.youtube.com/" .. (args.youtube or "")} },
        douyin={ "douyin",      {"www.douyin.com/user/" .. (args.douyin or "")} },
        kuaishou={ "kuaishou",    {"www.kuaishou.com/profile/" .. (args.kuaishou or "")} },
        weibo={ "weibo",       {"weibo.com/u/" .. (args.weibo or "")} },
        discord={ "discord",     {"discordapp.com/users/" .. (args.discord or "")} },
        qq={ "qq",          {"res.abeim.cn/api/qq/?qq=" .. (args.qq or "")} },
        lofter={ "lofter",      {(args.lofter or "") .. ".lofter.com" }},
        vk={ "vk",          {"vk.com/" .. (args.vk or "")} },
        reddit={ "reddit",      {"www.reddit.com/user/" .. (args.reddit or "")} },
        pixiv={ "pixiv",       {"www.pixiv.net/users/" .. (args.pixiv or "")} },
        imgur={ "imgur",       {"imgur.com/user/" .. (args.imgur or "")} },
        comicfury={ "comicfury",   {"comicfury.com/profile.php?username=" .. (args.comicfury or "")} },
	    kofi = { "kofi",   {"ko-fi.com/" .. (args.kofi or "")} },
	    clypit = { "clypit",   {"clyp.it/user/" .. (args.clypit or "")} },
	    bluesky = { "bluesky",   {"bsky.app/profile/" .. (args.bluesky or "")} },
    }
    return be_id2link_dict
end

function p.id2link_homepage()
	local be_id2link_dict = {
	    bilibili = { "bilibili",    {"bilibili.com/"} },
	    twitter = { "twitter",     {"twitter.com/"} },
	    tumblr = { "tumblr",      {".tumblr.com", "tumblr.com/"} },
	    gamejolt = { "gamejolt",    {"gamejolt.com"} },
	    deviantart = { "deviantart",  {"deviantart.com/"} },
	    utcwiki = { "utcwiki",     {"utcwiki.com/"} },
	    soundcloud = { "soundcloud",  {"soundcloud.com/"} },
	    youtube = { "youtube",     {"youtube.com/"} },
	    douyin = { "douyin",      {"douyin.com/"} },
	    kuaishou = { "kuaishou",    {"kuaishou.com/"} },
	    weibo = { "weibo",       {"weibo.com/"} },
	    discord = { "discord",     {"discordapp.com/"} },
	    lofter = { "lofter",      {".lofter.com" }},
	    vk = { "vk",          {"vk.com/"} },
	    reddit = { "reddit",      {"reddit.com/"} },
	    pixiv = { "pixiv",       {"pixiv.net/"} },
	    imgur = { "imgur",       {"imgur.com/"} },
	    comicfurycomic = { "comicfury",   {"comicfury.com/", ".thecomicseries.com", ".the-comic.org"}},
	    mspfa = { "mspfa",   {"mspfa.com/"}},
	    kofi = { "kofi",   {"ko-fi.com/"}},
	    clypit = { "clypit",   {"clyp.it/"}},
	    bluesky = { "bluesky",   {"bsky.app/"}},
	}
    return be_id2link_dict
end

function p.https_re(link)
    if not mw.ustring.find(link, "http://") and not mw.ustring.find(link, "https://") then
        local result = "https://" .. link
        return result
    else
        return link
    end
end

function p.maxnum(num_list)
    local maxnum = num_list[1]
    for i = 2, #num_list do
        if num_list[i] > maxnum then
            maxnum = num_list[i]
        end
    end
    return maxnum
end

function p.person(frame)
    local be_id2link_dict = p.id2link_person(frame.args)
    local args = {}
    local ICON = false
    local result_init = "<span style='display: none;'>模板:人物</span>"
    local result = ""
    local result_link = ""
    local result_set = ""
    result = result .. (frame.args[1] or "")
    for key, value in pairs(frame.args) do
        if b.empty(value) then
            args[key] = value
        end
    end

    for key, value in pairs(be_id2link_dict) do
        if b.is_include_key(key, args) then
            for _, link_match_string in pairs(value[2]) do
                local smwset_set_table = {
                    '人物链接组=' .. (frame.args[1] or "") .. ";" .. "https://" .. link_match_string .. ";" .. value[1] .. ";;",
                }
                mw.smw.set(smwset_set_table)
                if not ICON then result_link = result_link .. "<span class='supimg'>" end
                result_link = result_link .. "[[file:" .. value[1] .. ".png|15px|link=" .. "https://" .. link_match_string .. "]]"
                ICON = true
                break
            end
        end
    end

    local link_list = b.str_split(frame.args["url"], "、")

    local be_set_list = { "创始者", "现持有者", "持有者", "参与制作者" }
    local set_list = b.str_split(frame.args["set"], "、")
    for key, value in ipairs(set_list) do
        for _, s_value in ipairs(be_set_list) do
            if mw.ustring.find(value, s_value) then
                set_list[key] = s_value
                break
            end
        end
    end

    local term_list = b.str_split(frame.args["代数"], "、")

    local link_source_list = b.str_split(b.empty(mw.text.decode(mw.text.unstripNoWiki(frame.args["链接来源"]))), "、")
    local link_note_list = b.str_split(b.empty(mw.text.decode(mw.text.unstripNoWiki(frame.args["链接注释"]))), "、")
    local set_source_list = b.str_split(b.empty(mw.text.decode(mw.text.unstripNoWiki(frame.args["职能来源"]))), "、")
    local set_note_list = b.str_split(b.empty(mw.text.decode(mw.text.unstripNoWiki(frame.args["职能注释"]))), "、")
    for key, value in ipairs(link_source_list) do
        link_source_list[key] = p.ref(value, "source")
    end
    for key, value in ipairs(link_note_list) do
        link_note_list[key] = p.ref(value, "note")
    end
    for key, value in ipairs(set_source_list) do
        set_source_list[key] = p.ref(value, "source")
    end
    for key, value in ipairs(set_note_list) do
        set_note_list[key] = p.ref(value, "note")
    end

    local site_list = {}
    local NOW_ICON = false
    local maxnum = p.maxnum({ #link_list, #set_list, #term_list, #link_source_list, #link_note_list, #set_source_list, #
    set_note_list })
    local IS_CAN_BREAK_LOOP = false


    for _, value in ipairs(link_list) do
        IS_CAN_BREAK_LOOP = false
        for _, s_value in pairs(be_id2link_dict) do
            if IS_CAN_BREAK_LOOP then
                break
            else
                NOW_ICON = false
            end
            for _, link_match_string in ipairs(s_value[2]) do
                link_match_string = b.escape_pattern_string(link_match_string)
                if mw.ustring.find(value, link_match_string) then
                    table.insert(site_list, s_value[1])
                    NOW_ICON = true
                    IS_CAN_BREAK_LOOP = false
                    break
                end
            end
        end
        if not NOW_ICON then table.insert(site_list, "") end
    end

    for i = 1, maxnum do
        local NOW = false
        if link_list[i] then
            if b.empty(link_list[i]) then
                link_list[i] = p.https_re(link_list[i])
            end
            local smwset_link_table2 = {
                '人物链接组=' ..
                (frame.args[1] or "") ..
                ";" ..
                (link_list[i] or "") ..
                ";" ..
                (site_list[i] or "") ..
                ";" .. ((link_source_list[i + maxnum]) or "") .. ";" .. ((link_note_list[i + maxnum]) or ""),
            }
            mw.smw.set(smwset_link_table2)
            if not ICON then result_link = result_link .. "<span class='supimg'>" end
            if b.empty(site_list[i]) then
                result_link = result_link ..
                    "[[file:" .. site_list[i] .. ".png|15px|link=" .. "https://" .. link_list[i] .. "]]"
            end
            ICON = true
        end

        if set_list[i] then
            if set_list[i] == "创始者" then
                set_list[i] = "持有者"
                term_list[i] = "1"
            end

            if set_list[i] == "现持有者" then
                NOW = true
                set_list[i] = "持有者"
            end

            local smwset_set_table1 = {
                '人物职能组=' ..
                (frame.args[1] or "") .. ";" ..
                (set_list[i] or "") ..
                ";" ..
                (term_list[i] or "") ..
                ";" .. (set_source_list[i] or "") .. ";" .. (set_note_list[i] or ""),
            }
            mw.smw.set(smwset_set_table1)

            if NOW then
                local smwset_set_table1 = {
                    '人物职能组=' ..
                    (frame.args[1] or "") .. ";" ..
                    "现持有者" ..
                    ";" ..
                    (term_list[i] or "") ..
                    ";" .. (set_source_list[i] or "") .. ";" .. (set_note_list[i] or ""),
                }
                mw.smw.set(smwset_set_table1)
            end

            if set_list[i] then
                if tonumber(b.empty(term_list[i])) then
                    if set_list[i] == "持有者" and term_list[i] == "1" then
                        result_set = result_set .. "(创始者)"
                    else
                        result_set = result_set ..
                            "(第" .. tonumber(b.empty(term_list[i])) .. "代" .. b.empty(set_list[i]) .. ")"
                    end
                elseif not NOW then
                    result_set = result_set .. "(" .. (set_list[i] or "") .. ")"
                end
                if NOW then result_set = result_set .. "(现持有者)" end
            end
        end
        result = result ..
            (link_source_list[i] or "") ..
            (link_note_list[i] or "") .. (set_source_list[i] or "") .. (set_note_list[i] or "")
    end
    if ICON then result_link = result_link .. "</span>" end
    result = frame:preprocess(b.trim(tostring(result_init .. result .. result_link .. result_set)))
    return result
end

function p.parsedatetime(time)
    local patterns = {
        { "^(%d%d%d%d)-(%d?%d)-(%d?%d) (%d?%d):(%d?%d):(%d?%d)$", "%04d-%02d-%02d %02d:%02d:%02d" },
        { "^(%d%d%d%d)-(%d?%d)-(%d?%d) (%d?%d):(%d?%d)$",         "%04d-%02d-%02d %02d:%02d" },
        { "^(%d%d%d%d)-(%d?%d)-(%d?%d) (%d?%d)$",                 "%04d-%02d-%02d %02d" },
        { "^(%d%d%d%d)-(%d?%d)-(%d?%d)$",                         "%04d-%02d-%02d" },
        { "^(%d%d%d%d)-(%d?%d)$",                                 "%04d-%02d" },
        { "^(%d%d%d%d)$",                                         "%04d" }
    }

    for _, pattern in ipairs(patterns) do
        local matches = { string.match(time, pattern[1]) }
        if #matches > 0 then
            return string.format(pattern[2], unpack(matches))
        end
    end

    return nil
end

function p.date(frame)
    local date_list = b.str_split(frame.args[1], "、")
    local set_list = b.str_split(frame.args["set"], "、")
    local timenum_list = b.str_split(frame.args["次数"], "、")

    local source_list = b.str_split(b.empty(mw.text.decode(mw.text.unstripNoWiki(frame.args["来源"]))), "、")
    local note_list = b.str_split(b.empty(mw.text.decode(mw.text.unstripNoWiki(frame.args["注释"]))), "、")
    for key, value in ipairs(source_list) do
        source_list[key] = p.ref(value, "source")
    end
    for key, value in ipairs(note_list) do
        note_list[key] = p.ref(value, "note")
    end

    local result_init = "<span style='display: none;'>模板:日期</span>"
    local result = ""
    local new_args = {}
    local new_frame = {}

    for key, value in ipairs(date_list) do
        date_list[key] = p.parsedatetime(value)
    end

    local maxnum = p.maxnum({ #date_list, #set_list, #timenum_list, #source_list, #note_list })

    for i = 1, maxnum do
        if date_list[i] then
            if set_list[i] == "发布日期" then
                set_list[i] = "发布"
            elseif set_list[i] == "重置日期" then
                set_list[i] = "重置"
            elseif set_list[i] == "重制日期" then
                set_list[i] = "重制"
            else
                local index = mw.ustring.find(set_list[i], "日期")
                if index then
                    set_list[i] = mw.ustring.sub(set_list[i], 1, index - 1)
                end
            end
            new_args[1] = set_list[i] or ""
            new_args["time"] = date_list[i]
            new_args["来源"] = source_list[i] or ""
            new_args["注释"] = note_list[i] or ""
            new_frame = mw.getCurrentFrame()
            new_frame.args = new_args
            result = result .. p.status(new_frame)
        end
    end
    result = frame:preprocess(b.trim(tostring(result_init .. result)))
    return result
end

function p.name(frame)
    local result_init = "<span style='display: none;'>模板:名称</span>"
    local result = ""

    local name_list = b.str_split(frame.args[1], "、")

    local be_set_list = { "现官方译名", "现正式译名", "现民间译名", "现原名", "官方译名", "正式译名", "民间译名", "原名" }
    local set_list = b.str_split(frame.args["set"], "、")

    for key, value in ipairs(set_list) do
        for _, s_value in ipairs(be_set_list) do
            if mw.ustring.find(value, s_value) then
                set_list[key] = s_value
                break
            end
        end
    end

    local term_list = {}
    local term1_list = {}
    local term2_list = {}
    if b.empty(frame.args["前者代数"]) and b.empty(frame.args["后者代数"]) then
        term1_list = b.str_split(frame.args["前者代数"], "、")
        term2_list = b.str_split(frame.args["后者代数"], "、")
    else
        term_list = b.str_split(frame.args["代数"], "、")
    end

    local source_list = b.str_split(b.empty(mw.text.decode(mw.text.unstripNoWiki(frame.args["来源"]))), "、")
    local note_list = b.str_split(b.empty(mw.text.decode(mw.text.unstripNoWiki(frame.args["注释"]))), "、")
    for key, value in ipairs(source_list) do
        source_list[key] = p.ref(value, "source")
    end
    for key, value in ipairs(note_list) do
        note_list[key] = p.ref(value, "note")
    end

    local smwset_set_table = {}

    for i = 1, #name_list do
        local NOW = false

        if mw.ustring.find((set_list[i] or ""), "现") then
            NOW = true
            set_list[i] = mw.ustring.gsub(set_list[i], "现", "")
        end

        if NOW then
            smwset_set_table = {
                '名称组=' ..
                (name_list[i] or "") ..
                ";" ..
                "现" .. set_list[i] ..
                ";" ..
                (term_list[i] or "") ..
                ";;" .. (source_list[i] or "") .. ";" .. (note_list[i] or ""),
            }
            mw.smw.set(smwset_set_table)
        end

        if b.empty(term_list) then
            smwset_set_table = {
                '名称组=' ..
                (name_list[i] or "") ..
                ";" ..
                (set_list[i] or "") ..
                ";" ..
                (term_list[i] or "") ..
                ";;" .. (source_list[i] or "") .. ";" .. (note_list[i] or ""),
            }
        else
            smwset_set_table = {
                '名称组=' ..
                (name_list[i] or "") ..
                ";" ..
                (set_list[i] or "") ..
                ";" ..
                (term1_list[i] or "") ..
                ";" ..
                (term2_list[i] or "") ..
                ";" ..
                (source_list[i] or "") .. ";" .. (note_list[i] or ""),
            }
        end

        mw.smw.set(smwset_set_table)

        if #result ~= 0 then
            result = result .. "<br>"
        end

        result = result .. name_list[i]

        if b.empty(term_list) then
            if b.empty(set_list[i]) then
                if tonumber(term_list[i]) then
                    result = result .. "(第" .. tonumber(term_list[i]) .. "代" .. set_list[i] .. ")"
                elseif not NOW then
                    result = result .. "(" .. set_list[i] .. ")"
                end
            end
            if NOW then result = result .. "(现" .. set_list[i] .. ")" end
        elseif tonumber(term1_list[i]) and tonumber(term2_list[i]) then
            result = result ..
                "(第" ..
                tonumber(term1_list[i]) ..
                "代原名的第" .. tonumber(term2_list[i]) .. "代" .. set_list[i] .. ")"
        elseif b.empty(set_list[i]) then
            if not NOW then result = result .. "(" .. set_list[i] .. ")" end
            if NOW then result = result .. "(现" .. set_list[i] .. ")" end
        end

        result = result .. (source_list[i] or "") .. (note_list[i] or "")
    end

    result = frame:preprocess(b.trim(tostring(result_init .. result)))
    return result
end

function p.type(frame)
    local type_list = b.str_split(frame.args[1], "、")
    local time_list = b.str_split(frame.args["time"], "、")
    local source_list = b.str_split(b.empty(mw.text.decode(mw.text.unstripNoWiki(frame.args["来源"]))), "、")
    local note_list = b.str_split(b.empty(mw.text.decode(mw.text.unstripNoWiki(frame.args["注释"]))), "、")
    for key, value in ipairs(source_list) do
        source_list[key] = p.ref(value, "source")
    end
    for key, value in ipairs(note_list) do
        note_list[key] = p.ref(value, "note")
    end

    local smwset_table = {
    }

    local be_a_type_list = { "平行时间轴", "准则变化", "正典偏离", "续写历史", "扩展宇宙" }
    local be_b_type_list = { "世界观变动", "宇宙迁移", "角色错位" }
    local be_c_type_list = { "交叉同人", "元素代入", "元素混杂", "跨界交叉" }

    local result_init = "<span style='display: none;'>模板:类型</span>"
    local result = ""

    for i = 1, #type_list do
        for key, value in ipairs(be_a_type_list) do
            if type_list[i]:find(value) then
                if #result ~= 0 then
                    result = result .. "<br>"
                end
                result = result .. be_a_type_list[key]
                table.insert(smwset_table,
                    '类型组=' ..
                    value ..
                    ";" ..
                    (time_list[i] or "") ..
                    ";" .. (source_list[i] or "") .. ";" .. (note_list[i] or ""))
            end
        end
        for key, value in ipairs(be_b_type_list) do
            if type_list[i]:find(value) then
                if #result ~= 0 then
                    result = result .. "<br>"
                end
                result = result .. be_b_type_list[key]
                table.insert(smwset_table,
                    '类型组=' ..
                    value ..
                    ";" ..
                    (time_list[i] or "") ..
                    ";" .. (source_list[i] or "") .. ";" .. (note_list[i] or ""))
            end
        end
        for key, value in ipairs(be_c_type_list) do
            if type_list[i]:find(value) then
                if #result ~= 0 then
                    result = result .. "<br>"
                end
                if key == 1 then
                    result = result .. be_c_type_list[key]
                else
                    result = result .. "交叉同人 - " .. be_c_type_list[key]
                end
                table.insert(smwset_table,
                    '类型组=' ..
                    value ..
                    ";" ..
                    (time_list[i] or "") ..
                    ";" .. (source_list[i] or "") .. ";" .. (note_list[i] or ""))
            end
        end

        if b.empty(time_list[i]) then
            result = result .. " (" .. time_list[i] .. ")" .. (source_list[i] or "") .. (note_list[i] or "")
        else
            result = result .. (source_list[i] or "") .. (note_list[i] or "")
        end
    end

    mw.smw.set(smwset_table)
    result = frame:preprocess(b.trim(tostring(result_init .. result)))
    return result
end

function p.status(frame)
    local smwset_set_table = {}
    local result_init = "<span style='display: none;'>模板:状态</span>"
    local result = ""

    local status_list = b.str_split(frame.args[1], "、")
    local time_list = b.str_split(frame.args["time"], "、")

    local source_list = b.str_split(b.empty(mw.text.decode(mw.text.unstripNoWiki(frame.args["来源"]))), "、")
    local note_list = b.str_split(b.empty(mw.text.decode(mw.text.unstripNoWiki(frame.args["注释"]))), "、")
    for key, value in ipairs(source_list) do
        source_list[key] = p.ref(value, "source")
    end
    for key, value in ipairs(note_list) do
        note_list[key] = p.ref(value, "note")
    end

    local maxnum = p.maxnum({ #status_list, #time_list, #source_list, #note_list })

    for i = 1, maxnum do
        table.insert(smwset_set_table,
            '状态组=' ..
            (status_list[i] or "") ..
            ";" ..
            (time_list[i] or "") ..
            ";" .. (source_list[i] or "") .. ";" .. (note_list[i] or ""))
        if #result ~= 0 then
            result = result .. "<br>"
        end

        if b.empty(time_list[i]) then
            result = result ..
                status_list[i] .. " (" .. (time_list[i] or "") .. ")" .. (source_list[i] or "") .. (note_list[i] or "")
        else
            result = result .. status_list[i] .. (source_list[i] or "") .. (note_list[i] or "")
        end
    end

    mw.smw.set(smwset_set_table)
    result = frame:preprocess(b.trim(tostring(result_init .. result)))
    return result
end

function p.style(frame)
    local smwset_set_table = {}
    local result_init = "<span style='display: none;'>模板:风格</span>"
    local result = ""

    local style_list = b.str_split(frame.args[1], "、")
    local time_list = b.str_split(frame.args["time"], "、")

    local source_list = b.str_split(b.empty(mw.text.decode(mw.text.unstripNoWiki(frame.args["来源"]))), "、")
    local note_list = b.str_split(b.empty(mw.text.decode(mw.text.unstripNoWiki(frame.args["注释"]))), "、")
    for key, value in ipairs(source_list) do
        source_list[key] = p.ref(value, "source")
    end
    for key, value in ipairs(note_list) do
        note_list[key] = p.ref(value, "note")
    end

    local maxnum = p.maxnum({ #style_list, #time_list, #source_list, #note_list })

    for i = 1, maxnum do
        table.insert(smwset_set_table,
            '风格组=' ..
            (style_list[i] or "") ..
            ";" ..
            (time_list[i] or "") ..
            ";" .. (source_list[i] or "") .. ";" .. (note_list[i] or ""))
        if #result ~= 0 then
            result = result .. "<br>"
        end
        result = result ..
            (style_list[i] or "") .. (time_list[i] or "") .. (source_list[i] or "") .. (note_list[i] or "")
    end

    mw.smw.set(smwset_set_table)
    result = frame:preprocess(b.trim(tostring(result_init .. result)))
    return result
end

function p.backdrop(frame)
    local smwset_set_table = {}
    local result_init = "<span style='display: none;'>模板:背景</span>"
    local result = ""

    local backdrop_list = b.str_split(frame.args[1], "、")
    local time_list = b.str_split(frame.args["time"], "、")

    local source_list = b.str_split(b.empty(mw.text.decode(mw.text.unstripNoWiki(frame.args["来源"]))), "、")
    local note_list = b.str_split(b.empty(mw.text.decode(mw.text.unstripNoWiki(frame.args["注释"]))), "、")
    for key, value in ipairs(source_list) do
        source_list[key] = p.ref(value, "source")
    end
    for key, value in ipairs(note_list) do
        note_list[key] = p.ref(value, "note")
    end

    local maxnum = p.maxnum({ #backdrop_list, #time_list, #source_list, #note_list })

    for i = 1, maxnum do
        table.insert(smwset_set_table,
            '背景组=' ..
            (backdrop_list[i] or "") ..
            ";" ..
            (time_list[i] or "") ..
            ";" .. (source_list[i] or "") .. ";" .. (note_list[i] or ""))
        if #result ~= 0 then
            result = result .. "<br>"
        end
        result = result ..
            (backdrop_list[i] or "") .. (time_list[i] or "") .. (source_list[i] or "") .. (note_list[i] or "")
    end

    mw.smw.set(smwset_set_table)
    result = frame:preprocess(b.trim(tostring(result_init .. result)))
    return result
end

function p.homepage(frame)
    local term_list = b.str_split(frame.args["代数"], "、")

    local source_list = b.str_split(b.empty(mw.text.decode(mw.text.unstripNoWiki(frame.args["来源"]))), "、")
    local note_list = b.str_split(b.empty(mw.text.decode(mw.text.unstripNoWiki(frame.args["注释"]))), "、")
    for key, value in ipairs(source_list) do
        source_list[key] = p.ref(value, "source")
    end
    for key, value in ipairs(note_list) do
        note_list[key] = p.ref(value, "note")
    end

    local result_init = "<span style='display: none;'>模板:主页</span>"
    local result = ""

    local smwset_set_table = {}
    local link_list = {}
    local site_list = {}
    local SITE = false
    local NOW_ICON = false
    local IS_CAN_BREAK_LOOP = false
    local be_id2link_dict = p.id2link_homepage()
    local args1 = b.str_split(frame.args[1], "、")
    
    for _, value in pairs(be_id2link_dict) do
        for _, s_value in pairs(args1) do
            if value[1] == s_value then
                SITE = true
                break
            end
        end
    end

    if SITE then
        site_list = args1
        link_list = b.str_split(frame.args[2], "、")
    else
        link_list = args1
    end

    for i, value in ipairs(link_list) do
        if b.empty(value) then
            link_list[i] = p.https_re(value)
        end
    end

    if SITE == false then
        for _, value in ipairs(link_list) do
            IS_CAN_BREAK_LOOP = false
            for _, s_value in pairs(be_id2link_dict) do
                if IS_CAN_BREAK_LOOP then
                    break
                else
                    NOW_ICON = false
                end
                for _, link_match_string in ipairs(s_value[2]) do
                    link_match_string = b.escape_pattern_string(link_match_string)
                    if mw.ustring.find(value, link_match_string) then
                        table.insert(site_list, s_value[1])
                        NOW_ICON = true
                        IS_CAN_BREAK_LOOP = true
                        break
                    end
                end
            end
            if not NOW_ICON then table.insert(site_list, "") end
        end
    end

    for i = 1, #link_list do
        table.insert(smwset_set_table,
            '主页组=' ..
            link_list[i] ..
            ";" ..
            (site_list[i] or frame.args[1]) ..
            ";" ..
            (term_list[i] or "") ..
            ";" .. (source_list[i] or "") .. ";" .. (note_list[i] or ""))
        result = result .. "[[file:" .. (site_list[i] or frame.args[1]) .. ".png|25px|link=" .. link_list[i] .. "]]"
        result = result .. (source_list[i] or "") .. (note_list[i] or "")
    end

    mw.smw.set(smwset_set_table)
    result = frame:preprocess(b.trim(tostring(result_init .. result)))
    return result
end

function p.licence(frame)
    local licence_list = b.str_split(frame.args[1], "、")

    local source_list = b.str_split(b.empty(mw.text.decode(mw.text.unstripNoWiki(frame.args["来源"]))), "、")
    local note_list = b.str_split(b.empty(mw.text.decode(mw.text.unstripNoWiki(frame.args["注释"]))), "、")
    for key, value in ipairs(source_list) do
        source_list[key] = p.ref(value, "source")
    end
    for key, value in ipairs(note_list) do
        note_list[key] = p.ref(value, "note")
    end

    local result_init = "<span style='display: none;'>模板:许可</span>"
    local result = ""
    local CC = false
    local OTHER = false
    local INLIST = false
    local smw_licence_result = ""

    local be_licence_list1 = { "CC" }
    local be_licence_list2 = { "BY", "NC", "ND", "SA" }
    local be_licence_list3 = { "1.0", "2.0", "2.5", "3.0", "4.0" }
    local be_licence_list_cc = {
        "CC",
        "CC0",
        "CC BY",
        "CC BY-SA",
        "CC BY-NC",
        "CC BY-NC-SA",
        "CC BY-ND",
        "CC BY-NC-ND",
        "CC0 1.0",
        "CC BY 1.0",
        "CC BY 2.0",
        "CC BY 2.5",
        "CC BY 3.0",
        "CC BY 4.0",
        "CC BY-SA 1.0",
        "CC BY-SA 2.0",
        "CC BY-SA 2.5",
        "CC BY-SA 3.0",
        "CC BY-SA 4.0",
        "CC BY-NC 1.0",
        "CC BY-NC 2.0",
        "CC BY-NC 2.5",
        "CC BY-NC 3.0",
        "CC BY-NC 4.0",
        "CC BY-NC-SA 1.0",
        "CC BY-NC-SA 2.0",
        "CC BY-NC-SA 2.5",
        "CC BY-NC-SA 3.0",
        "CC BY-NC-SA 4.0",
        "CC BY-ND 1.0",
        "CC BY-ND 2.0",
        "CC BY-ND 2.5",
        "CC BY-ND 3.0",
        "CC BY-ND 4.0",
        "CC BY-NC-ND 1.0",
        "CC BY-NC-ND 2.0",
        "CC BY-NC-ND 2.5",
        "CC BY-NC-ND 3.0",
        "CC BY-NC-ND 4.0",
    }

    local be_licence_list_other = {
        "Copyright",
        "Authorized",
        "Copyright @ UTCWIKi",
    }

    local smwset_set_table = {}

    for i = 1, #licence_list do
        for _, value in ipairs(be_licence_list_other) do
            if mw.ustring.find(licence_list[i], value) then
                OTHER = true
                result = "{{" .. value .. "}}"
                smw_licence_result = smw_licence_result .. value
            end
        end

        for _, value in ipairs(be_licence_list1) do
            if mw.ustring.find(licence_list[i]:upper(), value) then
                CC = true
            end
        end

        for _, value in ipairs(be_licence_list2) do
            if mw.ustring.find(licence_list[i]:upper(), value) then
                result = result .. "[[文件:CC " .. value .. ".png|50px]]"
                CC = true
                if #smw_licence_result == 0 then
                    smw_licence_result = smw_licence_result .. value
                else
                    smw_licence_result = smw_licence_result .. "-" .. value
                end
            end
        end

        if CC == true and #smw_licence_result == 0 then
            if mw.ustring.find(licence_list[i]:upper(), "CC0") or mw.ustring.find(licence_list[i]:upper(), "CC 0") or mw.ustring.find(licence_list[i]:upper(), "CC ZERO") or mw.ustring.find(licence_list[i]:upper(), "CCZERO") then
                smw_licence_result = "CC 0"
            end
        end

        for _, value in ipairs(be_licence_list3) do
            if mw.ustring.find(licence_list[i], value) then
                result = result .. value
                smw_licence_result = smw_licence_result .. " " .. value
            end
        end

        if CC == true then
            result = "[[文件:CC.png|50px]]" .. result
            if #smw_licence_result == 0 then
                smw_licence_result = "CC" .. smw_licence_result
            else
                smw_licence_result = "CC " .. smw_licence_result
            end
        end

        for _, value in ipairs(be_licence_list_cc) do
            if value == smw_licence_result then
                INLIST = true
                break
            end
        end

        if (CC == true and INLIST == false) then
            result = result .. "输入的许可中,CC协议的搭配不正确。"
        else
            table.insert(smwset_set_table,
                '许可组=' ..
                smw_licence_result .. ";" .. (source_list[i] or "") .. ";" .. (note_list[i] or ""))
        end

        if CC == false and OTHER == false then
            result = result .. licence_list[i]
            smw_licence_result = smw_licence_result .. licence_list[i]
            table.insert(smwset_set_table,
                '许可组=' ..
                smw_licence_result .. ";" .. (source_list[i] or "") .. ";" .. (note_list[i] or ""))
        end
    end

    mw.smw.set(smwset_set_table)
    result = frame:preprocess(b.trim(tostring(result_init .. result)))
    return result
end

return p