跳转到内容

模組:首页3

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

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

local z = {}

function getItems(args, onlytitle)
	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
			if onlytitle then
				m = m:gsub('^%:', '')
					:gsub('(.*)%|.*', '%1')
			end
			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
    else
        args = frame
        if type(args) ~= type({}) then args = {frame} end
    end
	local d = getItems(args)
	for i, page in ipairs(d) do
		wt = wt .. ']]-[[' .. page
	end
	return '[[' .. wt .. ']]'
end

function z.ramdomtitle( frame )
	local args
	local wt
	if frame == mw.getCurrentFrame() then
        args = frame.args
    else
        args = frame
        if type(args) ~= type({}) then args = {frame} end
    end
	local d = getItems(args, true)
	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