Modul:Qnr
Spring til navigation
Spring til søgning
local p = {}
-- Get the Wikidata entity name for:
-- - With no arguments:
-- The item connected to the current page
-- - With one unnamed argument (title):
-- The item connected to the page with the given title on this wiki
-- - With two unnamed arguments (title and language code):
-- The item connected to the page with the given title on the Wikipedia with the given language code
-- If no entity is found, and the given title is already in form of an entity name (like Q12345), it will be returned unchanged. Otherwise nothing will be returned, if no entity is found.
function p.qnr (frame)
local page = mw.text.trim(frame.args[1] or '')
if page == '' then
return mw.wikibase.getEntityIdForCurrentPage()
end
local wiki = mw.text.trim(frame.args[2] or '')
local item
if wiki == '' then
item = mw.wikibase.getEntityIdForTitle(page)
else
item = mw.wikibase.getEntityIdForTitle(page, wiki .. 'wiki')
end
if item then
return item
end
return string.find(page, '^Q%d+$') and page
end
return p