Module:Past events
From The Museum of Human Achievement
Documentation for this module may be created at Module:Past events/doc
local p = {}
function p.main()
local data = mw.smw.ask {
'[[Category:Events]][[Date End::<{{#time: Y-m-d|now}}]][[Modification date::+]]',
'mainlabel=-',
'?#-=page',
'?Associated Program#-=program',
'?Display title of=display',
'?Date Start#-F[Y-m-d]=dstart',
'?Date Start#-F[m]=dm',
'?Date Start#-F[Y]=dy',
'?Event format=format',
'?Event medium=medium',
'?Event location=location',
'?Is public=ispublic',
'limit=5000'
}
local html = mw.html.create()
local pastevents = html:tag('table')
:attr('id', 'pastEventsTable')
:addClass('dataTable no-footer')
for _, event in ipairs(data) do
local page = event['page'] or ''
local edisplay = event.display or page
local dstart = event.dstart or ''
local dm = event.dm or ''
local dy = event.dy or ''
local ispublic = event.ispublic or 'No'
local eprogram = event.program or ''
local programTable = {}
if type(eprogram) == 'table' then
if #eprogram > 0 then
programTable = eprogram
end
else
for item in eprogram:gmatch("[^,|;\t]+") do
table.insert(programTable, item:match("^%s*(.-)%s*$"))
end
end
local eformat = event.format or ''
local formatTable = {}
if type(eformat) == 'table' then
if #eformat > 0 then
formatTable = eformat
end
else
for item in eformat:gmatch("[^,|;\t]+") do
table.insert(formatTable, item:match("^%s*(.-)%s*$"))
end
end
local emedium = event.medium or ''
local mediumTable = {}
if type(emedium) == 'table' then
if #emedium > 0 then
mediumTable = emedium
end
else
for item in emedium:gmatch("[^,|;\t]+") do
table.insert(mediumTable, item:match("^%s*(.-)%s*$"))
end
end
local elocation = event.location or ''
local locationTable = {}
if type(elocation) == 'table' then
if #elocation > 0 then
locationTable = elocation
end
else
for item in elocation:gmatch("[^,|;\t]+") do
table.insert(locationTable, item:match("^%s*(.-)%s*$"))
end
end
local printProgram, printFormat, printMedium, printLocation, labels = '', '', '', '', {}
if #programTable > 0 then
for i, v in ipairs(programTable) do
if type(v) == "string" then
programTable[i] = string.format('<span>[[%s]]</span>', v)
end
end
printProgram = table.concat(programTable, ' · ')
table.insert(labels, printProgram)
end
if #formatTable > 0 then
for i, v in ipairs(formatTable) do
if type(v) == "string" then
formatTable[i] = string.format('<span>%s</span>', v)
end
end
printFormat = table.concat(formatTable, ' · ')
table.insert(labels, printFormat)
end
if #mediumTable > 0 then
for i, v in ipairs(mediumTable) do
if type(v) == "string" then
mediumTable[i] = string.format('<span>%s</span>', v)
end
end
printMedium = table.concat(mediumTable, ' · ')
table.insert(labels, printMedium)
end
if #locationTable > 0 then
printLocation = table.concat(locationTable, ' · ')
table.insert(labels, printLocation)
end
local printLabels = table.concat(labels, ' | ')
pastevents:tag('tr')
:tag('td'):wikitext(string.format('<big>[[%s|%s]]</big><br>%s', page, edisplay, printLabels)):done()
:tag('td'):wikitext(table.concat(programTable, ' | ')):done()
:tag('td'):wikitext(table.concat(formatTable, ' | ')):done()
:tag('td'):attr('data-sort', dm):wikitext(dm):done()
:tag('td'):wikitext(dy):done()
:tag('td'):wikitext(table.concat(mediumTable, ' | ')):done()
end
return html
end
return p