模組:PatternedCandidateUtils

被永久保护的模块
维基百科,自由的百科全书
文档图示 模块文档[查看] [编辑] [历史] [清除缓存]

本模块用于生成页面的标题列表。

用法

基本用法:{{#invoke:PatternedCandidateUtils|list|title=Wikipedia:特色圖片評選|pattern={{((}}Wikipedia:特色圖片評選/(.-){{))}}|black=header|blackregex=除名/|linkprefix=Wikipedia:特色圖片評選/}}

具体用法可参见Wikipedia:特色圖片評選/列表

参见

模块:PatternedCandidateUtils2

local z = {}

function getCandidates( frame )
    local page = mw.title.new( frame.args.title ):getContent()
    local matches = {}
    local black = {}
    if frame.args.black then
        for b in mw.text.gsplit( frame.args.black, '|', true ) do
            black[b] = true
        end
    end
    for m in mw.ustring.gmatch( page, frame.args.pattern ) do
        if not black[m] and not ( frame.args.blackregex and mw.ustring.match( m, frame.args.blackregex ) ) then
            table.insert( matches, m )
        end
    end
    return matches
end

function z.count( frame )
    return #getCandidates( frame )
end

function z.list( frame )
    local list = getCandidates( frame )
    local linkprefix = frame.args.linkprefix
    for i = 1, #list do
        if linkprefix then
            list[i] = '[[:' .. linkprefix .. list[i] .. '|' .. string.gsub(list[i], "_", " ") .. ']]'
        else
            list[i] = '[[:' .. string.gsub(list[i], "_", " ") .. ']]'
        end
    end
    if #list > 0 then
        return table.concat( list, '-' )
    else
        return '暂无'
    end
end

return z