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 Country = require('Module:Country').main 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 teamDisplay(a,b) if not a then return nil end local tbl = { Team{a, 'plainlinked'} } if b then tbl[2] = Team{b, 'plainlinked'} end return table.concat(tbl,' ') end

function roleDisplay(tbl) if not next(tbl) then return nil end for k, v in ipairs(tbl) do		tbl[k] = Role{v, 'roleonly'} end return table.concat(tbl,' ') end

function championDisplay(tbl) if not next(tbl) then return nil end for k, v in ipairs(tbl) do		tbl[k] = Champion{v, 'onlyimagelinked'} end return table.concat(tbl,'') end

function idDisplay(tbl) if not next(tbl) then return nil end return table.concat(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 Country{args.country, 'rightlong'}, Birthday = processed.bday.displayandage, Residency = args.residency and Region{args.residency, 'rightmedium'}, ResidencyPrev = formatPrevRev(args['residency-prev1'], args['residency-prev2']), -- competitive Team = teamDisplay(args.team, args.team2), Role = args.role and Role{args.role, 'roleonly'}, PreviousRole = roleDisplay({ args.prev1, args.prev2, args.prev3, args.prev4, args.prev5 }), --Champions = championDisplay(util_table.removeFalseEntries({ args.favchamp, args.favchamp2, args.favchamp3, args.favchamp4, args.favchamp5, args.favchamp6, args.favchamp7 },7)), CompIDs = idDisplay({ args.compID1, args.compID2, args.compID3, args.compID4, args.compID5, args.compID6, args.compID7, args.compID8 }), 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, Country_Markup = Country{args.country, 'rightlong'}, 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 = table.concat(util_table.removeFalseEntries({ args.favchamp, args.favchamp2, args.favchamp3, args.favchamp4, args.favchamp5, args.favchamp6, args.favchamp7 },7), ','), 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] = Country{args.country, 'localization'} .. ' Personalities' elseif args.checkboxIsPersonality == 'No' then tbl[#tbl+1] = 'Players Born in ' .. Country{args.country, 'namethe'} end end --util_table.removeFalseEntries(tbl) 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