Modul:WikidataClassHierarchy
Körüniş
Documentation for this module may be created at Modul:WikidataClassHierarchy/doc
local p = {}
local Wikidata = require('Modul:Wikidata-ro')
local getArgs = require('Modul:Arguments').getArgs
local illWd = require('Modul:Ill-wd').fromArgs
function p.getClassIdsList(qid, limitQid)
local crtQid = qid or mw.wikibase.getEntityIdForCurrentPage()
local entities = {}
while (crtQid and crtQid ~= limitQid) do
table.insert(entities, crtQid)
local subclassOfClaims = Wikidata.findBestClaimsForProperty(crtQid, 'P279')
if not subclassOfClaims or #subclassOfClaims == 0 then
crtQid = nil
else
for _,eachClaim in ipairs(subclassOfClaims) do
if eachClaim.type == 'statement' and eachClaim.mainsnak and eachClaim.mainsnak.snaktype == 'value' then
crtQid = eachClaim.mainsnak.datavalue.value.id
break
end
end
end
end
return entities
end
function p.fromArgs(qid, limitqid, styling)
local classes = p.getClassIdsList(qid, limitqid)
local classesLinks = {}
local classIdx = #classes
while classIdx > 0 do
table.insert(classesLinks, illWd(classes[classIdx]))
classIdx = classIdx - 1
end
if #classesLinks == 0 then return '' end
if styling == 'br' then
return table.concat(classesLinks, tostring(mw.html.create('br')))
elseif styling == 'listă-ierarhică' then
local topElement = mw.html.create('div'):css('margin-left', '15px')
topElement:wikitext(classesLinks[1])
local crtElement = topElement
for classLinkIdx=2,#classesLinks do
crtElement = crtElement:tag('ul'):css('line-height', '100%'):css('margin-left', '5px')
:tag('li')
crtElement:wikitext(classesLinks[classLinkIdx])
end
return tostring(topElement)
elseif styling == 'listă' then
local listElement = mw.html.create('ul')
for _,eachClass in ipairs(classesLinks) do
listElement:tag('li'):wikitext(eachClass)
end
return tostring(listElement)
end
end
function p.fromArray(args)
return p.fromArgs(args.qid, args['id_limită'] or args.limitqid, args.styling or args.stil)
end
function p.fromFrame(frame)
local args = getArgs(frame)
return p.fromArray(args)
end
return p;