求真百科欢迎当事人提供第一手真实资料,洗刷冤屈,终结网路霸凌。

模块:PatternedCandidateUtils查看源代码查看历史

事实揭露 揭密真相
跳转至: 导航搜索

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

用法

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

具体用法可参见求真百科:特色图片评选/列表

参见

模块: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] .. '|' .. list[i] .. ']]'
        else
            list[i] = '[[:' .. list[i] .. ']]'
        end
    end
    if #list > 0 then
        return table.concat( list, '-' )
    else
        return '暂无'
    end
end

return z