Siirry sisältöön

Moduuli:Kirjaviite

Tämä moduuli on osittain suojattu muutoksilta.
Wikipediasta


Käyttöohje ja tekniset tiedot moduulille Kirjaviite

Toteuttaa mallineen Malline:Kirjaviite.

Käsittely {{Kirjaviite}}-mallineen parametreille ja muotoilulle.

Tuki myös englanninkielisille parametreille helpottamaan siirtämistä.


local t={}

-- patterns copied from template Onko päiväys ISO 8601 -muodossa?
local function istimeinISO( datestring )
	if not datestring then
		return false
	end
	local result
	result = mw.ustring.match( datestring, "^%s*-?%d%d%d%d%-%d%d%-%d%d%s*$", 1 ) -- 2016-05-05
	if result then 
		return true
	end
	result = mw.ustring.match( datestring, "^%s*-?%d%d%d%d%-%d%d%-%d%dT%d%d:%d%d:%d%d?Z%s*$", 1 ) -- 2016-05-05T10:09:04Z
	if result then 
		return true
	end
	result = mw.ustring.match( datestring, "^%s*-?%d%d%d%d%d%d%d%dT%d%d%d%d%d%d?Z%s*$", 1 ) -- 20160505T100904Z
	if result then 
		return true
	end
	return false
end

local function localizedate( datestring )
	local tmp = datestring
	-- check for non-breakable spaces
	tmp = tmp:gsub( '\194\160', ' ' ):gsub( ' ', ' ' )

	local lang = mw.language.getContentLanguage()
	-- same as #time parser
	return lang:formatDate( "j.n.Y", tmp, true )
end

local function encbrackets( s )
	local tmp = s
	if mw.ustring.find(tmp, '%]') then
		tmp = mw.ustring.gsub( tmp, '%]', "]" )
	end
	if mw.ustring.find(tmp, '%[') then
		tmp = mw.ustring.gsub( tmp, '%[', "[" )
	end
	return tmp
end

local function formatpubmedid( pmid )
	-- some extra validation that id is a number
	local num = tonumber(pmid)
	if num ~= nil then
		return "[[PubMed]]:[https://pubmed.ncbi.nlm.nih.gov/".. pmid .. " " .. pmid .."]"
	end
	-- could just give error instead?
	return "PubMed: Virheellinen PMID: ".. pmid .." [[Luokka:Sivut, joissa on virheellinen PubMed-tunniste]]"
end

local function formatpubmedcentral( pmcid )
	-- should be plain number after PMC?
	local pmc_num = mw.ustring.sub( pmcid, 1, 3 )
	if pmc_num == "PMC" then
		-- begins with PMC
		pmc_num = mw.ustring.sub( pmcid, 4 )
	else
		-- plain number given
		pmc_num = pmcid
	end

	-- add PMC to url if there isn't,
	-- check there are only numbers in string
	local num = tonumber(pmc_num)
	if num ~= nil then
		return "[[PubMed Central]]:[https://www.ncbi.nlm.nih.gov/pmc/articles/PMC".. pmc_num .. " " .. pmc_num .."]"
	end
	return "PubMed Central: Virheellinen PMC: ".. pmc_num .." [[Luokka:Sivut, joissa on virheellinen PMC-tunniste]]"
end

-- todo: try to catch common issues (typos)
local function validatedoi( doiid )
	-- should have format: prefix/suffix
	-- should have both parts or it is not complete
	-- prefix should start with "10."
	-- at least : exists in suffix in some cases, likely others as well
	-- often ending with . is an error
	-- also no spaces
	-- may have subdivisions, different separators, is not case-sensitive

	-- should start with "10." 
	local doinum = mw.ustring.sub( doiid, 1, 3 )
	if doinum ~= "10." then
		return false
	end
	
	-- should have prefix/suffix format
	if not mw.ustring.find(doiid, '/') then
		return false
	end

	-- no spaces
	if mw.ustring.find(doiid, ' ') then
		return false
	end
	
	return true
