Halo Esports Wiki
[checked revision][checked revision]
Donut (talk | contribs)
m (Syncing content across wikis)
No edit summary
(6 intermediate revisions by 3 users not shown)
Line 1: Line 1:
local util = require('Module:Util')
+
local util_args = require('Module:ArgsUtil')
 
local util_cargo = require('Module:CargoUtil')
 
local util_cargo = require('Module:CargoUtil')
local util_dpl = require('Module:DPLUtil')
+
local util_map = require("Module:MapUtil")
  +
local util_page = require("Module:PageUtil")
 
local util_table = require('Module:TableUtil')
 
local util_table = require('Module:TableUtil')
local util_title = require('Module:TitleUtil')
 
 
local util_text = require('Module:TextUtil')
 
local util_text = require('Module:TextUtil')
  +
local util_title = require('Module:TitleUtil')
  +
local util_vars = require('Module:VarsUtil')
 
local m_team = require('Module:Team')
 
local m_team = require('Module:Team')
  +
 
local lang = mw.getLanguage('en')
 
local lang = mw.getLanguage('en')
 
local systems = mw.loadData('Module:Systems')
 
local systems = mw.loadData('Module:Systems')
  +
  +
local TeamMembers = require('Module:QueryTeamMembers').main
  +
  +
local SUFFIX, SYSTEM
  +
  +
-- structure of data:
  +
  +
-- aboveFold = thisteam, [thisteam] = { list of players }
  +
-- belowFold = {
  +
-- active = { team, team, team, }
  +
-- inactive = { list, of, teams },
  +
-- [team] = { list of players }, ........
  +
-- }
  +
   
 
local p = {}
 
local p = {}
  +
local h = {}
   
 
function p.main(frame)
 
function p.main(frame)
  +
local args = util_args.merge()
if frame == mw.getCurrentFrame() then
 
  +
if util_vars.getBool('suppressorgnavbox') then return '' end
args = require('Module:ProcessArgs').merge(true)
 
else
 
frame = mw.getCurrentFrame()
 
end
 
if frame:callParserFunction('#var','suppressorgnavbox') == 'true' then
 
return ''
 
end
 
 
-- get inputs
 
-- get inputs
local settings = p.getSettings(args)
+
h.castArgs(args)
local vars = p.getVariables(settings)
+
local vars = h.getVariables(args)
  +
return p._makeNavbox(vars)
 
return p.makeNavbox(vars, frame, settings)
 
 
end
 
end
   
function p.getSettings(args)
+
function p._makeNavbox(vars)
return {
+
if not vars.team then return '' end
  +
local data = h.getData(vars)
suffix = (args.suffix == 'Yes'),
 
  +
if not data then return '' end
team = args[1],
 
  +
SUFFIX = vars.suffix
from_player = args.useplayer,
 
  +
SYSTEM = vars.system
state = args.innerstate
 
  +
h.processLinks(data)
}
 
  +
return h.makeOutput(data, vars)
 
end
 
end
   
function p.getVariables(settings)
+
function h.castArgs(args)
-- gets team & suffix
+
-- args provided include team and is_player
  +
-- if we're on a player page, we also will know system already
  +
-- but if we're on a team page we'll have to query here, which we'll do later
  +
-- suffix is whether or not we care about the suffix of the page we're on
  +
args.suffix = util_args.castAsBool(args.suffix)
  +
args.team = args[1]
  +
end
  +
  +
function h.getVariables(args)
  +
-- copy args to a separate internal object
 
local title = util_title.titleTable()
 
local title = util_title.titleTable()
local tbl = {}
+
local ret = {}
 
local titleteam = table.remove(title,1)
 
local titleteam = table.remove(title,1)
tbl.team = settings.team or titleteam
+
ret.team = args.team
  +
ret.organization = args.organization
tbl.system = title[1] and systems[title[1]] and systems[table.remove(title,1)]
 
  +
ret.system = args.system and systems[args.system] or h.getSystemFromTitle(title)
if settings.from_player then
 
  +
ret.teamlink = util_title.concatSubpage(ret.team, ret.system)
p.teamFromPlayer(tbl)
 
  +
ret.suffix = args.suffix and next(title) and table.concat(title,'/')
end
 
  +
