m (Voltando 2 versões atrás) |
(atualização) |
||
(Há 8 revisões intermédias de 2 utilizadores que não estão a ser apresentadas) | |||
Linha 1: | Linha 1: | ||
local p = {} |
local p = {} |
||
+ | |||
− | local |
+ | local cargoQuery = mw.ext.cargo.query |
− | local getArgs = require(' |
+ | local getArgs = require( 'Módulo:Arguments' ).getArgs |
local i18n = { |
local i18n = { |
||
error = { |
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( ' ', '_' ) |
||
⚫ | |||
+ | end |
||
− | local function query(table, page, property) |
+ | local function query( table, page, property ) |
− | property = |
+ | property = preprocessProperty( property ) |
− | return |
+ | return cargoQuery( table, property, { |
+ | where = string.format( '_pageName="%s"', page ), |
||
+ | groupBy = '_pageID' |
||
+ | } )[1][property] |
||
end |
end |
||
− | function p.main(frame) |
+ | function p.main( frame ) |
− | local args = getArgs(frame, { |
+ | local args = getArgs( frame, { wrappers = { 'Template:Show' } } ) |
+ | return p._main( args ) |
||
− | wrappers = { |
||
− | 'Template:Show' |
||
− | } |
||
− | }) |
||
⚫ | |||
end |
end |
||
− | function p._main(args) |
+ | function p._main( args ) |
− | assert(args[1] and args[2] and args[3], i18n.error. |
+ | assert( args[1] and args[2] and args[3], i18n.error.incompleteInput ) |
− | local type = |
+ | local type = i18n.stringLowerFunc( args[1] ) |
if type == 'h' then |
if type == 'h' then |
||
− | return query('heroes', args[2], args[3]) |
+ | return query( 'heroes', args[2], args[3] ) |
elseif type == 't' then |
elseif type == 't' then |
||
− | return query('talents', args[2], args[3]) |
+ | return query( 'talents', args[2] .. '/Talentos', args[3] ) |
elseif type == 'i' then |
elseif type == 'i' then |
||
− | return query('items', args[2], args[3]) |
+ | return query( 'items', args[2], args[3] ) |
elseif type == 'u' then |
elseif type == 'u' then |
||
− | return query('units', args[2], args[3]) |
+ | return query( 'units', args[2], args[3] ) |
+ | elseif type == 'c' then |
||
+ | return query( 'camps', args[2], args[3] ) |
||
elseif type == 'a' then |
elseif type == 'a' then |
||
− | assert(args[4], i18n.error. |
+ | assert( args[4], i18n.error.incompleteInput ) |
+ | |||
− | args[4] = string.gsub(string.lower(args[4]), ' ', '_') |
||
+ | local property = preprocessProperty( args[4] ) |
||
− | |||
− | if |
+ | if property:find( 'trait' ) or property:find( 'value' ) then |
− | return |
+ | return cargoQuery( 'abilities_traits', property, { |
+ | where = string.format( 'uid="%s&%s"', args[2], args[3] ), |
||
⚫ | |||
+ | groupBy = 'uid' |
||
− | return cargo.query('abilities_buffs', args[4], { where='_pageName LIKE "' .. args[2] .. '%" AND title="' .. args[3] .. '"', groupBy='_pageName, title' })[1][args[4]] |
||
+ | } )[1][property] |
||
⚫ | |||
+ | return cargoQuery( 'abilities_buffs', property, { |
||
+ | where = string.format( 'uid="%s&%s"', args[2], args[3] ), |
||
+ | groupBy = 'uid' |
||
+ | } )[1][property] |
||
else |
else |
||
+ | return cargoQuery( 'abilities', property, { |
||
− | return cargo.query('abilities', args[4], { where='source="' .. args[2] .. '" AND title="' .. args[3] .. '"', groupBy='source, title' })[1][args[4]] |
||
+ | where = string.format( 'uid="%s&%s"', args[2], args[3] ), |
||
+ | groupBy = 'source, title' |
||
+ | } )[1][property] |
||
end |
end |
||
end |
end |
||
end |
end |
||
− | |||
return p |
return p |
Edição atual desde as 17h58min de 21 de maio de 2019
▶️
Planeshift.
A documentação deste módulo pode ser encontrada em Predefinição:Show.
Você pode ser redirecionado para uma wiki em outro idioma, se de não houver tradução disponível.
local p = {}
local cargoQuery = mw.ext.cargo.query
local getArgs = require( 'Módulo: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] .. '/Talentos', 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 == '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( '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