Module:Infobox/Format de données

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 Format de données.


-- Module pour afficher un format de données

-- Importe les modules nécessaires
local wikidata = require( 'Module:Wikidata' )
local general = require( 'Module:Infobox/Fonctions' )
local localdata = require( 'Module:Infobox/Localdata' )

-- Variables et fonctions utilisées dans certaines lignes d'infobox
local isContainer = wikidata.isInstance('Q167772', item, 0) 

local function specification(number)
	if (number == '1') then
		return '[[Format propriétaire]] [[Catégorie:Format fermé]]'
	elseif (number == '2') then
		return '[[Format ouvert]] [[Catégorie:Format ouvert]]'
	end
	return nil
end

local function affichageHexa(x)
  local t = ""
  for c in x:gmatch".." do
    t = t .. c .. " "
  end
  return "<code>" .. t:gsub("^%s*(.-)%s*$", "%1") .. "</code> ([[Système hexadécimal|hexa]])"
end

local function affichageSignature(value, qual)
	if not qual then
		return "<code>" .. value .. "</code>"
	end
	local qualifierId = qual[1].datavalue.value.id
	--for k,v in pairs(qual) do
	--	qualifierId = v.datavalue.value.id
	--	break
	--end
    if (qualifierId == "Q82828") then
        return affichageHexa(value)
    elseif (qualifierId == "Q8815") then
        return "<code>" .. value .. "</code> ([[American Standard Code for Information Interchange|ascii]])"
    elseif (qualifierId == "Q35432091") then
        return "<code>" .. value .. "</code> ([[Base PRONOM|PRONOM]] [[Expression régulière|regex]])"
    elseif (qualifierId == "Q125267") then
        return "<code>" .. value .. "</code> ([[PCRE|PCRE]])"
    elseif (qualifierId == "Q185612") then
        return "<code>" .. value .. "</code> ([[Expression régulière|regex]])"
    else
        return "<code>" .. value .. "</code>"
    end
end

-- voir https://fr.wikipedia.org/wiki/Aide:Infobox_en_Lua
return {
	maincolor = '#C0C0C0',
	parts = {
		-- paramètre 'nom complet' en sous-titre
		general.title('informatique', nil, 'nom complet'),
		general.mainimage('Article à illustrer Format de données'),
		general.logo(),
		{ type = 'table', title = 'Caractéristiques', rows = {
			{	type = 'row',
				label = '[[Extension de nom de fichier|Extension]]',
				plurallabel = '[[Extension de nom de fichier|Extensions]]',
				value = 'extension',
				wikidata = {
						-- Les propriétés de rang normal et preferred
						entity = item,
						property = 'P1195',
						rank = 'valid',
						conjtype = 'comma',
						linkback = 'P1195',
						displayformat = function(snak) 
							return '<code>.' .. snak.datavalue.value .. '</code>'
						end,
				}
			},
			{	type = 'row',
				label = '[[Type de médias|Type MIME]]',
				value = 'mime',
				wikidata = {
					property = 'P1163',
					separator = ' ',
					rank = 'valid',
					ucfirst = '-',
					displayformat = function(snak) 
							return '<code> ' .. snak.datavalue.value .. '</code>'
					end,
				}
			},
			{	type = 'row',
				label = '[[Base PRONOM|PUID]]',
				value = 'puid',
				wikidata = {
						entity = item, property = 'P2748', excludespecial = true,
						conjtype = 'comma', 
						linkback = 'P2748',
						urlpattern = 'https://www.nationalarchives.gov.uk/pronom/$1' -- définit la forme de l'url pour chaque propriété
					}
			},
			{	type = 'row',
				label = '[[Nombre magique (programmation)|Signature]]',
				plurallabel = '[[Nombre magique (programmation)|Signatures]]',
				value = 'signature',
				-- Affichage selon le type d'encodage (P3294)
				wikidata = {
						property = 'P4152', excludespecial = true, conjtype = '<br />', 
						linkback = 'P4152',
						statementformat = function(statement)
							return affichageSignature(statement.mainsnak.datavalue.value, wikidata.getQualifiers(statement, {"P3294"}))
						end
					}
			},
			{	type = 'row',
				label = 'Développé par',
				value = 'développeur',
				property = 'P178',
			},
			{	type = 'row',
				label = 'Version initiale',
				value = 'version initiale',
				property = {'P577','P571'},
			},
			{	type = 'row',
				label = 'Type de format',
				value = 'genre',
				property = 'P136',
			},
			{	type = 'row',
				label = '[[Format conteneur|Conteneur]] de fichiers',
				value = 'conteneur de',
				wikidata = {
					property = 'P527',
					condition = function() return isContainer end,
					ucfirst = '-'
					}
			},
			{	type = 'row',
				label = '[[Format conteneur|Contenu]] par',
				value = 'contenu par',
			},
			{	type = 'row',
				label = 'Basé sur',
				value = 'extension de',
				property = 'P144',
			},
			{	type = 'row',
				label = 'Origine de',
				value = 'origine de',
			},
			{	type = 'row',
				label = 'Norme',
				value = 'standard'
			},
			{	type = 'row',
				label =  '[[Organisation internationale de normalisation|ISO]]',
				blockers = 'standard', -- pour éviter les doublons cette ligne Wikidata est désactivé lorsque le champ "standard" est renseigné localement
				property = 'P503'
			},
			{	type = 'row',
				label = 'Spécification',
				value = function ( localdata )
					return specification(localdata['spécification'] or localdata['specification'] )
				end,
			},
			general.website(), 
		}  }, 
	}
}