Module:Infobox/Aéroport

Une page de Wikipédia, l'encyclopédie libre.

 Documentation[voir] [modifier] [historique] [purger]

Cette page définit un module d'infobox. Pour les conseils sur l'usage de ce module, voyez Modèle:Infobox Aéroport.


local building = require "Module:Infobox/Fonctions/Bâtiment"
local general = require "Module:Infobox/Fonctions"
local wikidata = require "Module:Wikidata"
local linguistic = require "Module:Linguistique"
local convert = require( 'Module:Conversion' ).displayvalue
local makelink = require( 'Module:Weblink' ).makelink

local function displayLength(lengthM, lengthFt)
	if (not lengthM and not lengthFt) then
		return nil
	end
	local function conv(length, u1, u2)
		local success, val = pcall( 
			convert,
			length,
			u1, 
			{ targetunit = u2, rounding = 0, showunit = true }
		)
		if success then
			return val
		else
			return ''
		end
	end
	if lengthM then
		if not lengthFt then
			lengthFt = conv( lengthM, 'metre', 'foot' )
		else
			lengthFt = lengthFt .. ' ft'
		end
		lengthM = lengthM .. ' m'
	else
		lengthM = conv( lengthFt, 'foot', 'metre' )
		lengthFt = lengthFt .. ' ft'
	end
	return lengthM .. (linguistic.inparentheses(lengthFt) or '')
end

local runwayheader = mw.html.create('tr')
	:tag('th'):wikitext('Direction'):done()
	:tag('th'):wikitext('Longueur'):done()
	:tag('th'):wikitext('Surface'):done()
	:done()


local helisurfaceheader = mw.html.create('tr')
	:tag('th'):css{ width = '700px', ['margin-left'] = 'auto', ['margin-right'] = 'auto'}:wikitext('Numéro'):done()
	:tag('th'):wikitext('Longueur')
	:tag('th'):wikitext('Surface')
	:done()
	
local function getDate(event, item) 
	return wikidata.getTheDate{targetvalue = event, property = 'P793', addcat = true, entity = item}
end

local function runwayrow(direction, surface, lengthM, lengthFt)
	if not (direction or surface or lengthM or lengthFt) then
		return nil
	end
	local length = displayLength(lengthM, lengthFt)

	local row = mw.html.create('tr')
		:tag('td'):wikitext(direction or '<i>à renseigner</i>'):done()
		:tag('td'):wikitext(length or '<i>à renseigner</i>'):done()
		:tag('td'):wikitext(surface or '<i>à renseigner</i>'):done()
		:done()
	return row
end

