More actions
Skycrafter (talk | contribs) Created page with "-- Module:TrackInfobox local p = {} local function safe(s) if not s then return '' end return mw.html.escape(tostring(s)) end function p.formatWR(frame) -- args: time_ms, player, fallback local time_ms = frame.args[1] or '' local player = frame.args[2] or '' local fallback = frame.args[3] or '' if time_ms == '' or time_ms == nil then if fallback ~= '' then return fallback end return 'Unknown' end local ms = tonumber(time_ms) if not ms then..." |
Skycrafter (talk | contribs) No edit summary |
||
Line 1: | Line 1: | ||
local p = {} | local p = {} | ||
local function | local function escape_html(s) | ||
if | if s == nil then return '' end | ||
s = tostring(s) | |||
s = s:gsub("&", "&") | |||
s = s:gsub("<", "<") | |||
s = s:gsub(">", ">") | |||
s = s:gsub('"', """) | |||
s = s:gsub("'", "'") | |||
return s | |||
end | end | ||
function p.formatWR(frame) | function p.formatWR(frame) | ||
local time_ms = frame.args[1] or '' | local time_ms = frame.args[1] or '' | ||
local player = frame.args[2] or '' | local player = frame.args[2] or '' | ||
Line 27: | Line 31: | ||
local mins = math.floor(total_seconds / 60) | local mins = math.floor(total_seconds / 60) | ||
local secs = total_seconds - mins * 60 | local secs = total_seconds - mins * 60 | ||
local time_str = string.format("%d:%06. | local time_str = string.format("%d:%06.3f", mins, secs) | ||
if player ~= '' then | if player ~= '' then | ||
return time_str .. ' by ' .. | return time_str .. ' by ' .. escape_html(player) | ||
else | else | ||
return time_str | return time_str |
Revision as of 12:51, 14 August 2025
Documentation for this module may be created at Module:TrackInfobox/doc
local p = {}
local function escape_html(s)
if s == nil then return '' end
s = tostring(s)
s = s:gsub("&", "&")
s = s:gsub("<", "<")
s = s:gsub(">", ">")
s = s:gsub('"', """)
s = s:gsub("'", "'")
return s
end
function p.formatWR(frame)
local time_ms = frame.args[1] or ''
local player = frame.args[2] or ''
local fallback = frame.args[3] or ''
if time_ms == '' or time_ms == nil then
if fallback ~= '' then return fallback end
return 'Unknown'
end
local ms = tonumber(time_ms)
if not ms then
if fallback ~= '' then return fallback end
return 'Unknown'
end
local total_seconds = ms / 1000
local mins = math.floor(total_seconds / 60)
local secs = total_seconds - mins * 60
local time_str = string.format("%d:%06.3f", mins, secs)
if player ~= '' then
return time_str .. ' by ' .. escape_html(player)
else
return time_str
end
end
return p