Module:AutomaticInfoboxItem

local p = {} local cargo = mw.ext.cargo

function p.InfoboxItem( frame ) local id = frame.args[1] or 'fu_carbon' local tables = 'item' local fields = 'name,description,category,tier,rarity,price,stackSize,twoHanded,upgradeable,wikiPage,id,tags,colonyTags' local args = { where = 'item.id="' .. id .. '"', limit = 1 }   local row = ( cargo.query( tables, fields, args or {} ) )[1] if not row then return 'Item not found: ' + mw.text.nowiki( id ); end mw.logObject( row ); local ret = '{| class="infobox"\n' -- Check if there are images that can be added automatically. local iconTitle = mw.title.new( 'Item icon ' .. id .. '.png', 6 ) if iconTitle.fileExists then ret = ret .. frame:expandTemplate{ title = 'infobox/image', args = { iconTitle.text } } end

if row.category == "block" then local blockImageTitle = mw.title.new( 'Block image ' .. id .. '.png', 6 ) if blockImageTitle.fileExists then -- TODO: display this on the same row as icon (via infobox/field) ret = ret .. frame:expandTemplate{ title = 'infobox/image', args = { blockImageTitle.text } } end end ret = ret .. frame:expandTemplate{ title = 'infobox/title', args = { row.name } } ret = ret .. frame:expandTemplate{ title = 'infobox/line', args = { row.description } } ret = ret .. frame:expandTemplate{ title = 'infobox/field', args = { 'Category', row.category } } ret = ret .. frame:expandTemplate{ title = 'infobox/field', args = { 'Tier', row.tier } } ret = ret .. frame:expandTemplate{ title = 'infobox/field', args = { 'Rarity', row.rarity } } ret = ret .. frame:expandTemplate{ title = 'infobox/field', args = { 'Price', row.price } } ret = ret .. frame:expandTemplate{ title = 'infobox/field', args = { 'Stack size', row.stackSize } } ret = ret .. frame:expandTemplate{ title = 'infobox/field/bool', args = { 'Two-handed?', row.twoHanded } } if row.upgradeable == '1' then ret = ret .. frame:expandTemplate{ title = 'infobox/field', args = { 'Upgradeable?', 'Yes' } } end -- TODO: these fields should be split into individual values and made into categories if row.tags and row.tags ~= '' then local tagsLine = '' for _, tag in ipairs( mw.text.split( row.tags, ',' ) ) do	       -- TODO: move inline CSS into TemplateStyles or something tagsLine = tagsLine .. ' ' .. tag .. ' ' end ret = ret .. frame:expandTemplate{ title = 'infobox/field', args = { 'Tags', tagsLine } } end

ret = ret .. frame:expandTemplate{ title = 'infobox/field', args = { 'Colony tags', row.colonyTags } } ret = ret .. '\n|}' return ret end

return p