Modul:Sports series: Perbedaan antara revisi

Konten dihapus Konten ditambahkan
tim pemenang otomatis cetak tebal
penyederhanaan pranala jangkar; konversi otomatis "-" menjadi "–" (en dashes); hapus kode-kode duplikat
Baris 8:
return frame:expandTemplate{ title = templateName, args = params }
end
-- Function to check the existence of template passed via |flag=flagTemplate
local function templateExists(templateName)
local title = mw.title.new('Templat:' .. templateName)
Baris 189:
end
 
-- Function to add a legend to below the table when |matches_style=FBRisFBRStyle is true
local function createFBRLegend()
return mw.html.create('div')
Baris 195:
:css('margin-bottom', '0.5em')
:wikitext("Legenda: Biru = tim kandang menang; Kuning = imbang; Merah = tim tandang menang.")
end
 
-- Function to format the dashes for aggregate/leg score parameters
local function format_score(s)
s = mw.ustring.gsub(s or '', '^%s*([%d%.]+)%s*[–−—%-]%s*([%d%.]+)', '%1–%2')
s = mw.ustring.gsub(s, '^%s*([%d%.]+)%s*&[MmNn][Dd][Aa][Ss][Hh];%s*([%d%.]+)', '%1–%2')
s = mw.ustring.gsub(s, '^%s*(%[%[[^%[%]]*%|[%d%.]+)%s*%-%s*([%d%.]+)', '%1–%2')
s = mw.ustring.gsub(s, '^%s*(%[[^%[%]%s]*%s+[%d%.]+)%s*%-%s*([%d%.]+)', '%1–%2')
s = mw.ustring.gsub(s, '^%s*(%[%[[^%[%]]*%|[%d%.]+)%s*&[MmNn][Dd][Aa][Ss][Hh];%s*([%d%.]+)', '%1–%2')
s = mw.ustring.gsub(s, '^%s*(%[[^%[%]%s]*%s+[%d%.]+)%s*&[MmNn][Dd][Aa][Ss][Hh];%s*([%d%.]+)', '%1–%2')
return s
end
 
-- Function to rewrite anchor links of match scores
local function rewriteAnchorLinks(text, baselink)
if not text then
return text
end
return text:gsub('(%[%[)(#[^%[%]]*%|)', '%1' .. baselink .. '%2')
end
 
Baris 216 ⟶ 235:
local noFlagIcons = false
local fillBlanks = args.fill_blanks and (args.fill_blanks == 'y' or args.fill_blanks == 'yes' or args.fill_blanks == '1' or args.fill_blanks == 'true')
local baselink = frame:getParent():getTitle()
if mw.title.getCurrentTitle().text == baselink then baselink = '' end
-- Process the font size parameter
Baris 386 ⟶ 407:
 
local row = table:tag('tr')
local team1, team2, aggregateScore, team2team1Icon, team2Icon, team1Variant, team2Variant
local team1Winner, team2Winner, manualBold, manualColor, isDraw = false, false, false, false, false
local leg1Score, leg2Score = false, false
local team1Asterick, team2Asterick = false, false
 
-- Process rows for both national team and club matches
if matchType == 'NT' then
-- Check if team parameter beings with an asterick instead of a country code, indicating a string will be displayed instead of national team flag
team1 = args[i]
if team1 and team1:match("^%s*%*") then
Baris 409 ⟶ 429:
team2, team2Variant = processIcon(args[i+2])
end
else
team1 = args[i]
if noFlagIcons then
aggregateScore = args[i+1]
team2 = args[i+2]
else
team1Icon, team1Variant = processIcon(args[i+1])
aggregateScore = args[i+2]
team2 = args[i+3]
team2Icon, team2Variant = processIcon(args[i+4])
end
end
 
-- Name the 1st/2nd --leg Cleanscores thefor aggregatetwo-legged scoreties
if legs == 2 then
local cleanAggregate = cleanScore(aggregateScore)
if matchType == 'NT' or noFlagIcons then
-- Name the 1st/2nd leg scores for two-legged ties for possibly determining the winner on away goals
if legs == 2 thenleg1Score = args[i+3]
leg1Score leg2Score = args[i+34]
leg2Score = args[i+4]else
leg1Score = args[i+5]
leg2Score = args[i+6]
end
end
-- Determine the winning team on aggregate
 
