Μετάβαση στο περιεχόμενο

Module:Infobox/Fonctions

Από τη Βικιπαίδεια, την ελεύθερη εγκυκλοπαίδεια
-- 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.onlytitle(icon, style)
	local title = localdata['nom'] or wikidata.getLabel(item) or mw.title.getCurrentTitle().text
	return {
			type = 'title',
			value = function() return title end,
			icon = icon,
			style = style,
		}
end
	
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} .. '<br />'
				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 [http://example.org 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 = '<br />', 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