Module:SubpageTable
来自OTTOWiki
更多操作
local p = {}
function p.showSubpages(frame)
local args = frame.args
local currentTitle = mw.title.getCurrentTitle()
-- 参数处理
local namespace = args.namespace or currentTitle.namespace
local limit = tonumber(args.limit) or 100
local class = args.class or 'wikitable sortable'
local showCount = args.showcount or 'yes'
-- 获取子页面
local subpages = {}
local allPages = mw.site.allPages({
prefix = currentTitle.prefixedText .. '/',
namespace = namespace,
limit = limit
})
-- 构建表格
local tableHtml =
'{| class="' .. class .. '"\n' ..
'! 页面名称\n' ..
'! 最后修改\n' ..
'! 大小\n' ..
'! 编辑者\n'
for page in allPages do
local pageTitle = mw.title.new(page)
if pageTitle then
local revision = pageTitle.getCurrentRevision and pageTitle:getCurrentRevision()
local timestamp = revision and revision.timestamp or '未知'
local user = revision and revision.user or '未知'
tableHtml = tableHtml ..
'|-\n' ..
'| [[' .. pageTitle.prefixedText .. ']]\n' ..
'| ' .. timestamp .. '\n' ..
'| ' .. pageTitle.length .. ' 字节\n' ..
'| ' .. user .. '\n'
end
end
tableHtml = tableHtml .. '|}'
-- 添加计数信息
if showCount == 'yes' then
local count = 0
for _ in mw.site.allPages({prefix = currentTitle.prefixedText .. '/', namespace = namespace}) do
count = count + 1
end
tableHtml = tableHtml ..
'<div class="subpage-count" style="font-size:90%; color:#666; margin-top:5px;">' ..
'注:共 ' .. count .. ' 个子页面(显示最近 ' .. limit .. ' 个)' ..
'</div>'
end
return tableHtml
end
return p