Modul:Wikibase

Ez a lap műszaki védett
A Wikipédiából, a szabad enciklopédiából

Wikibase[mi ez?] • [dokumentáció: mutat, szerkeszt] • [tesztek: létrehozás]

Segédfüggvények az mw.wikibase Scribunto-modulhoz.

require('strict')
local p = {}
local getArgs = require'Modul:Arguments'.getArgs

local function getIdIfNil(id)
	if id then
		return id
	else
		return mw.wikibase.getEntityIdForCurrentPage()
	end
end

-- Return the item ID of the item linked to the current page.
function p.id(frame)
	return mw.wikibase.getEntityIdForCurrentPage() or '(no item connected)'
end

-- Return the item ID of the item linked to the given page.
function p.idForPage(frame)
	return mw.wikibase.getEntityIdForTitle(frame.args[1], frame.args[2])
end

-- Return the label of a given data item.
function p.label(frame)
	local id = getIdIfNil(frame.args[1])
	if not id then
		return nil
	end
	return mw.wikibase.label(id)
end

-- Return the local page about a given data item.
function p.page(frame)
	local id = getIdIfNil(frame.args[1])
	if not id then
		return nil
	end
	return mw.wikibase.getSitelink(id)
end

function p.renderSnaks(frame)
	local entity = mw.wikibase.getEntity()
	local property = frame.args[1]
	if entity and entity.claims and entity.claims[property] and entity.claims[property][1].qualifiers then
		return mw.wikibase.renderSnaks(entity.claims[property][1].qualifiers)
	end
	return nil
end

function p.renderReference(frame)
	local entity = mw.wikibase.getEntity()
	local property = frame.args[1]
	local statementIndex = tonumber(frame.args[2]) or 1
	local referenceIndex = tonumber(frame.args[3]) or 1
	if entity and entity.claims and entity.claims[property] and entity.claims[property][statementIndex] and 
	entity.claims[property][statementIndex].references and entity.claims[property][statementIndex].references[referenceIndex] then
		return mw.wikibase.renderSnaks(entity.claims[property][statementIndex].references[referenceIndex].snaks)
	end
	return nil
end

-- Return the sitelink on globalSiteId wiki (connected to entityId entity)
-- Burkolósablonok: Projektlink
function p.sitelink(frame)
	local args = getArgs(frame)
	local globalSiteId = args.globalSiteId or args[1]
	local entityId = args.entityId or args[2]
	local entity = mw.wikibase.getEntity(entityId)
	return entity and entity:getSitelink(globalSiteId)
end

--[[
	Wd sablon megvalósítása
  ]]
function p.wd(frame)
	local ret = ''
	local args = getArgs(frame, { wrappers = 'Sablon:Wd', removeBlanks = false })
	local hibas = false
	if args[1] and mw.wikibase.isValidEntityId(args[1]) and mw.wikibase.entityExists(args[1]) then
		local title = mw.title.getCurrentTitle()
		local sitelink = mw.wikibase.getSitelink(args[1])
		if sitelink then
			ret = ret .. (title:inNamespace(0) and
				'[[Kategória:Lapok láthatatlanná vált wd sablonnal]]' or
				('[[Kategória:Lapok láthatatlanná vált wd sablonnal (kézi)|%s]]'):format(title.prefixedText))
		else
			ret = ret .. ([=[<span class="noprint"
				style="font-family:monospace; font-weight:bold; font-size:small; font-style:normal">[[d:%s#sitelinks-wikipedia|<span
				title="A magyar cikket még nem írták meg, de ide kattintva megtekinthető a témáról szóló Wikipédia-cikkek listája más
				nyelveken (új oldalon: CTRL + kattintás).">(wd)</span>]]</span>]=]):format(args[1])
			if not title:inNamespaces('Speciális', 'MediaWiki') then
				ret = ret .. '[[Kategória:Lefordítandó cikkekre való utalást tartalmazó lapok]]'
			end
		end
	else
		hibas = true
	end
	if args[2] then
		hibas = true
	end
	if hibas then
		ret = ret .. '<strong class="error">Hibásan használt Wd sablon</strong>[[Kategória:Hibásan használt Wd sablon]]'
	end
	return ret
end

return p