Module:Sandbox/Frietjes: Difference between revisions

Content deleted Content added
No edit summary
No edit summary
Line 1:
local p = {}
 
local lang -- Lazy initialize
function p.main(frame)
local function formatDate(fmt, d)
local getArgs = require('Module:Arguments').getArgs
lang = lang or mw.language.getContentLanguage()
local args = getArgs(frame, {parentFirst = true,
local success, newDate = pcall(lang.formatDate, lang, fmt, d)
valueFunc = function (key, val)
if key == 'text_IPS'success then
return nilnewDate
else
end
if typeerror(val) == 'string' then.format(
"invalid date '%s' passed to getDate",
val = val:match('^%s*(.-)%s*$')
tostring(date)
if val == '' then
))
return nil
end
else
end
return val
local function caltoc(days, unk, footer, month, year)
local weekdays = {'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'}
local j = tonumber(formatDate('N','1 ' .. month .. ' ' .. year))
local N = tonumber(formatDate('t','1 ' .. month .. ' ' .. year))
local res = {}
 
table.insert(res, '__NOTOC__<table role="navigation" id="toc" class="wikitable toc plainlinks" style="text-align:center">')
table.insert(res, '<tr><th colspan=7 id="toctitle" style="background:inherit"><span id="tocheading" style="font-weight:bold">' .. month .. ' ' .. year .. '</th></tr>')
table.insert(res, '<tr><th scope="col">' .. table.concat(weekdays, '</th><th scope="col">') .. '</th></tr>')
 
local d = 1-j
while d <= N do
table.insert(res, '<tr>')
for i=1,7 do
d = d + 1
if d > 0 and d <= N then
local f = days[tostring(d)]
if f and f == 'df' then
table.insert(res, '<td>[[#' .. d .. ' ' .. month .. '|' .. d .. ']]</td>')
elseif f and f == 'mf' then
table.insert(res, '<td>[[#' .. month .. ' ' .. d .. '|' .. d .. ']]</td>')
else
table.insert(res, '<td>' .. d .. '</td>')
end
else
local cs = (d <= 0) and (1 - d) or (8 - i)
table.insert(res, '<td' .. (cs > 1 and ' colspan=' .. cs or '') .. '></td>')
i = i + (cs - 1)
end
end
table.insert(res, '</tr>')
end
if unk ~= nil then
table.insert(res, '<tr><td colspan=7>[[#' .. unk .. '|' .. unk .. ']]</td></tr>')
end
if #footer > 0 then
table.insert(res, '<tr>')
if #footer > 1 then
table.insert(res, '<td colspan=7 style="padding: 0.2em;"><div class="hlist">')
for k,v in ipairs(footer) do
table.insert(res, '* [[#' .. v .. '|' .. v .. ']]')
end
table.insert(res, '</td></div>')
else
table.insert(res, '<td colspan=7>[[#' .. table.concat(footer,'') .. '|' .. table.concat(footer,'') .. ']]</td>')
return val
end
table.insert(res, '</tr>')
end
table.insert(res, '</table>')
})
local team_list = {}
local ii = 1
while args['team'..ii] ~= nil do
team_list[args['team'..ii]] = ii
ii = ii + 1
end
local max_team = ii - 1
return table.concat(res, '\n')
local first_team, last_team = 1, max_team
end
if args['showteam'] and team_list[args['showteam']] then
 
