[刷新]
This is the documentation page. It should be transcluded into the main template page. See Template:Documentation for more informationThis module implements {{infobox}}
. The module should generally be invoked directly on template pages, rather than using the infobox template.
Parent arguments are automatically merged with directly passed arguments (the latter overwriting the former) and all arguments are normalised to trim whitespace and set empty arguments to nil
.
Dependencies[编辑源代码]
- Module:Animate (when using animated images)
- Module:ProcessArgs
See also[编辑源代码]
- Minecraft
{{Biome}}
{{Block}}
{{Development phase}}
{{Enchantment}}
{{Effect}}
{{Entity}}
{{Fluid}}
{{Item}}
{{ItemEntity}}
{{Structure}}
- SCP
{{Subject}}
local p = {}
function p.infobox(f)
local args = f
if f == mw.getCurrentFrame() then
args = require('Module:ProcessArgs').merge(true)
end
f = mw.getCurrentFrame()
local isSubBox = args.subbox
local title
local imageArea = args.imagearea
local subHeader = args.subheader
local footer = args.footer
if not isSubBox then
if args.title and args.title ~= 'none' then
title = args.title
local titleNode = mw.html.create('div')
:addClass('infobox-title')
:cssText(args.titlestyle)
:wikitext(title)
title = tostring(titleNode)
end
if imageArea == 'none' then
imageArea = nil
end
if not imageArea then
local images = {}
local invImages = {}
local defaultImageSize = args.defaultimagesize or '160px'
args.image1 = args.image1 or args.image
args.image1size = args.image1size or args.imagesize or defaultImageSize
args.invimage1 = args.invimage1 or args.invimage
local imgCount = {}
local invImgCount = {}
for k, v in pairs(args) do
if type(k) == 'string' then
local name, num = mw.ustring.match(k, '^(.*image)(%d+)$')
if mw.ustring.lower(v) ~= 'none' then
if name == 'image' then
table.insert(imgCount, tonumber(num))
elseif name == 'invimage' then
table.insert(invImgCount, tonumber(num))
end
end
end
end
table.sort(imgCount)
local animate = require('Module:Animate').animate
for _, v in ipairs(imgCount) do
local image = args['image' .. v]
local size = args['image' .. v .. 'size'] or defaultImageSize
if mw.ustring.match(image, ';') then
image = animate {image, size}
else
image = '[[File:' .. image .. '|' .. size .. ']]'
end
table.insert(images, '<div>' .. image .. '</div>')
end
images = table.concat(images, '\n')
if #invImgCount > 0 then
table.sort(invImgCount)
local slot = require('Module:Inventory slot').slot
for _, v in ipairs(invImgCount) do
local image = args['invimage' .. v]
if image == '----' then
table.insert(invImages, '</div><div style="padding-top:.5em">')
elseif image then
table.insert(invImages, slot {image, link = 'none', mod = args.mod})
end
end
if slot and #invImages > 0 then
invImages = '<div class="infobox-invimages"><div>' .. table.concat(invImages, '') .. '</div></div>'
else
invImages = ''
end
else
invImages = ''
end
if images ~= '' or invImages ~= '' then
imageArea = '<div class="infobox-imagearea">' .. images .. '\n' .. invImages .. '</div>'
else
imageArea = nil
end
else
imageArea = '<div class="infobox-imagearea">' .. imageArea .. '</div>'
end
if subHeader then
local subHeaderNode = mw.html.create('div')
:addClass('infobox-subheader')
:cssText(args.subheaderstyle)
:wikitext(subHeader)
subHeader = tostring(subHeaderNode)
end
if footer then
footer = '<div class="infobox-footer">' .. footer .. '</div>'
end
end
local rows = args.rows
if rows then
if isSubBox then
rows = '<div class="infobox-rows subinfobox">' .. rows .. '</div>'
else
rows = '<div class="infobox-rows">' .. rows .. '</div>'
end
end
if not (title or imageArea or subHeader or rows or footer) then
return ''
end
local styles = f:extensionTag {name = 'templatestyles', args = {src = 'Infobox/styles.css'}}
local html = {}
if not isSubBox then
html = {
'<div class="notaninfobox">',
title or '',
imageArea or '',
subHeader or '',
rows or '',
footer or '',
'</div>'
}
else
html = {rows}
end
return styles .. table.concat(html)
end
return p