|
|
| (未显示同一用户的2个中间版本) |
| 第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 | | end |
| | | |
| return dplResult | | return result |
| 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
| |
|
| |
| -- 生成统计信息 - 修复了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')
| |
| end | | end |
|
| |
|
| return p | | return p |
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