Module:Sports series: Difference between revisions

Content deleted Content added
improve logic
use templatestyles for styling
Line 78:
 
-- Function to determine the winner based on scores within parentheses (first) or regular format (second)
local function determineWinner(cleanAggregate, team1, team2, boldWinner, colorWinner, aggregate, isFBRStyle, legs, leg1Score, leg2Score, disableAwayGoals, skipAutoWinner)
local team1Winner, team2Winner = false, false
local score1, score2
Line 140:
 
-- Regular winner determination logic if manual bolding or coloring is not conclusive
if not team1Winner and not team2Winner and not isDraw and not skipAutoWinner and (boldWinner or colorWinner or isFBRStyle) then
local parenthetical = cleanAggregate:match('%((%d+%-+%d+)%)')
local outsideParenthetical = cleanAggregate:match('^(%d+%-+%d+)')
Line 246:
-- Remove opening and closing HTML tags
str = str:gsub("</?%w+[^>]*>", "")
 
-- Remove apostrophes
str = str:gsub("''+", "")
 
-- Remove all whitespace
Line 259 ⟶ 262:
 
-- Function to format the dashes and winning notes for aggregate/leg score parameters, and divide the score from references/notes/superscripts
local function format_and_extract_score(s, doWrapnoWrap, disableNoWrap)
if not s then return '', '' end -- Return empty strings if input is nil
 
Line 276 ⟶ 279:
 
-- Format winning notes in brackets
iflocal doWraphas_multiple_parentheses and= not (s:match("%(.*%(")) then
local doWrapadd_span = (disableNoWrap or (not noWrap and not disableNoWrap and has_multiple_parentheses))
s = mw.ustring.gsub(s, '(%(%d+%s*–%s*%d+)%s+[Pp]%.?[EeSs]?%.?[NnOo]?%.?%)', '%1 [[Penalty shoot-out (association football)|p]])')
 
s = mw.ustring.gsub(s, '%([Aa]%.?[Ee]%.?[Tt]%.?%)', '([[Overtime (sports)#Association football|a.e.t.]])')
if noWrapadd_span then
else
s = mw.ustring.gsub(s, '(%(%d+%s*–%s*%d+)%s+[Pp]%.?[EeSs]?%.?[NnOo]?%.?%)', '<span class="nowrap">%1 [[Penalty shoot-out (association football)|p]])</span>')
s = mw.ustring.gsub(s, '%([Aa]%.?[Ee]%.?[Tt]%.?%)', '<span class="nowrap">([[Overtime (sports)#Association football|a.e.t.]])</span>')
else
s = mw.ustring.gsub(s, '(%(%d+%s*–%s*%d+)%s+[Pp]%.?[EeSs]?%.?[NnOo]?%.?%)', '%1 [[Penalty shoot-out (association football)|p]])')
s = mw.ustring.gsub(s, '%([Aa]%.?[Ee]%.?[Tt]%.?%)', '([[Overtime (sports)#Association football|a.e.t.]])')
end
s = mw.ustring.gsub(s, '%([Aa]%.?[Gg]?%.?[Rr]?%.?%)', '([[Away goals rule|a]])')
Line 431 ⟶ 437:
 
local divContent = mw.html.create('div')
:cssaddClass('fontsports-size', '90%series-notes')
:css('margin-bottom', '0.5em')
 
if isFBRStyle and legs == 0 then
Line 461 ⟶ 466:
if externalNotes then
local hiddenRefs = mw.html.create('span')
:cssaddClass('display', 'nonesports-series-hidden')
:wikitext(table.concat(noteDefinitions))
if isFBRStyle and legs == 0 then
Line 511 ⟶ 516:
 
local root = mw.html.create()
local templatestyles = frame:extensionTag{
name = 'templatestyles',
args = { src = 'Module:Sports series/styles.css' }
end}
root:wikitext(templatestyles)
 
local noFlagIcons = false
local fillBlanks = isTrue(args.fill_blanks)
Line 516 ⟶ 527:
local solidCell = isTrue(args.solid_cell) or args.solid_cell == 'grey' or args.solid_cell == 'gray'
local baselink = frame:getParent():getTitle()
iflocal currentPageTitle = mw.title.getCurrentTitle().text == baselink then baselink = '' endfullText
if currentPageTitle == baselink then baselink = '' end
local notes = {}
local noteGroup = args.note_group or 'lower-alpha'
Line 573 ⟶ 585:
local noWrap = isTrue(args.nowrap)
local disableNoWrap = isFalse(args.nowrap)
local doWrap = not noWrap and not disableNoWrap
 
