Module:Team

function getGlobalDate local globalDate = mw.ext.VariablesLua.var('date') if not(globalDate and globalDate ~= '') then globalDate = mw.ext.VariablesLua.var('tournament_edate') if not(globalDate and globalDate ~= '') then globalDate = mw.ext.VariablesLua.var('tournament_sdate') if not(globalDate and globalDate ~= '') then globalDate = os.date( '%F' ) end end end return globalDate end

function getNullMessage(name) mw.log('Missing team: ' .. name) return ' No team template exists for name "' .. name .. '". ' .. '' end

function checkLegacy(frame, name, date, suffix) local check, tempOutput if date ~= nil and name ~= '' then check, tempOutput = pcall(frame.expandTemplate, frame, {title = suffix .. name:lower, args = {date}}) else check, tempOutput = pcall(frame.expandTemplate, frame, {title = suffix .. name:lower}) end if check then mw.log('Legacy Template: ' .. name) return tempOutput .. ''	else return nil end end

function getTemplate(frame, form, name, date, legacySuffix, skipOverride) date = date or getGlobalDate if not(skipOverride) then local override = require('Module:Team/override').template(form, name, date) if override then return override end end if mw.ext.TeamTemplate.teamexists(name) then return mw.ext.TeamTemplate[form](name, date) elseif mw.ext.TeamTemplate.teamexists(mw.text.trim(name)) then return mw.ext.TeamTemplate[form](mw.text.trim(name), date) .. ''	elseif mw.ext.TeamTemplate.teamexists(name:gsub("_", " ")) then return mw.ext.TeamTemplate[form](name:gsub("_", " "), date) .. ''	elseif mw.ext.TeamTemplate.teamexists(name:gsub(" ", "_")) then return mw.ext.TeamTemplate[form](name:gsub(" ", "_"), date) .. ''	else return checkLegacy(frame, name, date, legacySuffix) end end

local p = { ['team'] = function (frame, name, date) return getTemplate(frame, 'team', name, date, 'Team/') or getNullMessage(name) end,

['team2'] = function (frame, name, date) return getTemplate(frame, 'team2', name, date, 'Team2/') or getNullMessage(name) end,

['short'] = function (frame, name, date) return getTemplate(frame, 'teamshort', name, date, 'TeamShort/') or (' ' .. name .. ' (missing) ' .. '') end,

['short2'] = function (frame, name, date) return getTemplate(frame, 'team2short', name, date, 'Team2Short/') or (' (missing) ' .. name .. ' ' .. '') end,

['bracket'] = function (frame, name, date, skipOverride) return getTemplate(frame, 'teambracket', name, date, 'TeamBracket/', skipOverride) or (' Missing: ' .. name .. ' ' .. '') end,

['bracketShort'] = function (frame, name, date, skipOverride) date = date or getGlobalDate if not(skipOverride) then local override = require('Module:Team/override').template('teambracket', name, date) if override then return override end end local output if mw.ext.TeamTemplate.teamexists(name) then output = mw.ext.TeamTemplate.raw(name, date) elseif mw.ext.TeamTemplate.teamexists(mw.text.trim(name)) then output = mw.ext.TeamTemplate.raw(mw.text.trim(name), date) elseif mw.ext.TeamTemplate.teamexists(name:gsub("_", " ")) then output = mw.ext.TeamTemplate.raw(name:gsub("_", " "), date) elseif mw.ext.TeamTemplate.teamexists(name:gsub(" ", "_")) then output = mw.ext.TeamTemplate.raw(name:gsub(" ", "_"), date) else mw.log('Missing team: ' .. name) return checkLegacy(frame, name, date, 'TeamBracket/') or ' Missing: ' .. name .. ' ' .. ''		end return '  ' .. output.shortname .. ' '	end,

['icon'] = function (frame, name, date) return getTemplate(frame, 'teamicon', name, date, 'TeamIcon/') or getNullMessage(name) end,

['iconFile'] = function (frame, name, date) date = date or getGlobalDate local output = require('Module:Team/override').template('iconfile', name, date) if output then return output elseif mw.ext.TeamTemplate.teamexists(name) then output = mw.ext.TeamTemplate.raw(name, date) elseif mw.ext.TeamTemplate.teamexists(mw.text.trim(name)) then output = mw.ext.TeamTemplate.raw(mw.text.trim(name), date) elseif mw.ext.TeamTemplate.teamexists(name:gsub("_", " ")) then output = mw.ext.TeamTemplate.raw(name:gsub("_", " "), date) elseif mw.ext.TeamTemplate.teamexists(name:gsub(" ", "_")) then output = mw.ext.TeamTemplate.raw(name:gsub(" ", "_"), date) else mw.log('Missing team: ' .. name .. ' (icon)') return 'Dotalogo std.png' end return output.image end,

['part'] = function (frame, name, date) return getTemplate(frame, 'teampart', name, date, 'TeamPart/') or getNullMessage(name) end,

['page'] = function (frame, name, date) date = date or getGlobalDate local override = require('Module:Team/override').template('teampage', name, date) if override then return override elseif mw.ext.TeamTemplate.teamexists(name) then return mw.ext.TeamTemplate.teampage(name, date) elseif mw.ext.TeamTemplate.teamexists(mw.text.trim(name)) then return mw.ext.TeamTemplate.teampage(mw.text.trim(name), date) elseif mw.ext.TeamTemplate.teamexists(name:gsub("_", " ")) then return mw.ext.TeamTemplate.teampage(name:gsub("_", " "), date) elseif mw.ext.TeamTemplate.teamexists(name:gsub(" ", "_")) then return mw.ext.TeamTemplate.teampage(name:gsub(" ", "_"), date) else return name end end }

function p.get(frame) local args = require('Module:Arguments').getArgs(frame) if args[1] then return p[args[1]](frame, args[2] or '', args[3]) else return ' Invalid team template form specified. '	end end

return p