Module:Classement : Différence entre versions
m (faute de frappe) |
m |
||
(3 révisions intermédiaires par 2 utilisateurs non affichées) | |||
Ligne 1 : | Ligne 1 : | ||
local p = {} | local p = {} | ||
− | local formattingdata = | + | local formattingdata = require "Module:Classement/Données" --libellés spéciaux et logos |
− | local wikidata = require | + | local wikidata = require "Module:Interface Wikidata".fromLua |
− | local linguistic = require | + | local linguistic = require "Module:Linguistique" |
− | local function groupstatements(statements) -- regroupe les statements avec même mainid | + | local function groupstatements(statements) -- regroupe les statements avec même mainid |
local newlist = {} | local newlist = {} | ||
− | for i, j in pairs(statements) do -- si cet id est déjà utilisé par un autre élément, | + | for i, j in pairs(statements) do -- si cet id est déjà utilisé par un autre élément, à déplacer vers un module + général ? |
local mainid = wikidata.getmainid(j) | local mainid = wikidata.getmainid(j) | ||
if not mainid then | if not mainid then | ||
Ligne 28 : | Ligne 28 : | ||
end | end | ||
if logo then | if logo then | ||
− | str = '[[File:' .. logo .. '|x18px]] ' .. str | + | str = '[[File:' .. logo .. '|x18px|alt=|link=]] ' .. str |
end | end | ||
return str | return str | ||
Ligne 52 : | Ligne 52 : | ||
function p.formattedList(item) | function p.formattedList(item) | ||
-- créé une liste des status patrimoniaux de l'élement | -- créé une liste des status patrimoniaux de l'élement | ||
− | local claims = wikidata.getClaims({entity = item, property = 'P1435', | + | local claims = wikidata.getClaims({entity = item, property = 'P1435', excludespecial = true}) |
if not claims then | if not claims then | ||
return nil | return nil | ||
Ligne 63 : | Ligne 63 : | ||
end | end | ||
− | local val = | + | local val = linguistic.conj(stringtable, "new line") .. wikidata.addtrackingcat('P1435') |
return wikidata.addLinkback(val, item, 'P1435') | return wikidata.addLinkback(val, item, 'P1435') | ||
end | end | ||
return p | return p |
Version actuelle datée du 20 mars 2016 à 22:34
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:Interface Wikidata".fromLua local linguistic = require "Module:Linguistique" local function groupstatements(statements) -- regroupe les statements avec même mainid local newlist = {} for i, j in pairs(statements) do -- si cet id est déjà utilisé par un autre élément, à déplacer vers un module + général ? local mainid = wikidata.getmainid(j) if not mainid then -- pas d'id, c'est une "special value" elseif not newlist[mainid] then newlist[mainid] = {j} else table.insert(newlist[mainid], 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) -- créé une liste des status patrimoniaux de l'élement local claims = wikidata.getClaims({entity = item, property = 'P1435', excludespecial = true}) if not claims then return nil end local statuses = groupstatements(claims) local stringtable = {} -- liste des chaînes à retourner for id, data in pairs(statuses) do table.insert(stringtable, formatstatus(id, data)) end local val = linguistic.conj(stringtable, "new line") .. wikidata.addtrackingcat('P1435') return wikidata.addLinkback(val, item, 'P1435') end return p