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], args[3] ) elseif type == 'i' then return query( 'items', args[2], args[3] ) elseif type == 'u' then return query( 'units', args[2], args[3] ) elseif type == 'a' then assert( args[4], i18n.error.incompleteInput )

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

return p