@DeletedUser41170185 (talk | contribs) m (variable names ...) |
@DeletedUser41170185 (talk | contribs) mNo edit summary |
||
(32 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
⚫ | |||
⚫ | |||
local p = {} |
local p = {} |
||
⚫ | |||
+ | local fileExists = require('Module:FileExists') |
||
⚫ | |||
+ | local mFileLink = require('Module:File link')._main |
||
− | function p.main( frame ) |
||
− | local args = frame:getParent().args |
||
⚫ | |||
⚫ | |||
− | function p. |
+ | function p.main(frame) |
+ | local args = getArgs(frame, { |
||
⚫ | |||
+ | wrappers = { |
||
⚫ | |||
+ | 'Template:Team icon' |
||
− | |||
+ | } |
||
− | if pcall( p.cargo, args[1] ) then |
||
+ | }) |
||
− | icon = p.cargo( args[1] ) |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
− | |||
− | return '[[' .. icon .. '|' .. size .. '|link=' .. args[1] .. ']]' |
||
end |
end |
||
− | function p. |
+ | function p._main(args) |
+ | assert(args[1], 'Check your input') |
||
⚫ | |||
+ | |||
+ | local name = args[1] |
||
⚫ | |||
⚫ | |||
+ | |||
+ | -- Attempt to get the data through Cargo. |
||
+ | -- _pageName matches are prioritized over matches in the names table. |
||
+ | -- If multiple teams have the same name in their names table the first one is used. |
||
⚫ | |||
+ | if not cargo_output then |
||
+ | cargo_output = cargo.query( 'professional_teams', 'icon, name', { where='names HOLDS "' .. args[1] .. '"', groupBy='_pageID' } )[1] |
||
⚫ | |||
+ | |||
+ | if cargo_output and cargo_output['icon'] ~= '' then |
||
+ | name = cargo_output['name'] |
||
+ | icon = cargo_output['icon'] |
||
+ | else |
||
⚫ | |||
⚫ | |||
+ | end |
||
⚫ | |||
+ | |||
+ | return mFileLink{ |
||
+ | file = icon, |
||
+ | size = size, |
||
+ | link = args[1], |
||
+ | alt = name |
||
+ | } |
||
end |
end |
||
+ | |||
return p |
return p |
Latest revision as of 20:36, 17 May 2018
▶️
Planeshift.
The documentation for this module can be found at Template:Team icon.
You may be forwarded to another wiki language, in case a translation is not available.
Dependencies
local p = {}
local cargo = mw.ext.cargo
local fileExists = require('Module:FileExists')
local getArgs = require('Module:Arguments').getArgs
local mFileLink = require('Module:File link')._main
function p.main(frame)
local args = getArgs(frame, {
wrappers = {
'Template:Team icon'
}
})
return p._main(args)
end
function p._main(args)
assert(args[1], 'Check your input')
local name = args[1]
local size = args[2] or '40px'
local icon = 'Team icon Default.png'
-- Attempt to get the data through Cargo.
-- _pageName matches are prioritized over matches in the names table.
-- If multiple teams have the same name in their names table the first one is used.
local cargo_output = cargo.query( 'professional_teams', 'icon, name', { where='_pageName="' .. args[1] .. '"', groupBy='_pageID' } )[1]
if not cargo_output then
cargo_output = cargo.query( 'professional_teams', 'icon, name', { where='names HOLDS "' .. args[1] .. '"', groupBy='_pageID' } )[1]
end
if cargo_output and cargo_output['icon'] ~= '' then
name = cargo_output['name']
icon = cargo_output['icon']
else
if fileExists('File:Team icon ' .. args[1] .. '.png') then
icon = 'Team icon ' .. args[1] .. '.png'
end
end
return mFileLink{
file = icon,
size = size,
link = args[1],
alt = name
}
end
return p