ret.state = args.innerstate or 'mw-collapsed'
tbl.teamlink = util_title.concatSubpage(tbl.team, tbl.system)
 
  +
return ret
tbl.suffix = settings.suffix and next(title) and table.concat(title,'/')
 
tbl.state = settings.state or 'mw-collapsed'
 
return tbl
 
 
end
 
end
   
function p.teamFromPlayer(tbl)
+
function h.getSystemFromTitle(title)
  +
-- if we're on a team page then the system will be the 2nd part of the title
local result = util_cargo.getOneRow({
 
  +
-- this only applies to team pages because players aren't system-specific
tables = 'InfoboxPlayer',
 
  +
if title[1] and systems[title[1]] then
fields = {'Team','TeamSystem'},
 
  +
return systems[table.remove(title,1)]
where = string.format('_pageName="%s"',tbl.team)
 
})
+
end
  +
return nil
tbl.team = result.Team
 
tbl.system = result.TeamSystem or ''
 
return
 
 
end
 
end
   
  +
function h.getData(vars)
-- below this can be called directly from a module
 
  +
-- to make a navbox, we must have either an active roster or sister teams
function p.makeNavbox(vars, frame)
 
  +
-- if we have an active roster, we query that and it will go above the fold
if not vars.team then return '' end
 
  +
-- if we have sister teams, all of that goes below the fold
if not frame then frame = mw.getCurrentFrame() end
 
-- get data,
 
local data = p.getData(vars)
 
if not data then return '' end
 
p.processLinks(frame, data, vars.suffix)
 
-- print data
 
return p.printNavbox(frame, data, vars)
 
end
 
 
function p.getData(vars)
 
 
local data = {}
 
local data = {}
local localsettings = {}
+
local active = false
 
local thisteam = vars.team
 
local thisteam = vars.team
 
local thisteamlink = vars.teamlink
 
local thisteamlink = vars.teamlink
if thisteamlink and mw.title.makeTitle('',thisteamlink).exists then
+
if h.isActive(thisteamlink) then
  +
active = true
if p.isActive(thisteamlink) then
 
  +
data.aboveFold = thisteam
localsettings.active = true
 
  +
data[thisteam] = h.getPlayers(thisteamlink)
data.aboveFold = thisteam
 
data[thisteam] = { links = {}, names = {} }
 
p.getPlayers(thisteamlink, data[thisteam])
 
end
 
else
 
localsettings.exists = false
 
 
end
 
end
  +
if vars.team then
localsettings.hasSister = p.getSisterTeamInfo(vars, data)
 
  +
h.addSisterTeamInfoToData(vars, data)
return (localsettings.active or localsettings.hasSister) and data
 
  +
end
  +
return (active or data.hasSister) and data
 
end
 
end
   
function p.isActive(teamlink)
+
function h.isActive(teamlink)
  +
-- a team is active if both its page exists and also it's not disbanded
local isDisbanded = util_cargo.getOneResult(
 
  +
if not mw.title.makeTitle('',teamlink).exists then return false end
'InfoboxTeam',
 
  +
local query = {
'IsDisbanded',
 
  +
tables = 'Teams',
{ where = string.format('_pageName="%s"',teamlink) }
 
  +
fields = 'IsDisbanded [boolean]',
)
 
  +
where = string.format('_pageName="%s"',teamlink),
return isDisbanded == 'No'
 
  +
}
  +
return not util_cargo.getOneResult(query)
 
end
 
end
   
function p.getPlayers(thisteamlink, data)
+
function h.getPlayers(team)
local result = mw.ext.cargo.query('ListplayerCurrent', 'Link,ID', {
+
local result = TeamMembers(team)
  +
local playerData = {}
where = string.format('_pageName="%s" AND ID IS NOT NULL',thisteamlink),
 
  +
for i, row in ipairs(result) do
groupBy = 'Link',
 
  +
playerData[i] = row.Link
orderBy = 'N'
 
  +
playerData[row.Link] = {
})
 
  +
link = row.Link,
for key, row in ipairs(result) do
 
data.links[key] = row.Link
+
ID = row.ID,
data.names[key] = row.ID
+
RoleList = row.RoleList,
  +
}
 
end
 
end
  +
return playerData
  +
end
  +
  +
function h.addSisterTeamInfoToData(vars, data)
  +
-- all data about sister teams goes below the fold except sisterDataLocation & hasSister
  +
