« Module:Classement » : différence entre les versions

De Lagny-sur-Marne Wiki
Aller à la navigation Aller à la recherche
0x010D (discussion | contributions)
Aucun résumé des modifications
0x010D (discussion | contributions)
Aucun résumé des modifications
Ligne 15 : Ligne 15 :
for i, j in pairs(claims) do
for i, j in pairs(claims) do
local pstatus = wikidata.getmainid(j)
local pstatus = wikidata.getmainid(j)
if not statuses[pstatus] then  
if not pstatus then
-- pas d'id, c'est une "special value"
elseif not statuses[pstatus] then  
statuses[pstatus] = {j}
statuses[pstatus] = {j}
else
else

Version du 25 mars 2015 à 11:15

local p = {} local formattingdata = mw.loadData('Module:Classement/Données') local wikidata = require('Module:Wikidata')

function p.formattedList(item) -- créé une liste des status patrimoniaux de l'élement --utilise Module:Classement/Données pour les abréviations, redirects et logos

local claims = wikidata.getClaims({entity = item, property = 'P1435', exludespecial = true}) if not claims then return nil end

local statuses = {}-- nouvelle table pour ne pas afficher séparément deux statements décrivant le même statut for i, j in pairs(claims) do local pstatus = wikidata.getmainid(j) if not pstatus then -- pas d'id, c'est une "special value" elseif not statuses[pstatus] then statuses[pstatus] = {j} else table.insert(statuses[pstatus], j) end end

local stringtable = {} -- liste des chaînes à retourner for i, j in pairs(statuses) do local mainstr = if formattingdata[i] then mainstr = formattingdata[i][1] else mainstr = wikidata.formatEntity(i) end local logostr = if formattingdata[i] and formattingdata[i][2] then logostr = '[[File:' .. formattingdata[i][2] .. '|x18px]] ' end

local t = {} -- informations complémentaires sur les dates et les parties concernées for k, l in pairs(j) do local protectiondate = wikidata.getFormattedQualifiers(l, {'P580'}, {precision = 'year'}) if protectiondate then table.insert(t, protectiondate) end end local details = table.concat(t, ", ") if details ~= then details = ' (' .. details .. ')' else details = end table.insert(stringtable, logostr .. mainstr .. details) end local val = table.concat(stringtable, '
') .. wikidata.addtrackingcat('P1435') return wikidata.addLinkback(val, item, 'P1435') end return p