Module:Infobox: Difference between revisions

No edit summary
Tag: Reverted
No edit summary
Tag: Reverted
Line 3: Line 3:
function p.infobox(f)
function p.infobox(f)
local args = require('Module:Arguments').getArgs(f)
local args = require('Module:Arguments').getArgs(f)
local titleObject = mw.title.getCurrentTitle()
local titleObject = mw.title.getCurrentTitle()
local title = args.title or titleObject.baseText
local title = args.title or titleObject.baseText
Line 17: Line 16:
if not imageArea and imageArea ~= 'none' then
if not imageArea and imageArea ~= 'none' then
local images = {}
local images = {}
local defaultImageSize = args.defaultimagesize or '150px'
local defaultImageSize = args.defaultimagesize or '150px'
local defaultImageClass = args.defaultimageclass
local defaultImageClass = args.defaultimageclass
Line 24: Line 22:
args.image1size = args.image1size or args.imagesize
args.image1size = args.image1size or args.imagesize
args.image1class = args.image1class or args.imageclass
args.image1class = args.image1class or args.imageclass
args.group1 = args.group1 or args.group
args.group1 = args.group1 or args.group
args.group1size = args.group1size or args.groupsize
args.group1size = args.group1size or args.groupsize
Line 30: Line 27:


local imgCount = {}
local imgCount = {}
local invImgCount = {}
local groupCount = {}
local groupCount = {}
local groupImgList = {}
local groupImgList = {}
Line 37: Line 33:
if type(k) == 'string' and type(v) == 'string' then
if type(k) == 'string' and type(v) == 'string' then
local image, num = k:match('^(image)(%d+)$')
local image, num = k:match('^(image)(%d+)$')
local invImage, invNum = k:match('^(invimage)(%d+)$')
local group, groupNum = k:match('^(group)(%d+)$')
local group, groupNum = k:match('^(group)(%d+)$')
local groupImg, groupImgNum = k:match('^(%d+)-(%d+)$')
local groupImg, groupImgNum = k:match('^(%d+)-(%d+)$')
Line 44: Line 39:
if image then
if image then
table.insert(imgCount, tonumber(num))
table.insert(imgCount, tonumber(num))
elseif invImage then
table.insert(invImgCount, tonumber(invNum))
elseif group then
elseif group then
table.insert(groupCount, tonumber(groupNum))
table.insert(groupCount, tonumber(groupNum))
 
groupImgList['group' .. groupNum] = groupImgList['group' .. groupNum] or {}
if not groupImgList['group' .. groupNum] then
groupImgList['group' .. groupNum] = {}
end
 
elseif groupImg then
elseif groupImg then
if not groupImgList['group' .. groupImg] then
groupImgList['group' .. groupImg] = groupImgList['group' .. groupImg] or {}
groupImgList['group' .. groupImg] = {}
end
 
table.insert(groupImgList['group' .. groupImg], tonumber(groupImgNum))
table.insert(groupImgList['group' .. groupImg], tonumber(groupImgNum))
end
end
Line 77: Line 61:
local groupSize = args['group' .. v .. 'size'] or defaultImageSize
local groupSize = args['group' .. v .. 'size'] or defaultImageSize
local groupClass = args['group' .. v .. 'class'] or defaultImageClass
local groupClass = args['group' .. v .. 'class'] or defaultImageClass
local groupImages = {}
local groupImages = {}


Line 88: Line 71:
local class = args[v .. '-' .. w .. 'class'] or groupClass
local class = args[v .. '-' .. w .. 'class'] or groupClass


if string.match(image, 'UNIQ%-%-gallery%-') then
if image and string.match(image, 'UNIQ%-%-gallery%-') then
image = image
image = image
 
elseif image and image:match(';') then
elseif image:match(';') then
if not animate then
if not animate then
animate = require('Module:Animate').animate
animate = require('Module:Animate').animate
end
end
 
