Modul:Cite

Från Wikipedia

Dokumentation [visa] [redigera] [historik] [rensa sidcachen]


--/-- Creates a timeline for an item based on various properties
local propsamling = {"P50" ,"P123", "P143", "P304", "P212", "P957", "P854", "P478", "P98", "P393", "P1476", "P577", "P248", "P433", "P275", "P698", "P356", "P958", "P1433", "P1680", 'P1683', 'P518', "P1552", "P3452", "P3865", "P973"}

local p = {}
local olampliga = {'Q11032', -- tidning
					'Q1110794', -- dagstidning
					'Q1002697', -- periodisk litteratur
					'Q2016362'} -- morgontidning
				
local wikidata = require('Modul:Wikidata2').formatStatementsFromLua
local wikidata2 = require('Modul:Wikidata2').formatEntityId

local function itemcheck(items)
	if items then
		for i, item in pairs(items) do
			local typer = wikidata({entityId = item, property = 'P31', noref = 'true', raw = 'true'})
			if typer then
				for j, typ in pairs(typer) do
					for k, olamplig in pairs(olampliga) do
						if typ.item == olamplig then
							return '[[Kategori:Sidor med mindre lämplig användning av P248]]'
						end
					end
				end
			end
		end
	end
end

local function helpednumber(items, property)
	for i, item in pairs(items) do
		local ednumber = wikidata({entityId = item, property = property, enbarten = 'yes', noref = 'true'})
		if ednumber then 
			return ednumber 
		end
	end
end

local function getPage(items, refsnak)
	local page = wikidata({property = 'P304', enbarten = 'true'}, refsnak)
	if not page then
		page = helpednumber(items, "P304")
	end
	if page then
		return 's. ' .. page
	end
end


local function getarticle(items, refsnak)
	local s = {}
	for i, item in pairs(items) do
		local s2 = wikidata({entityId = item, property = 'P958', noref = 'true'})
		if s2 then table.insert(s, '”' .. s2 .. '”') end
	end
	local s3 = wikidata({property = 'P958'}, refsnak)
	if s3 then table.insert(s, '”' .. s3 .. '”') end

	return table.concat(s, ', ')
end


local function getquote(items, refsnak)
	local s = {}
	for i, item in pairs(items) do
		local s2 = wikidata({entityId = item, property = 'P1683', noref = 'true'})
		if s2 then table.insert(s, '”' .. s2 .. '”') end
	end
	local s3 = wikidata({property = 'P1683'}, refsnak)
	if s3 then table.insert(s, '”' .. s3 .. '”') end

	return table.concat(s, ', ')
end

local function getauthor(items, refsnak)
	local s = {}
	for i, item in pairs(items) do
		if item ~= 'Q36578' then
			table.insert(s, wikidata({entityId = item, property = 'P50', noref = 'true', conjunction = ' & ', novalue = ''}))
		end
	end
	table.insert(s, wikidata({property = 'P50', conjunction = ' & ', novalue = ''}, refsnak))
	return table.concat(s, ', ')
end

local function getappliestopart(items, refsnak)
	local s = {}
	for i, item in pairs(items) do
		table.insert(s, wikidata({entityId = item, property = 'P518', noref = 'true'}))
	end
	table.insert(s, wikidata({property = 'P518'}, refsnak))
	return table.concat(s, ', ')
end

local function getISBN(items, refsnak)
	local ISBN = nil
	for i, item in pairs(items) do
		ISBN = wikidata({entityId = item, property = 'P212', enbarten = 'yes', noref = 'true'}) --ISBN 13
		if ISBN then return mw.getCurrentFrame():preprocess('{{ISBN|' .. ISBN .. '}}') end
	end
	ISBN = wikidata({property = 'P212', enbarten = 'true'}, refsnak)
	if ISBN then return mw.getCurrentFrame():preprocess('{{ISBN|' .. ISBN .. '}}') end 
	for i, item in pairs(items) do
		ISBN = wikidata({entityId = item, property = 'P957', enbarten = 'yes', noref = 'true'}) --ISBN 10
		if ISBN  then return mw.getCurrentFrame():preprocess('{{ISBN|' .. ISBN .. '}}') end
	end
	ISBN = wikidata({property = 'P957', enbarten = 'true'}, refsnak)
	if ISBN  then return mw.getCurrentFrame():preprocess('{{ISBN|' .. ISBN .. '}}') end
	return nil
end

