Module:Infobox Item
Jump to navigation
Jump to search
Documentation for this module may be created at Module:Infobox Item/doc
--<nowiki>
local p = {}
local onmain = require('Module:Mainonly').on_main
local yesno = require('Module:Yesno')
local infobox = require('Module:Infobox')
local cleanimg = require('Module:Clean image').clean
local paramtest = require('Module:Paramtest')
function p.main(frame)
local args = frame:getParent().args
local ret = infobox.new(args)
ret:defineParams{
{ name = 'vanchor', func = { name = 'has_content', params = { 'version' }, flag = 'p' } },
{ name = 'name', func = 'has_content' },
{ name = 'image', func = imgarg },
{ name = 'creator', func = 'creator' },
}
ret:useSMWSubobject({
vanchor = 'Version anchor',
name = 'Item name'
})
ret:setMaxButtons(6)
ret:create()
ret:cleanParams()
ret:customButtonPlacement(true)
ret:defineLinks({ links = {{ 'Template:%s', 'Infobox' },
{ 'Template_talk:%s', 'Talk page' }}, colspan = '2' })
ret:defineName('Infobox Item')
ret:addClass('tsw-infobox plainlinks')
ret:addButtonsCaption()
-- PARAMETER: image
ret:addRow{
{ tag = 'argd', content = 'image', class = 'infobox-image', colspan = '2' }
}
-- PARAMETER: name
ret:addRow{
{ tag = 'argh', content = 'name', class = 'infobox-header', colspan = '2' }
}
-- PARAMETER: creator
ret:addRow{
{ tag = 'th', content = 'Creator' },
{ tag = 'argd', content = 'creator' }
}
ret:finish()
if onmain() then
local a1 = ret:param('all')
local a2 = ret:categoryData()
ret:wikitext(addcategories(a1, a2))
end
return ret:tostring()
end
function imgarg(arg)
if infobox.isDefined(arg) then
return cleanimg{ file = arg, width = 300, height = 300 }
end
return nil
end
function addcategories(args, catargs)
local ret = { 'Items' }
local cat_map = {
-- Added if the parameter has content
defined = {},
-- Added if the parameter has no content
notdefined = {
image = 'Needs image'
}
}
for n, v in pairs(cat_map.defined) do
if catargs[n] and catargs[n].one_defined then
table.insert(ret, v)
end
end
for n, v in pairs(cat_map.notdefined) do
if catargs[n] and catargs[n].all_defined == false then
table.insert(ret, v)
end
end
for i, v in ipairs(ret) do
if (v ~= '') then
ret[i] = string.format('[[Category:%s]]', v)
end
end
return table.concat(ret, '')
end
return p
--</nowiki>