image = animate{image, size, class = class}
image = animate{
elseif image then
image,
json.images[#json.images + 1] = image
size,
local altText = image .. ': Infobox image for ' .. title .. ' the ' .. template .. '.'
class = class
image = '[[File:' .. image .. '|' .. size .. '|class=' .. (class or '') .. '|alt=' .. altText .. ']]'
}
 
else
else
json.images[#json.images + 1] = image
image = ''
end


local altText =
if image ~= '' then
image ..
table.insert(groupImages, image)
': Infobox image for ' ..
title ..
' the ' ..
template ..
'.'
 
image =
'[[File:' ..
image ..
'|' ..
size ..
'|class=' ..
(class or '') ..
'|alt=' ..
altText ..
']]'
end
end
table.insert(groupImages, image)
end
end
end
end


table.insert(
table.insert(tabber, '|-|' .. group .. '=\n' .. table.concat(groupImages, '<br />'))
tabber,
'|-|' .. group .. '=' .. table.concat(groupImages, '')
)
end
end


table.insert(
table.insert(images, f:extensionTag('tabber', table.concat(tabber, '\n')))
images,
f:extensionTag('tabber', table.concat(tabber, ''))
)
end
end


Line 153: Line 110:
if #groupCount == 0 and imageTitle and imageTitle.exists then
if #groupCount == 0 and imageTitle and imageTitle.exists then
json.images[#json.images + 1] = title .. '.png'
json.images[#json.images + 1] = title .. '.png'
 
local altText = title .. '.png: Infobox image for ' .. title .. ' the ' .. template .. '.'
local altText =
image = '[[File:' .. title .. '.png|' .. size .. '|class=' .. (class or '') .. '|alt=' .. altText .. ']]'
title ..
'.png: Infobox image for ' ..
title ..
' the ' ..
template ..
'.'
 
image =
'[[File:' ..
title ..
'.png|' ..
size ..
'|class=' ..
(class or '') ..
'|alt=' ..
altText ..
']]'
else
else
image = ''
image = ''
end
end
 
elseif image and string.match(image, 'UNIQ%-%-gallery%-') then
elseif string.match(image, 'UNIQ%-%-gallery%-') then
image = image
image = image
 
elseif image then
json.images[#json.images + 1] = image
local altText = image .. ': Infobox image for ' .. title .. ' the ' .. template .. '.'
image = '[[File:' .. image .. '|' .. size .. '|class=' .. (class or '') .. '|alt=' .. altText .. ']]'
else
else
json.images[#json.images + 1] = image
image = ''
 
local altText =
image ..
': Infobox image for ' ..
title ..
' the ' ..
template ..
'.'
 
image =
'[[File:' ..
image ..
'|' ..
size ..
'|class=' ..
(class or '') ..
'|alt=' ..
altText ..
']]'
end
end


Line 207: Line 130:
end
end


images = table.concat(images, '')
if #images > 0 then
 
imageArea = table.concat(images, '<br />')
if images ~= '' then
imageArea = images
else
else
imageArea = 'none'
imageArea = 'none'
Line 216: Line 137:
end
end


if imageArea and imageArea ~= 'none' then
if not imageArea or imageArea == 'none' then
imageArea =
imageArea = args.grouparea or ''
'<div class="infobox-imagearea animated-container">' ..
end
imageArea ..
'</div>'
else
local groupArea = args.grouparea


if groupArea then
local extraText = args.extratext
imageArea = groupArea
 
else
if not extraText or extraText == 'none' then
imageArea = ''
extraText = ''
end
end
end


local extraText = args.extratext
local html = {}
 
table.insert(html, '{| class="infobox"')


if extraText and extraText ~= 'none' then
table.insert(html, '|-')
json.extratext = extraText
table.insert(html, '! colspan="2" class="infobox-title" | ' .. title)


extraText =
if imageArea ~= '' then
'<div class="infobox-extratext">' ..
table.insert(html, '|-')
extraText ..
table.insert(html, '| colspan="2" class="infobox-imagearea animated-container" | ' .. imageArea)
'</div>'
else
extraText = ''
end
end


local footer = args.footer
if extraText ~= '' then
table.insert(html, '|-')
table.insert(html, '| colspan="2" class="infobox-extratext" | ' .. extraText)
end


if footer then
if args.rows and args.rows ~= '' then
json.footer = footer
table.insert(html, args.rows)
footer = '|-\n| class="infobox-footer" colspan="2" | ' .. footer
else
footer = ''
end
end


json.title = title
if args.footer and args.footer ~= '' then
json.footer = args.footer
table.insert(html, '|-')
table.insert(html, '| colspan="2" class="infobox-footer" | ' .. args.footer)
end


local rows = mw.getCurrentFrame():preprocess(args.rows or '')
table.insert(html, '|}')


local html = {
json.title = title
'<div class="infobox">',
'<div class="infobox-title">' .. title .. '</div>',
imageArea .. extraText,
'{| class="infobox-rows" cellspacing="1" cellpadding="4"',
rows,
footer,
'|}',
'</div>'
}


return table.concat(html, '')
return f:preprocess(table.concat(html, '\n'))
end
end


return p
return p