Jump to content

Module:POTD transcluder

Permanently protected module
From Wikipedia, the free encyclopedia
This is the current revision of this page, as edited by Pppery (talk | contribs) at 04:56, 17 February 2024 (Protected "Module:POTD transcluder": Always cascade-protected, FPER for consistency ([Edit=Require administrator access] (indefinite) [Move=Require administrator access] (indefinite))). The present address (URL) is a permanent link to this version.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)

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
		n = string.match( wikitext, '^{{POTD protected/%d%d%d%d%-%d%d%-%d%d/{{#invoke:random|number|(%d+)}}|{{{1|{{{style|default}}}}}}}}' )
	end
	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