Module:Infobox/Fonctions

De Wikipedia

La documentation pour ce module peut être créée à Module:Infobox/Fonctions/doc

-- Fonctions communes à diverses infobox
local wikidata = require('Module:Wikidata')
local d = require('Module:Wikidata/Dates')

local p = {}

function p.title(class)
	return {
			type = 'title',
			value = function(localdata, item) return localdata['nom'] or wikidata._getLabel(item) or mw.title.getCurrentTitle().text end,
			subtitle = function(localdata, item)
				if localdata['nom local'] then
					return localdata['nom local']
				end
				if not item then 
					return nil
				end
				local subtitles = wikidata.getClaims({item=item, property = 'P1448'})
				local subtitlestr = ''
				if not subtitles then return 
					nil
				end
				local title = localdata['nom'] or wikidata._getLabel(item) or mw.title.getCurrentTitle().text
				local langspan = require('Module:Langue').langue
				local dones = {}
				local text, textlang
				for i, j in pairs(subtitles) do
					if j.mainsnak.snaktype then
						text, textlang = j.mainsnak.datavalue.value.text, j.mainsnak.datavalue.value.language
					end
					if text ~= title and not dones[text] then
						subtitlestr = subtitlestr .. langspan{textlang, text} .. '<br />'
						dones[text]= true
					end
				end
				return subtitlestr
				end
			,
			class = class, 
	}
end

function p.mainimage(cat)
	return {
		type = 'images',
		imageparameters =  {'image'},
		defaultimage = {defaultimage},
		maintenancecat =
			function(localdata, item, params)
			if (cat == '-') or localdata['image'] == 'non' then
				return nil
			elseif cat then
				return cat
			else
				return 'Article à illustrer'
			end
			end,
		captionparameter = 'légende',
		defaultcaption = function() return defaultcaption end,
		property = 'P18',
		numval = 1,
	}
end

-- Liens externes
function p.website() --texte libre [http://example.org example.org] ou url seule
	return { 
            type = 'mixed',
            label = "Site web",
            wikidata = function(localdata, item) return wikidata._formatAndCat({property='p856', displayformat = 'weblink', item=item}) end,
            value = function(localdata) 
            	local website = localdata['site web'] or localdata['site_web']
            	if website then
            		return website
            	elseif localdata['url'] then
	            	return require("Module:Weblink").makelink(localdata['url'])
            	end
            	end
            }
end

return p