Modul:Sports series: Perbedaan antara revisi
Konten dihapus Konten ditambahkan
Tidak ada ringkasan suntingan |
Membalikkan revisi 26260203 oleh 182.253.116.11 (bicara) Tag: Pembatalan |
||
Baris 6:
end
local function templateExists(templateName)
local title = mw.title.new('
return title and title.exists
end
Baris 30 ⟶ 29:
local last_digit = n % 10
local last_two_digits = n % 100
if last_digit == 1
return n
else
return n
end
end
Baris 56 ⟶ 41:
if not score or score:match("^%s*$") then
return ''
end
-- Function to replace wiki links with their display text or link text
local function replaceLink(match)
local pipePos = match:find("|")
if pipePos then
return match:sub(pipePos + 1, -3) -- Return text after the '|'
else
return match:sub(3, -3) -- Return text without the brackets
end
end
Baris 62 ⟶ 57:
-- Remove MediaWiki's unique placeholder sequences for references
score = score:gsub(
-- Remove superscript tags and their contents
Baris 68 ⟶ 63:
-- Convert dashes to a standard format
score = score:gsub('[–—―‒−]
-- Strip all characters except numbers, dashes and parentheses
Baris 75 ⟶ 70:
-- Function to determine the winner based on scores within parentheses (first) or regular format (second)
local function determineWinner(
local team1Winner, team2Winner = false, false
local score1, score2
local manualBold = false
local manualColor = false
-- Handling for manual bolding
Baris 101 ⟶ 95:
end
-- Handling for manual coloring
if team1 and type(team1) == 'string' then
manualColor1 = team1:find("''") and not (team1:gsub("''", ""):match("^%s*$"))
Baris 109 ⟶ 103:
manualColor2 = team2:find("''") and not (team2:gsub("''", ""):match("^%s*$"))
team2 = team2:gsub("''", "")
end
Baris 131 ⟶ 117:
manualColor = true
end
-- Additional check for empty team names in NT matches
if matchType == 'NT' and ((not team1 or team1:match("^%s*$")) or (not team2 or team2:match("^%s*$"))) then
-- Skip further processing if either team name is effectively empty
return team1, team2, team1Winner, team2Winner, manualBold, manualColor
end
-- Regular winner determination logic if manual bolding or coloring is not conclusive
if not team1Winner and not team2Winner
local parenthetical =
local outsideParenthetical =
if parenthetical then
score1, score2 = parenthetical:match('(%d+)%-+(%d+)')
elseif outsideParenthetical then
Baris 147 ⟶ 135:
if score1 and score2 then
end
end
return team1, team2, team1Winner, team2Winner, manualBold, manualColor
end
Baris 189 ⟶ 151:
end
return false
end
Baris 286 ⟶ 156:
function p.main(frame)
local args = require'Modul:Arguments'.getArgs(frame, {trim = true})
local root = mw.html.create()
local matchType = (args.type == 'WNT' or args.type == 'MNT') and 'NT' or (args.type or 'club') -- Set default match type to 'club'
Baris 302 ⟶ 162:
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')
-- Process flag parameter to determine flag template and variant
Baris 358 ⟶ 198:
local legs = (args.legs == '1' or args.legs == 'n' or args.legs == 'no' or args.legs == 'false' or args.legs == 'null' or args.legs == 'none' or args.legs == 'single' or args.legs == 'one') and 0 or tonumber(args.legs) or 2
local teamWidth = (tonumber(args['team_width']) and args['team_width'] .. 'px') or '250px'
local scoreWidth = (tonumber(args['score_width']) and args['score_width'] .. 'px') or '80px'
local boldWinner =
local colorWinner = args.color_winner and (args.color_winner == 'y' or args.color_winner == 'yes' or args.color_winner == '1' or args.color_winner == 'true')
local tableClass = 'wikitable'
Baris 376 ⟶ 207:
if args.collapsed and (args.collapsed == 'y' or args.collapsed == 'yes' or args.collapsed == '1' or args.collapsed == 'true') then
tableClass = 'wikitable mw-collapsible mw-collapsed'
tableStyle =
end
if args.nowrap and (args.nowrap == 'y' or args.nowrap == 'yes' or args.nowrap == '1' or args.nowrap == 'true') then
tableStyle = tableStyle .. ' white-space: nowrap;'
end
Baris 391 ⟶ 219:
if args.id then
table:attr('id', args.id) -- Optional id parameter to allow anchor to table
end
Baris 412 ⟶ 234:
titleRow:tag('th')
:attr('colspan', colCount)
:
:wikitext(args.title)
end
Baris 418 ⟶ 240:
-- Create the header row with team and score columns
local header = table:tag('tr')
local defaultTeam1 =
local defaultTeam2 =
header:tag('th'):css('text-align', 'right'):css('width', teamWidth):wikitext(args['team1'] or defaultTeam1)
header:tag('th'):css('width', scoreWidth):wikitext(args['aggregate'] or legs == 0 and 'Hasil' or 'Agregat')
-- Add columns for each leg if applicable
Baris 448 ⟶ 259:
-- Check if leg_prefix is y, yes, 1, or true
if args.leg_prefix == 'y' or args.leg_prefix == 'yes' or args.leg_prefix == '1' or args.leg_prefix == 'true' then
legHeading = '
else
legHeading = args.leg_prefix .. ' ' .. leg
Baris 454 ⟶ 265:
-- Check if "leg_suffix" parameter is present and does not equal y, yes, 1, or true
elseif args.leg_suffix and args.leg_suffix ~= 'y' and args.leg_suffix ~= 'yes' and args.leg_suffix ~= '1' and args.leg_suffix ~= 'true' then
legHeading =
else
legHeading =
end
end
header:tag('th'):css('width', scoreWidth):wikitext(legHeading)
end
end
Baris 477 ⟶ 285:
headingRow:tag('td')
:attr('colspan', colCount)
:css('text-align', 'center')
:css('background', 'whitesmoke')
:wikitext('<strong>' .. headingParam .. '</strong>')
Baris 482 ⟶ 291:
local row = table:tag('tr')
local team1
local team1Winner, team2Winner, manualBold, manualColor
local team1Asterick, team2Asterick = false, false
-- Process rows for
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 504 ⟶ 313:
team2, team2Variant = processIcon(args[i+2])
end
-- Clean the aggregate score
local cleanAggregate = cleanScore(aggregateScore)
-- Determine the winning team on aggregate
team1, team2, team1Winner, team2Winner, manualBold, manualColor = determineWinner(cleanAggregate, matchType, team1, team2, boldWinner, colorWinner)
-- 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 to display for each team
local team1Text, team2Text
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
team2Text = (not team2Asterick and team2 ~= "" and team2 ~= nil) and (expandTemplate(frame, flagTemplate, {flagParam1, team2, variant = team2Variant})) or team2
else -- Use standard national team flag template without age level
team1Text = (not team1Asterick and team1 ~= "" and team1 ~= nil) and (expandTemplate(frame, flagTemplate .. '-rt', {team1, variant = team1Variant})) or team1
team2Text = (not team2Asterick and team2 ~= "" and team2 ~= nil) and (expandTemplate(frame, flagTemplate, {team2, variant = team2Variant})) or team2
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 team1Asterick then
team1Text = team1Text .. ' <span class="flagicon">[[Berkas:Flag placeholder.svg|25x17px|link=]]</span>'
end
if team2Asterick then
team2Text = '<span class="flagicon">[[Berkas:Flag placeholder.svg|25x17px|link=]]</span> ' .. team2Text
end
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 '<strong>' .. team1Text .. '</strong>' or team1Text)
row:tag('td'):css('text-align', 'center'):css('width', scoreWidth):wikitext(aggregateScore)
row:tag('td'):cssText(team2Style):wikitext((team2Winner and (boldWinner or manualBold)) 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]
Baris 515 ⟶ 355:
team2Icon, team2Variant = processIcon(args[i+4])
end
-- Clean the aggregate score
local cleanAggregate = cleanScore(aggregateScore)
--
team1, team2, team1Winner, team2Winner, manualBold, manualColor = determineWinner(cleanAggregate, matchType, team1, team2, boldWinner, colorWinner)
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 (team1Icon ~= "" and team1Icon ~= nil) and (team1 .. ' ' .. expandTemplate(frame, flagTemplate, {team1Icon, variant = team1Variant})) or team1
local team2Text = noFlagIcons and team2 or (team2Icon ~= "" and team2Icon ~= nil) and (expandTemplate(frame, flagTemplate, {team2Icon, variant = team2Variant}) .. ' ' .. team2) or team2
-- When set by user, adds blank flags when country code parameter is left blank
if not noFlagIcons then
if not team1Icon or team1Icon == "" then
team1Text = team1Text .. ' <span class="flagicon">[[Berkas:Flag placeholder.svg|25x17px|link=]]</span>'
if not team2Icon or team2Icon == "" then
team2Text = '<span class="flagicon">[[Berkas:Flag placeholder.svg|25x17px|link=]]</span> ' .. team2Text
end
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 '<strong>' .. team1Text .. '</strong>' or team1Text)
row:tag('td'):css('text-align', 'center'):css('width', scoreWidth):wikitext(aggregateScore)
row:tag('td'):cssText(team2Style):wikitext((team2Winner and (boldWinner or manualBold)) and '<strong>' .. team2Text .. '</strong>' or team2Text)
end
-- Add columns for each leg score if applicable
Baris 610 ⟶ 387:
local legIndex = i + 4 + leg + (matchType == 'NT' and -2 or (noFlagIcons and -2 or 0))
local legScore = args[legIndex]
if legScore ~= "
end
end
|