[checked revision] | [checked revision] |
No edit summary |
No edit summary |
||
(45 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
local lang = mw.getLanguage('en') |
local lang = mw.getLanguage('en') |
||
⚫ | |||
local m_team = require('Module:Team') |
local m_team = require('Module:Team') |
||
⚫ | |||
⚫ | |||
⚫ | |||
local teamhist = require('Module:Infobox/TeamHist') |
local teamhist = require('Module:Infobox/TeamHist') |
||
+ | local util_args = require('Module:ArgsUtil') |
||
local util_infobox = require('Module:InfoboxUtil') |
local util_infobox = require('Module:InfoboxUtil') |
||
− | local util_html = require('Module: |
+ | local util_html = require('Module:HtmlUtil') |
local util_cargo = require('Module:CargoUtil') |
local util_cargo = require('Module:CargoUtil') |
||
⚫ | |||
local util_table = require('Module:TableUtil') |
local util_table = require('Module:TableUtil') |
||
local util_time = require('Module:TimeUtil') |
local util_time = require('Module:TimeUtil') |
||
local util_form = require('Module:FormUtil') |
local util_form = require('Module:FormUtil') |
||
+ | local util_text = require('Module:TextUtil') |
||
+ | local i18n = require('Module:i18nUtil') |
||
+ | |||
⚫ | |||
⚫ | |||
+ | local Region = require('Module:Region') |
||
local NOIMAGE = 'Unknown Infobox Image - Tournament.png' |
local NOIMAGE = 'Unknown Infobox Image - Tournament.png' |
||
⚫ | |||
⚫ | |||
+ | |||
⚫ | |||
sections = { 'Tournament Information', 'Location & Dates', 'Broadcast', 'Results' }, |
sections = { 'Tournament Information', 'Location & Dates', 'Broadcast', 'Results' }, |
||
contents = { |
contents = { |
||
− | { 'Organizer', 'Rulebook', 'Sponsor', |
+ | { 'Organizer', 'Host', 'Rulebook', 'Sponsor', 'Format', 'PrizePool','NumberofTeams', 'Links' }, |
{ 'Server', 'Type', 'Game', 'Tier', 'Mode', 'Platform', 'Country', 'Location', 'Venue', 'StartDate', 'EndDate', 'Date', }, |
{ 'Server', 'Type', 'Game', 'Tier', 'Mode', 'Platform', 'Country', 'Location', 'Venue', 'StartDate', 'EndDate', 'Date', }, |
||
{ 'Casters', 'Streams', 'Schedule' }, |
{ 'Casters', 'Streams', 'Schedule' }, |
||
{ 'Winner', 'Second', 'Third', 'Fourth', 'Qualified', }, |
{ 'Winner', 'Second', 'Third', 'Fourth', 'Qualified', }, |
||
}, |
}, |
||
⚫ | |||
} |
} |
||
⚫ | |||
− | local FORM_INFO = { |
+ | local FORM_INFO = { |
+ | SFS = { form = 'SpoilerFreeSchedule', template = 'SFS' }, |
||
+ | MCE = { form = 'MatchCalendarExport', template = 'MCE' } |
||
⚫ | |||
+ | |||
+ | local CCMT_PARAMS = { 'StandardName', 'TournamentLevel', 'IsQualifier', 'IsPlayoffs', 'IsOfficial', 'Year', 'LeagueIconKey' } |
||
+ | |||
+ | local ALLOWED_TIMEZONES = { 'PST', 'KST', 'CET' } |
||
local h = {} |
local h = {} |
||
⚫ | |||
+ | |||
⚫ | |||
+ | local args = util_args.merge() |
||
+ | return Infobox(args):run() |
||
⚫ | |||
+ | |||
+ | function Infobox:validateArgs(args) |
||
+ | if args.closest_timezone and not util_table.keyOf(ALLOWED_TIMEZONES, args.closest_timezone) then |
||
+ | -- error(i18n.print('error_invalidTimezone')) |
||
+ | end |
||
+ | end |
||
+ | |||
+ | function Infobox:castArgs(args) |
||
⚫ | |||
+ | args.region = Region(args.region) |
||
+ | args.country = Country(args.country) |
||
+ | args.currency = Currency(args.currency) |
||
+ | end |
||
− | function |
+ | function Infobox:getProcessed(args) |
⚫ | |||
− | local result = util_cargo.getOneRow({ |
||
− | tables = 'CCMTournaments', |
||
− | fields = { 'StandardName', 'Region', 'League' }, |
||
− | where = ('OverviewPage="%s"'):format(pagename) |
||
− | }) |
||
local tbl = { |
local tbl = { |
||
− | pagename = pagename, |
+ | pagename = args.pagename or mw.title.getCurrentTitle().text, |
− | name = |
+ | name = args.CM_StandardName or args.storedname or args.name, |
+ | type = util_text.ucfirst(args.type), |
||
− | region = (result.Region and m_region.medium(args.region)) or (args.region and m_region.medium(args.region)), |
||
⚫ | |||
} |
} |
||
return tbl |
return tbl |
||
end |
end |
||
− | function |
+ | function Infobox:getDisplay(args, processed) |
⚫ | |||
− | local frame = mw.getCurrentFrame() |
||
local tbl = { |
local tbl = { |
||
title = args.name, |
title = args.name, |
||
Line 58: | Line 83: | ||
Server = args.server, |
Server = args.server, |
||
Type = args.type, |
Type = args.type, |
||
− | Game = args.game, |
+ | Game = args.game and ('[[%s]]'):format(args.game), |
Tier = args.tier, |
Tier = args.tier, |
||
Mode = args.mode, |
Mode = args.mode, |
||
Platform = args.platform, |
Platform = args.platform, |
||
− | Region = |
+ | Region = args.region:flair(), |
− | EventType = |
+ | EventType = processed.type, |
− | Country = args.country |
+ | Country = args.country:flair(), |
Location = args.location, |
Location = args.location, |
||
Venue = args.venue, |
Venue = args.venue, |
||
Line 73: | Line 98: | ||
StartDate = args.sdate, |
StartDate = args.sdate, |
||
EndDate = args.edate, |
EndDate = args.edate, |
||
− | Links = |
+ | Links = h.getLinks(args), |
Casters = args.caster or args.casters, |
Casters = args.caster or args.casters, |
||
Streams = args.streams and (args.streams .. (args.linkstreams and '<br>[[#Streams|Full List]]' or '')), |
Streams = args.streams and (args.streams .. (args.linkstreams and '<br>[[#Streams|Full List]]' or '')), |
||
Schedule = h.makeSchedule(processed.pagename), |
Schedule = h.makeSchedule(processed.pagename), |
||
+ | Host = h.getHost(args), |
||
} |
} |
||
h.addResults(tbl, args) |
h.addResults(tbl, args) |
||
− | return tbl |
+ | return Infobox.mergeDisplay(display, tbl) |
+ | end |
||
+ | |||
+ | function h.getHost(args) |
||
+ | if args.host then |
||
+ | return m_team.plainlinked(args.host) |
||
+ | end |
||
+ | end |
||
+ | |||
+ | function h.getHostForCargo(args) |
||
+ | if args.host then |
||
+ | return m_team.teamname(args.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 |
||
⚫ | |||
+ | 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 args.currency:short(args.prizepool) |
||
end |
end |
||
function h.makeSchedule(pagename) |
function h.makeSchedule(pagename) |
||
if util_cargo.getOneResult({ tables = 'MatchSchedule', fields = 'OverviewPage', where = ('OverviewPage="%s"'):format(pagename) }) then |
if util_cargo.getOneResult({ tables = 'MatchSchedule', fields = 'OverviewPage', where = ('OverviewPage="%s"'):format(pagename) }) then |
||
− | local |
+ | 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 |
end |
||
return nil |
return nil |
||
Line 105: | Line 167: | ||
end |
end |
||
− | function |
+ | function Infobox:getCargo(args, processed) |
⚫ | |||
+ | if util_args.castAsBool(args.nocargo) then return cargo end |
||
local tbl = { |
local tbl = { |
||
{ |
{ |
||
Line 112: | Line 176: | ||
DateStart = util_time.strToDateStr(args.sdate or args.date or '') or '', |
DateStart = util_time.strToDateStr(args.sdate or args.date or '') or '', |
||
Date = util_time.strToDateStr(args.edate or args.date or '') or '', |
Date = util_time.strToDateStr(args.edate or args.date or '') or '', |
||
+ | ClosestTimezone = args.closest_timezone, |
||
⚫ | |||
− | + | League = args.league, |
|
+ | StandardLeague = args.league, |
||
+ | Region = args.region, |
||
Prizepool = args.prizepool, |
Prizepool = args.prizepool, |
||
+ | Currency = args.currency, |
||
Country = args.country, |
Country = args.country, |
||
Location = args.location, |
Location = args.location, |
||
Line 123: | Line 190: | ||
Tier = args.tier, |
Tier = args.tier, |
||
Mode = args.mode, |
Mode = args.mode, |
||
⚫ | |||
Links = args.web, |
Links = args.web, |
||
Sponsors = args.sponsors, |
Sponsors = args.sponsors, |
||
Line 129: | Line 197: | ||
First = args.first, |
First = args.first, |
||
Second = args.second, |
Second = args.second, |
||
+ | Host = h.getHostForCargo(args), |
||
+ | SuppressTopSchedule = util_args.castAsBool(args.no_topschedule), |
||
⚫ | |||
} |
} |
||
} |
} |
||
+ | for _, param in ipairs(CCMT_PARAMS) do |
||
− | return tbl |
||
+ | tbl[1][param] = args['CM_' .. param] |
||
+ | end |
||
+ | return util_table.mergeArrays(cargo, tbl) |
||
end |
end |
||
− | function |
+ | function Infobox:getCategories(args, processed) |
local tbl = { |
local tbl = { |
||
− | args.country and ('%s Tournaments'):format |
+ | args.country:exists() and ('%s Tournaments'):format(args.country:get('adjective')), |
− | not |
+ | not args.region:exists() and 'Tournaments Without Region', |
args.game and args.game .. ' Tournaments', |
args.game and args.game .. ' Tournaments', |
||
args.tier and args.tier .. ' Tournaments', |
args.tier and args.tier .. ' Tournaments', |
||
args.type and args.type .. ' Tournaments', |
args.type and args.type .. ' Tournaments', |
||
args.mode and args.mode .. ' Tournaments', |
args.mode and args.mode .. ' Tournaments', |
||
+ | args.platform and args.platform .. ' Tournaments', |
||
'Tournaments', |
'Tournaments', |
||
processed.name:find('<br>') and 'Tournaments with br In Stored Name', |
processed.name:find('<br>') and 'Tournaments with br In Stored Name', |
||
Line 148: | Line 223: | ||
end |
end |
||
− | function |
+ | function Infobox:getVariables(args, processed) |
⚫ | |||
local tbl = { |
local tbl = { |
||
['Event Date'] = args.edate or args.date, |
['Event Date'] = args.edate or args.date, |
||
− | ['Event Tier'] = |
+ | ['Event Tier'] = processed.type, |
['Event Prizepool'] = args.prizepool, |
['Event Prizepool'] = args.prizepool, |
||
['Event Name'] = processed.name, |
['Event Name'] = processed.name, |
||
['Event League'] = processed.league, |
['Event League'] = processed.league, |
||
− | ['Event Region'] = |
+ | ['Event Region'] = args.region:get(), |
⚫ | |||
− | return tbl |
||
⚫ | |||
− | |||
⚫ | |||
⚫ | |||
− | local processed = h.getProcessed(args) |
||
− | |||
⚫ | |||
− | lc = processed.lc, |
||
− | nocargo = mw.title.getCurrentTitle().nsText ~= '' or args.nocargo, |
||
− | nocat = mw.title.getCurrentTitle().nsText ~= '' or args['no-cat'], |
||
− | } |
||
− | |||
− | return { |
||
⚫ | |||
⚫ | |||
− | settings = settings, |
||
− | categories = h.processCategories(args, processed), |
||
⚫ | |||
− | layout = LAYOUT |
||
} |
} |
||
+ | return util_table.merge(variables, tbl) |
||
end |
end |
||
Revision as of 22:42, 21 October 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 Currency = require('Module:Currency')
local m_team = require('Module:Team')
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_table = require('Module:TableUtil')
local util_time = require('Module:TimeUtil')
local util_form = require('Module:FormUtil')
local util_text = require('Module:TextUtil')
local i18n = require('Module:i18nUtil')
local Country = require('Module:Country')
local League = require('Module:League')
local Region = require('Module:Region')
local NOIMAGE = 'Unknown Infobox Image - Tournament.png'
local Infobox = require('Module:Infobox'):extends()
Infobox.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', },
},
}
Infobox.type = 'Tournament'
local FORM_INFO = {
SFS = { form = 'SpoilerFreeSchedule', template = 'SFS' },
MCE = { form = 'MatchCalendarExport', template = 'MCE' }
}
local CCMT_PARAMS = { 'StandardName', 'TournamentLevel', 'IsQualifier', 'IsPlayoffs', 'IsOfficial', 'Year', 'LeagueIconKey' }
local ALLOWED_TIMEZONES = { 'PST', 'KST', 'CET' }
local h = {}
local p = {}
function p.main(frame)
local args = util_args.merge()
return Infobox(args):run()
end
function Infobox:validateArgs(args)
if args.closest_timezone and not util_table.keyOf(ALLOWED_TIMEZONES, args.closest_timezone) then
-- error(i18n.print('error_invalidTimezone'))
end
end
function Infobox:castArgs(args)
args.league = League(args.CM_StandardLeague or args.league)
args.region = Region(args.region)
args.country = Country(args.country)
args.currency = Currency(args.currency)
end
function Infobox:getProcessed(args)
local tbl = {
pagename = args.pagename or mw.title.getCurrentTitle().text,
name = args.CM_StandardName or args.storedname or args.name,
type = util_text.ucfirst(args.type),
}
return tbl
end
function Infobox:getDisplay(args, processed)
local display = self:super('getDisplay', args, processed)
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 and ('[[%s]]'):format(args.game),
Tier = args.tier,
Mode = args.mode,
Platform = args.platform,
Region = args.region:flair(),
EventType = processed.type,
Country = args.country:flair(),
Location = args.location,
Venue = args.venue,
Format = args.format,
PrizePool = args.prizepool,
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 Infobox.mergeDisplay(display, tbl)
end
function h.getHost(args)
if args.host then
return m_team.plainlinked(args.host)
end
end
function h.getHostForCargo(args)
if args.host then
return m_team.teamname(args.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 args.currency:short(args.prizepool)
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 Infobox:getCargo(args, processed)
local cargo = self:super('getCargo', args, processed)
if util_args.castAsBool(args.nocargo) then return cargo 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 '',
ClosestTimezone = args.closest_timezone,
League = args.league,
StandardLeague = args.league,
Region = args.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 = h.getHostForCargo(args),
SuppressTopSchedule = util_args.castAsBool(args.no_topschedule),
OverviewPage = mw.title.getCurrentTitle().text,
}
}
for _, param in ipairs(CCMT_PARAMS) do
tbl[1][param] = args['CM_' .. param]
end
return util_table.mergeArrays(cargo, tbl)
end
function Infobox:getCategories(args, processed)
local tbl = {
args.country:exists() and ('%s Tournaments'):format(args.country:get('adjective')),
not args.region:exists() 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 Infobox:getVariables(args, processed)
local variables = self:super('getVariables', 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'] = args.region:get(),
}
return util_table.merge(variables, tbl)
end
return p