local p = {}
local wd = require("Module:Wikidata")
-- دالة مساعدة: ترجمة QID لتسمية
local function getLabel(id)
if not id then return nil end
local entity = mw.wikibase.getEntity(id)
if entity and entity.labels then
return entity.labels["arz"] and entity.labels["arz"].value
or entity.labels["ar"] and entity.labels["ar"].value
or entity.labels["en"] and entity.labels["en"].value
end
return nil
end
-- دالة تجيب كل القيم من خاصية معينة (زي P31, P279...)
local function getPropertyValues(qid, prop)
local vals = {}
local entity = mw.wikibase.getEntity(qid)
if entity and entity.claims and entity.claims[prop] then
for _, claim in pairs(entity.claims[prop]) do
if claim.mainsnak and claim.mainsnak.datavalue then
local id = claim.mainsnak.datavalue.value.id
table.insert(vals, id)
end
end
end
return vals
end
-- الدالة الرئيسية
function p.getCategories(frame)
local args = frame.args
local qid = args.qid or mw.wikibase.getEntityIdForCurrentPage()
if not qid then return "" end
local cats = {}
local props = {"P31", "P279", "P171"} -- الخواص اللي هندور فيها
for _, prop in ipairs(props) do
local vals = getPropertyValues(qid, prop)
for _, v in ipairs(vals) do
local label = getLabel(v)
if label then
table.insert(cats, "")
end
end
end
if #cats > 0 then
return table.concat(cats, "\n")
end
return ""
end
return p
|