local function getLink(items, refsnak )
	local links = {}
	for i, item in pairs(items) do
		local p854 = wikidata({entityId = item, property = 'P854', label = 'läs online', noref = 'true'}) or wikidata({entityId = item, property = 'P953', label = 'läs online', noref = 'true'}) or wikidata({entityId = item, property = 'P973', label = 'läs online', noref = 'true'})
		table.insert(links, p854)
	end
	table.insert(links, wikidata({property = 'P854', label = 'läs online'}, refsnak))
	return table.concat(links)
end

local function getHamtdatum(items, refsnak )
	local hamtdatum = {}
	for i, item in pairs(items) do
		table.insert(hamtdatum, wikidata({entityId = item, property = 'P813', noref = 'true', modifytime = 'longdate' }))
	end
	table.insert(hamtdatum, wikidata({property = 'P813', modifytime = 'longdate'}, refsnak))
	local tot =  table.concat(hamtdatum)
	if tot and tot ~= '' then
		return 'läst: ' .. tot
	end
end

local function getVolume(items, refsnak )
	local page = wikidata({property = 'P478', enbarten = 'true'}, refsnak) or helpednumber(items, "P478")
	if page then
		return 'vol. ' .. page
	end
end

local function getMost(items, refsnak, property )
	local B = {wikidata({property = property, enbarten = 'true', pattern = 'auktoritetsdata2'}, refsnak)}	
	for i, item in pairs(items) do
		table.insert(B, wikidata({entityId = item, property = property, pattern = 'auktoritetsdata2', noref = 'true'}))
		--TODO: detta verkar skriva sönder pattern för huvudmodulen Wikidata2
	end
	if #B > 0 then
		local res = ''
		res = table.concat(B)
		if property == 'P1810' then  -- normalisera stil för namn så att endast förstabokstaven är versal
			for k in  string.gmatch(res, '[A-ZÅÄÖ][A-ZÅÄÖ]+') do
				res = res:gsub(k,string.sub(k,1,1)..string.lower(string.sub(k,2)):gsub('Å','å'):gsub('Ä','ä'):gsub('Ö','ö'))
			end
		end
		return res
	end
end

local function getEditor(items, refsnak )
	local s = {}
	for i, item in pairs(items) do
		table.insert(s, wikidata({entityId = item, property = 'P98', noref = 'true', conjunction = ' & '}))
	end
	table.insert(s, wikidata({property = 'P98', conjunction = ' & '}, refsnak))
	local tot = table.concat(s, ', ')
	if tot and tot ~= '' then
		return tot .. ' (red.)'
	end
end

local function getedition(items, refsnak )
	local ordning = {'första', 'andra', 'tredje', 'fjärde', 'femte', 'sjätte', 'sjunde', 'åttonde', 'nionde', 'tionde', '11:e', '12:e'}
	local ednumber = wikidata({property = 'P393', enbarten = 'true'}, refsnak)
	if not ednumber then
		ednumber = helpednumber(items, "P393")
	end
	
	if not ednumber then 
		return nil
	end
	if not tonumber(ednumber) then
		return ednumber .. ' utgåvan'
	end
	if ordning[tonumber(ednumber)] then
		return ordning[tonumber(ednumber)] .. ' utgåvan'
	end
	local sist = string.sub(ednumber, string.len(ednumber))
	if sist == '1' or sist == '2' then
		return ednumber .. ':a utgåvan'
	else
		return ednumber .. ':e utgåvan'
	end
	
end

local function getsubtitle(items, refsnak)-- needs i18n some languages do not use this format
	local s = {}
	table.insert(s, wikidata({property = 'P1680', enbarten = 'true'}, refsnak))
	for i, item in pairs( items ) do
		local lab = wikidata({property = 'P1680', entityId = item, enbarten = 'true', noref = 'true'})
		local sitelink = mw.wikibase.sitelink( item )
		if sitelink and lab then
			table.insert(s, '[[:' .. sitelink .. '|' .. lab .. ']]')
		elseif lab then
			table.insert(s, lab)
		end
	end
	tot = table.concat(s, ', ')
	if tot and tot ~= '' then
		return tot
	else
		return nil
	end
end


