跳转到内容

模組:首页3

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

这是本页的一个历史版本,由SunAfterRain留言 | 贡献2020年7月2日 (四) 11:11编辑。这可能和当前版本存在着巨大的差异。

local z = {}

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

function z.listall( frame )
	local args
	local wt
	if frame == mw.getCurrentFrame() then
        args = frame.args or {}
    else
        args = frame or {}
        if type(args) ~= type({}) then args = {frame} end
    end
	local d = getItems(title)
	for i, page in ipairs(d) do
		if wt == '' then
			wt = page
		else
			wt = wt .. ',' .. page
		end
	end
	return wt
end

function z.ramdomtitle( frame )
	local args
	local wt
	if frame == mw.getCurrentFrame() then
        args = frame.args or {}
    else
        args = frame or {}
        if type(args) ~= type({}) then args = {frame} end
    end
	local d = getItems(title)
	local n = 0
	for i, page in ipairs(d) do
		n = n +1
	end
	return d[require('Module:Random').number({1, n})]
end

return z