Jump to content

Module:POTD transcluder

Permanently protected module
From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Anomie (talk | contribs) at 13:05, 11 July 2019 (Anomie moved page Module:User:Anomie/POTD transcluder to Module:POTD transcluder without leaving a redirect: Moving out of userspace, see WT:POTD#Use of Module:Random may be problematic). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

local p = {}

function p.transclude( frame )
	local page = frame.args[1] or error( 'No page was specified' )
	local wikitext = mw.title.new( page ):getContent()
	if wikitext == nil then
		return '[[:' .. page .. ']] does not exist'
	end
	
	local n = string.match( wikitext, '^{{POTD/%d%d%d%d%-%d%d%-%d%d/{{#invoke:random|number|(%d+)}}|{{{1|{{{style|default}}}}}}}}' )
	if n == nil then
		return frame:expandTemplate{ title = page, args = { 'row' } }
	end
	
	local t = {}
	for i = 1, tonumber( n ) do
		t[i] = frame:expandTemplate{ title = page .. '/' .. i, args = { 'row' } }
	end
	return table.concat( t, "\n" )
end

return p