Module:Tableau qualificateurs
Apparence
[voir] [modifier] [historique] [purger]
Module contenant le code de Modèle:Tableau qualificateurs.
La documentation de ce module est générée par le modèle {{Documentation module}}.
Elle est incluse depuis sa sous-page de documentation. Veuillez placer les catégories sur cette page-là.
Les éditeurs peuvent travailler dans le bac à sable (modifier).
Voir les statistiques d'appel depuis le wikicode sur l'outil wstat et les appels depuis d'autres modules.
local wikidata = require 'Module:Wikidata'
local recup = require 'Module:Wikidata/Récup'
local p = {}
function propertyLabel(propertyId, options)
local i = 0
while options[propertyId] ~= nil and i < 10 do
propertyId = options[propertyId]
i = i + 1
end
if string.match(propertyId, 'P%d+') then
return mw.wikibase.label(propertyId)
else
return propertyId
end
end
function claimsToArray(claims, options)
local headers = {}
local rows = {{}}
local newCol = 1
for i, claim in pairs(claims) do
rows[i + 1] = {}
property = propertyLabel(claim.mainsnak.property, options)
if headers[property] == nil then
headers[property] = newCol
newCol = newCol + 1
end
rows[i + 1][headers[property]] = wikidata.formatSnak(claim.mainsnak, {})
if claim.qualifiers ~= nil then
for _, qs in pairs(claim.qualifiers) do
for _, qualifier in pairs(qs) do
property = propertyLabel(qualifier.property, options)
if headers[property] == nil then
headers[property] = newCol
newCol = newCol + 1
end
if rows[i + 1][headers[property]] ~= nil then
rows[i + 1][headers[property]] = rows[i + 1][headers[property]] .. '<br />' .. wikidata.formatSnak(qualifier, {})
else
rows[i + 1][headers[property]] = wikidata.formatSnak(qualifier, {})
end
end
end
end
end
for property, i in pairs(headers) do
rows[1][i] = property
end
return rows
end
function formatArray(rows)
local str = '{| class="wikitable sortable"'
for i,row in pairs(rows) do
str = str .. '\n|-'
for j,_ in pairs(rows[1]) do
if row[j] == nil then
str = str .. '\n|'
else
if i == 1 or j == 1 then
str = str .. '\n!'
else
str = str .. '\n|'
end
str = str .. ' ' .. row[j]
end
end
end
return str .. '\n|}\n'
end
function p.tableau(frame)
local args = frame:getParent().args
local claims = recup.getClaims(args)
local rows = claimsToArray(claims, args)
return formatArray(rows)
end
return p