Module:Show

local p = {}

local cargoQuery = mw.ext.cargo.query local getArgs = require( 'Module:Arguments' ).getArgs

local i18n = { error = { incompleteInput = 'Missing or incomplete input' }, stringLowerFunc = string.lower -- Change to mw.ustring.lower on wikis using non-latin characters. }

local function preprocessProperty( property ) property = i18n.stringLowerFunc( property ) property = property:gsub( ' ', '_' ) return property end

local function query( table, page, property ) property = preprocessProperty( property ) return cargoQuery( table, property, {   where = string.format( '_pageName="%s"', page ),    groupBy = '_pageID'  } )[1][property] end

function p.main( frame ) local args = getArgs( frame, { wrappers = { 'Template:Show' } } ) return p._main( args ) end

function p._main( args ) assert( args[1] and args[2] and args[3], i18n.error.incompleteInput ) local type = i18n.stringLowerFunc( args[1] ) if type == 'h' then return query( 'heroes', args[2], args[3] ) elseif type == 't' then return query( 'talents', args[2] .. '/Talents', args[3] ) --elseif type == 'i' then --old Show Items code --return query( 'items', args[2], args[3] ) elseif type == 'i' then assert( args[3], i18n.error.incompleteInput )

local property = preprocessProperty( args[3] ) if property:find( 'bonus' ) then -- can't figure what to do here. return cargoQuery( 'items_bonustraits', property, {       where = string.format( 'title="%s"', args[2], args[3] ),        groupBy = 'title'      } )[1][property] else return cargoQuery( 'items', property, {       where = string.format( 'title="%s"', args[2], args[3] ),        groupBy = 'title'      } )[1][property] end

elseif type == 'u' then return query( 'units', args[2], args[3] ) elseif type == 'c' then return query( 'camps', args[2], args[3] ) elseif type == 'a' then assert( args[4], i18n.error.incompleteInput )

local property = preprocessProperty( args[4] ) if property:find( 'value%d+_aghs' ) or property:find( 'value%d+_shard' ) then return cargoQuery( 'abilities_aghstraits', property, {       where = string.format( 'uid="%s&%s"', args[2], args[3] ),        groupBy = 'uid'      } )[1][property] elseif property:find( 'trait' ) or property:find( 'value' ) then return cargoQuery( 'abilities_traits', property, {       where = string.format( 'uid="%s&%s"', args[2], args[3] ),        groupBy = 'uid'      } )[1][property] elseif property:find( 'buff' ) or property:find( 'debuff' ) then return cargoQuery( 'abilities_buffs', property, {       where = string.format( 'uid="%s&%s"', args[2], args[3] ),        groupBy = 'uid'      } )[1][property] else return cargoQuery( 'abilities', property, {       where = string.format( 'uid="%s&%s"', args[2], args[3] ),        groupBy = 'source, title'      } )[1][property] end end end

return p