« Module:Classement » : différence entre les versions
Apparence
Modèle:Infobox>Zolo Prise d'indépendance de Module:Infobox Monument |
m 22 versions importées |
||
| (23 versions intermédiaires par 9 utilisateurs non affichées) | |||
| Ligne 1 : | Ligne 1 : | ||
local | local p = {} | ||
local wikidata = require | local formattingData = require "Module:Classement/Données" --libellés spéciaux et logos | ||
local wikidata = require "Module:Wikidata" | |||
local linguistic = require "Module:Linguistique" | |||
function | local function groupStatements(statements) -- regroupe les statements avec même mainid | ||
local | local newlist = {} | ||
local indexbyid = {} --par mainid, indice où sont rangés les statements dans newlist | |||
for i, j in pairs(statements) do | |||
local mainid = wikidata.getMainId(j) | |||
if not mainid then | |||
-- pas d'id, c'est une "special value" | |||
elseif not indexbyid[mainid] then | |||
table.insert(newlist, {mainid = mainid, data = {j}}) | |||
indexbyid[mainid] = #newlist | |||
else | |||
table.insert(newlist[indexbyid[mainid]].data, j) | |||
end | |||
end | |||
return newlist | |||
end | |||
local function formatMainStr(id) -- affiche le nom du statut du protection avec éventuellement un logo | |||
local str, logo | |||
if formattingData[id] then | |||
str = formattingData[id][1] | |||
logo = formattingData[id][2] | |||
else | |||
str = wikidata.formatEntity(id) | |||
end | |||
if logo then | |||
str = '[[File:' .. logo .. '|x18px|alt=|link=]] ' .. str | |||
end | |||
return str | |||
end | |||
local function formatStatus(id, data) | |||
local mainstr = formatMainStr(id) -- | |||
local details = {} -- informations complémentaires stockées dans les qualificatifs | |||
for i, j in pairs(data) do | |||
local pdate = wikidata.getFormattedQualifiers(j, {'P580'}, {precision = 'year'}) -- date de classement | |||
local part = wikidata.getFormattedQualifiers(j, {'P518'}, {link = '-'}) -- partie protégée | |||
local str = linguistic.conj({part, pdate}, ' en ') | |||
table.insert(details, str) | |||
end | |||
details = linguistic.conj(details, 'comma') | |||
details = linguistic.inparentheses(details) | |||
if details then | |||
return mainstr .. ' <small>' .. details .. '</small>' | |||
end | |||
return mainstr | |||
end | |||
function p.formattedList(item, params) | |||
-- créé une liste des status patrimoniaux de l'élement | |||
params = params or { entity = item } | |||
params.excludespecial = true | |||
params.property = 'P1435' | |||
local claims = wikidata.getClaims(params) | |||
if not claims then | if not claims then | ||
return nil | return nil | ||
end | end | ||
local statuses = groupStatements(claims) | |||
local statuses = | |||
local stringtable = {} -- liste des chaînes à retourner | local stringtable = {} -- liste des chaînes à retourner | ||
for i, j in pairs(statuses) do | for i, j in pairs(statuses) do | ||
table.insert(stringtable, formatStatus(j.mainid, j.data)) | |||
end | |||
local val = linguistic.conj(stringtable, "new line") .. wikidata.addTrackingCat('P1435') | |||
return wikidata.addLinkBack(val, item, 'P1435') | |||
return | |||
end | end | ||
return p | |||
Dernière version du 22 février 2026 à 00:17
La documentation pour ce module peut être créée à Module:Classement/doc
local p = {}
local formattingData = require "Module:Classement/Données" --libellés spéciaux et logos
local wikidata = require "Module:Wikidata"
local linguistic = require "Module:Linguistique"
local function groupStatements(statements) -- regroupe les statements avec même mainid
local newlist = {}
local indexbyid = {} --par mainid, indice où sont rangés les statements dans newlist
for i, j in pairs(statements) do
local mainid = wikidata.getMainId(j)
if not mainid then
-- pas d'id, c'est une "special value"
elseif not indexbyid[mainid] then
table.insert(newlist, {mainid = mainid, data = {j}})
indexbyid[mainid] = #newlist
else
table.insert(newlist[indexbyid[mainid]].data, j)
end
end
return newlist
end
local function formatMainStr(id) -- affiche le nom du statut du protection avec éventuellement un logo
local str, logo
if formattingData[id] then
str = formattingData[id][1]
logo = formattingData[id][2]
else
str = wikidata.formatEntity(id)
end
if logo then
str = '[[File:' .. logo .. '|x18px|alt=|link=]] ' .. str
end
return str
end
local function formatStatus(id, data)
local mainstr = formatMainStr(id) --
local details = {} -- informations complémentaires stockées dans les qualificatifs
for i, j in pairs(data) do
local pdate = wikidata.getFormattedQualifiers(j, {'P580'}, {precision = 'year'}) -- date de classement
local part = wikidata.getFormattedQualifiers(j, {'P518'}, {link = '-'}) -- partie protégée
local str = linguistic.conj({part, pdate}, ' en ')
table.insert(details, str)
end
details = linguistic.conj(details, 'comma')
details = linguistic.inparentheses(details)
if details then
return mainstr .. ' <small>' .. details .. '</small>'
end
return mainstr
end
function p.formattedList(item, params)
-- créé une liste des status patrimoniaux de l'élement
params = params or { entity = item }
params.excludespecial = true
params.property = 'P1435'
local claims = wikidata.getClaims(params)
if not claims then
return nil
end
local statuses = groupStatements(claims)
local stringtable = {} -- liste des chaînes à retourner
for i, j in pairs(statuses) do
table.insert(stringtable, formatStatus(j.mainid, j.data))
end
local val = linguistic.conj(stringtable, "new line") .. wikidata.addTrackingCat('P1435')
return wikidata.addLinkBack(val, item, 'P1435')
end
return p