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

Module:SubpageTable:修订间差异

来自OTTOWiki
琪露若
琪露若留言 | 贡献 (debug)
 
琪露若
琪露若留言 | 贡献 (debug)
 
(未显示同一用户的5个中间版本)
第1行: 第1行:
local p = {}
local p = {}


function p.showSubpages(frame)
function p.table(frame)
    local args = frame.args
     local currentTitle = mw.title.getCurrentTitle()
     local currentTitle = mw.title.getCurrentTitle()
      
      
     -- 参数处理
     -- 获取子页面的另一种方法
     local namespace = args.namespace or currentTitle.namespace
     local result = frame:preprocess('{{Special:PrefixIndex/' .. currentTitle.prefixedText .. '/|hideredirects=1|stripprefix=1|format=table}}')
    local limit = tonumber(args.limit) or 100
    local class = args.class or 'wikitable sortable'
    local order = args.order or 'title'
    local sort = args.sort or 'ascending'
    local showCount = args.showcount or 'yes'
      
      
     -- 构建DPL查询
     -- 如果返回空,添加提示
     local dplQuery = {
     if result == "" then
        'namespace = ' .. namespace,
         return "此页面没有子页面。"
        'titlematch = ' .. currentTitle.prefixedText .. '/%',
        'mode = userformat',
        'listseparators = {| class="' .. class .. '"\\n! 页面名称\\n! 最后修改\\n! 大小\\n! 编辑者\\n|-,\\n| [[%PAGE%]]\\n| %DATE%\\n| %SIZE% 字节\\n| %USER%,\\n|-,\\n|}',
        'ordermethod = ' .. order,
        'order = ' .. sort,
        'count = ' .. limit,
        'distinct = true',
        'suppresserrors = true'
    }
   
    -- 执行DPL
    local dplResult = frame:preprocess(table.concat({'<dpl>', table.concat(dplQuery, '\n|'), '</dpl>'}, ''))
   
    -- 添加计数信息
    if showCount == 'yes' then
         local countInfo = mw.html.create('div')
            :addClass('subpage-count')
            :css('font-size', '90%')
            :css('color', '#666')
            :css('margin-top', '5px')
            :wikitext('注:显示最近 ' .. limit .. ' 个子页面')
       
        dplResult = dplResult .. tostring(countInfo)
    end
   
    return dplResult
end
 
function p.getSubpageStats(frame)
    local currentTitle = mw.title.getCurrentTitle()
    local subpages = {}
    local totalSize = 0
    local pageCount = 0
   
    -- 使用DPL获取子页面统计
    local dplQuery = {
        'namespace = ' .. (frame.args.namespace or currentTitle.namespace),
        'titlematch = ' .. currentTitle.prefixedText .. '/%',
        'mode = userformat',
        'listseparators = ,%PAGE%:%SIZE%,',
        'count = 500',
        'suppresserrors = true'
    }
   
    local rawResult = frame:preprocess(table.concat({'<dpl>', table.concat(dplQuery, '\n|'), '</dpl>'}, ''))
   
    -- 解析结果并计算统计
    for pageInfo in string.gmatch(rawResult, '([^,]+)') do
        local page, size = string.match(pageInfo, '(.+):(%d+)')
        if page and size then
            table.insert(subpages, {
                title = page,
                size = tonumber(size)
            })
            totalSize = totalSize + tonumber(size)
            pageCount = pageCount + 1
        end
     end
     end
      
      
    -- 生成统计信息
     return result
    local stats = mw.html.create('div')
        :addClass('subpage-stats')
        :css('border', '1px solid #ccc')
        :css('padding', '10px')
        :css('background', '#f9f9f9')
   
    stats:tag('strong')
        :wikitext('子页面统计:')
        :done()
        :tag('br')
   
    stats:wikitext('总数量: ' .. pageCount .. ' 个页面')
        :tag('br')
        :wikitext('总大小: ' .. totalSize .. ' 字节')
        :tag('br')
        :wikitext('平均大小: ' .. (pageCount > 0 and math.floor(totalSize / pageCount) or 0) .. ' 字节')
   
     return tostring(stats)
end
 
function p.smartSubpageTable(frame)
    local args = frame.args
    local result = {}
   
    -- 显示统计信息
    if args.stats ~= 'no' then
        table.insert(result, p.getSubpageStats(frame))
    end
   
    -- 显示子页面表格
    table.insert(result, p.showSubpages(frame))
   
    return table.concat(result, '\n')
end
end


return p
return p

2025年10月3日 (五) 01:27的最新版本

local p = {}

function p.table(frame)
    local currentTitle = mw.title.getCurrentTitle()
    
    -- 获取子页面的另一种方法
    local result = frame:preprocess('{{Special:PrefixIndex/' .. currentTitle.prefixedText .. '/|hideredirects=1|stripprefix=1|format=table}}')
    
    -- 如果返回空,添加提示
    if result == "" then
        return "此页面没有子页面。"
    end
    
    return result
end

return p