跳转到内容

模組:PatternedCandidateUtils/sandbox

维基百科,自由的百科全书

这是本页的一个历史版本,由Xiplus留言 | 贡献2017年12月5日 (二) 09:49 建立内容为“local z = {} function getCandidates( frame ) local page = mw.title.new( frame.args.title ):getContent() local matches = {} local black…”的新页面)编辑。这可能和当前版本存在着巨大的差异。

(差异) ←上一修订 | 最后版本 (差异) | 下一修订→ (差异)
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
    	local inblackregex = false
	    if frame.args.blackregex then
	        for t in mw.text.gmatch( m, frame.args.blackregex ) do
	            inblackregex = true
	            break
	        end
	    end
        if not black[m] and not inblackregex 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