Module:Infobox/Player

local lang = mw.getLanguage('en') local Team = require('Module:Team').team local Role = require('Module:Role').role --local Champion = require('Module:Champion').champion local Region = require('Module:Region').region local m_country = require('Module:Country') local social = require('Module:Infobox/Social') local teamhist = require('Module:Infobox/TeamHist') local util_infobox = require('Module:InfoboxUtil') local util_html = require('Module:HTMLUtil') local util_cargo = require('Module:CargoUtil') local util_dpl = require('Module:DPLUtil') local util_table = require('Module:TableUtil')

local NOIMAGE = 'Unknown Infobox Image - Player.png'

local LAYOUT = { tabs = 'PlayerTabsHeader', sections = { 'Background Information', 'Competitive', 'Social Media & Links', 'Team History' }, contents = { { 'Name', 'Country', 'Birthday', 'Residency', 'ResidencyPrev' }, { 'Team', 'Role', 'PreviousRole', 'Champions', 'CompIDs', 'SoloIDs' }, { 'social', social = 'wide' }, { 'teamhist', teamhist = 'wide' }, },	i18n = { -- not a true i18n as-is but could be made into one whatever Country = 'Country of Birth', CompIDs = 'Competitive IDs', SoloIDs = 'Soloqueue IDs', PreviousRole = 'Previous Role(s)', Champions = 'Favorite Champs', ResidencyPrev = 'Prev Residencies', } }

local directstore = { ID = 'id', AltIDs = 'compIDs', Stream = 'stream', Twitter = 'twitter', Facebook = 'facebook', Askfm = 'askfm', Reddit = 'reddit', Youtube = 'youtube', Youtube2 = 'Youtube2', Weibo = 'weibo', Vk = 'vk', Instagram = 'instagram', IsRetired = 'isretired', IsPersonality = 'checkboxIsPersonality' }

function getProcessed(args) local tbl = { pagename = mw.title.getCurrentTitle.text, bday = util_infobox.makeBday(args.birth_date_year, args.birth_date_month, args.birth_date_day), lc = args.id and lang:lcfirst(args.id) == args.id, }	tbl.redirects = util_dpl.whatRedirectsHere(		tbl.pagename,		{ notuses = 'Template:NoDPL/PlayerRedirects' }	) return tbl end

function processDisplay(args, processed) local social = social.makeSocialSection(args) local display = { title = args.id or processed.pagename, image = util_infobox.getFile(args.image, NOIMAGE), notice = args.isretired == 'Yes' and 'Player has retired.', -- background info Name = args.name and (args.name .. (args.nativename and (' (%s)'):format(args.nativename) or '')), Country = args.country and m_country.rightlong(args.country), Birthday = processed.bday.displayandage, Residency = args.residency and Region{args.residency, 'rightmedium'}, ResidencyPrev = formatPrevRev(args['residency-prev1'], args['residency-prev2']), -- competitive Team = args.team and util_table.concatSpecial({ args.team, args.team2, args.team3 }, ' ', Team, { [2] = 'plainlinked'}), Role = args.role and Role{args.role, 'roleonly'}, PreviousRole = args.prev1 and util_table.concatFromArgsSpecial(args, 'prev', ' ', Role, { [2] = 'roleonly' }), Champions = args.favchamp and util_table.concatFromArgsSpecial(args, 'favchamp', '', Champion, { [2] = 'onlyimagelinked' }), CompIDs = args.compID1 and util_table.concatFromArgsSpecial(args, 'compID',', '), SoloIDs = args.ids, -- social social = next(social) and tostring(util_html.blockBox(social)), }	processed.last = teamhist.teamHist(display, args) return display end

function formatPrevRev(res1, res2) if not res1 then return false end local tbl = { Region{res1, 'rightmedium'} } if res2 then tbl[2] = Region{res2, 'rightmedium'} end return table.concat(tbl,' ') end

