Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LPA-6687: Pagenames should be stored with _ and not spaces #1802

Draft
wants to merge 13 commits into
base: main
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,11 @@ end

function CustomPlayer._getMatchupData()
local yearsActive
local player = string.gsub(_player.pagename, '_', ' ')
local playerWithoutUnderscore = string.gsub(_player.pagename, '_', ' ')
local player = _player.pagename
local queryParameters = {
conditions = '[[opponent::' .. player .. ']] AND [[walkover::]] AND [[winner::>]]',
conditions = '([[opponent::' .. player .. ']] OR [[opponent::' .. playerWithoutUnderscore .. ']])' ..
'AND [[walkover::]] AND [[winner::>]]',
query = 'match2opponents, date',
}

Expand All @@ -205,7 +207,7 @@ function CustomPlayer._getMatchupData()
local foundData = false
local processMatch = function(match)
foundData = true
vs = CustomPlayer._addScoresToVS(vs, match.match2opponents, player)
vs = CustomPlayer._addScoresToVS(vs, match.match2opponents, player, playerWithoutUnderscore)
local year = string.sub(match.date, 1, 4)
years[tonumber(year)] = year
end
Expand Down Expand Up @@ -278,12 +280,12 @@ function CustomPlayer._setVarsForVS(table)
end
end

function CustomPlayer._addScoresToVS(vs, opponents, player)
function CustomPlayer._addScoresToVS(vs, opponents, player, playerWithoutUnderscore)
local plIndex = 1
local vsIndex = 2
-- catch matches vs empty opponents
if opponents[1] and opponents[2] then
if opponents[2].name == player then
if opponents[2].name == player or opponents[2].name == playerWithoutUnderscore then
plIndex = 2
vsIndex = 1
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,10 @@ end

