Module:Infobox/Team

From Leaguepedia | League of Legends Esports Wiki
Jump to: navigation, search

To edit the documentation or categories for this module, click here. This module has an i18n file. Click here to edit it.


local util_args = require('Module:ArgsUtil')
local util_infobox = require('Module:InfoboxUtil')
local util_html = require('Module:HtmlUtil')
local util_cargo = require('Module:CargoUtil')
local util_table = require('Module:TableUtil')
local util_title = require("Module:TitleUtil")

local Country = require('Module:Country')
local Region = require('Module:Region')
local m_team = require('Module:Team')

local IntroSentence = require('Module:IntroSentence/Team').main

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

local Infobox = require('Module:Infobox'):extends()

Infobox.LAYOUT = {
	tabs = 'TeamTabsHeader',
	sections = { 'Team Information', 'History', 'Social Media & Links', 'Current Roster' },
	contents = {
		{ 'Org Location', 'Team Location', 'FoundedIn', 'Region', 'Owner', 'HeadCoach', 'Sponsor', 'Partner' },
		{ 'history', history = 'wide' },
		{ 'social', social = 'wide' },
		{ 'rosterimage', rosterimage = 'wide' }
	},
}
Infobox.type = 'Team'

local SPECIAL = {
	allstar = { cat = 'All-Star Regional Teams', nonav = true, nocargo = true },
	aprilfools = { nonav = true, nocargo = true },
	city = { nonav = true, nocargo = true },
	clubmasters = { nonav = true, nocargo = true },
	collegiate = { cat = 'Collegiate Teams', nocargo = false },
	iesf = { cat = 'IESF Teams', nonav = true, nocargo = true },
	nasg = { nonav = true },
	national = { cat = 'National Teams', nonav = true, nocargo = true },
}

local h = {}
local p = {}
function p.main(frame)
	local args = util_args.merge()
	return Infobox(args):run()
end

function Infobox:castArgs(args)
	args.region = Region(args.region)
	
	args.special = args.special and args.special:lower()
	args._title = args.name
	
	args.isdisbanded = util_args.castAsBool(args.isdisbanded)
	args.neworg = util_args.norm(args.neworg)
	args.isrenamed = util_args.norm(args.isrenamed)
	
	args.orgcountry = Country(args.orgcountry)
	args.country = Country(args.country)
	args.foundedcountry = Country(args.foundedcountry)
	args.effective_country = args.country:_or(args.orgcountry)
end

function Infobox:validateArgs(args)
	if args.special and not SPECIAL[args.special] then
		error('Invalid special specification - perhaps you need to add new preload at Module:Infobox/Team?')
	end
end

function Infobox:getProcessed(args)
	local processed = self:super('getProcessed', args)
	processed.isdisbanded = args.isdisbanded or args.neworg or args.isrenamed
	processed.special = args.special and SPECIAL[args.special] or {}
	processed.image = h.getImage(args.image, processed.pagename)
	return processed
end

function Infobox:getDisplay(args, processed)
	local display = self:super('getDisplay', args, processed)
	local tbl = {
		title = args.name or processed.pagename,
		image = not processed.isLowContent and processed.image,
		notice = h.makeNotice(args),

		['Org Location'] = args.orgcountry:flair(),
		['Team Location'] = args.country:flair(),
		FoundedIn = args.foundedcountry:flair(),
		Region = args.region:flair(),
		Owner = args.owner,
		HeadCoach = args.headcoach,
		Sponsor = args.sponsor,
		Partner = args.partner,
		
		history = h.makeHistory(args),
		
		rosterimage = args.rosterphoto and ('[[File:%s|center|320px]]'):format(args.rosterphoto),
		
		class = h.getClass(args, processed)

	}
	return Infobox.mergeDisplay(display, tbl)
end