end

local function formatdoi( doiid )
	if (validatedoi(doiid) == false) then
		return "doi:Virheellinen Doi-tunniste [[Luokka:Sivut, joissa on virheellinen Doi-tunniste]]"
	end
	local url = '//dx.doi.org/' .. mw.uri.encode( doiid ) 
	local htmlenc = mw.text.encode(doiid)
	if mw.ustring.find(htmlenc, '%]') then
		-- check: what was this case for? should just give error?
		htmlenc = mw.ustring.gsub( htmlenc, '%]', "]" )
	end
	return "[[Digital object identifier|doi]]:[" .. url .. " " .. htmlenc .."]"
end

local function formathdl( hdlid )
	local url = 'https://hdl.handle.net/' .. mw.uri.encode( hdlid ) 
	local htmlenc = mw.text.encode(hdlid)
	return "HDL:[" .. url .. " " .. htmlenc .."]"
end

local function formatbibcode( bibcode )
	local CheckBibcode = require('Moduuli:Check bibcode')
	local err = CheckBibcode._verify_bibcode(bibcode)
	if err == nil then
		local url = 'http://adsabs.harvard.edu/abs/' .. mw.uri.encode( bibcode )
		local htmlenc = mw.text.encode(bibcode)
		return "[[Bibcode]]:[" .. url .. " " .. htmlenc .."]" -- .. err
	end
	return "Bibcode:Virheellinen Bibcode: ".. bibcode ..", ".. err .." [[Luokka:Sivut, joissa on virheellinen Bibcode-tunniste]]"
end

-- Semantic Scholar Corpus ID
local function formats2cid( s2cid )
	-- just a number
	local num = tonumber(s2cid)
	if num ~= nil then
		return "S2CID:[https://api.semanticscholar.org/CorpusID:".. s2cid .. " " .. s2cid .."]"
	end
	-- could just give error instead?
	return "S2CID:Virheellinen S2CID: ".. s2cid .." [[Luokka:Sivut, joissa on virheellinen S2CID-tunniste]]"
end

local function formatarxiv(arxiv)
	local arxivid = mw.uri.encode( arxiv )
	return '[[Arxiv|arXiv]]:[https://arxiv.org/abs/' .. arxivid .. ' ' .. arxiv .. ']'
end

local function formatjstor(jstor)
	-- should be number only?
	local jstorid = mw.uri.encode( jstor )
	return '[[JSTOR]]:[http://www.jstor.org/stable/' .. jstorid .. ' ' .. jstor .. ']'
end

local function formatisbn(isbn)
	local Isxn = require('Moduuli:ISxN')
	if Isxn._check_isbn(isbn) then
		return '[[Toiminnot:Kirjalähteet/' .. isbn .. '|ISBN ' .. isbn ..']]'
	end
	return "Virhe: Virheellinen ISBN-tunniste [[Luokka:Sivut, joissa on virheellinen ISBN-tunniste]]"
end

local function formatissn(issn)
	local Isxn = require('Moduuli:ISxN')
	if Isxn._check_issn(issn) then
		return '[http://www.worldcat.org/issn/' .. issn .. ' ISSN ' .. issn ..']'
	end
	return "Virhe: Virheellinen ISSN-tunniste [[Luokka:Sivut, joissa on virheellinen ISSN-tunniste]]"
end

local function formateissn(eissn)
	local Isxn = require('Moduuli:ISxN')
	if Isxn._check_issn(eissn) then
		return '[http://www.worldcat.org/issn/' .. eissn .. ' E-ISSN ' .. eissn ..']'
	end
	return "Virhe: Virheellinen ISSN-tunniste [[Luokka:Sivut, joissa on virheellinen ISSN-tunniste]]"
end

local function formatismn(ismn)
	-- TODO: hakupalvelu?
	return 'ISMN:' .. ismn
