模組:首页2
外观
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