team1, team2, team1Winner, team2Winner, manualBold, manualColor, isDraw, aggregateScore = determineWinner(cleanAggregate, matchType, team1, team2, boldWinner, colorWinner, aggregateScore, isFBRStyle, legs, leg1Score, leg2Score, disableAwayGoals)
-- Clean the aggregate score
-- Add background-color for winning team if set by user
local cleanAggregate = cleanScore(aggregateScore)
local team1Style = team1Winner and ((colorWinner or manualColor) and 'background-color: #CCFFCC;' or '') .. 'text-align: right;' or 'text-align: right;'
-- Format and rewrite anchor links for aggregate score
local team2Style = team2Winner and ((colorWinner or manualColor) and 'background-color: #CCFFCC;' or '') .. 'text-align: left;' or 'text-align: left;'
aggregateScore = format_score(aggregateScore)
-- Generate text to display for each team
if baselink ~= '' local team1Text, team2Textthen
aggregateScore = rewriteAnchorLinks(aggregateScore, baselink)
end
 
-- Determine the winning team on aggregate
team1, team2, team1Winner, team2Winner, manualBold, manualColor, isDraw, aggregateScore = determineWinner(cleanAggregate, matchType, team1, team2, boldWinner, colorWinner, aggregateScore, isFBRStyle, legs, leg1Score, leg2Score, disableAwayGoals)
 
-- Add background-color for winning team if set by user
local team1Style = 'text-align: right;'
local team2Style = 'text-align: left;'
if team1Winner and (colorWinner or manualColor) then
team1Style = team1Style .. ' background-color: #CCFFCC;'
end
if team2Winner and (colorWinner or manualColor) then
team2Style = team2Style .. ' background-color: #CCFFCC;'
end
 
-- Generate text to display for each team
local team1Text, team2Text
if matchType == 'NT' then
if flagParam1 then -- Check whether youth team flag template with age level is used
team1Text = (not team1Asterick and team1 ~= "" and team1 ~= nil) and (expandTemplate(frame, flagTemplate .. '-rt', {flagParam1, team1, variant = team1Variant})) or (team1 ~= nil and team1 or "")
Baris 431 ⟶ 484:
team2Text = (not team2Asterick and team2 ~= "" and team2 ~= nil) and (expandTemplate(frame, flagTemplate, {team2, variant = team2Variant})) or (team2 ~= nil and team2 or "")
end
else
-- When set by user, adds blank flags when string is used for a team instead of national team flag template
team1Text = noFlagIcons and (team1 or '') or ((team1Icon ~= "" and team1Icon ~= nil) and ((team1 or '') .. ' ' .. expandTemplate(frame, flagTemplate, {team1Icon, variant = team1Variant})) or (team1 or ''))
if fillBlanks then
team2Text = noFlagIcons and (team2 or '') or ((team2Icon ~= "" and team2Icon ~= nil) and (expandTemplate(frame, flagTemplate, {team2Icon, variant = team2Variant}) .. ' ' .. (team2 or '')) or (team2 or ''))
end
 