function CustomPlayer._getMatchupData(player)
local yearsActive
player = string.gsub(player, '_', ' ')
local playerWithoutUnderscore = string.gsub(player, '_', ' ')
local queryParameters = {
conditions = '[[opponent::' .. player .. ']] AND [[walkover::]] AND [[winner::>]]',
conditions = '([[opponent::' .. player .. ']] OR [[opponent::' .. playerWithoutUnderscore .. ']])' ..
'AND [[walkover::]] AND [[winner::>]]',
order = 'date desc',
query = table.concat({
'match2opponents',
Expand Down Expand Up @@ -235,7 +236,7 @@ function CustomPlayer._getMatchupData(player)
local foundData = false
local processMatch = function(match)
foundData = true
vs = CustomPlayer._addScoresToVS(vs, match.match2opponents, player)
vs = CustomPlayer._addScoresToVS(vs, match.match2opponents, player, playerWithoutUnderscore)
local year = string.sub(match.date, 1, 4)
years[tonumber(year)] = year
if #_player.recentMatches <= NUMBER_OF_RECENT_MATCHES then
Expand Down Expand Up @@ -311,12 +312,12 @@ function CustomPlayer._setVarsForVS(table)
end
end

function CustomPlayer._addScoresToVS(vs, opponents, player)
function CustomPlayer._addScoresToVS(vs, opponents, player, playerWithoutUnderscore)
local plIndex = 1
local vsIndex = 2
--catch matches vs empty opponents
if opponents[1] and opponents[2] then
if opponents[2].name == player then
if opponents[2].name == player or opponents[2].name == playerWithoutUnderscore then
plIndex = 2
vsIndex = 1
end
Expand Down
2 changes: 1 addition & 1 deletion components/match2/commons/match_group_input.lua
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ function MatchGroupInput.mergeRecordWithOpponent(record, opponent)
return {
displayname = player.displayName,
flag = player.flag,
name = player.pageName,
name = player.pageName and player.pageName:gsub(' ', '_') or nil,
}
end)
end
Expand Down
11 changes: 8 additions & 3 deletions components/match2/commons/match_ticker/match_ticker_query.lua
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,17 @@ end

function BaseConditions:participantConditions(queryArgs)
if String.isNotEmpty(queryArgs.team) then
return {ConditionNode(ColumnName('opponent'), Comparator.eq, queryArgs.team)}
return ConditionTree(BooleanOperator.any):add{
ConditionNode(ColumnName('opponent'), Comparator.eq, queryArgs.team),
ConditionNode(ColumnName('opponent'), Comparator.eq, queryArgs.team:gsub(' ', '_')),
}
elseif String.isNotEmpty(queryArgs.player) then
return ConditionTree(BooleanOperator.any):add({
return ConditionTree(BooleanOperator.any):add{
ConditionNode(ColumnName('player'), Comparator.eq, queryArgs.player),
ConditionNode(ColumnName('opponent'), Comparator.eq, queryArgs.player),
})
ConditionNode(ColumnName('player'), Comparator.eq, queryArgs.player:gsub(' ', '_')),
ConditionNode(ColumnName('opponent'), Comparator.eq, queryArgs.player:gsub(' ', '_')),
}
end
end

Expand Down
5 changes: 4 additions & 1 deletion components/match2/commons/player_ext.lua
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,10 @@ function PlayerExt.populatePageName(player)
or globalVars:get(player.displayName .. '_page')
or player.displayName and mw.ext.TeamLiquidIntegration.resolve_redirect(player.displayName)

player.pageIsResolved = player.pageName and true or nil
if player.pageName then
player.pageIsResolved = true
player.pageName = player.pageName:gsub(' ', '_')
end
end

--[[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ function StarcraftMatchGroupInput.ProcessSoloOpponentInput(opponent)
opponent[1] or ''
)
local link = Logic.emptyOr(opponent.link, Variables.varDefault(name .. '_page'), name)
link = mw.ext.TeamLiquidIntegration.resolve_redirect(link)
link = mw.ext.TeamLiquidIntegration.resolve_redirect(link):gsub(' ', '_')
local race = Logic.emptyOr(opponent.race, Variables.varDefault(name .. '_race'), '')
local players = {}
local flag = Logic.emptyOr(opponent.flag, Variables.varDefault(name .. '_flag'))
Expand All @@ -550,12 +550,12 @@ function StarcraftMatchGroupInput.ProcessDuoOpponentInput(opponent)
opponent.p1link,
Variables.varDefault(opponent.p1 .. '_page'),
opponent.p1
))
)):gsub(' ', '_')
opponent.link2 = mw.ext.TeamLiquidIntegration.resolve_redirect(Logic.emptyOr(
opponent.p2link,
Variables.varDefault(opponent.p2 .. '_page'),
opponent.p2
))
)):gsub(' ', '_')
if Logic.readBool(opponent.extradata.isarchon) then
opponent.p1race = Faction.read(opponent.race) or Faction.defaultFaction
opponent.p2race = opponent.p1race
Expand Down Expand Up @@ -605,7 +605,7 @@ function StarcraftMatchGroupInput.ProcessOpponentInput(opponent, playernumber)
opponent['p' .. playerIndex .. 'link'],
Variables.varDefault(playerName .. '_page'),
playerName
))
)):gsub(' ', '_')
local race = Logic.emptyOr(
opponent['p' .. playerIndex .. 'race'],
Variables.varDefault(playerName .. '_race'),
Expand Down Expand Up @@ -667,7 +667,7 @@ function StarcraftMatchGroupInput._getManuallyEnteredPlayers(playerData)
playerData['p' .. playerIndex .. 'link'],
playerData['p' .. playerIndex],
''
))
)):gsub(' ', '_')
if String.isNotEmpty(name) then
players[playerIndex] = {
name = name,
Expand All @@ -693,7 +693,7 @@ function StarcraftMatchGroupInput._getPlayersFromVariables(teamName)
if Logic.isNotEmpty(name) then
local flag = Variables.varDefault(teamName .. '_p' .. playerIndex .. 'flag')
players[playerIndex] = {
name = name,
name = name:gsub(' ', '_'),
displayname = Variables.varDefault(teamName .. '_p' .. playerIndex .. 'display'),
flag = Flags.CountryName(flag),
extradata = {faction = Variables.varDefault(teamName .. '_p' .. playerIndex .. 'race')}
Expand All @@ -719,7 +719,7 @@ function StarcraftMatchGroupInput.ProcessTeamOpponentInput(opponent, date)
end
opponent.template = 'default'
icon = defaultIcon
name = Logic.emptyOr(opponent.link, opponent.name, opponent[1] or '')
name = Logic.emptyOr(opponent.link, opponent.name, opponent[1] or ''):gsub(' ', '_')
opponent.extradata = opponent.extradata or {}
opponent.extradata.display = Logic.emptyOr(opponent.name, opponent[1], '')
opponent.extradata.short = Logic.emptyOr(opponent.short, opponent.name, opponent[1] or '')
Expand All @@ -742,7 +742,7 @@ function StarcraftMatchGroupInput.ProcessTeamOpponentInput(opponent, date)
icondark = iconDark,
template = opponent.template,
type = opponent.type,
name = name,
name = name:gsub(' ', '_'),
score = opponent.score,
extradata = opponent.extradata,
match2players = players
Expand Down Expand Up @@ -993,7 +993,7 @@ function StarcraftMatchGroupInput._processDefaultPlayerMapData(players, map, opp
for playerIndex = 1, #players do
local faction = map['t' .. opponentIndex .. 'p' .. playerIndex .. 'race']
participants[opponentIndex .. '_' .. playerIndex] = {
faction = Faction.read(faction) or players[playerIndex].extradata.faction or Faction.defaultFaction,
faction = Faction.read(faction or players[playerIndex].extradata.faction) or Faction.defaultFaction,
player = players[playerIndex].name
}
end
Expand Down Expand Up @@ -1033,7 +1033,7 @@ function StarcraftMatchGroupInput._processTeamPlayerMapData(players, map, oppone
map[playerKey .. 'link'] or
Variables.varDefault(map[playerKey] .. '_page') or
map[playerKey]
)
):gsub(' ', '_')
if Logic.readBool(map['opponent' .. opponentIndex .. 'archon']) then
playerData[mapPlayer] = {
faction = Faction.read(Logic.emptyOr(
Expand Down
5 changes: 3 additions & 2 deletions components/opponent/commons/opponent.lua
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,8 @@ function Opponent.toName(opponent)
return TeamTemplate.getPageName(opponent.template)
elseif Opponent.typeIsParty(opponent.type) then
local pageNames = Array.map(opponent.players, function(player)
return player.pageName or player.displayName
local pageName = player.pageName or player.displayName
return pageName and pageName:gsub(' ', '_') or nil
hjpalpha marked this conversation as resolved.
Show resolved Hide resolved
end)
return table.concat(pageNames, ' / ')
else -- opponent.type == Opponent.literal
Expand Down Expand Up @@ -379,7 +380,7 @@ function Opponent.toLpdbStruct(opponent)
for playerIndex, player in ipairs(opponent.players) do
local prefix = 'p' .. playerIndex

players[prefix] = player.pageName
players[prefix] = player.pageName and player.pageName:gsub(' ', '_') or nil
players[prefix .. 'dn'] = player.displayName
players[prefix .. 'flag'] = player.flag
players[prefix .. 'team'] = player.team and Opponent.toName({type = Opponent.team, template = player.team}) or nil
Expand Down