Module:Team icon

local p = {} local cargo = mw.ext.cargo local getArgs = require('Module:Arguments').getArgs

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 = 'File: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 = 'File:' .. cargo_output['icon'] else local success, result = pcall(function(file) return mw.title.new(file).fileExists end, 'File:Team icon ' .. args[1] .. '.png') if success == true and result == true then icon = 'File:Team icon ' .. args[1] .. '.png' end end return  .. size .. '|link=' .. args[1] .. '|' .. name ..  end

return p