m (Bug fixes) |
mNo edit summary |
||
Line 27: | Line 27: | ||
function p.main( frame ) |
function p.main( frame ) |
||
local args = getArgs( frame, { wrappers = "Template:Show" } ) |
local args = getArgs( frame, { wrappers = "Template:Show" } ) |
||
− | return p._main( |
+ | return p._main( args ) |
end |
end |
||
Revision as of 17:36, 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( frame )
local args = getArgs( frame, { wrappers = "Template:Show" } )
mw.logObject(args)
end
return p