打开/关闭菜单
打开/关闭外观设置菜单
打开/关闭个人菜单
未登录
未登录用户的IP地址会在进行任意编辑后公开展示。

Module:SubpageTable

来自OTTOWiki
琪露若留言 | 贡献2025年10月3日 (五) 01:16的版本 (debug)
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