local function gettitle(items, refsnak)-- needs i18n some languages do not use this format
	local subtitle = getsubtitle(items, refsnak)
	local s = {}
	local titel = wikidata({property = 'P1476', enbarten = 'true', noref = 'true'}, refsnak) or wikidata({property = 'P357', enbarten = 'true'}, refsnak)
	if titel then
		local link = wikidata({property='P854', enbarten = 'true'}, refsnak)
		if link then
			table.insert(s, '[' .. link .. ' ' .. titel .. ']')
		else
			table.insert(s, titel)
		end
	end
	local language = nil
	local sprakparentes = ''
	if refsnak["P1476"] and refsnak["P1476"][1].datavalue.value.language then
		language = refsnak["P1476"][1].datavalue.value.language
		if language and language ~= 'sv' and language ~= 'und' then
			sprakparentes = ' (på ' .. mw.language.fetchLanguageName(language, 'sv') .. ')'
		end
	end
	for i, item in pairs( items ) do
		local lab = wikidata({property = 'P1476', entityId = item, enbarten = 'true', noref = 'true'}) or wikidata({property = 'P357', entityId = item, enbarten = 'true', noref = 'true'})
		if not lab then 
			lab = wikidata2(item, {nolink = 'true', noref = 'true'}).value
		end
		local sitelink = mw.wikibase.sitelink( item )
		if sitelink then
			table.insert(s, '[[:' .. sitelink .. '|' .. lab .. ']]')
		elseif mw.wikibase.getSitelink(item, 'svwikisource') then
			table.insert(s, '[[:src:' .. mw.wikibase.getSitelink(item, 'svwikisource') .. '|' .. lab .. ']]')
		elseif mw.wikibase.getSitelink(item, 'enwikisource') then
			table.insert(s, '[[:src:en:' .. mw.wikibase.getSitelink(item, 'enwikisource') .. '|' .. lab .. ']]')
		elseif mw.wikibase.getSitelink(item, 'dewikisource') then
			table.insert(s, '[[:src:de:' .. mw.wikibase.getSitelink(item, 'dewikisource') .. '|' .. lab .. ']]')
		elseif mw.wikibase.getSitelink(item, 'ruwikisource') then
			table.insert(s, '[[:src:ru:' .. mw.wikibase.getSitelink(item, 'ruwikisource') .. '|' .. lab .. ']]')
		else			
			table.insert(s, lab)
		end
	end
	tot = table.concat(s, ', ')
	if tot and tot ~= '' then
		if subtitle and subtitle ~= '' then
			return '<i>' .. tot .. ' : ' .. subtitle .. '</i>'
		else
			return '<i>' .. tot .. '</i>' .. sprakparentes
		end
	else
		return nil
	end
end

local function getissue(items, refsnak)
	local issue = wikidata({property = 'P433', enbarten = 'true'}, refsnak)
	if not issue then
		issue = helpednumber(items, "P433")
	end
	if issue then
		return issue
	end
end

local function getpublisher(items, refsnak )
	local s = {}
	for i, item in pairs(items) do
		table.insert(s, wikidata({entityId = item, property = 'P123', noref = 'true'}))
	end
	table.insert(s, wikidata({property = 'P123'}, refsnak))
	local tot = table.concat(s, ', ')
	if tot and tot ~= '' then
		return tot
	end
end

local function getpublishedin(items, refsnak )
	local s = {}
	for i, item in pairs(items) do
		table.insert(s, wikidata({entityId = item, property = 'P1433', noref = 'true'}))
	end
	table.insert(s, wikidata({property = 'P1433'}, refsnak))
	local tot = table.concat(s, ', ')
	if tot and tot ~= '' then
		return tot
	end
end

local function getPublishdate(items, refsnak )
	local publishdate = {}
	for i, item in pairs(items) do
		table.insert(publishdate, wikidata({entityId = item, property = 'P577', noref = 'true', modifytime = 'longdate' }))
	end
	table.insert(publishdate, wikidata({property = 'P577', modifytime = 'longdate'}, refsnak))
	local tot =  table.concat(publishdate)
	if tot and tot ~= '' then
		return tot
	end
end

local function getreftype(items, refsnak )
	local s = {}
	for i, item in pairs(items) do
		table.insert(s, wikidata({entityId = item, property = 'P3865', noref = 'true'}))
	end
	table.insert(s, wikidata({property = 'P3865'}, refsnak))
	local tot = table.concat(s, ', ')
	if tot and tot ~= '' then
		return tot
	end
end

local function getharegenskap(items, refsnak )
	local s = {}
	table.insert(s, wikidata({property = 'P1552'}, refsnak))
	local tot = table.concat(s, ', ')
	if tot and tot ~= '' then
		return tot
	end
end

