Modul:Wikibase

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'.getArgslocal function getIdIfNil(id)if id thenreturn idelsereturn mw.wikibase.getEntityIdForCurrentPage()endend-- 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 thenreturn nilendreturn 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 thenreturn nilendreturn mw.wikibase.getSitelink(id)endfunction 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 thenreturn mw.wikibase.renderSnaks(entity.claims[property][1].qualifiers)endreturn nilendfunction p.renderReference(frame)local entity = mw.wikibase.getEntity()local property = frame.args[1]local statementIndex = tonumber(frame.args[2]) or 1local referenceIndex = tonumber(frame.args[3]) or 1if 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] thenreturn mw.wikibase.renderSnaks(entity.claims[property][statementIndex].references[referenceIndex].snaks)endreturn nilend-- Return the sitelink on globalSiteId wiki (connected to entityId entity)-- Burkolósablonok: Projektlinkfunction 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 = falseif args[1] and mw.wikibase.isValidEntityId(args[1]) and mw.wikibase.entityExists(args[1]) thenlocal title = mw.title.getCurrentTitle()local sitelink = mw.wikibase.getSitelink(args[1])if sitelink thenret = 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))elseret = ret .. ([=[<span class="noprint"style="font-family:monospace; font-weight:bold; font-size:small; font-style:normal">[[d:%s#sitelinks-wikipedia|<spantitle="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ásnyelveken (új oldalon: CTRL + kattintás).">(wd)</span>]]</span>]=]):format(args[1])if not title:inNamespaces('Speciális', 'MediaWiki') thenret = ret .. '[[Kategória:Lefordítandó cikkekre való utalást tartalmazó lapok]]'endendelsehibas = trueendif args[2] thenhibas = trueendif hibas thenret = ret .. '<strong class="error">Hibásan használt Wd sablon</strong>[[Kategória:Hibásan használt Wd sablon]]'endreturn retendreturn p