Module:Infobox/Film

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 Film.


local localdata = require 'Module:Infobox/Localdata'
local general = require "Module:Infobox/Fonctions"
local person = require "Module:Infobox/Fonctions/Personne"
local wikidata = require "Module:Wikidata"
local linguistic = require "Module:Linguistique"
local convert = require "Module:Conversion"
local country_data = require "Module:Country data"

local function italics(query)
	local val = wikidata.formatAndCat(query)
	if val then
		return '<i>' .. val .. '</i>'
	end
end

local function formatCountry(stmt, args)
	local snak = stmt.mainsnak
	if snak.snaktype == 'value' and snak.datatype == 'wikibase-item' then
		local countryId = wikidata.getId(snak)
		local text, valid = country_data.standarddisplay(countryId)
		if valid and type(text) == "string" then
			return text
		end
	end
	return wikidata.formatSnak(snak, args)
end

local function isNotInFrench(claim)
	local snak = claim.mainsnak
	if snak.snaktype == 'value' and snak.datatype == 'monolingualtext' then
		return snak.datavalue.value.language ~= 'fr'
	end
	return true
end

local function countSitelinks(eid)
	local entity = wikidata.getEntity(eid)
	if (not entity) or (not entity.sitelinks) then
		return 0
	end
	local count = 0
	for k, v in pairs(entity.sitelinks) do
		if k:match("^.+wiki$") then
			count = count + 1
		end
	end
	return count
end