first_team = team_list[args['showteam']] - 2
local function listtoc(founddays, days, unk, footer, month)
last_team = first_team + 4
local starttxt = [[
if first_team < 1 then
__NOTOC__<!--
first_team = 1
--><div role="navigation" id="toc" class="toc plainlinks hlist" aria-labelledby="tocheading" style="text-align:left;">
last_team = first_team + 4
<div id="toctitle" class="toctitle" style="text-align:center;"><span id="tocheading" style="font-weight:bold;">Contents</span></div>
<div style="margin:auto;">
]]
local closetxt = [[</div></div>]]
local entries = (#founddays > 0) and { ';' .. month} or {}
for k,d in ipairs(founddays) do
local fmt = days[d]
if fmt == 'df' then
table.insert(entries, ': [[#' .. d .. ' ' .. month .. '|' .. d .. ']]')
elseif fmt == 'mf' then
table.insert(entries, ': [[#' .. month .. ' ' .. d .. '|' .. d .. ']]')
end
if last_team > max_team then
last_team = max_team
first_team = max_team - 4
end
if first_team < 1 then first_team = 1 end
end
if unk ~= nil then
table.insert(entries, ': [[#' .. unk .. '|' .. unk .. ']]')
local hasnotes = false
end
for k,v in ipairs(footer) do
table.insert(entries, ': [[#' .. v .. '|' .. v .. ']]')
end
return starttxt .. table.concat(entries,"\n") .. closetxt
end
 
local function getYear(s,y)
if y and mw.ustring.match(y, '^%d+$') then
return y
end
y = mw.ustring.gsub(s, '^.-(%d+).-$', '%1')
return y
end
 
local function getMonth(s,m)
local mnames = {
['January']=1,
['February']=2,
['March']=3,
['April']=4,
['May']=5,
['June']=6,
['July']=7,
['August']=8,
['September']=9,
['October']=10,
['November']=11,
['December']=12
}
if m and mnames[m] then
return m
end
for k,n in pairs(mnames) do
local ii = first_team
if mw.ustring.match(s or '', k) then
local res = '{| class="wikitable"\n'
return k
res = res .. '! Pos. !! Team !! Result\n'
while args['team'..ii] ~= nil and (ii <= last_team) do
res = res .. '|-\n'
res = res .. '| ' .. ii .. '\n'
res = res .. '| ' .. (args['name_'..args['team' .. ii]] or '') .. '\n'
local text_result = args['result'..ii] and args['text_'..args['result'..ii]] or ''
local style_text = ''
if text_result:match('fbmulticompefn') then
hasnotes = true
style_text = style_text .. 'padding:0;'
end
style_text = style_text .. (args['result'..ii] and ('background:' .. args['col_'..args['result'..ii]]) or '')
res = res .. '| style="' .. style_text .. '" | ' .. text_result .. '\n'
ii = ii + 1
end
res = res .. '|}'
return ''
if hasnotes == true then
end
res = res .. '<b>Table notes:</b>' .. frame:expandTemplate{ title = 'notelist'}
 
function p.main(frame)
local args = frame.args
local pargs = frame:getParent().args
local current_title = mw.title.getCurrentTitle()
local pagename = current_title.text
local content = current_title:getContent()
local outfmt = args['format'] or pargs['format'] or ''
local unknown = nil
if args['_demo'] or pargs['_demo'] then
content = args['_demo'] or pargs['_demo'] or ''
end
if not content then
-- Generate tracking
error "The current page has no content"
if not args['notracking'] then
end
-- Step 1: Generate a team and result list
 
for k,v in pairs(args) do
-- Get the month and year
-- nothing
local month = getMonth(pagename, args['month'] or pargs['month'] or '')
local year = getYear(pagename, args['year'] or pargs['year'] or '')
 
-- Get list of valid footer links
local extra = args['extra'] or pargs['extra'] or ''
local footerlinks = {}
if extra ~= '' then
footerlinks = mw.text.split(extra, '%s*=%s*')
else
footerlinks = {"See also", "References", "Notes", "Further reading", "External links"}
end
local validfooter = {}
for k,v in ipairs(footerlinks) do
validfooter[v] = 1
end
-- Get all the level two headings for days of the month
local days = {}
local founddays = {}
local footer = {}
for v in mw.ustring.gmatch(content, "%f[^\n]==%s*([^\r\n]-)%s*==%f[^=]") do
v = mw.ustring.gsub(v,'^[=%s]*(.-)[%s=]*', '%1')
local df = mw.ustring.gsub(v,'^(%d+[%-–%d]*)%s*' .. month .. '$', '%1')
local mf = mw.ustring.gsub(v,'^' .. month .. '%s*(%d+[%-–%d]*)$', '%1')
if tonumber(df) then
days[df] = 'df'
table.insert(founddays, df)
elseif tonumber(mf) then
days[df] = 'mf'
table.insert(founddays, mf)
elseif v == "Unknown date" then
unknown = "Unknown date"
elseif validfooter[v] then
table.insert(footer, v)
end
end
 
-- Now generate the TOC
return res
if outfmt ~= 'list' then
return caltoc(days, unknown, footer, month, year)
end
 
return listtoc(founddays, days, unknown, footer, month)
end