-- When set by user, adds blank flags when string is used for a team instead of national team flag template
if fillBlanks then
if matchType == 'NT' then
if team1Asterick then
team1Text = team1Text .. ' <span class="flagicon">[[Berkas:Flag placeholder.svg|25x17px|link=]]</span>'
Baris 439 ⟶ 498:
team2Text = '<span class="flagicon">[[Berkas:Flag placeholder.svg|25x17px|link=]]</span> ' .. team2Text
end
endelseif not noFlagIcons then
-- Create aggregate score cellif withnot conditionalteam1Icon stylingor team1Icon == "" then
team1Text = team1Text .. ' <span class="flagicon">[[Berkas:Flag placeholder.svg|25x17px|link=]]</span>'
local aggregateStyle = 'text-align: center;'
if isFBRStyle and legs == 0 then
if team1Winner then
aggregateStyle = aggregateStyle .. '; background-color: #BBF3FF;'
elseif team2Winner then
aggregateStyle = aggregateStyle .. '; background-color: #FFBBBB;'
elseif isDraw then
aggregateStyle = aggregateStyle .. '; background-color: #FFFFBB;'
end
elseif isDraw if not team2Icon or team2Icon == "" then
team2Text = '<span class="flagicon">[[Berkas:Flag placeholder.svg|25x17px|link=]]</span> ' .. team2Text
aggregateStyle = aggregateStyle .. '; background-color: #FFFFBB;'
end
-- Create rows for aggregate score and team names, bolded if set by user
row:tag('td'):cssText(team1Style):wikitext((team1Winner and (boldWinner or manualBold) and team1Text ~= '') and ('<strong>' .. team1Text .. '</strong>') or team1Text)
row:tag('td'):cssText(aggregateStyle):wikitext(aggregateScore)
row:tag('td'):cssText(team2Style):wikitext((team2Winner and (boldWinner or manualBold) and team2Text ~= '') and ('<strong>' .. team2Text .. '</strong>') or team2Text)
else
-- Process rows for club matches
team1 = args[i]
if noFlagIcons then -- Remove use of flag icons if set by user
aggregateScore = args[i+1]
team2 = args[i+2]
else
team1Icon, team1Variant = processIcon(args[i+1])
aggregateScore = args[i+2]
team2 = args[i+3]
team2Icon, team2Variant = processIcon(args[i+4])
end
-- Clean the aggregate score
local cleanAggregate = cleanScore(aggregateScore)
-- Name the 1st/2nd leg scores for two-legged ties for possibly determining the winner on away goals
if legs == 2 then
if noFlagIcons then
leg1Score = args[i+3]
leg2Score = args[i+4]
else
leg1Score = args[i+5]
leg2Score = args[i+6]
end
end
-- Determine the winning team on aggregate
team1, team2, team1Winner, team2Winner, manualBold, manualColor, isDraw, aggregateScore = determineWinner(cleanAggregate, matchType, team1, team2, boldWinner, colorWinner, aggregateScore, isFBRStyle, legs, leg1Score, leg2Score, disableAwayGoals)
-- Add background-color for winning team if set by user
local team1Style = team1Winner and ((colorWinner or manualColor) and 'background-color: #CCFFCC;' or '') .. 'text-align: right;' or 'text-align: right;'
local team2Style = team2Winner and ((colorWinner or manualColor) and 'background-color: #CCFFCC;' or '') .. 'text-align: left;' or 'text-align: left;'
-- Generate text, and flags (if not disabled), to display for each team
local team1Text = noFlagIcons and (team1 or '') or ((team1Icon ~= "" and team1Icon ~= nil) and ((team1 or '') .. ' ' .. expandTemplate(frame, flagTemplate, {team1Icon, variant = team1Variant})) or (team1 or ''))
local team2Text = noFlagIcons and (team2 or '') or ((team2Icon ~= "" and team2Icon ~= nil) and (expandTemplate(frame, flagTemplate, {team2Icon, variant = team2Variant}) .. ' ' .. (team2 or '')) or (team2 or ''))
-- When set by user, adds blank flags when country code parameter is left blank
if fillBlanks then
if not noFlagIcons then
if not team1Icon or team1Icon == "" then
team1Text = team1Text .. ' <span class="flagicon">[[Berkas:Flag placeholder.svg|25x17px|link=]]</span>'
end
if not team2Icon or team2Icon == "" then
team2Text = '<span class="flagicon">[[Berkas:Flag placeholder.svg|25x17px|link=]]</span> ' .. team2Text
end
end
end
end

-- Create aggregate score cell with conditional styling
local aggregateStyle = 'text-align: center;'
if isFBRStyle and legs == 0 then
if team1Winner then
aggregateStyle = aggregateStyle .. '; background-color: #BBF3FF;'
elseif team2Winner then
aggregateStyle = aggregateStyle .. '; background-color: #FFBBBB;'
elseif isDraw then
aggregateStyle = aggregateStyle .. '; background-color: #FFFFBB;'
end
elseif isDraw then
aggregateStyle = aggregateStyle .. '; background-color: #FFFFBB;'
end
elseif isDraw then
-- Create rows for aggregate score and team names, bolded if set by user
aggregateStyle = aggregateStyle .. '; background-color: #FFFFBB;'
row:tag('td'):cssText(team1Style):wikitext((team1Winner and (boldWinner or manualBold)) and '<strong>' .. team1Text .. '</strong>' or team1Text)
row:tag('td'):cssText(aggregateStyle):wikitext(aggregateScore)
row:tag('td'):cssText(team2Style):wikitext((team2Winner and (boldWinner or manualBold)) and '<strong>' .. team2Text .. '</strong>' or team2Text)
end
 
-- Create rows for aggregate score and team names, bolded if set by user
row:tag('td'):cssText(team1Style):wikitext((team1Winner and (boldWinner or manualBold) and team1Text ~= '') and ('<strong>' .. team1Text .. '</strong>') or team1Text)
row:tag('td'):cssText(aggregateStyle):wikitext(aggregateScore)
row:tag('td'):cssText(team2Style):wikitext((team2Winner and (boldWinner or manualBold) and team2Text ~= '') and ('<strong>' .. team2Text .. '</strong>') or team2Text)
 
-- Add columns for each leg score if applicable
Baris 525 ⟶ 533:
local legScore = args[legIndex]
if legScore ~= "null" then
-- Format and rewrite anchor links for leg scores
legScore = format_score(legScore)
if baselink ~= '' then
legScore = rewriteAnchorLinks(legScore, baselink)
end
-- Write cells for legs
row:tag('td'):css('text-align', 'center'):wikitext(legScore)
end