Module:Infomation
跳到导航
跳到搜索
local p = {}
-- 辅助函数:获取参数值,支持多个可能的参数名
local function getParam(args, possibleNames)
for _, name in ipairs(possibleNames) do
if args[name] and args[name] ~= '' then
return args[name]
end
end
return nil
end
-- 生成表格HTML
local function generateTable(args)
local output = {}
-- 开始表格
table.insert(output, '<table cellpadding="3" class="toccolours" width="100%">')
-- 说明字段
local description = getParam(args, {'A', 'Description', 'description', '说明', '説明'})
if description then
table.insert(output, '<tr style="vertical-align: top">')
table.insert(output, '<th id="fileinfotpl_desc" class="fileinfo-paramfield" width="15%">说明</th>')
table.insert(output, '<td>' .. description .. '</td>')
table.insert(output, '</tr>')
else
table.insert(output, '<tr style="vertical-align: top">')
table.insert(output, '<th id="fileinfotpl_desc" class="fileinfo-paramfield" width="15%">说明</th>')
table.insert(output, '<td>{{Description missing}}</td>')
table.insert(output, '</tr>')
end
-- 来源字段
local source = getParam(args, {'B', 'Source', 'source', '来源', '來源'})
if source then
table.insert(output, '<tr style="vertical-align: top">')
table.insert(output, '<th id="fileinfotpl_src" class="fileinfo-paramfield">来源</th>')
table.insert(output, '<td>' .. source .. '</td>')
table.insert(output, '</tr>')
else
table.insert(output, '<tr style="vertical-align: top">')
table.insert(output, '<th id="fileinfotpl_src" class="fileinfo-paramfield">来源</th>')
table.insert(output, '<td>{{Source missing}}</td>')
table.insert(output, '</tr>')
end
-- 日期字段
local date = getParam(args, {'C', 'Date', 'date', '日期'})
table.insert(output, '<tr style="vertical-align: top">')
table.insert(output, '<th id="fileinfotpl_date" class="fileinfo-paramfield">日期</th>')
table.insert(output, '<td>{{ISOdate|' .. (date or '') .. '}}</td>')
table.insert(output, '</tr>')
-- 作者字段
local author = getParam(args, {'D', 'Author', 'author', '作者'})
if author then
table.insert(output, '<tr style="vertical-align: top">')
table.insert(output, '<th id="fileinfotpl_aut" class="fileinfo-paramfield">作者</th>')
table.insert(output, '<td>' .. author .. '</td>')
table.insert(output, '</tr>')
else
table.insert(output, '<tr style="vertical-align: top">')
table.insert(output, '<th id="fileinfotpl_aut" class="fileinfo-paramfield">作者</th>')
table.insert(output, '<td>{{Author missing}}</td>')
table.insert(output, '</tr>')
end
-- 许可字段(条件显示)
local permission = getParam(args, {'E', 'Permission', 'permission', '许可', '許可'})
if permission and permission ~= '' and permission ~= '-' and permission ~= 'none' then
table.insert(output, '<tr style="vertical-align: top">')
table.insert(output, '<th id="fileinfotpl_perm" class="fileinfo-paramfield">许可</th>')
table.insert(output, '<td>' .. permission .. '</td>')
table.insert(output, '</tr>')
end
-- 其他版本字段(条件显示)
local otherVersions = getParam(args, {'F', 'other_versions', 'Other_Versions', 'Other Versions', 'other versions', '其他版本'})
if otherVersions and otherVersions ~= '' and otherVersions ~= '-' and otherVersions ~= 'none' then
table.insert(output, '<tr style="vertical-align: top">')
table.insert(output, '<th id="fileinfotpl_ver" class="fileinfo-paramfield">其他版本</th>')
table.insert(output, '<td>' .. otherVersions .. '</td>')
table.insert(output, '</tr>')
end
-- 其他字段
local otherFields = getParam(args, {'other_fields', 'Other_fields', 'Other fields', 'other fields', '其他领域', '其他領域'})
if otherFields then
table.insert(output, otherFields)
end
-- 处理动态的其他字段(other_fields1, other_fields2, ...)
local i = 1
while true do
local fieldName = 'other_fields' .. i
local fieldValue = getParam(args, {fieldName, 'Other_fields' .. i, 'Other fields' .. i, 'other fields' .. i, '其他领域' .. i, '其他領域' .. i})
if not fieldValue then
break
end
table.insert(output, fieldValue)
i = i + 1
end
-- 结束表格
table.insert(output, '</table>')
return table.concat(output, '\n')
end
-- 主函数
function p.main(frame)
local args
if frame == mw.getCurrentFrame() then
args = frame:getParent().args
else
args = frame
end
return generateTable(args)
end
return p