Jump to content

Module:Dashboard entry

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Pppery (talk | contribs) at 23:44, 23 April 2019 (Create module to implement Wikipedia:Dashboard). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)

local p = {}
--[[ Unfortunately, the bot that this is replacing uses "prop=sections", which isn't accessible to Lua.
Therefore, we have to parse the page manuallly ]]--
function p.main(frame) 
	local page = frame.args[1]
	local pipe = frame.args[2]
	local content = mw.title.new(page):getContent()
	local sections = content:gmatch("== *([^=]-) *==")
	local count = 0
	local output = string.format("{{Dashboard grouping|1='''[[%s|%s]]''' (<count> threads)'''<div style='font-size:85%; padding-left:1.5em;'>''Most recent:''",
		page, pipe)
	for sect in sections do
		output = output .. string.format("\n* [[%s#%|%s]]", page, mw.uri.anchorEncode(sect), sect)
		count = count + 1
		if count == 3 then
			output = output .. "\n</div>}}\n<div style=\"padding-left:3em;\">"
		end
	end
	if count < 3 then
		output = output .. "</div>}} {{end}}"
	else
		output = output .. "</div>\n{{end}}"
	end
	return frame:preprocess(output.replace("<count>",count))
end