Module:Infobox

Jump to navigation Jump to search

Documentation for this module may be created at Module:Infobox/doc

-- Do not edit, thank you
local getArgument = require('Module:Arguments').getArgument

local p = {}

function p.Main(frame)
	local oArgs = frame:getParent().args
	local args = {}
	local maxArgs = 0
	local i = 0
	
	for k, v in pairs(oArgs) do
		v = v:match('^%s*(.-)%s*$')
		if v ~= '' then
			args[k] = v
		end
	end
	
	for k in pairs(args) do
		if type(k) == "string" then -- match function does not auto-convert integers apparently
			local n = k:match("^label(%d+)$") or k:match("^desc(%d+)$")
			if n then
    			n = tonumber(n)
    			if n > maxArgs then
    				maxArgs = n
    			end
			end
		end
	end
	
	
	local infobox = '{|class="infobox"'
	
	if args["title"] then
		local storeVal = args["title"]
		infobox = infobox .. '\n|class="title-cell" colspan=2|' .. storeVal .. '\n|-'
	end
	if args["alttitle"] then
		local storeVal = args["alttitle"]
		infobox = infobox .. '\n|class="alt-title-cell" colspan=2|' .. storeVal .. '\n|-'
	end
	
	-- Media handling
	if args["image"] then
		if string.sub(args["image"], 1, 4) == '<div' or string.sub(args["image"], 1, 4) == '[[Fi' then
			local storeVal = args["image"]
			infobox = infobox .. '\n|class="media-group-cell" colspan=2|' .. storeVal .. '\n|-'
		else
			local storeVal = args["image"]
			infobox = infobox .. '\n|class="media-group-cell" colspan=2|[[File:' .. storeVal .. '|270x350px]]\n|-'
			mw.ext.seo.set({ image = storeVal })
		end
	end
	if args["imagecover"] then
		if string.sub(args["imagecover"], 1, 4) == '<div' or string.sub(args["imagecover"], 1, 4) == '[[Fi' then
			local storeVal = args["imagecover"]
			infobox = infobox .. '\n|class="media-group-cell" colspan=2|' .. storeVal .. '\n|-'
		else
			local storeVal = args["imagecover"]
			infobox = infobox .. '\n|class="media-group-cell" colspan=2|[[File:' .. storeVal .. '|270x350px]]\n|-'
			mw.ext.seo.set({ image = storeVal })
		end
	end
	if args["imagepage"] then
		if string.sub(args["imagepage"], 1, 4) == '<div' or string.sub(args["imagepage"], 1, 4) == '[[Fi' then
			local storeVal = args["imagepage"]
			infobox = infobox .. '\n|class="media-group-cell" colspan=2|' .. storeVal .. '\n|-'
		else
			local storeVal = args["imagepage"]
			infobox = infobox .. '\n|class="media-group-cell" colspan=2|[[File:' .. storeVal .. '|270x350px]]\n|-'
			mw.ext.seo.set({ image = storeVal })
		end
	end
	if args["imagemap"] then
		if string.sub(args["imagemap"], 1, 4) == '<div' or string.sub(args["imagemap"], 1, 4) == '[[Fi' then
			local storeVal = args["imagemap"]
			infobox = infobox .. '\n|class="media-group-cell" colspan=2|' .. storeVal .. '\n|-'
		else
			local storeVal = args["imagemap"]
			infobox = infobox .. '\n|class="media-group-cell" colspan=2|[[File:' .. storeVal .. '|270x350px]]\n|-'
		end
	end
	if args["imagelogo"] then
		local storeVal = args["imagelogo"]
		infobox = infobox .. '\n|class="media-group-cell media-group-logo" colspan=2|[[File:' .. storeVal .. '|270x130px]]\n|-'
	end
	if args["seoimage"] then
		mw.ext.seo.set({ image = args["seoimage"] })
	end
	
	repeat -- main loop for labels and descriptions
		if args['label' .. i+1] and args['desc' .. i+1] then
			local storeLabel = args['label' .. i+1]
			local storeDesc = args['desc' .. i+1]
			infobox = infobox .. '\n|class="item-cell item-cell-label"|' .. storeLabel .. '\n|class="item-cell item-cell-description"|' .. storeDesc .. '\n|-'
		end
		i = i + 1
	until i > maxArgs
	
	if args["theme"] then -- I'd probably want to make this a loop of 'fulldesc' iteratives at some point but we really only use one of these at the moment
		local storeVal = args["theme"]
		infobox = infobox .. '\n|class="item-cell item-cell-full-description" colspan=2|' .. storeVal .. '\n|-'
	end
	
	infobox = infobox .. '\n|}'
	
	if args['displaytitle'] then
		infobox = infobox .. frame:callParserFunction('DISPLAYTITLE', args['displaytitle'], 'noreplace')
	end
	
	if args["image"] then
		if string.sub(args["image"], 4, 8) == '`UNIQ' then
				infobox = infobox .. '[[Category:Infoboxes using old gallery format]]'
		end
	end
	if args["imagecover"] then
		if string.sub(args["imagecover"], 4, 8) == '`UNIQ' then
				infobox = infobox .. '[[Category:Infoboxes using old gallery format]]'
		end
	end
	if args["imagelogo"] then
		if string.sub(args["imagelogo"], 4, 8) == '`UNIQ' then
				infobox = infobox .. '[[Category:Infoboxes using old gallery format]]'
		end
	end
	if args["imagemap"] then
		if string.sub(args["imagemap"], 4, 8) == '`UNIQ' then
				infobox = infobox .. '[[Category:Infoboxes using old gallery format]]'
		end
	end
	if args["imagepage"] then
		if string.sub(args["imagepage"], 4, 8) == '`UNIQ' then
				infobox = infobox .. '[[Category:Infoboxes using old gallery format]]'
		end
	end
	
	return infobox
end

return p