local function getwhatever(items, refsnak, property)
	local a = wikidata({property = 'P1629', entityId = property, enbarten = 'true', noref = 'true', label = wikidata2(property, {nolink = 'true', noref = 'true'}).value}) 
	if property == "P143" then a = '[[Kategori:Artiklar med importerade Wikidatavärden]]hämtat från' end
	if property == "P3452" then a = '[[Kategori:Artiklar med härledda Wikidatavärden]]härlett från' end
	local s = {}
	for i, item in pairs(items) do
		table.insert(s, wikidata({entityId = item, property = property, noref = 'true', conjunction = ', '}))
	end
	table.insert(s, wikidata({property = property, conjunction = ', '}, refsnak))
	if #s > 0 then
		return a .. ': ' .. table.concat(s, ', ')
	end
end

local function gettherest(items, refsnak)
	local s = {}
	for i, j in pairs(refsnak) do
		finns = false
		for k, l in pairs(propsamling) do
			if i == l then 
				finns = true
			end
		end
		if not finns then
			local entity = mw.wikibase.getEntityObject( i )
			if ( entity.datatype == 'string' or entity.datatype == 'external-id' ) and entity.claims and entity.claims.P1629 then
				table.insert(s, getMost(items, refsnak, i))
			end
		end
	end
	if #s > 0 then
		return table.concat(s,', ')
	end
end

local function citebook(item, lang, page)
	local publishdate = getpublishdate(item )
	local author = getauthor(item )
	local editor = getEditor(item )
	local title = getbooktitle(item )
	local publisher = getpublisher(item )
	local publishedin = getpublishedin(item )
	local edition = getedition(item )
	local reftype = getreftype(item )
	local haregenskap = getharegenskap(item )
	local isbn = getISBN(item )
	local doi = getDoi(item )
	local pmid = getPmid(item )
	local link = getLink(item )
	local volume = getVolume(item )
	local pagenumber = formatpage(page, lang)
	local license = getlicense(item )

	local fields = {}
	table.insert(fields, author)
	table.insert(fields, editor)
	table.insert(fields, title)
	table.insert(fields, edition)
	table.insert(fields, volume)
	table.insert(fields, publisher)
	table.insert(fields, publishedin)
	table.insert(fields, publishdate)
	table.insert(fields, pagenumber)
	table.insert(fields, reftype)
	table.insert(fields, haregenskap)
	table.insert(fields, isbn)
	table.insert(fields, doi)
	table.insert(fields, pmid)
	table.insert(fields, link)
	table.insert(fields, license)
	return linguistic.conj(fields, lang, "comma")
end

local function citearticle(item, lang, page)

	local fields = {}
	table.insert(fields, author)
	table.insert(fields, title)
	table.insert(fields, publisher)
	table.insert(fields, publishedin)
	table.insert(fields, journal)
	table.insert(fields, volume)
	table.insert(fields, issue)
	table.insert(fields, publishdate)
	table.insert(fields, pagenumber)
	table.insert(fields, reftype)
	table.insert(fields, haregenskap)
	table.insert(fields, doi)
	table.insert(fields, pmid)
	table.insert(fields, link)
	table.insert(fields, license)
	return linguistic.conj(fields, lang, "comma")
end

