跳转到内容

模組:首页2

被永久保护的模块
维基百科,自由的百科全书

这是本页的一个历史版本,由Gakmo留言 | 贡献2014年5月12日 (一) 09:22 (model on module:PatternedCandidateUtils编辑。这可能和当前版本存在着巨大的差异。

(差异) ←上一修订 | 最后版本 (差异) | 下一修订→ (差异)
local z = {}

function getItems( 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] then
			table.insert ( matches, m )
		end
	end
	return matches
end

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


function z.list( frame )
	local d = getItems( frame )
	math.randomseed( os.time() )
	x = math.random( 1, #d )
	if x == #d then return d[x].." - "..d[x-1].." - "..d[1]
		elseif x == 1 then return d[1].." - "..d[2].." - "..d[#d]
		else return d[x-1].." - "..d[x].." - "..d[x+1]
	end
end

return z