Overwatch Wiki
No edit summary
mNo edit summary
Line 12: Line 12:
   
 
local function preprocessProperty( property )
 
local function preprocessProperty( property )
property = i18n.stringLowerFunc( property )
+
--property = i18n.stringLowerFunc( property )
property = property:gsub( ' ', '_' )
+
--property = property:gsub( ' ', '_' )
 
return property
 
return property
 
end
 
end

Revision as of 17:28, 1 May 2020

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

function p.debug( args )
  mw.log("Log")
  mw.logObject(args)

end

return p