local tableClass = 'wikitable sports-series'
local tableStyle = 'text-align: center;'
if isTrue(args.collapsed) then
tableClass = tableClass .. 'wikitable mw-collapsible mw-collapsed'
tableStyle = tableStyle .. ' width: 100%;'
end
if isTrue(args.center_table) then
tableStyletableClass = tableStyletableClass .. ' margincenter-left: auto; margin-right: auto; border: none;table'
end
if noWrap then
tableStyle = tableStyle .. ' white-space: nowrap;'
end
if fontSize then
tableStyle = tableStyle .. table:css(' font-size: ' .., fontSize .. '%;')
end
 
Line 597 ⟶ 603:
if args.id then
table:attr('id', args.id) -- Optional id parameter to allow anchor to table
end
if doWrapnoWrap then
table:cssattr('margindata-bottomnowrap', '0.5emy')
elseif not disableNoWrap then
table:attr('scopedata-nowrap', 'coln')
end
 
Line 618 ⟶ 629:
-- Create the header row with team and score columns
local header = table:tag('tr')
if doWrap then
header:css('white-space', 'nowrap')
end
local defaultTeam1 = isHA and 'Home team' or 'Team 1'
local defaultTeam2 = isHA and 'Away team' or 'Team 2'
header:tag('th'):attr('scope', 'col'):css('width', teamWidth):wikitext(args['team1'] or defaultTeam1)
header:tag('th')
header:tag('th'):attr('scope', 'col'):css('width', scoreWidth):wikitext(args['aggregate'] or legs == 0 and 'Score' or '[[Aggregate score|<abbr title="Aggregate score">Agg.</abbr>]]<span class="sports-series-sr-only">Tooltip Aggregate score</span>')
:attr('scope', 'col')
header:tag('th'):attr('scope', 'col'):css('width', teamWidth):wikitext(args['team2'] or defaultTeam2)
:css('text-align', 'right')
:css('width', teamWidth)
:wikitext(args['team1'] or defaultTeam1)
header:tag('th')
:attr('scope', 'col')
:css('width', scoreWidth)
:wikitext(args['aggregate'] or legs == 0 and 'Score' or '[[Aggregate score|<abbr title="Aggregate score">Agg.</abbr>]]<span class="sr-only" style="border: 0; clip: rect(0, 0, 0, 0); clip-path: polygon(0px 0px, 0px 0px, 0px 0px); height: 1px; margin: -1px; overflow: hidden; padding: 0; position: absolute; width: 1px; white-space: nowrap;">Tooltip Aggregate score</span>')
header:tag('th')
:attr('scope', 'col')
:css('text-align', 'left')
:css('width', teamWidth)
:wikitext(args['team2'] or defaultTeam2)
 
-- Add columns for each leg if applicable
Line 654 ⟶ 651:
end
 
header:tag('th'):attr('scope', 'col'):css('width', scoreWidth):wikitext(legHeading)
:attr('scope', 'col')
:css('width', scoreWidth)
:wikitext(legHeading)
end
end
Line 688 ⟶ 682:
-- Add a heading above a given row in the table
if headingParam and not showCountry then
local headingRow = table:tag('tr'):addClass('heading-row')
headingRow:tag('td')
:attr('colspan', colCount)
:css('background', 'whitesmoke')
:wikitext('<strong>' .. headingParam .. '</strong>')
end
Line 710 ⟶ 703:
-- Clean the aggregate score
local cleanAggregate = cleanScore(aggregateScore)
-- Format and rewrite anchor links for aggregate score
aggregateScore, aggregateEndText = format_and_extract_score(aggregateScore, doWrapnoWrap, disableNoWrap)
aggregateEndText, notes = processNote(frame, notes, 'agg', aggNote, aggregateEndText, rowIndex, rand_val, noteGroup)
if generateLinks and legs == 0 then
aggregateScore = cleanAndGenerateLinks(team1, team2, aggregateScore, false)
end
 
local skipDetermineWinnerskipAutoWinner = legs == 0 and aggregateScore ~= '' and checkSmallText(aggregateScore)
 
-- Determine the winning team on aggregate
team1, team2, team1Winner, team2Winner, manualBold, manualColor, isDraw, aggregateScore = determineWinner(cleanAggregate, team1, team2, boldWinner, colorWinner, aggregateScore, isFBRStyle, legs, leg1Score, leg2Score, disableAwayGoals, skipAutoWinner)
local skipDetermineWinner = legs == 0 and aggregateScore ~= '' and checkSmallText(aggregateScore)
 
