[checked revision] | [checked revision] |
No edit summary |
No edit summary |
||
Line 106: | Line 106: | ||
function h.getHost(args) |
function h.getHost(args) |
||
− | if args.host then |
+ | if args.host ~= '' then |
return m_team.plainlinked(host) |
return m_team.plainlinked(host) |
||
end |
end |
Revision as of 15:53, 22 March 2020
To edit the documentation or categories for this module, click here. This module has an i18n file. Click here to edit it.
local lang = mw.getLanguage('en')
local m_currency = require('Module:Currency')
local m_team = require('Module:Team')
local m_region = require('Module:Region')
local m_country = require('Module:Country')
local social = require('Module:Infobox/Social')
local teamhist = require('Module:Infobox/TeamHist')
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_dpl = require('Module:DPLUtil')
local util_table = require('Module:TableUtil')
local util_time = require('Module:TimeUtil')
local util_form = require('Module:FormUtil')
local util_text = require('Module:TextUtil')
local NOIMAGE = 'Unknown Infobox Image - Tournament.png'
LAYOUT = {
sections = { 'Tournament Information', 'Location & Dates', 'Broadcast', 'Results' },
contents = {
{ 'Organizer', 'Host', 'Rulebook', 'Sponsor', 'Format', 'PrizePool','NumberofTeams', 'Links' },
{ 'Server', 'Type', 'Game', 'Tier', 'Mode', 'Platform', 'Country', 'Location', 'Venue', 'StartDate', 'EndDate', 'Date', },
{ 'Casters', 'Streams', 'Schedule' },
{ 'Winner', 'Second', 'Third', 'Fourth', 'Qualified', },
},
i18nFile = 'Infobox/Tournament',
}
local FORM_INFO = {
SFS = { form = 'SpoilerFreeSchedule', template = 'SFS' },
MCE = { form = 'MatchCalendarExport', template = 'MCE' }
}
local CCMT_PARAMS = { 'StandardName', 'TournamentLevel', 'IsQualifier', 'IsPlayoffs', 'IsOfficial', 'Year', 'StandardLeague', 'LeagueIconKey' }
local h = {}
local p = {}
function p.main(args)
local processed = h.getProcessed(args)
local settings = {
lc = processed.lc,
nocargo = mw.title.getCurrentTitle().nsText ~= '' or args.nocargo,
nocat = mw.title.getCurrentTitle().nsText ~= '' or args['no-cat'],
}
return {
display = h.processDisplay(args, processed),
cargo = h.processCargo(args, processed),
settings = settings,
categories = h.processCategories(args, processed),
variables = h.processVariables(args, processed),
layout = LAYOUT
}
end
function h.getProcessed(args)
local tbl = {
pagename = args.pagename or mw.title.getCurrentTitle().text,
name = args.CM_StandardName or args.storedname or args.name,
region = args.region and m_region.medium(args.region),
league = args.CM_StandardLeague or args.league,
type = util_text.ucfirst(args.type),
}
return tbl
end
function h.processDisplay(args, processed)
local frame = mw.getCurrentFrame()
local tbl = {
title = args.name,
image = util_infobox.getFile(args.image, NOIMAGE),
notice = args.rednotice,
Organizer = args.organizer and util_table.concatFromArgs(args, 'organizer', '<br>'),
Rulebook = args.rulebook and ('[%s Rulebook]'):format(args.rulebook),
Sponsor = args.sponsor,
Server = args.server,
Type = args.type,
Game = args.game,
Tier = args.tier,
Mode = args.mode,
Platform = args.platform,
Region = processed.region and m_region.rightmedium(processed.region),
EventType = processed.type,
Country = args.country and m_country.rightlong(args.country),
Location = args.location,
Venue = args.venue,
Format = args.format,
PrizePool = h.getPrizePool(args),
NumberofTeams = args.numberofteams,
Date = args.date,
StartDate = args.sdate,
EndDate = args.edate,
Links = h.getLinks(args),
Casters = args.caster or args.casters,
Streams = args.streams and (args.streams .. (args.linkstreams and '<br>[[#Streams|Full List]]' or '')),
Schedule = h.makeSchedule(processed.pagename),
Host = h.getHost(args),
}
h.addResults(tbl, args)
return tbl
end
function h.getHost(args)
if args.host ~= '' then
return m_team.plainlinked(host)
end
end
function h.getLinks(args)
if not args.bracket then
return args.web and ('[%s Website]'):format(args.web)
elseif not args.web then
return args.bracket and ('[%s Bracket]'):format(args.bracket)
else
local links = {
args.web and ('[%s Website]'):format(args.web),
args.bracket and ('[%s Bracket]'):format(args.bracket),
}
return util_table.concat(links, '<br>')
end
end
function h.getPrizePool(args)
if not args.currency then
return args.prizepool
end
return m_currency.short(args.prizepool, args.currency)
end
function h.makeSchedule(pagename)
if util_cargo.getOneResult({ tables = 'MatchSchedule', fields = 'OverviewPage', where = ('OverviewPage="%s"'):format(pagename) }) then
local links = {
('[%s Spoiler-Free Schedule]'):format(util_form.fullURL(FORM_INFO.SFS, { pagename })),
('[%s Calendar Export]'):format(util_form.fullURL(FORM_INFO.MCE, { pagename })),
}
return util_table.concat(links, '<br>')
end
return nil
end
function h.addResults(tbl, args)
local format = not args.freeedit
local places = { first = 'Winner', second = 'Second', third = 'Third', fourth = 'Fourth' }
for k, v in pairs(places) do
if args[k] then
tbl[v] = format and m_team.rightmediumlinked(args[k]) or args[k]
end
end
if args.third1 or args.third2 then
tbl.Third = util_table.concatFromArgs(args, 'third', '<br>', format and m_team.rightmediumlinked)
end
tbl.Qualified = args.qual1 and util_table.concatFromArgs(args, 'qual', '<br>', format and m_team.rightmediumlinked)
return
end
function h.processCargo(args, processed)
if util_args.castAsBool(args.nocargo) then return {} end
local tbl = {
{
_table = 'Tournaments',
Name = processed.name,
DateStart = util_time.strToDateStr(args.sdate or args.date or '') or '',
Date = util_time.strToDateStr(args.edate or args.date or '') or '',
League = processed.league,
Region = processed.region,
Prizepool = args.prizepool,
Currency = args.currency,
Country = args.country,
Location = args.location,
Rulebook = args.rulebook,
Platform = args.platform,
Type = args.type,
Game = args.game,
Tier = args.tier,
Mode = args.mode,
EventType = processed.type,
Links = args.web,
Sponsors = args.sponsors,
Organizer = args.organizer,
NumberofTeams = args.numberofteams,
First = args.first,
Second = args.second,
Host = m_team.teamlinkname(args.host),
SuppressTopSchedule = util_args.castAsBool(args.no_topschedule),
}
}
for _, param in ipairs(CCMT_PARAMS) do
tbl[1][param] = args['CM_' .. param]
end
return tbl
end
function h.processCategories(args, processed)
local tbl = {
args.country and ('%s Tournaments'):format(m_country.localization(args.country) or ''),
not processed.region and 'Tournaments Without Region',
args.game and args.game .. ' Tournaments',
args.tier and args.tier .. ' Tournaments',
args.type and args.type .. ' Tournaments',
args.mode and args.mode .. ' Tournaments',
args.platform and args.platform .. ' Tournaments',
'Tournaments',
processed.name:find('<br>') and 'Tournaments with br In Stored Name',
}
return tbl
end
function h.processVariables(args, processed)
local tbl = {
['Event Date'] = args.edate or args.date,
['Event Tier'] = processed.type,
['Event Prizepool'] = args.prizepool,
['Event Name'] = processed.name,
['Event League'] = processed.league,
['Event Region'] = processed.region,
}
return tbl
end
return p