end

local function formatsbn(sbn)
	return 'SBN:' .. sbn
end

local function formatoclc( oclc )
	local oclcid = mw.uri.encode( oclc )
	return '[[OCLC]]:[http://www.worldcat.org/oclc/' .. oclcid .. ' ' .. oclc .. ']'
end

-- Finna-tietueen tunniste, esimerkiksi vaari.1088896
local function formatfinna( finna )
	local finnaid = mw.uri.encode( finna )
	return 'Finna:[https://finna.fi/Record/' .. finnaid .. ' ' .. finna .. ']'
end

local function formatlanguagecode( kielinimi )
	return '(' .. kielinimi .. ')'
end

-- expecting two- or three-character code for language as input
local function getlanguagenamebycode( koodi )

	local tmpkoodi;
	-- split two-part code into one for lookup
	if mw.ustring.find(koodi, '-') then
		local codes = mw.text.split( koodi, '-' )
		tmpkoodi = mw.ustring.lower(mw.text.trim(codes[1]))
	else
		-- not a two-part code? try to find with as it is
		tmpkoodi = mw.ustring.lower(mw.text.trim(koodi))
	end

	-- fast mode to get localized (short list)
	local Symbolit = require('Moduuli:Kielisymbolit')
	local kieliteksti = Symbolit._kieli( tmpkoodi )
	if kieliteksti ~= "" then
		-- localized form
		return kieliteksti
	end

	-- check the code is ok
	local Langue = require('Module:Fr:Langue')
	local kielikoodi = Langue.getCodeLangue3fin( koodi )
	if kielikoodi ~= "" then
		-- get localized name for language (plain name)
		return Langue.getLanguageName(kielikoodi)
	end
	return ""
end

-- jos määritellään wikidata-tunniste, hae puuttuvat tiedot wikidatasta
-- fetchfromwikidata( qid ) ?