function processCargo(args, processed) local idlist = mw.clone(processed.redirects) idlist[#idlist+1] = processed.pagename local cargo = { {			_table = 'InfoboxPlayer', IDList = table.concat(idlist,','), Image = args.image or NOIMAGE, Name = args.name, NativeName = args.nativename, NameAlphabet = args.namealphabet, NameFull = args.name and (args.name .. (args.nativename and (' (%s)'):format(args.nativename) or '')), Country = args.country, Age = processed.bday.age or '', Birthdate = processed.bday.store or '', ResidencyFormer = args['residency-prev1'], Team = Team{args.team, 'teamlinkname'}, Team2 = args.team2 and Team{args.team2, 'teamlinkname'} or '', TeamSystem = 'PC', Team2System = 'PC', Residency = args.residency and Region{args.residency, 'regionname'}, Role = args.role, FavChamps = util_table.concatFromArgsSpecial(args, 'favchamp', ','), TeamLast = processed.last.team, RoleLast = processed.last.role and Role{processed.last.role, 'roleonly'} or args.role, IsSubstitute = args.checkboxIsSub, IsLowercase = processed.lc and 'Yes' or 'No' },		{			_table = 'PlayerRedirects', AllName = processed.pagename }	}	addUnprocessedArgs(cargo[1], args, directstore) for _, v in ipairs(processed.redirects) do		cargo[#cargo+1] = saveRedirectCargo(v) end return cargo end

function addUnprocessedArgs(tbl, args, arglist) for k, v in pairs(arglist) do		tbl[k] = args[v] end end

function saveRedirectCargo(name) return { _table = 'PlayerRedirects', AllName = name, OtherName = name } end

function processVariables(args, processed) local name = mw.text.split(args.name or '', ' ') local firstname = table.remove(name, 1) local lastname = table.concat(name, ' ') local tbl = { twitchstream = args.stream and (args.stream):find('twitch.tv',1,true) and 'true', STREAM = args.stream and args.stream:gsub('.*/([^/]*)','%1'), id = args.id, firstname = firstname, lastname = lastname, nativename = args.nativename, namealphabet = args.namealphabet, lastteam = processed.last.team, team = Team{args.team, 'teamname'}, teamStr = Team{args.team, 'teamlinkname'}, role = args.role or processed.lastrole, sharesrole = args.checkboxSharesRole, isasub = args.checkboxIsSub, lastteampresent = processed.last.date and processed.last.date:find('Present') and 'true', whatredirectshere = table.concat(processed.redirects,';'), suppressorgnavbox = args.checkboxSuppressOrgNavbox == 'Yes' and 'true', }	return tbl end

function processCategories(args, processed) local tbl = { args.residency and Region{args.residency, 'regionadjectivename'} .. ' Residents', args['residency-prev1'] and ('Former %s Residents'):format(Region{args['residency-prev1'], 'regionadjectivename'}), args['residency-prev2'] and ('Former %s Residents'):format(Region{args['residency-prev2'], 'regionadjectivename'}), (not args.role) and 'Players Without Role', processed.last.team == 'Suspended' and processed.last.date:find('Present') and 'Suspended Players', (not args.team and args.isretired ~= 'Yes') and 'Free Agents', args.isretired == 'Yes' and 'Retired Players', args.birth_date_year and 'Players Born In ' .. args.birth_date_year }	if args.country then if args.checkboxIsPersonality == 'Yes' then tbl[#tbl+1] = ('%s Personalities'):format(m_country.localization(args.country)) elseif args.checkboxIsPersonality == 'No' then tbl[#tbl+1] = 'Players Born in ' .. m_country.namethe(args.country) end end return tbl end

local p = {} function p.main(args) local processed = getProcessed(args) local settings = { lc = processed.lc, nocargo = mw.title.getCurrentTitle.nsText ~= '' or args.nocargo, nocat = mw.title.getCurrentTitle.nsText ~= '' or args['no-cat'], }	local display = processDisplay(args, processed) local cargo = processCargo(args, processed) local variables = processVariables(args, processed) local categories = processCategories(args, processed) return { display = display, cargo = cargo, settings = settings, categories = categories, variables = variables, layout = LAYOUT } end

return p