local function distribution(item)
	local claims = wikidata.getClaims({entity = item, property = 'P161'})
	
	if not claims then
		return nil
	end
	
	local actors = {}
	for i, claim in pairs(claims) do
		local snak = claim.mainsnak
		if snak.snaktype == "value" and snak.datatype == "wikibase-item" then
			local actorId = wikidata.getId(snak)
			local actorWeight = countSitelinks(actorId)
			local actorLink = wikidata.formatEntity(actorId)
			actors[#actors+1] = {actorWeight, actorId, actorLink}
		end
	end
	
	if #actors == 0 then
		return nil
	end

	table.sort(actors, function (x, y) return x[1] > y[1] end)
	
	local result, idx = "", 1
	while idx <= 5 and idx <= #actors do
		result = result .. "<br/>" .. actors[idx][3]
		idx = idx + 1
	end
	
	return string.sub(result, 6), idx-1
end

return 
	{
	maincolor = "09C8BD",
	secondcolor = "5CF8F0",
	parts =
    	{
			general.title( "cinema"),
			general.mainimage{ 
				cat = "Article à illustrer Arts et culture",
				defaultimage = "Defaut 2.svg", 
				wikidata = {property = {"P3383", "P2716", "P18", "P10"}, numval = 1}
				},
		{type = "table", title = "Informations générales", rows = {
			{type = "row", label = "Type", value = "type" , plurallabel = "Types", wikidata = {property = 'P31' , excludevalues = "Q11424,Q24869"}},
			{type = "row", label = "Titre original", value = "titre original", plurallabel = "Titres originaux" , wikidata = function ( item )
					return italics({entity = item, property = 'P1476', conjtype = 'new line' , condition = isNotInFrench, showlang = true })--trouver un moyen de retirer lorsque le titre original est en français
				end
			},
			{type = "row", label = "Date de production", value = "date de production", plurallabel = "Dates de sortie" , wikidata = {property = 'P571' , sorttype = 'chronological' , numval = 1 }},
			{type = "row", label = "Date de sortie", value = "date de sortie", plurallabel = "Dates de sortie" , wikidata = {property = 'P577' , conjtype = 'new line' , sorttype = 'chronological' , showqualifiers = 'P291,P276' }},
			{type = "row", label = "Diffuseur", value = "diffuseur", plurallabel = "Diffuseurs" , property = 'P449'},
			{type = "row", label = "Durée", value = "durée", plurallabel = "Durées" , wikidata = {property = 'P2047' , showunit = 'long' }},
			{type = "row", label = "Langue", value = "langue originale" , plurallabel = "Langues", property = 'P364'},
			{type = "row", label = "Genre", value = "genre" , plurallabel = "Genres", property = 'P136'},
			{type = "row", label = "Format", value = "format" , plurallabel = "Formats", wikidata = {property = 'P462' , excludevalues = "Q22006653"}},
			{type = "row", label = "Basé sur", value = "basé sur" , wikidata = function ( item )
					return italics({entity = item, property = 'P144'})
				end
			},
			{type = "row", label = "Sujet", value = "sujet" , plurallabel = 'Sujets', property = 'P921'},
			{type = "row", label = "Pays", value = "pays d\'origine" , wikidata = { property = 'P495', statementformat = formatCountry, conjtype = 'new line' } }, -- ça serait bien d'afficher le drapeau avant le pays. Peut-être en pouvant mettre en forme la propriété ainsi : {{propriété}}.
			{type = "row", label = "Lieu de tournage", value = "lieu de tournage" , plurallabel = 'lieux de tournage' , property = 'P915'},
			--{type = "row", label = "Format", value = "format", plurallabel = "Formats" , property = 'P3803'}, plus détaillé que nécessaire pour l'infobox
			general.website
			}
		},
		{type = "table", title = "Équipe du film", rows = {
			{type = "row", label = "Réalisation", value = "réalisation", property = 'P57'},
			{type = "row", label = "Scénario", value = "scénario", property = 'P58'},
			{type = "row", label = "Société de production", plurallabel = "Sociétés de production", value = "production", wikidata = {property = 'P272' , conjtype = 'new line'}},
			{type = "row", label = "Producteur", plurallabel = "Producteurs", value = "producteur", property = "P162"},
			{type = "row", label = "Producteur délégué", plurallabel = "Producteurs délégués", value = "production déléguée", property = 'P1431'},
			{type = "row", label = "Storyboard", value = "storyboard", property = 'P3275'},
			{type = "row", label = "Décors", value = "décors", property = 'P2554'},
			{type = "row", label = "Costumes", value = "costumes", property = 'P2515'},
			{type = "row", label = "Photographie", value = "photographie", property = 'P344'},
			{type = "row", label = "Distribution", value = "distribution", wikidata = distribution}, --problématique. Il y a souvent plus de 10 valeurs et les 10 premières ne sont pas nécessairement représentatives du poids dans l'oeuvre. Il faudrait une fonction qui place les 5 premiers noms par ordre décroissant d'interwikis existants (le plus grand nombre d'interwikis = les plus gros noms = les principaux remarqués) et place le reste en liste déroulante semblable à celle des distinctions. )
			{type = "row", label = "Musique", value = "musique", property = 'P86'},
			{type = "row", label = "Montage", value = "montage", property = 'P1040'},
			
		}
		},
		{type = "table", title = "Économie", rows = {
			--{type = "row", label = "Visa d'exploitation", value = "visa d'exploitation",  wikidata = {property = 'P2755', urlpattern="http://www.cnc.fr/web/fr/rechercher-une-oeuvre/-/visa/$1"}}, plus détaillé que nécessaire pour une infobox
			{type = "row", label = "Coût", value = "coût" , plurallabel = "Coûts", property = 'P2130'},
			{type = "row", label = "[[Box-office]]", value = "box-office" , wikidata = {property = 'P2142' , showunit = 'short'}},
			person.awards(),
			}
		},
		{type = "table", title = "Séquence", rows = {
			{type = "row", label = "Série", value = "série", plurallabel = "Séries" , wikidata = function ( item )
					return italics({entity = item, property = 'P179', conjtype = 'new line' , showlang = true })
				end
			},
			{type = "row", label = "Précédé par" , value = "précédent" , wikidata = function ( item )
					return italics({entity = item, property = 'P155', conjtype = 'new line' , showlang = true })
				end
			},
			{type = "row", label = "Suivi par" , value = "suivant" ,wikidata = function ( item )
					return italics({entity = item, property = 'P156', conjtype = 'new line' , showlang = true })
				end
			},
		},
		}
	}
}