local function kirjaviite( args )
	local wiki = {}	
	local function insert( value )
		wiki[#wiki+1] = value
	end

	-- jos määritellään wikidata-tunniste, hae puuttuvat tiedot wikidatasta
	-- local qid = args['QID'] or args['Qid'] or args['qid'] or ""
	-- if qid ~= "" then
	--	fetchfromwikidata(qid)
	-- end
	
	insert('')

	-- vauthors is just a list in vancouver system
	local author = args['Tekijä'] or args['author'] or args['tekijä'] or args['vauthors'] or ""
	--local coauthor = args['coauthors'] or "" -- additional field used in cite book
	if author ~= "" then
		insert(author)
		insert(": ")
	else
		local numeroton = false
		local sukunimi = args['Sukunimi'] or args['sukunimi'] or args['last'] or ""
		local etunimi = args['Etunimi'] or args['etunimi'] or args['first'] or ""
		if sukunimi  ~= "" and etunimi  ~= "" then
			insert(sukunimi)
			insert(", ")
			insert(etunimi)
			numeroton = true
		elseif sukunimi ~= "" then
			insert(sukunimi)
			numeroton = true
		elseif etunimi  ~= "" then
			insert(etunimi)
			numeroton = true
		end

		-- numeroidut rivit (jos käännös toisenkielistä wikistä)
		local addauthorcomma = false
		local numeroitu = false
		local rivinro = 1
		while (rivinro <= 9) do
			local nro = tostring(rivinro)
			local sukunimi = args['Sukunimi' .. nro] or args['sukunimi' .. nro] or args['last' .. nro] or ""
			local etunimi = args['Etunimi' .. nro] or args['etunimi' .. nro] or args['first' .. nro] or ""
			local author = args['Tekijä' .. nro] or args['author' .. nro] or args['tekijä' .. nro] or ""

			if sukunimi  ~= "" and etunimi  ~= "" then
				if (numeroton == true or addauthorcomma == true) then
					-- päätä edellinen ennen seuraavaa nimeä
					insert('; ')
				end
				insert(sukunimi)
				insert(", ")
				insert(etunimi)
				numeroitu = true
				addauthorcomma = true
			end
			if author  ~= "" then
				if (numeroton == true or addauthorcomma == true) then
					-- päätä edellinen ennen seuraavaa nimeä
					insert('; ')
				end
				insert(author)
				numeroitu = true
				addauthorcomma = true
			end
			rivinro = rivinro +1
		end
		if (numeroton == true or numeroitu == true) then
			-- päätä tekijä(t)
			insert(": ")
		end
	end

	local kappale = args['Kappale'] or args['kappale'] or args['chapter'] or ""
	if kappale ~= "" then
		insert('”')
		insert(kappale)
		insert('”, ')
	end

	local luku = args['Luku'] or args['luku'] or ""
	if luku ~= "" then
		insert('”')
		insert(luku)
		insert('”, ')
	end
	local otsikko = args['Nimeke'] or args['Nimike'] or args['nimeke'] or args['nimike'] or args['Otsikko'] or args['otsikko'] or args['title'] or ""
	if otsikko ~= "" then
		insert('')
		insert(otsikko)
		insert('')

		local loppupiste = true
		local pilkku = true

		-- jos viimeinen merkki on kysymysmerkki tai muu ja käyttäjä ei halua erotinmerkkiä
		local lopetusmerkki = args['Lopetusmerkki'] or args['lopetusmerkki'] or ""
		if lopetusmerkki == "pois" then
			loppupiste = false
			pilkku = false
		end
		-- jos nimeke päättyy kysymysmerkkiin ei lisätä välimerkkiä otsikon jälkeen
		-- ei lisätä välipilkkua myöskään
		local viimeinen = mw.ustring.sub(otsikko, -1, -1)
		if viimeinen == '?' or viimeinen == '!' then
			loppupiste = false
			pilkku = false
		end
		if viimeinen == '.' then
			loppupiste = false
			pilkku = false
		end
		-- jos otsikko päättyy pilkkuun ei tarvita toista pilkkua erottamaan muita kohtia
		-- pilkun voisi poistaa artikkelista?
		if viimeinen == ',' then
			pilkku = false
		end

		local sivu = args['Sivu'] or args['sivu'] or args['page'] or ""
		local sivut = args['Sivut'] or args['sivut'] or args['pages'] or ""
		if sivu ~= "" then
			if (pilkku == true) then
				insert(',')
			end
			insert(' s. ')
			insert(sivu)
			loppupiste = true
			pilkku = true --
		end
		if sivut ~= "" then
			if (pilkku == true) then
				insert(',')
			end
			insert(' s. ')
			insert(sivut)
			loppupiste = true
			pilkku = true 
		end

		local palstat = args['Palstat'] or args['palstat'] or ""
		local palsta = args['Palsta'] or args['palsta'] or ""
		if palstat ~= "" then
			if (pilkku == true) then
				insert(',')
			end
			insert(' palstat ')
			insert(palstat)
			loppupiste = true
		end
		if palsta ~= "" then
			if (pilkku == true) then
				insert(',')
			end
			insert(' palsta ')
			insert(palsta)
			loppupiste = true
		end
		if loppupiste == true then
			insert('.')
		end
		insert(" ")
	else
		insert("Määritä nimeke![[Luokka:Sivut, joiden viitemallineissa on virheitä]][[Luokka:Nimeke-parametri puuttuu]]")
	end

	local selite = args['Selite'] or args['selite'] or ""
	if selite ~= "" then
		local addpar = true
		if mw.ustring.sub(selite, 1, 1) == '(' and mw.ustring.sub(selite, -1, -1) == ')' then
			addpar = false
		end
		insert(' ')
		if addpar == true then
			insert('(')
		end
		insert(selite)
		if addpar == true then
			insert(")")
		end
		insert(" ")
	end
	local suomentaja = args['Suomentaja'] or args['suomentaja'] or ""
	if suomentaja ~= "" then
		insert(" Suomentanut ")
		insert(suomentaja)
		insert('.')
		insert("[[Luokka:Suomentaja-parametria käyttävät viitteet]]")
	end
	-- jos käännetty johonkin muuhun kieleen
	local lokalisoija = args['Kääntäjä'] or args['kääntäjä'] or args['translator'] or ""
	if lokalisoija ~= "" then
		insert(" Kääntänyt ")
		insert(lokalisoija)
		insert('.')
		insert("[[Luokka:Kääntäjä-parametria käyttävät viitteet]]")
	end

	-- näitä ei ole aiemmin ollut suomenkielisessä kirjaviitteessä,
	-- mutta esim. ranskan ja englanninkieliset wikidataviitteet käyttävät painosnumeroa
	-- joten lisätään
	local vuosikerta = args['Vuosikerta'] or args['vuosikerta'] or ""
	local osa = args['Osa'] or args['osa'] or args['volume'] or ""
	local sarja = args['Sarja'] or args['sarja'] or args['series'] or ""
	local painos = args['Painos'] or args['painos'] or args['edition'] or ""
	local numero = args['Numero'] or args['numero'] or args['issue'] or ""
	--local nide = args['Nide'] or args['nide'] or args['tome'] or ""  -- onko tarvetta?
	if vuosikerta ~= "" then
		insert(' ')
		insert(vuosikerta)
		insert('. vsk')
	end
	if numero ~= "" then
		insert(' ')
		insert(' nro ')
		insert(numero)
	end
	if osa ~= "" then
		insert(' ')
		insert(osa)
		insert(' ')
	end
	if sarja ~= "" then
		insert(' ')
		insert(sarja)
		insert('.')
	end
	if painos ~= "" then
		insert(' ')
		insert(painos)
		insert(' painos')
		insert('.')
	end

	local julkaisija = args['Julkaisija'] or args['julkaisija'] or args['publisher'] or args['agency'] or ""
	local julkaisupaikka = args['Julkaisupaikka'] or args['julkaisupaikka'] or args['location'] or ""
	local ajankohta = args['Ajankohta'] or args['ajankohta'] or args['Vuosi'] or args['vuosi'] or args['year'] or args['date'] or args['publication-date'] or ""
	if julkaisupaikka ~= "" then
		insert(" ")
		insert(julkaisupaikka)

		-- semicolon if place is followed by publisher, otherwise dot
		if julkaisija ~= "" and julkaisija ~= "-" then
			insert(": ")
		else
			insert(".")
			insert(' ')
		end
	end
	-- julkaisija (ilman julkaisupaikkaa)
    if julkaisija == "-" then
        -- PASS
	elseif julkaisija ~= "" then
		insert(" ")
		insert(julkaisija)

		if ajankohta ~= "" then
			--year, month, day eriteltynä? 
			--local month = args['month'] or ""
			--local day = args['day'] or ""
			if istimeinISO(ajankohta) then
				ajankohta = localizedate(ajankohta)
			end
			insert(', ')
			insert(ajankohta)
		end
		insert(".")
		insert(' ')
	else
		insert("Määritä julkaisija![[Luokka:Sivut, joiden viitemallineissa on virheitä]][[Luokka:Julkaisija-parametri puuttuu]]")
	end

	local lainaus = args['Lainaus'] or args['lainaus'] or args['quote'] or ""
	if lainaus ~= "" then
		--...
		insert(' ”')
		insert(lainaus)
		insert('”')
	end

	-- tunnisteet, joita aiemmin ei ole tuettu: ismn issn jfm jstor lccn mr oclc ol osti pmc pmid rfc ssrn zbl id
	local tunniste = args['Tunniste'] or args['tunniste'] or args['id'] or ""
	if tunniste ~= "" then
		insert(" ")
		insert(tunniste)
		--insert('.')
		insert(' ')
	end
	local pmid = args['PMID'] or args['Pmid'] or args['pmid'] or ""
	if pmid ~= "" then
		local pubmedlink = formatpubmedid(pmid)
		if pubmedlink ~= "" then
			insert(" ")
			insert(pubmedlink)
			--insert('.')
			insert(' ')
		end
	end
	local pmc = args['PMC'] or args['Pmc'] or args['pmc'] or ""
	if pmc ~= "" then
		local pmclink = formatpubmedcentral(pmc)
		if pmclink ~= "" then
			insert(" ")
			insert(pmclink)
			--insert('.')
			insert(' ')
		end
	end
	local doi = args['Doi'] or args['doi'] or args['DOI'] or ""
	if doi ~= "" then
		local doilink = formatdoi(doi)
		if doilink ~= "" then
			insert(" ")
			insert(doilink)
			--insert('.')
			insert(' ')
		end
	end
	local hdl = args['Hdl'] or args['hdl'] or args['HDL'] or ""
	if hdl ~= "" then
		local hdllink = formathdl(hdl)
		if hdllink ~= "" then
			insert(" ")
			insert(hdllink)
			--insert('.')
			insert(' ')
		end
	end
	
	local isbn = args['Isbn'] or args['ISBN'] or args['isbn'] or ""
	if isbn ~= "" then
		local isbnlink = formatisbn(isbn)
		if isbnlink ~= "" then
			insert(" ")
			insert(isbnlink)
			--insert('.')
			insert(' ')
		end
	end

	local issn = args['Issn'] or args['ISSN'] or args['issn'] or ""
	if issn ~= "" then
		local issnlink = formatissn(issn)
		if issnlink ~= "" then
			insert(" ")
			insert(issnlink)
			--insert('.')
			insert(' ')
		end
	end
	local eissn = args['Eissn'] or args['EISSN'] or args['eissn'] or ""
	if eissn ~= "" then
		local eissnlink = formateissn(eissn)
		if eissnlink ~= "" then
			insert(" ")
			insert(eissnlink)
			--insert('.')
			insert(' ')
		end
	end
	local ismn = args['Ismn'] or args['ISMN'] or args['ismn'] or ""
	if ismn ~= "" then
		local ismnlink = formatismn(ismn)
		if ismnlink ~= "" then
			insert(" ")
			insert(ismnlink)
			--insert('.')
			insert(' ')
		end
	end
	local sbn = args['Sbn'] or args['SBN'] or args['sbn'] or ""
	if sbn ~= "" then
		local sbnlink = formatsbn(sbn)
		if sbnlink ~= "" then
			insert(" ")
			insert(sbnlink)
			--insert('.')
			insert(' ')
		end
	end
	local bibcode = args['Bibcode'] or args['bibcode'] or ""
	if bibcode ~= "" then
		local bibcodelink = formatbibcode(bibcode)
		if bibcodelink ~= "" then
			insert(" ")
			insert(bibcodelink)
			--insert('.')
			insert(' ')
		end
	end
	local jstor = args['JSTOR'] or args['Jstor'] or args['jstor'] or ""
	if jstor ~= "" then
		local jstorlink = formatjstor(jstor)
		if jstorlink ~= "" then
			insert(" ")
			insert(jstorlink)
			--insert('.')
			insert(' ')
		end
	end
	local s2cid = args['S2CID'] or args['S2cid'] or args['s2cid'] or ""
	if s2cid ~= "" then
		local s2cidlink = formats2cid(s2cid)
		if s2cidlink ~= "" then
			insert(" ")
			insert(s2cidlink)
			--insert('.')
			insert(' ')
		end
	end
	local arxiv = args['Arxiv'] or args['arxiv'] or args['arXiv'] or ""
	if arxiv ~= "" then
		local arxivlink = formatarxiv(arxiv)
		if arxivlink ~= "" then
			insert(" ")
			insert(arxivlink)
			--insert('.')
			insert(' ')
		end
	end
	local oclc = args['OCLC'] or args['Oclc'] or args['oclc'] or ""
	if oclc ~= "" then
		local oclclink = formatoclc(oclc)
		if oclclink ~= "" then
			insert(" ")
			insert(oclclink)
			--insert('.')
			insert(' ')
		end
	end
	-- Finna-tietueen tunniste, esimerkiksi vaari.1088896
	local finnaid = args['Finna'] or args['finna'] or ""
	if finnaid ~= "" then
		local finnalink = formatfinna(finnaid)
		if finnalink ~= "" then
			insert(" ")
			insert(finnalink)
			--insert('.')
			insert(' ')
		end
	end

	local viitattu = args['Viitattu'] or args['Luettu'] or args['viitattu'] or args['luettu'] or args['accessdate'] or ""
	local url = args['Osoite'] or args['www'] or args['url'] or args['osoite'] or args['URL'] or ""
	if url ~= "" then
		-- jos wikidata-url osoitteessa niin ei näytetä mitään?
		if mw.ustring.match(url, "https://www.wikidata.org/wiki/") then
			url = ""
		end
	end
		
	if url ~= "" then
		local linkkiteksti = args['www-teksti'] or "Teoksen verkkoversio"
		insert(' ')
		insert('[')
		insert(url)
		insert(' ')
		insert(linkkiteksti)
		insert(']')

		local tiedostomuoto = args['Tiedostomuoto'] or args['tiedostomuoto'] or args['format'] or ""
		if tiedostomuoto ~= "" then
			insert(" ")
			insert("(")
			insert(tiedostomuoto)
			insert(")")
		end
		if viitattu ~= "" then
			if istimeinISO(viitattu) then
				viitattu = localizedate(viitattu)
			end
			insert(" ")
			insert('Viitattu ')
			insert(viitattu)
		end
		insert('.')
	end
	local archiveurl = args['Arkisto'] or args['arkisto'] or args['archiveurl'] or args['archive-url'] or ""
	local arkistoaika = args['Arkistoitu'] or args['arkistoitu'] or args['archivedate'] or args['archive-date'] or ""
	if archiveurl ~= "" then
		insert(' ')
		insert('[')
		insert(archiveurl)
		insert(' ')
		insert('Arkistoitu')
		insert(']')
		
		if arkistoaika ~= "" then
			if istimeinISO(arkistoaika) then
				arkistoaika = localizedate(arkistoaika)
			end
			insert(' ')
			insert(arkistoaika)
		end
		insert('.')
	end

	local kieli = args['Kieli'] or args['kieli'] or args['language'] or ""
	if kieli ~= "" then
		-- already expanded to lang from a template
		local isexpanded = false
		if mw.ustring.find(kieli, "span") then
			isexpanded = true
		end
		
		if (isexpanded == true) then
			-- as-is
			insert(' ')
			insert(kieli)
		else
			-- might need conversion of language code?
			-- plain two-letter code?
			local kielinimi = getlanguagenamebycode(kieli)
			if kielinimi ~= "" then
				-- format to correct tag
				insert(' ')
				insert(formatlanguagecode(kielinimi))
			else
				-- language code not recognized -> can't give language name
				-- could give error of unknown language code?
				--
				--insert("")
				insert(' ')
				insert(kieli)
				--insert("")
			end
		end
	end

	insert('')
	return table.concat( wiki )
end

function t.main( frame )
    local origArgs
    if frame == mw.getCurrentFrame() then
        origArgs = frame:getParent().args
        for k, v in pairs( frame.args ) do
            origArgs = frame.args
            break
        end
    else
        origArgs = frame
    end
    
    local args = {}
    for k, v in pairs( origArgs ) do
        if type( k ) == 'number' or v ~= '' then
            args[ k ] = v
        end
    end
    return kirjaviite( args )
end

return t;