Module:Luchthavens
Uiterlijk
local p = {}
local function property(qid, pid)
local s = mw.wikibase.getBestStatements(qid, pid)[1]
if s then
return s.mainsnak.datavalue.value
end
end
local function linkedLabel(qid)
local title = mw.wikibase.getSitelink(qid)
local r
if title then
local label = mw.wikibase.getLabel(qid)
if not label then
label = mw.text.split(title, ' %(')[1]
end
r = '[[' .. title .. '|' .. label .. ']]'
else
r = ''
end
return r
end
function p.tabelrij(frame)
frame = frame:getParent()
local airport = frame.args['luchthaven']
if not airport then -- mandatory parameter
return '|-\n|colspan="7"| Fout: ontbrekende parameter: "luchthaven"\n'
end
local qid = frame.args['qid']
if not qid then
local title = mw.title.new(airport)
if not title then
return '|-\n|colspan="7"| Fout: ongeldige luchthaven: ' .. airport .. '\n'
end
if title.isRedirect then
title = title.redirectTarget.fullText
else
title = airport
end
qid = mw.wikibase.getEntityIdForTitle(title)
end
local location = frame.args['locatie']
if qid and not location then
local p931 = property(qid, 'P931')
if p931 then
location = linkedLabel(p931.id)
end
end
local iata = frame.args['IATA']
if qid and not iata then
iata = property(qid, 'P238')
end
local icao = frame.args['ICAO']
if qid and not icao then
icao = property(qid, 'P239')
end
local passengers = frame.args['passagiers']
if qid and not passengers then
passengers = property(qid, 'P3872')
if passengers then
passengers = passengers.amount
end
end
if passengers and passengers ~= '' then
passengers = '{{formatnum:' .. tonumber(passengers) .. '}}'
else
passengers = '?'
end
local totalRunways = frame.args['banen_totaal']
if totalRunways then
totalRunways = tonumber(totalRunways)
elseif qid then
totalRunways = #mw.wikibase.getAllStatements(qid, 'P529')
end
if not totalRunways or totalRunways <= 1 then
totalRunways = 1
end
local largeRunways = frame.args['banen_groot']
if not largeRunways then
largeRunways = totalRunways
end
local runways
if totalRunways ~= largeRunways then
runways = largeRunways .. ' (' .. totalRunways .. ')'
else
runways = largeRunways
end
local website = frame.args['website']
if qid and not website then
website = property(qid, 'P856')
end
if website then
website = '[' .. website .. ' site luchthaven]'
else
website = ''
end
local r =
'|-\n' ..
'| ' .. (location or '') .. '\n' ..
'| [[' .. airport .. ']]\n' ..
'| ' .. (iata or '') .. '\n' ..
'| ' .. (icao or '') .. '\n' ..
'|style="text-align:right"| ' .. passengers .. '\n' ..
'| ' .. runways .. '\n' ..
'| ' .. website .. '\n'
return frame:preprocess(r)
end
return p