Module:Infobox: Difference between revisions
CaptainChris (talk | contribs) No edit summary Tag: Reverted |
CaptainChris (talk | contribs) 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 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 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 group then | elseif group then | ||
table.insert(groupCount, tonumber(groupNum)) | table.insert(groupCount, tonumber(groupNum)) | ||
groupImgList['group' .. groupNum] = groupImgList['group' .. groupNum] or {} | |||
elseif groupImg then | elseif groupImg then | ||
groupImgList['group' .. groupImg] = groupImgList['group' .. groupImg] or {} | |||
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 | ||
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 | ||
image = '' | |||
end | |||
if image ~= '' then | |||
table.insert(groupImages, image) | |||
end | end | ||
end | end | ||
end | end | ||
table.insert( | table.insert(tabber, '|-|' .. group .. '=\n' .. table.concat(groupImages, '<br />')) | ||
end | end | ||
table.insert( | table.insert(images, f:extensionTag('tabber', table.concat(tabber, '\n'))) | ||
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 .. ']]' | ||
image = | |||
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 | ||
image = '' | |||
end | end | ||
| Line 207: | Line 130: | ||
end | end | ||
images = table.concat(images, '') | if #images > 0 then | ||
imageArea = table.concat(images, '<br />') | |||
else | else | ||
imageArea = 'none' | imageArea = 'none' | ||
| Line 216: | Line 137: | ||
end | end | ||
if imageArea | if not imageArea or imageArea == 'none' then | ||
imageArea = | imageArea = args.grouparea or '' | ||
end | |||
local extraText = args.extratext | |||
if not extraText or extraText == 'none' then | |||
extraText = '' | |||
end | end | ||
local | local html = {} | ||
table.insert(html, '{| class="infobox"') | |||
table.insert(html, '|-') | |||
table.insert(html, '! colspan="2" class="infobox-title" | ' .. title) | |||
if imageArea ~= '' then | |||
table.insert(html, '|-') | |||
table.insert(html, '| colspan="2" class="infobox-imagearea animated-container" | ' .. imageArea) | |||
end | end | ||
if extraText ~= '' then | |||
table.insert(html, '|-') | |||
table.insert(html, '| colspan="2" class="infobox-extratext" | ' .. extraText) | |||
end | |||
if | if args.rows and args.rows ~= '' then | ||
table.insert(html, args.rows) | |||
end | end | ||
json. | 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 | |||
table.insert(html, '|}') | |||
json.title = title | |||
return table.concat(html, '') | return f:preprocess(table.concat(html, '\n')) | ||
end | end | ||
return p | return p | ||