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

Module:SubpageTable:修订间差异

来自OTTOWiki
琪露若
琪露若留言 | 贡献 (debug)
第1行: 第1行:
local p = {}
local p = {}


function p.showSubpages(frame)
function p.table(frame)
    local currentTitle = mw.title.getCurrentTitle()
     local args = frame.args
     local args = frame.args
    local currentTitle = mw.title.getCurrentTitle()
      
      
     -- 参数处理
     -- 参数处理
    local limit = args.limit or '50'
    local class = args.class or 'wikitable sortable'
     local namespace = args.namespace or currentTitle.namespace
     local namespace = args.namespace or currentTitle.namespace
    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查询
     -- 使用 DPL 查询子页面
     local dplQuery = {
     local dplQuery = {
         'namespace = ' .. namespace,
         'namespace = ' .. namespace,
         'titlematch = ' .. currentTitle.prefixedText .. '/%',
         'titlematch = ' .. currentTitle.prefixedText .. '/%',
         'mode = userformat',
         'mode = userformat',
         'listseparators = {| class="' .. class .. '"\\n! 页面名称\\n! 最后修改\\n! 大小\\n! 编辑者\\n|-,\\n| [[%PAGE%]]\\n| %DATE%\\n| %SIZE% 字节\\n| %USER%,\\n|-,\\n|}',
         'listseparators = {| class="' .. class .. '"\n! 页面名称\n! 最后修改\n! 大小\n|-,\n| [[%PAGE%]]\n| %DATE%\n| %SIZE% 字节,\n|-,\n|}',
         'ordermethod = ' .. order,
         'ordermethod = title',
         'order = ' .. sort,
         'order = ascending',
         'count = ' .. limit,
         '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'
         'suppresserrors = true'
     }
     }
      
      
     local rawResult = frame:preprocess(table.concat({'<dpl>', table.concat(dplQuery, '\n|'), '</dpl>'}, ''))
    -- 构建 DPL 标签
   
     local dplTag = '<dpl>\n' .. table.concat(dplQuery, '\n|') .. '\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
   
    -- 生成统计信息 - 修复了br标签问题
    local stats = mw.html.create('div')
        :addClass('subpage-stats')
        :css('border', '1px solid #ccc')
        :css('padding', '10px')
        :css('background', '#f9f9f9')
   
    -- 使用段落而不是br标签
    stats:tag('p')
        :css('margin', '0 0 5px 0')
        :tag('strong')
            :wikitext('子页面统计:')
        :done()
    :done()
   
    stats:tag('p')
        :css('margin', '0 0 3px 0')
        :wikitext('总数量: ' .. pageCount .. ' 个页面')
    :done()
   
    stats:tag('p')
        :css('margin', '0 0 3px 0')
        :wikitext('总大小: ' .. totalSize .. ' 字节')
    :done()
   
    stats:tag('p')
        :css('margin', '0')
        :wikitext('平均大小: ' .. (pageCount > 0 and math.floor(totalSize / pageCount) or 0) .. ' 字节')
    :done()
   
    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')
    -- 执行 DPL
     return frame:preprocess(dplTag)
end
end


return p
return p

2025年10月3日 (五) 01:25的版本

local p = {}

function p.table(frame)
    local currentTitle = mw.title.getCurrentTitle()
    local args = frame.args
    
    -- 参数处理
    local limit = args.limit or '50'
    local class = args.class or 'wikitable sortable'
    local namespace = args.namespace or currentTitle.namespace
    
    -- 使用 DPL 查询子页面
    local dplQuery = {
        'namespace = ' .. namespace,
        'titlematch = ' .. currentTitle.prefixedText .. '/%',
        'mode = userformat',
        'listseparators = {| class="' .. class .. '"\n! 页面名称\n! 最后修改\n! 大小\n|-,\n| [[%PAGE%]]\n| %DATE%\n| %SIZE% 字节,\n|-,\n|}',
        'ordermethod = title',
        'order = ascending',
        'count = ' .. limit,
        'suppresserrors = true'
    }
    
    -- 构建 DPL 标签
    local dplTag = '<dpl>\n' .. table.concat(dplQuery, '\n|') .. '\n</dpl>'
    
    -- 执行 DPL
    return frame:preprocess(dplTag)
end

return p