Module:POTD transcluder

MyWikiBiz, Author Your Legacy — Wednesday November 27, 2024
Jump to navigationJump to search

This module will transclude a POTD template, such as Template:POTD/2024-11-27 or Template:POTD protected/2024-11-27, detecting when that day has multiple pictures and transcluding all of the options. Its primary purpose is to be used in conjunction with a cascade-protected page to ensure that all of the multiple pictures are cascade-protected during the time that the POTD is on the main page, rather than only the one that was randomly chosen the last time the main page was reparsed.

Usage

{{#invoke:POTD transcluder|transclude|POTD template page title}}


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