local p = {}
function p.main(frame)
local args = require('Module:Arguments').getArgs(frame)
-- 参数处理
local width = args.width or '300px'
local height = args.height or '150px'
local title = args.title or '讨论存档'
local img = args.img or '[[File:File.svg|40px|link=]]'
-- pageName:避免空值
local pageName = args.page
if not pageName or pageName == '' then
pageName = mw.title.getCurrentTitle().prefixedText
end
local output = {}
table.insert(output, '<div style="width:' .. tostring(width) .. ';max-width:calc(1060% - 22px);background:#f5faff;border:1px solid gray;float:right;padding:10px;text-align:center;font-weight:bold">' .. img .. '<span style="font-size:larger;">' .. tostring(title) .. '</span><hr style="margin:10px 0;"/>')
table.insert(output, '<div style="font-weight:normal;text-align:left;max-height:' .. tostring(height) .. ';overflow-y:auto;margin-right:-10px">')
-- 用 <ul> 而不是 *
table.insert(output, '<ul class="plainlinks" style="padding-left:1.5em;margin:0;">')
local i = 1
while args['id' .. i] do
local oldid = args['id' .. i]
if oldid ~= '' then
local linkText = args['text' .. i] or oldid
oldid = tostring(oldid)
linkText = tostring(linkText)
-- 生成 URL
local url
local titleObj = mw.title.new(pageName)
if titleObj and titleObj.exists then
url = titleObj:fullUrl{ oldid = oldid }
else
url = mw.title.makeTitle(0, pageName):fullUrl{ oldid = oldid }
end
url = tostring(url)
-- 用 <li> 而不是 *
table.insert(output, '<li>[' .. url .. ' ' .. linkText .. ']</li>')
end
i = i + 1
end
table.insert(output, '</ul>')
table.insert(output, '</div></div>')
return table.concat(output)
end
return p