local function maplink(zone, oaci)
	--[[[http://www.sia.aviation-civile.gouv.fr/aip/enligne/PDF_AIPparSSection/{{Modèle:Infobox Aéroport/SIA|{{{OACI|}}}|VAC}}/AD/2/{{#time:ym|+1 month}}_AD-2.{{{OACI}}}.pdf VAC] {{#if: {{Modèle:Infobox Aéroport/SIA|{{{OACI|}}}|IAC}}| - [http://www.sia.aviation-civile.gouv.fr/aip/enligne/PDF_AIPparSSection/{{Modèle:Infobox Aéroport/SIA|{{{OACI|}}}|IAC}}/AD/2/{{#time:ym|+1 month}}_AD-2.{{{OACI}}}.pdf IAC]}} {{#if: {{Modèle:Infobox Aéroport/SIA|{{{OACI|}}}|ARRDEP}}| - [http://www.sia.aviation-civile.gouv.fr/aip/enligne/PDF_AIPparSSection/{{Modèle:Infobox Aéroport/SIA|{{{OACI|}}}|ARRDEP}}/AD/2/{{#time:ym|+1 month}}_AD-2.{{{OACI}}}.pdf ARR/DEP]}}]]--
	if zone == 'france' or zone == 'q142' then -- TODO utiliser module:Counry data pour faire plus propre
		local link
	end
	return 
end

return 
	{
	maincolor = '#98aec8', thirdcolor = 'white',
	parts =
		{
			{
				type = 'title', 
				value = 'nom',
				subtitle = function(localdata)
						local name1, name2 = localdata['nom_po'], localdata['nom_pa'] -- noms de paramètres à harmoniser avec les autres modèles
						if nam1 or name2 then
							return linguistic.conj({name1, name2}, '<br />')
						end
					end
			},
			-- ajouter ?	general.logo(),
			building.mainimage(),
			{type = 'images', size = '100px', parameters = {'cocarde', 'cocarde2'}},
			{type = 'table', title = 'Localisation', rows = {
				building.country(),
				{
					type = 'row',
					value = 'division',
					label = function(localdata)
						return localdata['nom de division'] or 'Division'
					end
				},
				{
					type = 'row',
					value = 'division 2',
					label = function(localdata)
						return localdata['nom de division 2'] or 'Division'
					end
				},
				{type = 'row', value = 'ville', label = 'Ville'},
				{
					type = 'row',
					label = 'Date d’ouverture',
					value = 'ouverture',
					wikidata = function(item)
						return getDate('Q18123869', item)
					end
				},
				{
					type = 'row',
					label = 'Date d’ouverture',
					value = 'ouverture',
					wikidata = function(item)
						return getDate('Q14954904', item)
					end
				},
				{type = 'row', label = 'Superficie', value = 'superficie'},
				{
					type = 'row',
					label = 'Altitude',
					value = function(localdata)
						return displayLength( localdata['altitude m'], localdata['altitude ft'])
					end
				},
				building.coordinates('Aéroport sans toponyme'), -- afficher l'avion dans le sens des pistes ?
			}},
			-- liste des pistes
			{type = 'table', title = 'Pistes', rows = {
				{
					type = 'row',
					value = function(localdata) 
						local tab = mw.html.create('table')
							:css{ display = 'block', ['margin-left'] = 'auto', ['margin-right'] = 'auto', ['text-align'] = "center", padding = '5px', ['line-height'] = "13px"}
							:node(runwayheader)
						local hasrows = false
						for i = 1, 10 do
							local row = runwayrow(
								localdata['direction piste'..tostring(i)],
								localdata['revetement piste'..tostring(i)],
								localdata['longueur piste'..tostring(i) .. ' m'],
								localdata['longueur piste'.. tostring(i) .. ' ft']
							)
							if row then
								tab:node(row)
								hasrows = true
							end
						end
						tab:allDone()
						if hasrows then
							return tostring(tab)
						end
					end
				},
			}},
				-- liste des hélisurfaces
			{type = 'table', title = 'Hélisurfaces', rows = {
				{
					type = 'row',
					value = function(localdata) 
						local tab = mw.html.create('table')
							:css{['align'] = 'center', ['text-align'] = "center", padding = '3px', ['line-height'] = "13px"}
							:node(runwayheader)
						local hasrows = false
						for i = 1, 10 do
							local row = runwayrow(
								localdata['numero helisurface'..tostring(i)],
								localdata['revetement helisurface'..tostring(i)],
								localdata['longueur helisurface'..tostring(i) .. ' m'],
								localdata['longueur helisurface'.. tostring(i) .. ' ft']
							)
							if row then
								tab:node(row)
								hasrows = true
							end
						end
						tab:allDone()
						if hasrows then
							return tostring(tab)
						end
					end
				},
			}},
			{type = 'table', title = 'Informations aéronautiques', rows = {
				{type = 'row', label = '[[code AITA]]', value = 'AITA', property = 'P238'},
				{type = 'row', label = '[[code OACI]]', value = 'OACI', property = 'P239'},
				{type = 'row', label = 'Nom cartographique', value = 'nom carto'},
				{type = 'row', label = 'Type d’aéroport', value = 'type'},
				{type = 'row', label = 'Gestionnaire', value = 'gestionnaire', property = 'P137'},
				{
					type = 'row',
					label = 'Site web gestionnaire',
					value = function(localdata)
						local url = localdata['site web gestion']
						return makelink(url, 'consulter')
					end
				},
				{
					type = 'row',
					label = 'Site web aéroport',
					value = function(localdata)
						local url = localdata['site web aéro']
						return makelink(url, 'consulter')
					end
				},
				-- todo : liens cartos
				{
					type = 'row',
					label = 'Cartes [[Service de l\'information aéronautique|SIA]]',
					value = function(localdata)
						local country = localdata['pays']
							or wikidata.formatStatements{
								entity = localdata.item,
								property = 'P17',
								displayformat = 'raw'
							}
						return maplink (country)
					end	
				}
			}
		},
		building.geoloc({marker='airport', default_zoom=14}),
	}
}