(Created page with "local cargo = mw.ext.cargo local PageEvents = {} function PageEvents.main(frame) local currentTitle = mw.title.getCurrentTitle().text local empty = true -- Check if there are any interviews for this page local tables = 'Tournaments' local fields = '_pageName, start, end, icon, venue, prize' local cargoArgs = { where = 'venue="' .. currentTitle .. '"', sortBy = 'end' } local results = cargo.query(tables, fields, cargoArgs) local list = mw.html.create('tabl...") |
mNo edit summary |
||
(One intermediate revision by the same user not shown) | |||
Line 1: | Line 1: | ||
local cargo = mw.ext.cargo | local cargo = mw.ext.cargo | ||
local func = require('Module:Functions') | |||
local PageEvents = {} | local PageEvents = {} | ||
Line 9: | Line 10: | ||
-- Check if there are any interviews for this page | -- Check if there are any interviews for this page | ||
local tables = 'Tournaments' | local tables = 'Tournaments' | ||
local fields = '_pageName, start, end, | local fields = '_pageName, start, end, logoAll, logoLight, logoDark, iconAll, iconLight, iconDark, venue, prize' | ||
local cargoArgs = { | local cargoArgs = { | ||
where = 'venue | where = 'venue HOLDS "' .. currentTitle .. '"', | ||
sortBy = 'end' | sortBy = 'end' | ||
} | } | ||
Line 38: | Line 39: | ||
local result = results[r] | local result = results[r] | ||
local eventRow = mw.html.create('tr'):addClass('bodyRow') | local eventRow = mw.html.create('tr'):addClass('bodyRow') | ||
local start = mw.html.create('td'):wikitext(result.start) | local start = mw.html.create('td'):wikitext(func.stringifyDate(result.start)) | ||
local endDate = mw.html.create('td'):wikitext(result['end']) | local endDate = mw.html.create('td'):wikitext(func.stringifyDate(result['end'])) | ||
local name = mw.html.create('td') | local name = mw.html.create('td') | ||
local nameDiv = mw.html.create('div'):addClass('eventName'):wikitext('[[File:' . | local icon = result.iconAll ~= '' and result.iconAll or result.iconLight ~= '' and result.iconLight or result.iconDark ~= '' and result.iconDark or result.logoAll ~= '' and result.logoAll or result.logoDark ~= '' and result.logoDark or result.logoLight ~= '' and result.logoLight | ||
if not icon then icon = 'Tournament_placeholder.png' end | |||
local nameDiv = mw.html.create('div'):addClass('eventName'):wikitext('[[File:' .. icon .. '|25px|link=' .. result._pageName ..']]'):wikitext('[[' .. result._pageName .. ']]') | |||
name:node(nameDiv) | name:node(nameDiv) | ||
local prize = mw.html.create('td'):wikitext(result.prize) | local prize = mw.html.create('td'):wikitext(func.prizeToString(result.prize)) | ||
list:node(eventRow:node(name):node(start):node(endDate):node(prize)) | list:node(eventRow:node(name):node(start):node(endDate):node(prize)) |
Latest revision as of 05:57, 2 October 2023
Documentation for this module may be created at Module:PageEvents/doc
local cargo = mw.ext.cargo
local func = require('Module:Functions')
local PageEvents = {}
function PageEvents.main(frame)
local currentTitle = mw.title.getCurrentTitle().text
local empty = true
-- Check if there are any interviews for this page
local tables = 'Tournaments'
local fields = '_pageName, start, end, logoAll, logoLight, logoDark, iconAll, iconLight, iconDark, venue, prize'
local cargoArgs = {
where = 'venue HOLDS "' .. currentTitle .. '"',
sortBy = 'end'
}
local results = cargo.query(tables, fields, cargoArgs)
local list = mw.html.create('table')
:addClass('striped-table')
local container = mw.html.create()
if #results > 0 then
empty = false
container:node(mw.html.create('h2'):wikitext('Events'))
local titleRow = mw.html.create('tr')
:addClass('headerRow')
local startCell = mw.html.create('th')
:wikitext('Start Date')
local endCell = mw.html.create('th')
:wikitext('End Date')
local nameCell = mw.html.create('th')
:wikitext('Name')
local prizeCell = mw.html.create('th')
:wikitext('Prize')
list:node(titleRow:node(nameCell):node(startCell):node(endCell):node(prizeCell))
for r = 1, #results do
local result = results[r]
local eventRow = mw.html.create('tr'):addClass('bodyRow')
local start = mw.html.create('td'):wikitext(func.stringifyDate(result.start))
local endDate = mw.html.create('td'):wikitext(func.stringifyDate(result['end']))
local name = mw.html.create('td')
local icon = result.iconAll ~= '' and result.iconAll or result.iconLight ~= '' and result.iconLight or result.iconDark ~= '' and result.iconDark or result.logoAll ~= '' and result.logoAll or result.logoDark ~= '' and result.logoDark or result.logoLight ~= '' and result.logoLight
if not icon then icon = 'Tournament_placeholder.png' end
local nameDiv = mw.html.create('div'):addClass('eventName'):wikitext('[[File:' .. icon .. '|25px|link=' .. result._pageName ..']]'):wikitext('[[' .. result._pageName .. ']]')
name:node(nameDiv)
local prize = mw.html.create('td'):wikitext(func.prizeToString(result.prize))
list:node(eventRow:node(name):node(start):node(endDate):node(prize))
end
container:node(list)
end
if empty then
return '<span class="d-none"></span>'
else
return container
end
end
return PageEvents