İçeriğe atla

Modul:WikidataClassHierarchy

QIRIMTATAR VİKİPEDİYASINIÑ MALÜMATI

Bu modül için bir Modul:WikidataClassHierarchy/belge belgelendirmesi oluşturabilirsiniz

local p = {}
local getArgs = require('Modul:Arguments').getArgs
-- local illWd = require('Modul:Ill-wd').fromArgs
local Wikidata = require('Modul:Wikidata')
local StringUtils = require('Modul:StringUtils')

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 = p.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, Wikidata.formatEntityIdFromFrame({}, classes[classIdx], {}))--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 == 'iyerarhik cedveli') or (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 == 'yalpaq cedvel') or (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.findBestClaimsForProperty(entity, propertyId)
	-- [[ro:Modul:Wikidata]]-dan kopiyalandı (bu modulni yoq etmek içün)
	if propertyId == nil then return nil end
	if entity == nil then entity = mw.wikibase.getEntityIdForCurrentPage() end
	if type(entity) == 'table' then return entity:getBestStatements(propertyId) end
	if type(entity) == 'number' then entity = StringUtils._prependIfMissing({tostring(entity), 'Q'}) end
	if entity == nil then return nil end
	return mw.wikibase.getBestStatements(entity, propertyId)
end


function p.fromArray(args)
	return p.fromArgs(args.qid, args['sıñırlağan id'] or args['id_limită'] or args.limitqid, args['üslüp'] or args.styling or args.stil)
end

function p.fromFrame(frame)
	local args = getArgs(frame)
	return p.fromArray(args)
end
return p;