Module:Infobox/Fonctions/Bac à sable
Apparence
[voir] [modifier] [historique] [purger]
Cette page définit un module d'infobox.
La documentation de ce module est générée par le modèle {{Documentation module}}.
Elle est incluse depuis la page Modèle:Documentation module d'infobox. Veuillez placer les catégories sur cette page-là.
Les éditeurs peuvent travailler dans le bac à sable (modifier).
Voir les statistiques d'appel depuis le wikicode sur l'outil wstat et les appels depuis d'autres modules.
-- Fonctions communes à diverses infobox
local localdata = require 'Module:Infobox/Localdata'
local wikidata = require 'Module:Wikidata'
local linguistic = require "Module:Linguistique"
local item = localdata.item
local p = {}
function p.title(icon, style, subtitleparam, subtitlequery, italic)
local function hide(param, value)
if localdata[param] ~= '-' then
return value
end
end
return {
type = 'title',
value = function()
return localdata['nom'] or localdata['association_nom'] or localdata['nom_think'] or localdata['acronymelaboratoire'] or localdata['titre']
or wikidata.getLabel(localdata.item) and mw.language.getContentLanguage():ucfirst( wikidata.getLabel(localdata.item) )
or mw.title.getCurrentTitle().text
end,
subtitle = function() if localdata[subtitleparam] ~= '-' then return localdata[subtitleparam] end end,
wikidatasubtitle = hide(subtitleparam, subtitlequery),
icon = icon,
style = style,
italic = italic,
setdisplaytitle = italic,
}
end
function p.mainimage(args, defaultimage)
if type( args ) ~= 'table' then
args = { cat = args, defaultimage = defaultimage }
end
return {
type = 'images',
imageparameters = {'image', 'photo', 'Photo'},
defaultimages = args.defaultimage or defaultimage,
defaultimagelink = 'Aide:Insérer une image',
sizeparameter = 'taille image',
uprightparameter = 'upright',
defaultupright = args.upright,
defaultsize = args.size,
maintenancecat = args.cat or 'Article à illustrer',
captionparameter = {'légende', 'légende image', 'Légende'},
altparameter = args.altparameter or 'alternative image',
-- defaultalt = args.alt or 'Image dans Infobox.',
defaultimagealt = args.defaultimagealt,
wikidata = args.wikidata or {property = {'P18', 'P5252'}},
numval = 1,
}
end
function p.interior(upright)
return {
type = 'images',
imageparameters = {'intérieur', 'interior'},
-- defaultimage = {},
-- maintenancecat =
captionparameter = 'légende intérieur',
property = 'P5775',
defaultupright = upright or '1',
uprightparameter = 'upright intérieur',
sizeparameter = 'taille intérieur',
numval = 1,
}
end
function p.standardImage(imageType, imageparameters, property, upright)
return {
type = 'images',
imageparameters = imageparameters or {imageType},
captionparameter = 'légende ' .. imageType,
property = property,
defaultupright = upright,
uprightparameter = 'upright ' .. imageType,
sizeparameter = 'taille ' .. imageType,
altparameter = 'alternative ' .. imageType,
-- defaultalt = imageType .. ' dans Infobox.',
numval = 1,
}
end
function p.logo(upright)
return p.standardImage('logo', {'logo', 'association_logo'}, 'P154', upright or '0.6')
end
function p.blason(upright)
return {
type = 'images',
imageparameters = {'blason', 'sceau'},
-- defaultimage = {},
-- maintenancecat =
captionparameter = {'légende blason', 'légende sceau'},
property = {'P94', 'P158'},
defaultupright = upright or '0.8',
uprightparameter = {'upright blason', 'upright sceau'},
sizeparameter = {'taille blason', 'taille sceau'},
numval = 1,
}
end
function p.flag(upright, id)
local drapeau = wikidata.formatStatements{entity = id, property = 'P163', defaultlink = '-'}
return {
type = 'images',
imageparameters = {'drapeau'},
-- defaultimage = {},
-- maintenancecat =
captionparameter = drapeau or 'légende drapeau',
property = 'P41',
defaultupright = upright or '1',
uprightparameter = 'upright drapeau',
sizeparameter = 'taille drapeau',
numval = 1,
}
end
function p.sign(upright)
return {
type = 'images',
imageparameters = {'signalisation'},
-- defaultimage = {},
-- maintenancecat =
captionparameter = 'légende signalisation',
property = 'P14',
defaultupright = upright or '0.4',
uprightparameter = 'upright signalisation',
sizeparameter = 'taille signalisation',
numval = 1,
}
end
function p.icon(upright)
return {
type = 'images',
imageparameters = {'icône'},
-- defaultimage = {},
-- maintenancecat =
captionparameter = 'légende icône',
property = 'P2910',
defaultupright = upright or '0.4',
uprightparameter = 'upright icône',
sizeparameter = 'taille icône',
numval = 1,
}
end
function p.bathymetricmap(upright)
return {
type = 'images',
imageparameters = {'carte bathymétrique'},
-- defaultimage = {},
-- maintenancecat =
captionparameter = 'légende carte bathymétrique',
property = 'P207',
defaultupright = upright or '1',
uprightparameter = 'upright carte bathymétrique',
sizeparameter = 'taille carte bathymétrique',
numval = 1,
}
end
function p.routemap(upright)
return {
type = 'images',
imageparameters = {'tracé'},
-- defaultimage = {},
-- maintenancecat =
captionparameter = 'légende tracé',
property = 'P15',
defaultupright = upright or '1',
uprightparameter = 'upright tracé',
sizeparameter = 'taille tracé',
numval = 1,
}
end
-- Liens externes
function p.website(localparam) -- texte libre [http://example.org example.org] ou url seule localparam est désigne le paramètre utilisé historiquement dans le modèle pour le site web (legacy)
return {
type = 'mixed',
label = '[[Site web]]',
plurallabel = '[[Site web|Sites web]]',
wikidata = function()
local values, num = wikidata.formatAndCat {
entity = localdata.item,
displayformat = 'weblink',
conjtype = '<br />',
property = 'P856',
isinlang = 'fr',
excludespecial = true, -- excludespecial car il peut y avoir marqué "aucune valeur" pour le français, mais y avoir un site en anglais
returnnumberofvalues = true,
}
if not values then
values, num = wikidata.formatAndCat {
entity = localdata.item,
displayformat = 'weblink',
conjtype = '<br />',
property = 'P856',
showlang = true,
excludespecial = true,
returnnumberofvalues = true,
}
end
return values, num
end,
value =
function()
local siteurl = localdata[localparam] or localdata['site web'] or localdata['site_web'] or localdata['site officiel'] or localdata['site internet'] or localdata['web']
local sitename = localdata['nom site']
if siteurl then
if siteurl:find("url") then
return siteurl
else
return require("Module:Weblink").makelink(siteurl, sitename)
end
end
end,
}
end
-- Son, prononciation
function p.selectSound(prop)
-- priorité au français
if wikidata.getClaims{entity = localdata.item, property = prop, qualifier = {'P407'}, qualifiervalue = {'Q150'} } then
return {property = prop, qualifier = {'P407'}, qualifiervalue = {'Q150'} }
end
return {property = prop}
end
function p.prononciation()
return {
type = 'images',
style = {['padding-top'] = '25px'},
defaultcaption = 'Prononciation',
captionparameter = 'légende prononciation',
value = 'prononciation',
defaultsize = '280',
wikidata = p.selectSound('P443'),
numval = 1,
}
end
-- Fonctions de géolocalisation
function p.country(default)
local coordfunctions = require 'Module:Infobox/Fonctions/Géolocalisation'
return coordfunctions.country(default)
end
--- localisation administrative par Wikidata
function p.wikidataDivRows(countryid) -- liste de lignes de divisions administrative basée sur des données de Wikidata
if not localdata.item then
return nil
end
-- récupération des valeurs
local list = wikidata.transitiveVals(localdata.item, {property = "P131", atdate = "today", excludespecial = true}, 3, 5, countryid)
if not list then
return nil
end
-- création des colonnes
local rows = {}
for i, div in pairs(list) do
if (div == countryid) then
break
end
local rowlabel, rowlabelid, rowlabeltext, rowlabellink, rowvalue
rowlabelid = wikidata.formatStatements{entity= div, property = 'P31', numval = 1, displayformat = 'raw', excludespecial = true}
rowlabeltext = wikidata.getLabel(rowlabelid, 'fr', function(id)
local str = wikidata.getLabel(id)
if str then
return linguistic.ucfirst(linguistic.removecomplement(str)) -- imposé par les libellés pas très logiques sur Wikidata du genre "canton de Suisse" plutôt que "canton" else
end
return ''
end
)
if (not rowlabeltext) then
rowlabeltext = 'Division'
end
if rowlabelid then
rowlabellink = wikidata.siteLink(rowlabelid, {defaultlink = '-', defaultlinkquery= {property = "P2354"}} ) -- si pas de lien, lier vers la page de liste e.g liste des Etats de Californie
end
if rowlabellink then
rowlabel = "[[" .. rowlabellink .. "|" .. rowlabeltext .. "]]"
else
rowlabel = rowlabeltext
end
rowvalue = wikidata.formatEntity(div, {labelformat = function(id)
local str = wikidata.getLabel(id) or ""
if mw.ustring.match(rowlabel, str) then
str = linguistic.keepcomplement(str)-- si le nom de la division administrative affiché est présent, ne pas le répéter
end
return str
end})
table.insert(rows, 1, {type = "row", label = rowlabel, value = function() return rowvalue end})
end
return rows
end
function p.geoloc(params)
local coordfunctions = require 'Module:Infobox/Fonctions/Géolocalisation'
return coordfunctions.geoloc(params)
end
function p.coordinates(params)
local coordfunctions = require 'Module:Infobox/Fonctions/Géolocalisation'
return coordfunctions.coordinates(params)
end
function p.locationmap(params)
local coordfunctions = require 'Module:Infobox/Fonctions/Géolocalisation'
return coordfunctions.locationmap(params)
end
function p.detailedmap(params)
local coordfunctions = require 'Module:Infobox/Fonctions/Géolocalisation'
return coordfunctions.detailedmap(params)
end
return p