if not skipDetermineWinner then
team1, team2, team1Winner, team2Winner, manualBold, manualColor, isDraw, aggregateScore = determineWinner(cleanAggregate, team1, team2, boldWinner, colorWinner, aggregateScore, isFBRStyle, legs, leg1Score, leg2Score, disableAwayGoals)
end
 
-- 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
 
-- Function to create flag template parameters
Line 758 ⟶ 739:
 
local aggregateContent
if not disableSmallText and skipDetermineWinnerskipAutoWinner then
aggregateContent = '<span styleclass="fontsports-size:85%;series-small">' .. aggregateScore .. '</span>' .. aggregateEndText
else
aggregateContent = aggregateScore .. aggregateEndText
Line 765 ⟶ 746:
 
-- Create aggregate score cell with conditional styling
local aggregateStyleaggregateClass = ''
if doWrap and not (cleanAggregate:match("%(.*%(")) then
aggregateStyle = 'white-space: nowrap;'
end
if isFBRStyle and legs == 0 then
if team1Winner then
aggregateStyleaggregateClass = aggregateStyle .. 'backgroundfbr-color: #BBF3FF;home-win'
elseif team2Winner then
aggregateStyleaggregateClass = aggregateStyle .. 'backgroundfbr-color: #FFBBBB;away-win'
elseif isDraw then
aggregateStyleaggregateClass = aggregateStyle .. 'background-color: #FFFFBB;draw'
end
elseif isDraw then
aggregateStyleaggregateClass = aggregateStyle .. 'background-color: #FFFFBB;draw'
end
if doWrapnot disableNoWrap and (not noWrap and (cleanAggregate:match("%(.*%("))) then
aggregateClass = aggregateClass .. ' allow-wrap'
end
 
-- Create rows for aggregate score and team names, bolded if set by user
row:tag('td'):cssTextaddClass(team1Styleteam1Winner and (colorWinner or manualColor) and 'winner' or nil):wikitext((team1Winner and (boldWinner or manualBold) and team1Text ~= '') and ('<strong>' .. team1Text .. '</strong>') or team1Text)
row:tag('td'):cssTextaddClass(aggregateStyleaggregateClass ~= '' and aggregateStyleaggregateClass or nil):wikitext(aggregateContent)
row:tag('td'):cssTextaddClass(team2Styleteam2Winner and (colorWinner or manualColor) and 'winner' or nil):wikitext((team2Winner and (boldWinner or manualBold) and team2Text ~= '') and ('<strong>' .. team2Text .. '</strong>') or team2Text)
 
-- Add columns for each leg score if applicable
Line 795 ⟶ 776:
if legScore == "null" then
if solidCell then
row:tag('td'):cssaddClass('background', '#BBBBBBsolid-cell')
else
legScore = '—'
Line 802 ⟶ 783:
 
if legScore ~= "null" then
-- Format and rewrite anchor links for leg scores
local cleanLeg = cleanScore(legScore)
legScore, legEndText = format_and_extract_score(legScore, doWrapnoWrap, disableNoWrap)
legEndText, notes = processNote(frame, notes, 'leg' .. leg, legNote, legEndText, rowIndex, rand_val, noteGroup)
if generateLinks and not aggregateContent:lower():find("bye") then
Line 815 ⟶ 796:
local legContent
if not disableSmallText and legScore ~= '' and checkSmallText(legScore) then
legContent = '<span styleclass="fontsports-size:85%;series-small">' .. legScore .. '</span>' .. legEndText
else
legContent = legScore .. legEndText
end
local legStylelegClass = ''
if doWrapnot disableNoWrap and (not noWrap and (cleanLeg:match("%(.*%("))) then
legStylelegClass = 'whiteallow-space: nowrap;wrap'
end
-- Write cells for legs
row:tag('td'):cssTextaddClass(legStylelegClass ~= '' and legStylelegClass or nil):wikitext(legContent)
end
end
Line 844 ⟶ 825:
tableCode = mw.ustring.gsub(tableCode, '(%[%[)(#[^%[%]]*%|)', '%1' .. baselink .. '%2')
end
local escapedTitle = currentPageTitle:gsub("([%(%)%.%%%+%-%*%?%[%^%$])", "%%%1")
local titlePattern = '%[%[' .. escapedTitle .. '(#[^%[%]]*%|)'
tableCode = mw.ustring.gsub(tableCode, titlePattern, '[[%1')
 
return tableCode