function p.citeitem(items, refsnak, options)
	if not items and not refsnak then return nil end
	if type(items) == 'string' then
		items = {items}
	end

	local author = getauthor(items, refsnak )
	local appliestopart = getappliestopart(items, refsnak)
	local editor = getEditor(items, refsnak )
	local article = getarticle(items, refsnak )
	local title = gettitle(items, refsnak )
	local publisher = getpublisher(items, refsnak )
	local publishedin = getpublishedin(items, refsnak )
	local publishdate = getPublishdate(items, refsnak )
	local edition = getedition(items, refsnak )
	local issue = getissue(items, refsnak )
	local page = getPage(items, refsnak )
	local reftype = getreftype(items, refsnak )
	local haregenskap = getharegenskap(items, refsnak )
	local isbn = getISBN(items, refsnak )
	local doi = getMost(items, refsnak, "P356" )
	local pmid = getMost(items, refsnak, "P698" )
	local import = getwhatever(items, refsnak, "P143" )
	local harledd = getwhatever(items, refsnak, "P3452" )
	local link = getLink(items, refsnak )
	local hamtdatum = getHamtdatum(items, refsnak )
	local volume = getVolume(items, refsnak )
	local license = getwhatever(items, refsnak, "P275" )
	local therest = gettherest(items, refsnak)
	local citatet = getquote(items, refsnak)
	local checket = itemcheck(items)
	if title and title ~= '' and subtitle and subtitle ~= '' then 
		--title = title .. ' : ' .. subtitle
	end

	local field = {}
	local barap854 = false -- Flagga för att se om "bara" P854 används i källan
	if import and import ~= '' then table.insert(field, import) end
	if harledd and harledd ~= '' then table.insert(field, harledd) end
	if author and author ~= '' then table.insert(field, author) end
	if editor and editor ~= '' then table.insert(field, editor) end
	if article and article ~= '' then table.insert(field, article) end
	if title and title ~= '' then table.insert(field, title) end
	if edition and edition ~= '' then table.insert(field, edition) end
	if volume and volume ~= '' then table.insert(field, volume) end
	if issue and issue ~= '' then table.insert(field, issue) end
	if publisher and publisher ~= '' then table.insert(field, publisher) end
	if publishedin and publishedin ~= '' then table.insert(field, publishedin) end
	if publishdate and publishdate ~= '' then table.insert(field, publishdate) end
	if appliestopart and appliestopart ~= '' then table.insert(field, appliestopart) end
	if reftype and reftype ~= '' then table.insert(field, reftype) end
	if page and page ~= '' then table.insert(field, page) end
	if isbn and isbn ~= '' then table.insert(field, isbn) end
	if doi and doi ~= '' then table.insert(field, doi) end
	if pmid and pmid ~= '' then table.insert(field, pmid) end
	if therest and therest ~= '' then table.insert(field, therest) end
	if haregenskap and haregenskap ~= '' then table.insert(field, haregenskap) end
	if link and link ~= '' then 
		if #field < 1 then
			barap854 = true
		end
		if not title or title == '' or link then
			table.insert(field, link)
		end
	end
	if barap854 then 
		toppdoman = string.match(link,'(%.[a-z]+)[/ ]')
		doman = string.match(link,'([%a%d%-%.]*%.[a-z]+)\:?[0-9]*[/ ]')
		if string.match(link, "nytimes.com/") then
			table.insert(field, '<i>The New York Times</i>[[Kategori:Länkkällor utan metadata: nytimes.com]]')
		elseif string.match(link, "grav") then
			table.insert(field, '<i>' .. string.gsub(doman,'%[https?://','') .. '</i>[[Kategori:Länkkällor utan metadata: grav]]')
		elseif string.match(link, ".imdb.com/") then
			table.insert(field, '<i>Internet Movie Database</i>[[Kategori:Länkkällor utan metadata: imdb.com]]')
		elseif string.match(link, ".runeberg.org/") then
			table.insert(field, '<i>Projekt Runeberg</i>[[Kategori:Länkkällor utan metadata: runeberg.org]]')
		elseif string.match(link, ".riksarkivet.se/") then
			table.insert(field, '<i>' .. doman .. '</i>[[Kategori:Länkkällor utan metadata: riksarkivet.se]]')
		elseif string.match(link, ".theguardian.com/") then
			table.insert(field, '<i>The Guardian</i>[[Kategori:Länkkällor utan metadata: theguardian.com]]')
		elseif string.match(link, ".washingtonpost.com/") then
			table.insert(field, '<i>The Washington Post</i>[[Kategori:Länkkällor utan metadata: washingtonpost.com]]')
		elseif string.match(link, ".latimes.com/") then
			table.insert(field, '<i>The Los Angeles Times</i>[[Kategori:Länkkällor utan metadata: latimes.com]]')
		elseif string.match(link, ".jstor.org/") then
			table.insert(field, '<i>JSTOR</i>[[Kategori:Länkkällor utan metadata: jstor.org]]')
		elseif string.match(link, ".tandfonline.com/") then
			table.insert(field, '<i>Taylor & Francis</i>[[Kategori:Länkkällor utan metadata: tandfonline.com]]')
		elseif string.match(link, ".wiley.com/") then
			table.insert(field, '<i>Wiley</i>[[Kategori:Länkkällor utan metadata: wiley.com]]')
		elseif string.match(link, ".springer.com/") then
			table.insert(field, '<i>Springer</i>[[Kategori:Länkkällor utan metadata: springer.com]]')
		elseif string.match(link, ".britannica.com/") then
			table.insert(field, '<i>Encyclopædia Britannica</i>[[Kategori:Länkkällor utan metadata: britannica.com]]')
		elseif string.match(link, ".nature.com/") then
			table.insert(field, '<i>Nature</i>[[Kategori:Länkkällor utan metadata: nature.com]]')
		elseif string.match(link, ".nobelprize.org/") then
			table.insert(field, '<i>Nobelprize.org</i>[[Kategori:Länkkällor utan metadata: nobelprize.org]]')
		elseif string.match(link, ".kb.se") then
			table.insert(field, '<i>' .. doman .. '</i>[[Kategori:Länkkällor utan metadata: kb.se]]')
		elseif string.match(link, ".bbc.co") then
			table.insert(field, '<i>BBC</i>[[Kategori:Länkkällor utan metadata: bbc.co]]')
		elseif string.match(link, "wiki") then
			table.insert(field, '<i>' .. doman .. '</i>[[Kategori:Länkkällor utan metadata: wiki]]')
		elseif string.match(link, ".facebook.com/") then
			table.insert(field, '<i>Facebook</i>[[Kategori:Länkkällor utan metadata: facebook.com]]')
		elseif string.match(link, ".twitter.com/") then
			table.insert(field, '<i>Twitter</i>[[Kategori:Länkkällor utan metadata: twitter.com]]')
		elseif string.match(link, "google") then
			table.insert(field, '<i>' .. doman .. '</i>[[Kategori:Länkkällor utan metadata: google]]')
		elseif string.match(link, ".archive.org/") then
			table.insert(field, '<i>Internet Archive</i>[[Kategori:Länkkällor utan metadata: archive.org]]')
		elseif string.match(link, "/10%.%d%d%d%d/") then
			table.insert(field, '<i>' .. doman .. '</i>[[Kategori:Länkkällor utan metadata: DOI]]')
		elseif toppdoman then
			table.insert(field, '<i>' .. doman .. '</i>[[Kategori:Länkkällor utan metadata: ' .. toppdoman .. ']]')
		else
			table.insert(field, '[[Kategori:Artiklar med svaga Wikidatabaserade källhänvisningar]]') 
		end
		-- Ovanstående elseif-träd sorterar på domännamn, nedanstående sorterar på resten av URLen
		if string.match(link, "nytimes.com/") then
		elseif string.match(link, "theguardian.com/") then
		elseif string.match(link, "archive.org/") then
		elseif string.match(link, "/[1-2]%d%d%d/[0-1]%d/") then
			table.insert(field, '[[Kategori:Länkkällor utan metadata: datum]]')
		elseif string.match(link, "/%d%d%d%d/%a%a%a/%d%d/") then
			table.insert(field, '[[Kategori:Länkkällor utan metadata: datum]]')
		elseif string.match(link, "%D[1-2]%d%d%d[0-1]%d[0-3]%d%D") then
			table.insert(field, '[[Kategori:Länkkällor utan metadata: datum]]')
		elseif string.match(link, "[1-2]%d%d%d%-[0-1]%d%-[0-3]%d") then
			table.insert(field, '[[Kategori:Länkkällor utan metadata: datum]]')
		elseif string.match(link, "[0-3]%d%-[0-3]%d%-[1-2]%d%d%d") then
			table.insert(field, '[[Kategori:Länkkällor utan metadata: datum]]')
		elseif string.match(link, "%Aarticles?%A") then
			table.insert(field, '[[Kategori:Länkkällor utan metadata: article]]')
		elseif string.match(link, "%Anews%A") then
			table.insert(field, '[[Kategori:Länkkällor utan metadata: news]]')
		end
		table.insert(field,'[[Kategori:Länkkällor utan metadata: samtliga]]')
	end
	if hamtdatum and hamtdatum ~= '' then table.insert(field, hamtdatum) end
	if license and license ~= '' then table.insert(field, license) end
	if citatet and citatet ~= '' then table.insert(field, citatet) end
	if checket and checket ~= '' then table.insert(field, checket) end
	if #field > 0 then table.insert(field, '<sup><small>[källa från Wikidata]</small></sup>') end
	return table.concat(field, ', '):gsub(', %[%[Kategori:',' [[Kategori:'):gsub(', %<sup%>%<small%>%[källa från Wikidata','.<sup><small>[källa från Wikidata')   -- inget kommatecken före [[Kategori: eftersom kategorin inte skrivs ut på samma rad, ersätter ", " med "." före [källa från Wikidata]
end

function p.cite(frame)
	local lang = frame.args.lang
	if not lang or lang == '' then
		lang = frame:preprocess('{{int:lang}}')
	end
	local page = frame.args.page
	if page == '' then
		page = nil
	end
	return p.citeitem(frame.args.item, lang, page)
end


return p