Module:Show

From Overwatch Wiki
Jump to: navigation, search

Documentation for this module may be created at Module:Show/doc

local p = {}

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

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

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 == 'c' then
     local property = args[3]
     return cargoQuery( 'Characters', property, {
        where = string.format( '_pageName="%s"', args[2] )
      } )[1][property]
  elseif type == 'a' then
     local property = args[3]
     return cargoQuery( 'Abilities', property, {
        where = string.format( 'ability_name="%s"', args[2] )
      } )[1][property]
  end
end

return p