« Module:Infobox/Fonctions » : différence entre les versions
Aucun résumé des modifications |
Annulation des modifications 118782523 de Jérémy-Günther-Heinz Jähnick (d) |
||
| Ligne 4 : | Ligne 4 : | ||
local lang = mw.language.new('fr') | local lang = mw.language.new('fr') | ||
local p = {} | local p = {} | ||
function p.title(icon, style) | function p.title(icon, style) | ||
Version du 19 septembre 2015 à 15:00
-- Fonctions communes à diverses infobox local wikidata = require 'Module:Interface Wikidata'.fromLua local coordfunctions = require 'Module:Infobox/Fonctions/Géolocalisation' local lang = mw.language.new('fr') local p = {}
function p.title(icon, style) local title = localdata['nom'] or wikidata.getLabel(item) or mw.title.getCurrentTitle().text local subtitle = localdata['nom local']
local subtitleclaims = wikidata.getClaims({item=item, property = 'P1448'} or {})
if (not subtitle) and subtitleclaims then
subtitle =
local dones = {}
local langspan = require('Module:Langue').langue
for i, j in pairs(subtitleclaims) do
local text, textlang
if j.mainsnak.snaktype then
text, textlang = j.mainsnak.datavalue.value.text, j.mainsnak.datavalue.value.language
end
if mw.ustring.lower(text) ~= mw.ustring.lower(title) and not dones[text] then
subtitle = subtitle .. langspan{textlang, text} .. '
'
dones[text] = true
end
end
if subtitle == then
subtitle = nil
end
end
return { type = 'title', value = function() return title end, subtitle = function() return subtitle end, icon = icon, style = style, } end
function p.mainimage(cat, defaultimage, size) return { type = 'images', imageparameters = {'image'}, defaultimages = defaultimage, defaultimagelink = 'Aide:Insérer une image', -- defaultimagesize = '100px', sizeparameter = 'taille image', defaultsize = size, maintenancecat = function(localdata, item, params) if cat and (cat ~= '-') then return cat else return 'Article à illustrer' end end, captionparameter = 'légende', defaultcaption = function() return defaultcaption end, property = 'P18', numval = 1, } end
function p.logo(size) return { type = 'images', imageparameters = {'logo'}, -- defaultimage = {}, -- maintenancecat = captionparameter = 'légende logo', property = 'P154', defaultupright = '0.8', sizeparameter = 'taillelogo', numval = 1, } end
-- Liens externes function p.website() --texte libre example.org ou url seule local function getLinks(item) return wikidata.getClaims {property='P856', entity = item} end return {
type = 'mixed',
label = 'Site web',
wikidatalabel = function()
local links = getLinks(item)
if links and #links > 1 then
return 'Sites web'
end
return 'Site web'
end,
wikidata = function()
local claims = getLinks(item)
return wikidata.formatAndCat{entity = item, claims = claims, displayformat = 'weblink', conjtype = '
', property = 'P856'}
end,
value = function(localdata)
local website = localdata['site web'] or localdata['site_web'] or localdata['site officiel']
if website then
if (string.sub(website, 1, 4) == 'http') and (not string.find(website, ' ')) then -- if website is url
return require("Module:Weblink").makelink(website)
else
return website
end
elseif localdata['url'] then
return require("Module:Weblink").makelink(localdata['url'])
end
end
}
end
-- Pays function p.country(default) return coordfunctions.country(default) end
return p