跳转到内容

模組:WikipediaHonors

维基百科,自由的百科全书

这是本页的一个历史版本,由SunAfterRain留言 | 贡献2020年2月14日 (五) 13:09编辑。这可能和当前版本存在着巨大的差异。

local data = require('Module:WikipediaHonor/data')

local z = {}

function typelist(type)
	local typelist = {
		["pagename"] = "頁面",
		["section"] = "章節",
		["honor"] = "榮譽"
	}
	if typelist[type] == nil then
		return "Unknow type <code>" .. type .. '</code>'
	end
	return typelist[type]
end

function extractAliases(item)
    allnames = {item['code']}
    for j, alias in ipairs(item['aliases']) do
        table.insert(allnames, alias)
    end
    return allnames
end

function z.data(frame)
	local wt = [=[
{|class="wikitable
|-
!資料類型!!編碼!!可使用的代碼!!名稱!!英文全名!!章節!!對應模板!!對應分類
	]=]
    for i, item in ipairs(data) do
        allnames = extractAliases(item)
        wt = wt .. string.format([=[
|-
|%s||%s
|
* %s
||%s||%s||%s||%s||%s
        ]=], 
        typelist(item['type']), 
        item['code'], 
        mw.text.listToText(allnames, '\n* ', '\n* '), 
        item['name'], 
        item['fullname'], 
        ((item['section'] and '[[WP:WPH#' .. item['section'] .. ']]') or ''), 
        ((item['template'] and '[[:Template:' .. item['template'] .. ']]') or ''), 
        ((item['category'] and '[[:Category:' .. item['category'] .. ']]') or '')
        )
    end
    wt = wt .. '|}'
    return frame:preprocess(wt)
end

function main(args,itemarg)
    map = {}
    for i, item in ipairs(data) do
        map[item['code']:lower()] = i
        for j, alias in ipairs(item['aliases']) do
            map[alias:lower()] = i
        end
    end
    arg = args[1]
    if arg ~= nil then
        if arg and map[mw.text.trim(arg:lower())] then
            item = data[map[mw.text.trim(arg:lower())]]
            return item[itemarg]
        elseif arg and mw.text.trim(arg) ~= '' then
            return 'error'
        end
    else
       	return nil
    end
end

return z