require('strict')
local p = local yesno = require('Module:Yesno')local constants =
local function makeInvokeFunc(funcName, league) return function (frame) local args = (frame.args[1] ~= nil) and frame.args or frame:getParent.args args['league'] = args['league'] or league or 'collegiate' return p[funcName](args) endend
local function stripwhitespace(text) return text:match("^%s*(.-)%s*$") end
local function load_data(args) local data_module = 'Module:PHL sports team/' .. args['league'] return mw.loadData(data_module)end
local function get_key_by_code(code, data) if (data[code] ~= nil and type(data[code])
constants.CODE_LEN) then for k,v in pairs(data) do if v[1]
local function get_icon(team, size, alt_team) local icon = '' return string.format(icon, team, size or '11px', alt_team or team)end
local function get_athlete_link(link, athl_name) if mw.title.new(link or athl_name, ).exists
local function show_empty_param(param) return mw.html.create('span'):css('color', 'red'):cssText('style'):wikitext(string.format('Value for parameter \'%s\' not provided.', param))end
local function get_link_by_evt(args, div, divLt, text, team) local evt = local mRdr = require('Module:Redirect') evt = evt[args[2]] or evt[args[3]] or evt[args['evt']] if evt
'number' and div < 3 then return mRdr.getTarget(team) else return mRdr.getTarget(text) end end if (type(div)
local function get_name_by_year(team, year) if not year then return team[1] end for k, v in pairs(team) do if mw.ustring.find(k, "%d%d%d%dthru%d%d%d%d$") then local start_year, end_year = mw.ustring.match(k, "(%d%d%d%d)thru(%d%d%d%d)$") if (tonumber(start_year) <= tonumber(year)) and (tonumber(year) <= tonumber(end_year)) then return v end end end return team[1]end
local function add_link(args, team, name, div, divLt, text) local evt_link = get_link_by_evt(args, div, divLt, team[div] or team[3], team[3]) if (type(div)
constants.SHORT) then return string.format('%s', evt_link or team[div], not p.isalias and team[args['inst']] or text) elseif (evt_link ~= nil) then return string.format('%s', evt_link, text) else return string.format('%s', text) end end return string.format('%s', evt_link or team[3], text)end
local function add_link_generic(args, team, text) local mRdr = require('Module:Redirect') local tln = team.link or get_name_by_year(team, args['season'] or args['team']) local dab = team.dab and (tln .. ' (' .. team.dab .. ')') or nil local fln = dab or tln if args['name'] then fln = team[args['name']] or dab or tln end if args['season'] then fln = args['season'] .. ' ' .. tln .. ' season' elseif args['team'] then fln = args['team'] .. ' ' .. tln .. ' team' else fln = mRdr.getTarget(fln) end return string.format('%s', fln or dab or tln, text)end
function p._main(args) local data = load_data(args) local in_team = stripwhitespace(args[1] or ) if (in_team:match('^$') ~= nil) then return show_empty_param(in_team) elseif (in_team
nil) then return error(string.format('Invalid team: %s', in_team)) end local out local divLt = if (in_div ~= constants.SHORT) then local div = in_div = div[in_div] or tonumber(in_div:match('[2-6]') or '3') if (args[3]
2) then out = p.isalias and team[in_team] or team[div['inst']] elseif (args[3]
nil) then return error('No ' .. divLt[in_div-2] .. ' team') end else out = team[7] or key or in_team end out = out:gsub("-", " - ") if yesno(args['add_link'] or 'y') then out = add_link(args, team, in_name, in_div, divLt, out) end
if yesno(args['icon'] or 'y') then local icon = get_icon(key or in_team, args['iconsize']) out = yesno(args['rt'] or 'n') and out .. constants.SPACE .. icon or icon .. constants.SPACE .. out end return outend
function p._rt(args) args['rt'] = 'y' return p._main(args)end
function p._name(args) args['icon'] = 'n' return p._main(args)end
function p._color(args) local data = load_data(args) local in_team = stripwhitespace(args[1] or ) local note = if in_team and in_team:match('[%*]$') then note = mw.ustring.gsub(in_team, '^(.-)([%*]*)$', '%2') in_team = mw.ustring.gsub(in_team, '^(.-)([%*]*)$', '%1') end if (in_team:match('^$') ~= nil) then return show_empty_param(in_team) .. note elseif (in_team
nil) then return string.format('', args['size'] or '11px') .. note end return get_icon(key or in_team, args['size'], args[2]) .. noteend
function p._generic(args) local data = load_data(args) local code, name, out = stripwhitespace(args[1] or ), args['name'] local team = data[code] if (code:match('^$') ~= nil) then return show_empty_param(code) elseif (code
if type(team)
constants.SHORT then out = team[2] or code elseif name then out = team[name] or name else out = get_name_by_year(team, args['season'] or args['team'] or args['yr']) end return add_link_generic(args, team, out)end
function p._athlete(args) local athl_1 = args['athl'] local athl_2 = args['athl2'] if athl_1
function p._athlete_bc(args) if (args['athl']
p.main = makeInvokeFunc('_main')p.rt = makeInvokeFunc('_rt')p.name = makeInvokeFunc('_name')p.color = makeInvokeFunc('_color')p.pba = makeInvokeFunc('_generic', 'PBA')p.athlete = makeInvokeFunc('_athlete_bc')
return p