-- might need to rewrite this to depend on the teamLink variable instead of the actual pagename
function h.getImage(image, pagename)
	if image and mw.title.makeTitle('Media', image).exists then
		return image
	end
	local profile = ('%slogo profile.png'):format(pagename)
	if mw.title.makeTitle('Media', profile).exists then
		return profile
	end
	local square = ('%slogo square.png'):format(pagename)
	if mw.title.makeTitle('Media', square).exists then
		return square
	end
	return NOIMAGE
end

function h.makeNotice(args)
	if args.isdisbanded then
		return 'Team has disbanded.'
	elseif args.neworg then
		return ('[[%s|Roster has joined a new organization.]]'):format(args.neworg)
	elseif args.isrenamed then
		return ('[[%s|Team has renamed.]]'):format(args.isrenamed)
	else
		return false
	end
end

function h.makeHistory(args)
	if not args.created then return false end
	local tbl = mw.html.create('table')
		:addClass('infobox-subtable')
	h.makeHistoryLine(tbl, 'Created', args.created, args.created2 and 1)
	h.makeHistoryLine(tbl, 'Disbanded', args.disbanded, args.created2 and 1)
	local i = 2
	while args['created' .. i] do
		h.makeHistoryLine(tbl, 'Created', args['created' .. i], i)
		h.makeHistoryLine(tbl, 'Disbanded', args['disbanded' .. i], i)
		i = i + 1
	end
	return tostring(tbl)
end

function h.makeHistoryLine(tbl, label, content, i)
	if not content then return end
	tbl:tag('tr')
		:tag('th')
			:addClass('teamdate')
			:wikitext(label .. (i and (' (%s)'):format(i) or ''))
		:done()
		:tag('td')
			:wikitext(content)
		:done()
	:done()
	return
end

function h.getClass(args, processed)
	local listOfClasses = {
		processed.isLowContent and 'infobox-low-content',
	}
	return util_table.concat(listOfClasses, ' ')
end

function Infobox:getCargo(args, processed)
	local cargo = self:super('getCargo', args, processed)
	if processed.special.nocargo then
		return cargo
	end
	cargo[#cargo+1] = {
		'',
		_table = 'Teams',
		Name = args.name,
		OverviewPage = mw.title.getCurrentTitle().text,
		Short = m_team.short(mw.title.getCurrentTitle().text),
		OrganizationPage = args.organization,
		Location = args.orgcountry,
		TeamLocation = args.country,
		Region = args.region,
		Image = args.image,
		Twitter = args.twitter,
		Website = args.website,
		Youtube = args.youtube,
		Facebook = args.facebook,
		Instagram = args.instagram,
		Discord = args.discord,
		Snapchat = args.snapchat,
		Vk = args.vk,
		Subreddit = args.subreddit,
		RosterPhoto = args.rosterphoto,
		IsDisbanded = processed.isdisbanded,
		IsLowercase = processed.lc,
		RenamedTo = h.renamedTo(args.isrenamed),
	}
	return cargo
end

function h.renamedTo(isrenamed)
	if not isrenamed then return nil end
	return m_team.teamlinkname(isrenamed)
end

function Infobox:getVariables(args, processed)
	local variables = self:super('getVariables', args, processed)
	local tbl = {
		suppressorgnavbox = processed.special.nonav,
		introSentence = h.getIntroSentence(args, processed),
		isdisbanded = args.isdisbanded or args.neworg or args.isrenamed
	}
	return util_table.merge(variables, tbl)
end

function h.getIntroSentence(args, processed)
	local data = mw.clone(args)
	data.name = args.name or processed.pagename
	return IntroSentence(data)
end

function Infobox:getCategories(args, processed)
	local categories = self:super('getCategories', args, processed)
	local tbl = {
		args.region:exists() and (args.region:get('adjective') .. ' Teams') or 'Teams Without Region In Infobox',
		'Teams',
		processed.isdisbanded and 'Inactive Teams' or 'Active Teams',
		args.effective_country:exists() and ('%s Teams'):format(args.effective_country:get('adjective')),
		processed.special.cat,
	}
	return util_table.mergeArrays(categories, tbl)
end

return p