-- sisterDataLocation is to be used for the edit button of the navbox
  +
-- hasSister will be checked to see if we proceed with making the navbox or not & then ignored
  +
local row = h.getSisterTeamData(vars.team)
  +
if not row or not next(row) then return end
  +
data.belowFold = h.parseSisterTeamData(row)
  +
h.addSisterTeamPlayersToActiveData(data.belowFold)
  +
data.sisterDataLocation = row._pageName
  +
data.hasSister = true
 
end
 
end
   
function p.getSisterTeamInfo(vars, data)
+
function h.getSisterTeamData(team)
local row = p.sisterTeamsCargo(vars.team)
+
local query = {
  +
tables = 'SisterTeams',
if not row then return nil end
 
data.belowFold = {
+
fields = {
  +
"Status=Status",
active = (row.ActiveList ~= '') and util_text.split(row.ActiveList,'%s*,%s*'),
 
  +
"_pageName",
inactive = (row.InactiveList ~= '') and { links = util_text.split(row.InactiveList,'%s*,%s*') }
 
  +
"ActiveList=ActiveList",
  +
"InactiveList=InactiveList"
  +
},
  +
where = ('Team="%s"'):format(m_team.teamlinkname(team)),
 
}
 
}
  +
return util_cargo.getOneRow(query)
for _, team in ipairs(data.belowFold.active or {}) do
 
data.belowFold[team] = { links = {}, names = {} }
 
p.getPlayers(team, data.belowFold[team])
 
end
 
if data.belowFold.inactive then
 
data.belowFold.inactive.names = mw.clone(data.belowFold.inactive.links)
 
end
 
return true
 
 
end
 
end
   
function p.sisterTeamsCargo(team)
+
function h.parseSisterTeamData(row)
local fieldstable = {
+
local teamData = {
  +
active = util_text.splitNonempty(row.ActiveList),
"Status=Status",
 
  +
inactive = util_text.split(row.InactiveList),
"CONCAT(_pageName)=Pagename",
 
"ActiveList=ActiveList",
 
"InactiveList=InactiveList"
 
 
}
 
}
  +
if not teamData.inactive then return end
local cargoresult = mw.ext.cargo.query(
 
  +
for _, team in ipairs(teamData.inactive) do
"CCSisterTeams",
 
  +
teamData.inactive[team] = { link = team, name = team }
table.concat(fieldstable, ","),
 
  +
end
{ where = 'Team="' .. team .. '"' }
 
  +
return teamData
)
 
  +
end
return cargoresult[1]
 
  +
  +
function h.addSisterTeamPlayersToActiveData(belowFold)
  +
for _, team in ipairs(belowFold.active) do
  +
belowFold[team] = h.getPlayers(team)
  +
end
 
end
 
end
   
Line 151: Line 172:
 
-- need to figure out how to deal with different systems & links
 
-- need to figure out how to deal with different systems & links
 
-- but i think that will be handled with team links / sister team concepts
 
-- but i think that will be handled with team links / sister team concepts
function p.processLinks(frame, data, suffix)
+
function h.processLinks(data)
  +
-- we want the navbox to link to corresponding subpages always
local links = p.getLinksListFromData(data)
 
  +
-- so make a long list of all links we have, and then determine existence
util_title.concatSubpages(links, suffix)
 
  +
-- make a lookup table that we'll refer to when printing to decide if we link to the subpage or not
local whatExists = util_table.lookup(util_dpl.whichPagesExist(links, frame))
 
  +
local linksToCheck = h.getListOfAllLinks(data)
p.processLinksInData(data, whatExists, suffix)
 
  +
util_map.inPlace(linksToCheck, util_title.concatSubpage, SUFFIX)
return
 
  +
local linksHash = util_table.hash(util_page.whichPagesExist(linksToCheck))
  +
h.processLinksInData(data, linksHash)
 
end
 
end
   
function p.getLinksListFromData(data)
+
function h.getListOfAllLinks(data)
local links = {}
+
local linksToCheck = {}
 
if data.aboveFold then
 
