local p = {}
function p.infobox( f )
local args = require( 'Module:ProcessArgs' ).merge( true )
local titleObject = mw.title.getCurrentTitle()
local title = args.title or titleObject.subpageText
local subtitle = args.subtitle or ''
local template = f:getParent():getTitle():lower():gsub( 'template:', '' ):gsub( 'infobox ', '' )
local headerArea = ''
local json = {
images = {},
invimages = {},
rows = {}
}
local titleArea = args.titlearea
if not titleArea then
json.title = title
if subtitle ~= '' then
json.subtitle = subtitle
subtitle = '
' .. subtitle .. ''
end
titleArea = title .. subtitle
end
local imageArea = args.imagearea
if not imageArea and imageArea ~= 'none' then
local images = {}
local invImages = {}
local defaultImageSize = args.defaultimagesize or '150px'
local defaultImageClass = args.defaultimageclass
args.image1 = args.image1 or args.image or 'title'
args.image1size = args.image1size or args.imagesize
args.image1class = args.image1class or args.imageclass
args.image1caption = args.image1caption or args.imagecaption or ''
args.invimage1 = args.invimage1 or args.invimage or 'none'
args.group1 = args.group1 or args.group
args.group1size = args.group1size or args.groupsize
args.group1class = args.group1class or args.groupclass
args.group1caption = args.group1caption or args.groupcaption or ''
local imgCount = {}
local invImgCount = {}
local groupCount = {}
local groupImgList = {}
for k, v in pairs( args ) do
if type( k ) == 'string' then
local image, num = k:match( '^(image)(%d+)$' )
local invImage, invNum = k:match( '^(invimage)(%d+)$' )
local group, groupNum = k:match( '^(group)(%d+)$' )
local groupImg, groupImgNum = k:match( '^(%d+)-(%d+)$' )
if v:lower() ~= 'none' then
if image then
table.insert( imgCount, tonumber( num ) )
elseif invImage then
table.insert( invImgCount, tonumber( invNum ) )
elseif group then
table.insert( groupCount, tonumber( groupNum ) )
if not groupImgList['group' .. groupNum] then
groupImgList['group' .. groupNum] = {}
end
elseif groupImg then
if not groupImgList['group' .. groupImg] then
groupImgList['group' .. groupImg] = {}
end
table.insert( groupImgList['group' .. groupImg], tonumber( groupImgNum ) )
end
end
end
end
local animate
if #groupCount > 0 then
table.sort( groupCount )
local tabber = {}
for k, v in ipairs( groupCount ) do
local group = args['group' .. v]
local groupSize = args['group' .. v .. 'size'] or defaultImageSize
local groupClass = args['group' .. v .. 'class'] or defaultImageClass
local groupCaption = args['group' .. v .. 'caption'] or ''
local groupImages = {}
table.sort( groupImgList['group' .. v] )
for _, w in ipairs( groupImgList['group' .. v] ) do
local image = args[v .. '-' .. w]
local size = args[v .. '-' .. w .. 'size'] or args['*-' .. w .. 'size'] or groupSize
local class = args[v .. '-' .. w .. 'class'] or args['*-' .. w .. 'class'] or groupClass
local caption = args[v .. '-' .. w .. 'caption'] or args['*-' .. w .. 'caption'] or ''
if string.match( image, 'UNIQ%-%-gallery%-' ) then
image = image
elseif image:match( ';' ) then
if not animate then
animate = require( 'Module:Animate' ).animate
end
image = animate{ image, size, class = class }
else
json.images[#json.images + 1] = image
local altText = image .. ': Infobox image for ' .. title .. ' the ' .. template .. ' in Minecraft'
image = '[[File:' .. image .. '|' .. size .. '|class=' .. ( class or '' ) .. '|alt=' .. altText .. ']]'
end
if caption ~= '' then
caption = '
{"label": (".-"), "field": (".-")}
\n', repl )
local html = {
'