Module:SongContestTable
Appearance
![]() | This module is rated as pre-alpha. It is unfinished, and may or may not be in active development. It should not be used from article namespace pages. Modules remain pre-alpha until the original editor (or someone who takes one over if it is abandoned for some time) is satisfied with the basic structure. |
![]() | This module depends on the following other modules: |
Usage
[edit]{{#invoke:SongContestTable|function_name}}
local getArgs = require('Module:Arguments').getArgs
local order = require('Module:SongContestData')._order
local rowTemplate = "Template:SongContestTableRow"
-- Attributes in Module:SongContestData
local dataAtts = {
number = 'number',
sf_draw = 'sf_draw',
gf_draw = 'gf_draw',
}
local sortConfig = {
--country/draw/number
['contest-pcps'] = 'country',
['round-result'] = 'draw',
['history-list'] = 'number',
['country-list'] = 'number',
}
local p = {}
local function pageExists(pageName)
local title = mw.title.new(pageName)
return title and title.exists or false
end
function p.main(f)
local args = getArgs(f)
local contest, year, roundInput = args[1], args[2], args[3]
local wikitable = args['table']
local sortInput = args['sort']
if not pageExists(rowTemplate..'/'..wikitable) then return '<span class="error">Unknown table "'..wikitable..'" <small>([[Template:SongContestTable|help]])</small></span>' end
local round, roundNo
if roundInput then
round, roundNo = roundInput:gsub("%d+", ""), tonumber(roundInput:match("%d+"))
end
local sortMethods = {
country = nil,
draw = dataAtts[(round or 'gf') .. '_draw'],
number = dataAtts['number']
}
local sorting = sortMethods[sortInput] or sortMethods[sortConfig[wikitable]]
local ordered = {}
if roundNo then
ordered = order({contest, year, sorting, desc=false, excludeAtt=round, excludeVal=roundNo, excludeInvert=true})
else
ordered = order({contest, year, sorting, desc=false})
end
-- build table from template
local result = f:expandTemplate{title=rowTemplate,args={contest, year, roundInput, ['table'] = wikitable, header=1}}
for _,entry in pairs(ordered) do
result = result ..'\n'.. f:expandTemplate{title=rowTemplate,args={contest, year, entry, round, ['table'] = wikitable}}
end
return result..'\n|}'
end
return p