Module:Bases
Εμφάνιση
![Documentation icon](http://upload.wikimedia.org/wikipedia/commons/thumb/4/43/Test_Template_Info-Icon_-_Version_%282%29.svg/50px-Test_Template_Info-Icon_-_Version_%282%29.svg.png)
Μπορείτε να συμβάλλετε στη δημιουργία σελίδας τεκμηρίωσης για αυτό το Scribunto module. Οι συντάκτες μπορούν να πειραματίζονται στο πρόχειρο (δημιουργία | αντίγραφο) και στις δοκιμαστικές σελίδες (δημιουργία) του module. Παρακαλούμε να προσθέτετε τις κατηγορίες στην υποσελίδα τεκμηρίωσης. Υποσελίδες αυτού του module. |
local p = {}
local wikidata = require "Module:Wikidata"
function p.main(frame)
-- Récupération des paramètres, soit ceux passés par le modèle,
-- soit ceux passés au modèle
local id = frame.args.id
local name = frame.args.name
local headername = frame.args.headername
local noarchive= frame.args.noarchive
if frame.getParent then
id = frame:getParent().args.id or id
end
-- Chargement des données de la base souhaitée
local bases = require("Module:Bases/" .. name)
-- Récupération des propriétés wikidata de l'entité sélectionné
local entity = mw.wikibase.getEntityObject(id)
if not entity then
return "[[Catégorie:Page utilisant le modèle Bases " .. name .. " inactif]]"
end
-- Pour chaque base dans notre liste, on vérifie si notre entité la possède
-- si c'est le cas, on formate et ajoute un lien vers elle dans une liste
local vals = {}
for i, base in pairs(bases) do
local val = wikidata.formatStatements{entity = entity, text = base[1], property = base[2], urlpattern = base[3], numval = 1, addcat = true, qualifier = 'P407', qualifiervalue = 'Q150', value = frame:getParent().args[base[1]]} or wikidata.formatStatements{entity = entity, text = base[1], property = base[2], urlpattern = base[3], numval = 1, addcat = true, value = frame:getParent().args[base[1]]}
if val then
table.insert(vals, val)
end
end
-- On catégorise si l'entité ne possède aucune des bases listés
if #vals == 0 then
return "[[Catégorie:Page utilisant le modèle Bases " .. name .. " inactif]]"
end
-- Ajout du label si l'id wikidata a été précisé manuellement
local entityInfo = ''
if id and entity then --Has "entity" parameter, Wikidata item was found
local label = entity:getLabel()
if label then
entityInfo = ' (pour [[' .. label .. ']])'
end
end
-- Concaténation des liens et formatage final
local header = ''
if #vals > 1 then
header = "Πηγές σχετιζόμενες " .. headername .. entityInfo .. " : "
else
header = "Πηγή σχετιζόμενη " .. headername .. entityInfo .. " : "
end
local footer = ''
-- Ajout de la class noarchive
if noarchive then
header = header .. "<span class=\"noarchive\">"
footer = "</span>"
end
-- Ajout des catégories qui vont bien
local categories = "[[Catégorie:Page pointant vers des bases externes]] [[Catégorie:Page pointant vers des bases relatives " .. headername .. "]]"
return wikidata.addLinkBack(header .. table.concat( vals, ' • ' ) .. footer , entity, "identifiers" ) .. categories -- lien vers la section approriété de Wikidata
end
return p