Module:Gebruiker:Bdijkstra/Luchthavens

Uit Wikipedia, de vrije encyclopedie

Documentatie voor deze module kan aangemaakt worden op de volgende pagina: Module:Gebruiker:Bdijkstra/Luchthavens/doc

local p = {}

local function property(qid, pid)
	return mw.wikibase.getBestStatements(qid, pid)[1].mainsnak.datavalue.value
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.main(frame)
	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
		location = linkedLabel(property(qid, 'P931').id)
	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')
	end
	if passengers then
		n = tonumber(passengers.amount)
		if n then
			passengers = '{{formatnum:' .. n .. '}}'
		else
			passengers = mw.dumpObject(passengers)
		end
	else
		passengers = '?'
	end
	
	local totalRunways = frame.args['banen_totaal']
	if qid and not totalRunways 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 = largeRunways .. ' (' .. totalRunways .. ')'

	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 .. '\n' ..
		'| [[' .. airport .. ']]\n' ..
		'| ' .. iata .. '\n' ..
		'| ' .. icao .. '\n' ..
		'|style="text-align:right"| ' .. passengers .. '\n' ..
		'| ' .. runways .. '\n' ..
		'| ' .. website .. '\n'
	return frame:preprocess(r)
end

return p