if data.aboveFold then
links[#links+1] = data.aboveFold
+
linksToCheck[#linksToCheck+1] = data.aboveFold
links[#links+1] = util_title.concatSubpageSystem(data.aboveFold, data.system)
+
linksToCheck[#linksToCheck+1] = util_title.concatSubpageSystem(data.aboveFold, SYSTEM)
util_table.mergeArrays(links,data[data.aboveFold].links)
+
util_table.mergeArrays(linksToCheck, data[data.aboveFold])
 
end
 
end
 
if data.belowFold then
 
if data.belowFold then
if data.belowFold.inactive then
+
util_table.mergeArrays(linksToCheck, data.belowFold.inactive)
util_table.mergeArrays(links,data.belowFold.inactive.links)
+
for k, v in ipairs(data.belowFold.active) do
  +
linksToCheck[#linksToCheck+1] = v
end
 
for k, v in ipairs(data.belowFold.active or {}) do
+
util_table.mergeArrays(linksToCheck, data.belowFold[v])
links[#links+1] = v
 
util_table.mergeArrays(links,data.belowFold[v].links)
 
 
end
 
end
 
end
 
end
return links
+
return linksToCheck
 
end
 
end
   
function p.processLinksInData(data, whatExists, suffix)
+
function h.processLinksInData(data, linksHash)
  +
-- we need 3 pieces of information per link: the link, the display, and whether the proper subpage exists (so we can add the class if needed)
p.linkLists(data[data.aboveFold], whatExists, suffix)
 
  +
-- where before we had a table of links, we can add tables of names/exists by adding extra data
data.aboveFold = p.linkToObject(data.aboveFold, whatExists, suffix)
 
  +
-- where we had a constant, we need to transform to having a table of information
  +
h.addExtraDataToLinkTables(data[data.aboveFold], linksHash)
  +
data.aboveFold = h.transformLinkToTable(data.aboveFold, linksHash)
 
if data.belowFold then
 
if data.belowFold then
for key, team in ipairs(data.belowFold.active or {}) do
+
for i, team in ipairs(data.belowFold.active) do
p.linkLists(data.belowFold[team], whatExists, suffix)
+
h.addExtraDataToLinkTables(data.belowFold[team], linksHash)
data.belowFold.active[key] = p.linkToObject(team, whatExists, suffix)
+
data.belowFold.active[i] = h.transformLinkToTable(team, linksHash)
 
end
 
end
p.linkLists(data.belowFold.inactive, whatExists, suffix)
+
h.addExtraDataToLinkTables(data.belowFold.inactive, linksHash)
  +
end
  +
return
  +
end
  +
  +
function h.addExtraDataToLinkTables(list, hash)
  +
if not list or not next(list) then return end
  +
for k, v in ipairs(list) do
  +
local newlink = util_title.concatSubpage(v, SUFFIX)
  +
local exists = hash[lang:ucfirst(newlink)]
  +
list[v].exists = exists
  +
list[v].link = exists and newlink or v
 
end
 
end
 
return
 
return
 
end
 
end
   
function p.linkToObject(link, whatExists, suffix)
+
function h.transformLinkToTable(link, linksHash)
 
if not link then return nil end
 
if not link then return nil end
local newlink = util_title.concatSubpage(link, suffix)
+
local newlink = util_title.concatSubpage(link, SUFFIX)
local exists = whatExists[lang:ucfirst(newlink)]
+
local exists = linksHash[lang:ucfirst(newlink)]
 
return {
 
return {
 
name = link,
 
name = link,
Line 202: Line 237:
 
end
 
end
   
  +
-- print output
function p.linkLists(list, lookup, suffix)
 
  +
function h.makeOutput(data, args)
if not list then return end
 
  +
-- navboxargs will be sent to Template:Navbox
if not list.exists then list.exists = {} end
 
  +
-- if there's an active roster, then the active roster is printed expanded above the fold
for k, v in ipairs(list.links) do
 
  +
-- then if there's sister team data we print that below the fold
newlink = util_title.concatSubpage(v, suffix)
 
list.exists[k] = lookup[lang:ucfirst(newlink)]
 
list.links[k] = list.exists[k] and newlink or v
 
end
 
return
 
end
 
 
-- below is printing only
 
function p.printNavbox(frame, data, settings)
 
 
local thisteam = data.aboveFold
 
local thisteam = data.aboveFold
 
local navboxargs = {
 
local navboxargs = {
name = 'OrgNavbox',
+
name = data.sisterDataLocation or 'OrgNavbox',
 
state = 'mw-collapsible'
 
state = 'mw-collapsible'
 
}
 
}
 
local i = 1
 
local i = 1
 
if thisteam then
 
if thisteam then
navboxargs.group1 = p.makeOutput(
+
navboxargs.group1 = h.makeOneLink(
util_title.concatSubpageSystem(thisteam.link,settings.system),
+
util_title.concatSubpageSystem(thisteam.link, SYSTEM),
thisteam.name,
+
m_team.teammediumname(thisteam.name),
(not settings.suffix) or thisteam.exists
+
thisteam.exists
 
)
 
)
navboxargs.list1 = p.makeListOutput(data[thisteam.name], settings.suffix)
+
navboxargs.list1 = h.makePlayersOutput(data[thisteam.name])
  +
navboxargs.title = h.makeNavboxTitle(thisteam.name, 'Roster')
 
i = i + 1
 
i = i + 1
navboxargs.title = p.makeNavboxTitle(thisteam.name, settings.suffix, settings.system, 'Roster')
 
 
else
 
else
navboxargs.title = p.makeNavboxTitle(settings.team, settings.suffix, settings.system, 'Organization')
+
navboxargs.title = h.makeNavboxTitle(args.team, 'Organization')
 
end
 
end
 
 
 
if data.belowFold then
 
if data.belowFold then
navboxargs['list' .. i] = p.afterFold(frame, data.belowFold, settings)
+
navboxargs['list' .. i] = h.belowFold(data.belowFold, args.innerstate)
 
end
 
end
return frame:expandTemplate{ title = 'Navbox', args = navboxargs }
+
return mw.getCurrentFrame():expandTemplate{ title = 'Navbox', args = navboxargs }
 
end
 
end
   
function p.makeNavboxTitle(thisteam, suffix, system, defaulttext)
+
function h.makeNavboxTitle(thisteam, defaulttext)
return string.format(
+
return ('<span class="%s">%s</span> %s'):format(
  +
SUFFIX and 'no-subpage' or '',
'<span class="%s">%s</span> %s',
 
  +
m_team.rightlonglinked(thisteam, { system = SYSTEM, size = 45 }),
suffix and 'no-subpage' or '',
 
  +
SUFFIX and ('- ' .. SUFFIX) or defaulttext
m_team.rightlonglinked(thisteam, { system = system, size = 45 }),
 
suffix and ('- ' .. suffix) or defaulttext
 
 
)
 
)
 
end
 
end
   
function p.afterFold(frame, data, settings)
+
function h.belowFold(data, state)
  +
-- print all of the active teams along with their list of players
  +
-- then print all of the inactive teams just as a list
  +
-- we return an already-made template that gets passed to the outer navbox as an arg
 
local navboxargs = {
 
local navboxargs = {
 
'child',
 
'child',
 
title = 'Other Teams In Organization (Click [Show] to the Right)',
 
title = 'Other Teams In Organization (Click [Show] to the Right)',
state = settings.state
+
state = state
 
}
 
}
for k, v in ipairs(data.active or {}) do
+
for i, v in ipairs(data.active) do
navboxargs['group' .. k] = p.makeOutput(
+
navboxargs['group' .. i] = h.makeOneLink(
util_title.concatSubpageSystem(v.link,settings.system),
+
util_title.concatSubpageSystem(v.link, SYSTEM),
 
v.name,
 
v.name,
(not settings.suffix) or v.exists
+
v.exists
 
)
 
)
navboxargs['list' .. k] = p.makeListOutput(data[v.name], settings.suffix)
+
navboxargs['list' .. i] = h.makePlayersOutput(data[v.name])
 
end
 
end
 
if data.inactive then
 
if data.inactive then
navboxargs.below = p.makeListOutput(data.inactive, settings.suffix)
+
navboxargs.below = h.makeTeamsOutput(data.inactive)
 
end
 
end
return frame:expandTemplate{ title = 'Navbox', args = navboxargs }
+
return mw.getCurrentFrame():expandTemplate{ title = 'Navbox', args = navboxargs }
 
end
 
end
   
function p.makeListOutput(list, suffix)
+
function h.makePlayersOutput(data)
local tbl = {}
+
local display = {}
for k, link in ipairs(list.links or {}) do
+
for _, link in ipairs(data) do
  +
local linkInfo = data[link]
tbl[k] = p.makeOutput(link, list.names[k], (not suffix) or list.exists[k])
 
  +
display[#display+1] = ('%s%s'):format(
  +
linkInfo.RoleList:images() or '',
  +
h.makeOneLink(linkInfo.link, linkInfo.ID, linkInfo.exists)
  +
)
 
end
 
end
local output = table.concat(tbl,' &#8226; ')
+
return util_table.concat(display,' &#8226; ')
  +
end
  +
  +
function h.makeTeamsOutput(data)
  +
local display = {}
  +
for _, link in ipairs(data or {}) do
  +
local linkInfo = data[link]
  +
display[#display+1] = h.makeOneLink(linkInfo.link, linkInfo.name, linkInfo.exists)
  +
end
  +
local output = table.concat(display,' &#8226; ')
 
return output
 
return output
 
end
 
end
   
function p.makeOutput(link, name, exists)
+
function h.makeOneLink(link, name, exists)
  +
-- concat link and display, adding the span class if it's not linking to the right subpage
if exists then
 
  +
if (not SUFFIX) or exists then
return string.format('[[%s|%s]]',link,name)
 
  +
return util_text.intLink(link, name)
 
else
 
else
  +
return ('<span class="no-subpage">[[%s|%s]]</span>'):format(link, name or link)
return string.format(
 
'<span class="no-subpage">[[%s|%s]]</span>',
 
link,
 
name
 
)
 
 
end
 
end
 
end
 
end

Revision as of 17:06, 18 August 2020

To edit the documentation or categories for this module, click here.


local util_args = require('Module:ArgsUtil')
local util_cargo = require('Module:CargoUtil')
local util_map = require("Module:MapUtil")
local util_page = require("Module:PageUtil")
local util_table = require('Module:TableUtil')
local util_text = require('Module:TextUtil')
local util_title = require('Module:TitleUtil')
local util_vars = require('Module:VarsUtil')
local m_team = require('Module:Team')

local lang = mw.getLanguage('en')
local systems = mw.loadData('Module:Systems')

local TeamMembers = require('Module:QueryTeamMembers').main

local SUFFIX, SYSTEM

-- structure of data:

-- aboveFold = thisteam, [thisteam] = { list of players }
-- belowFold = {
--		active = { team, team, team, }
--		inactive = { list, of, teams },
--		[team] = { list of players }, ........
-- }


local p = {}
local h = {}

function p.main(frame)
	local args = util_args.merge()
	if util_vars.getBool('suppressorgnavbox') then return '' end
	-- get inputs
	h.castArgs(args)
	local vars = h.getVariables(args)
	return p._makeNavbox(vars)
end

function p._makeNavbox(vars)
	if not vars.team then return '' end
	local data = h.getData(vars)
	if not data then return '' end
	SUFFIX = vars.suffix
	SYSTEM = vars.system
	h.processLinks(data)
	return h.makeOutput(data, vars)
end

function h.castArgs(args)
	-- args provided include team and is_player
	-- if we're on a player page, we also will know system already
	-- but if we're on a team page we'll have to query here, which we'll do later
	-- suffix is whether or not we care about the suffix of the page we're on
	args.suffix = util_args.castAsBool(args.suffix)
	args.team = args[1]
end

function h.getVariables(args)
	-- copy args to a separate internal object
	local title = util_title.titleTable()
	local ret = {}
	local titleteam = table.remove(title,1)
	ret.team = args.team
	ret.organization = args.organization
	ret.system = args.system and systems[args.system] or h.getSystemFromTitle(title)
	ret.teamlink = util_title.concatSubpage(ret.team, ret.system)
	ret.suffix = args.suffix and next(title) and table.concat(title,'/')
	ret.state = args.innerstate or 'mw-collapsed'
	return ret
end

function h.getSystemFromTitle(title)
	-- if we're on a team page then the system will be the 2nd part of the title
	-- this only applies to team pages because players aren't system-specific
	if title[1] and systems[title[1]] then
		return systems[table.remove(title,1)]
	end
	return nil
end

function h.getData(vars)
	-- to make a navbox, we must have either an active roster or sister teams
	-- if we have an active roster, we query that and it will go above the fold
	-- if we have sister teams, all of that goes below the fold
	local data = {}
	local active = false
	local thisteam = vars.team
	local thisteamlink = vars.teamlink
	if h.isActive(thisteamlink) then
		active = true
		data.aboveFold = thisteam
		data[thisteam] = h.getPlayers(thisteamlink)
	end
	if vars.team then
		h.addSisterTeamInfoToData(vars, data)
	end
	return (active or data.hasSister) and data
end

function h.isActive(teamlink)
	-- a team is active if both its page exists and also it's not disbanded
	if not mw.title.makeTitle('',teamlink).exists then return false end
	local query = {
		tables = 'Teams',
		fields = 'IsDisbanded [boolean]',
		where = string.format('_pageName="%s"',teamlink),
	}
	return not util_cargo.getOneResult(query)
end

function h.getPlayers(team)
	local result = TeamMembers(team)
	local playerData = {}
	for i, row in ipairs(result) do
		playerData[i] = row.Link
		playerData[row.Link] = {
			link = row.Link,
			ID = row.ID,
			RoleList = row.RoleList,
		}
	end
	return playerData
end

function h.addSisterTeamInfoToData(vars, data)
	-- all data about sister teams goes below the fold except sisterDataLocation & hasSister
	-- sisterDataLocation is to be used for the edit button of the navbox
	-- hasSister will be checked to see if we proceed with making the navbox or not & then ignored
	local row = h.getSisterTeamData(vars.team)
	if not row or not next(row) then return end
	data.belowFold = h.parseSisterTeamData(row)
	h.addSisterTeamPlayersToActiveData(data.belowFold)
	data.sisterDataLocation = row._pageName
	data.hasSister = true
end

function h.getSisterTeamData(team)
	local query = {
		tables = 'SisterTeams',
		fields = {
			"Status=Status",
			"_pageName",
			"ActiveList=ActiveList",
			"InactiveList=InactiveList"
		},
		where = ('Team="%s"'):format(m_team.teamlinkname(team)),
	}
	return util_cargo.getOneRow(query)
end

function h.parseSisterTeamData(row)
	local teamData = {
		active = util_text.splitNonempty(row.ActiveList),
		inactive = util_text.split(row.InactiveList),
	}
	if not teamData.inactive then return end
	for _, team in ipairs(teamData.inactive) do
		teamData.inactive[team] = { link = team, name = team }
	end
	return teamData
end

function h.addSisterTeamPlayersToActiveData(belowFold)
	for _, team in ipairs(belowFold.active) do
		belowFold[team] = h.getPlayers(team)
	end
end

-- process links

-- need to figure out how to deal with different systems & links
-- but i think that will be handled with team links / sister team concepts
function h.processLinks(data)
	-- we want the navbox to link to corresponding subpages always
	-- so make a long list of all links we have, and then determine existence
	-- make a lookup table that we'll refer to when printing to decide if we link to the subpage or not
	local linksToCheck = h.getListOfAllLinks(data)
	util_map.inPlace(linksToCheck, util_title.concatSubpage, SUFFIX)
	local linksHash = util_table.hash(util_page.whichPagesExist(linksToCheck))
	h.processLinksInData(data, linksHash)
end

function h.getListOfAllLinks(data)
	local linksToCheck = {}
	if data.aboveFold then
		linksToCheck[#linksToCheck+1] = data.aboveFold
		linksToCheck[#linksToCheck+1] = util_title.concatSubpageSystem(data.aboveFold, SYSTEM)
		util_table.mergeArrays(linksToCheck, data[data.aboveFold])
	end
	if data.belowFold then
		util_table.mergeArrays(linksToCheck, data.belowFold.inactive)
		for k, v in ipairs(data.belowFold.active) do
			linksToCheck[#linksToCheck+1] = v
			util_table.mergeArrays(linksToCheck, data.belowFold[v])
		end
	end
	return linksToCheck
end

function h.processLinksInData(data, linksHash)
	-- we need 3 pieces of information per link: the link, the display, and whether the proper subpage exists (so we can add the class if needed)
	-- where before we had a table of links, we can add tables of names/exists by adding extra data
	-- where we had a constant, we need to transform to having a table of information
	h.addExtraDataToLinkTables(data[data.aboveFold], linksHash)
	data.aboveFold = h.transformLinkToTable(data.aboveFold, linksHash)
	if data.belowFold then
		for i, team in ipairs(data.belowFold.active) do
			h.addExtraDataToLinkTables(data.belowFold[team], linksHash)
			data.belowFold.active[i] = h.transformLinkToTable(team, linksHash)
		end
		h.addExtraDataToLinkTables(data.belowFold.inactive, linksHash)
	end
	return
end

function h.addExtraDataToLinkTables(list, hash)
	if not list or not next(list) then return end
	for k, v in ipairs(list) do
		local newlink = util_title.concatSubpage(v, SUFFIX)
		local exists = hash[lang:ucfirst(newlink)]
		list[v].exists = exists
		list[v].link = exists and newlink or v
	end
	return
end

function h.transformLinkToTable(link, linksHash)
	if not link then return nil end
	local newlink = util_title.concatSubpage(link, SUFFIX)
	local exists = linksHash[lang:ucfirst(newlink)]
	return {
		name = link,
		exists = exists,
		link = exists and newlink or link
	}
end

-- print output
function h.makeOutput(data, args)
	-- navboxargs will be sent to Template:Navbox
	-- if there's an active roster, then the active roster is printed expanded above the fold
	-- then if there's sister team data we print that below the fold
	local thisteam = data.aboveFold
	local navboxargs = {
		name = data.sisterDataLocation or 'OrgNavbox',
		state = 'mw-collapsible'
	}
	local i = 1
	if thisteam then
		navboxargs.group1 = h.makeOneLink(
			util_title.concatSubpageSystem(thisteam.link, SYSTEM),
			m_team.teammediumname(thisteam.name),
			thisteam.exists
		)
		navboxargs.list1 = h.makePlayersOutput(data[thisteam.name])
		navboxargs.title = h.makeNavboxTitle(thisteam.name, 'Roster')
		i = i + 1
	else
		navboxargs.title = h.makeNavboxTitle(args.team, 'Organization')
	end
	
	if data.belowFold then
		navboxargs['list' .. i] = h.belowFold(data.belowFold, args.innerstate)
	end
	return mw.getCurrentFrame():expandTemplate{ title = 'Navbox', args = navboxargs }
end

function h.makeNavboxTitle(thisteam, defaulttext)
	return ('<span class="%s">%s</span> %s'):format(
		SUFFIX and 'no-subpage' or '',
		m_team.rightlonglinked(thisteam, { system = SYSTEM, size = 45 }),
		SUFFIX and ('- ' .. SUFFIX) or defaulttext
	)
end

function h.belowFold(data, state)
	-- print all of the active teams along with their list of players
	-- then print all of the inactive teams just as a list
	-- we return an already-made template that gets passed to the outer navbox as an arg
	local navboxargs = {
		'child',
		title = 'Other Teams In Organization (Click [Show] to the Right)',
		state = state
	}
	for i, v in ipairs(data.active) do
		navboxargs['group' .. i] = h.makeOneLink(
			util_title.concatSubpageSystem(v.link, SYSTEM),
			v.name,
			v.exists
		)
		navboxargs['list' .. i] = h.makePlayersOutput(data[v.name])
	end
	if data.inactive then
		navboxargs.below = h.makeTeamsOutput(data.inactive)
	end
	return mw.getCurrentFrame():expandTemplate{ title = 'Navbox', args = navboxargs }
end

function h.makePlayersOutput(data)
	local display = {}
	for _, link in ipairs(data) do
		local linkInfo = data[link]
		display[#display+1] = ('%s%s'):format(
			linkInfo.RoleList:images() or '',
			h.makeOneLink(linkInfo.link, linkInfo.ID, linkInfo.exists)
		)
	end
	return util_table.concat(display,' &#8226; ')
end

function h.makeTeamsOutput(data)
	local display = {}
	for _, link in ipairs(data or {}) do
		local linkInfo = data[link]
		display[#display+1] = h.makeOneLink(linkInfo.link, linkInfo.name, linkInfo.exists)
	end
	local output = table.concat(display,' &#8226; ')
	return output
end

function h.makeOneLink(link, name, exists)
	-- concat link and display, adding the span class if it's not linking to the right subpage
	if (not SUFFIX) or exists then
		return util_text.intLink(link, name)
	else
		return ('<span class="no-subpage">[[%s|%s]]</span>'):format(link, name or link)
	end
end	

return p