Siirry sisältöön

Moduuli:Verkkoviite

Tämä moduuli on osittain suojattu muutoksilta.
Wikipediasta


Käyttöohje ja tekniset tiedot moduulille Verkkoviite

Toteuttaa mallineen Malline:Verkkoviite.


local t={}

-- Palauttaa url-osoitteen perusteella arvon sivusto-parametrille
local function get_host_from_url(url)

	if url == "" then
		return ""
	end

	local u = mw.uri.new(url)
   
	-- poistetaan "www" alusta
	local ret = ""
	if u.host ~= nil then
		ret = string.gsub( u.host, "^www.", "", 1 )
	end
	return ret
end

-- 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: <span class='error'>Virheellinen PMID: ".. pmid .."</span> [[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: <span class='error'>Virheellinen PMC: ".. pmc_num .."</span> [[Luokka:Sivut, joissa on virheellinen PMC-tunniste]]"
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:<span class='error'>Virheellinen Bibcode: ".. bibcode ..", ".. err .."</span> [[Luokka:Sivut, joissa on virheellinen Bibcode-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:<span class='error'>Virheellinen Doi-tunniste</span> [[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, '%]', "&rsqb;" )
	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

-- 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:<span class='error'>Virheellinen S2CID: ".. s2cid .."</span> [[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 formatciteseerx(citeseerx)
	local citeseerid = mw.uri.encode( citeseerx )
	return '[[CiteSeerX]]:[https://citeseerx.ist.psu.edu/viewdoc/summary?doi=' .. citeseerid .. ' ' .. citeseerx .. ']'
end

-- Social Science Research Network
local function formatssrn( ssrnid )
	-- just a number
	local num = tonumber(ssrnid)
	if num ~= nil then
		-- or use https://ssrn.com/abstract= ?
		return "[[Social Science Research Network|SSRN]]:[https://papers.ssrn.com/sol3/papers.cfm?abstract_id=".. ssrnid .. " " .. ssrnid .."]"
	end
	-- could just give error instead?
	return "SSRN:<span class='error'>Virheellinen SSRN-tunniste: ".. ssrnid .."</span> [[Luokka:Sivut, joissa on virheellinen SSRN-tunniste]]"
end

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

local function formatisbn(isbn)
	local Isxn = require('Moduuli:ISxN')
	if Isxn._check_isbn(isbn) then
		return '[[Toiminnot:Kirjalähteet/' .. isbn .. '|ISBN&nbsp;' .. isbn ..']]'
	end
	return "<span class='error'>Virhe: Virheellinen ISBN-tunniste</span> [[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&nbsp;' .. issn ..']'
	end
	return "<span class='error'>Virhe: Virheellinen ISSN-tunniste</span> [[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&nbsp;' .. eissn ..']'
	end
	return "<span class='error'>Virhe: Virheellinen ISSN-tunniste</span> [[Luokka:Sivut, joissa on virheellinen ISSN-tunniste]]"
end

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

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

local function formatlanguagecode( kielinimi )
	if (kielinimi) then
		return '<span style="font-size: 0.95em;">(' .. kielinimi .. ')</span>'
	end
	return ''
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

	-- shortcut for most common cases
	if tmpkoodi == "fi" or tmpkoodi == "fi-fi" then
		return 'suomeksi' -- normally not shown
	elseif tmpkoodi == "en" or tmpkoodi == "en-en" then
		return 'englanniksi'
	elseif tmpkoodi == "sv" or tmpkoodi == "sv-sv" then
		return 'ruotsiksi'
	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

	local Langue = require('Module:Fr:Langue')
	
	-- fallback: get plain name for language (when no inflection case found),
	-- may be unlocalized name in worst case
	kieliteksti = Langue.getLanguageName(tmpkoodi)
	if kieliteksti ~= "" then
		-- localized form
		return kieliteksti
	end
	return ""
end

-- in case given parameter ends with punctuation character
-- we don't want a second one (dot) after it
local function ends_with_punctuation( text )
	-- in case of empty string
	if (text == "") then
		return false
	end
	
	local last = mw.ustring.sub(text, -1, -1)
	if last == '.' then
		return true
	end
	-- also skip dot in these cases?
	--if last == '?' or last == '!' then
	--	return true
	--end
	return false
end

-- verify url is correctly formatted,
-- let user know if there is some other issue with it
local function is_valid_url(url)
	if url == nil then
		--return "<span class='error'>tyhjä osoite</span> "
		return false
	end
	if url == "" then
		--return "<span class='error'>tyhjä osoite</span> "
		return false
	end

	-- must have valid protocol
	local protopos = mw.ustring.find(url, '://', 1, true)
	if (protopos == nil) then
		--return "<span class='error'>virheellinen protokolla</span> "
		return false
	end
	
	local protocol = mw.ustring.sub(url, 1, protopos-1)
	if (protocol == nil) then
		return false
	end
	protocol = protocol:lower()
	-- huomaa, ftp on joskus ollut tuettu..
	if (protocol ~= "http" and protocol ~= "https" and protocol ~= "ftp") then
		--return "<span class='error'>virheellinen protokolla</span> "
		return false
	end

	local protopostwo = mw.ustring.find(url, '://', protopos+2, true)
	if (protopostwo ~= nil) then
		-- there is a second protocol in the url ?
		-- note that archive.org urls may be valid with a second protocol 
		-- even without encoding it
		if ((protopostwo-protopos) < 10) then
			-- just two protocols next to each other, 
			-- not enough for a reasonable url with domain -> must be error
			return false
		end
		-- if there is more: pass through for obscure cases
	end
	
	return true
end

local function verkkoviite( args )
	local wiki = {}	
	local function insert( value )
		wiki[#wiki+1] = value
	end
	insert('<span class="verkkoviite" title="Verkkoviite">')

	local author = args['Tekijä'] or args['author'] or args['tekijä'] or ""
	if author ~= "" then
		insert(author)
		insert(":&#32;")
	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(';&#32;')
				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(';&#32;')
				end
				insert(author)
				numeroitu = true
				addauthorcomma = true
			end
			rivinro = rivinro +1
		end
		if (numeroton == true or numeroitu == true) then
			-- päätä tekijä(t)
			insert(":&#32;")
		end
	end

	-- verify url is correctly formatted
	local url = args['Osoite'] or args['url'] or args['osoite'] or args['URL'] or ""
	local publisherfromurl = ""
	local validurl = is_valid_url(url)
	if (validurl == true) then
		publisherfromurl = get_host_from_url(url)
		-- warn if url is from blocked domain?
	end
	
	local archiveurl = args['Arkisto'] or args['arkisto'] or args['archiveurl'] or args['archive-url'] or ""
	local title = args['Nimeke'] or args['Nimike'] or args['title'] or args['Otsikko'] or args['nimeke'] or args['nimike'] or args['otsikko'] or args['Title'] or ""
	if url ~= "" then
		if (validurl == false) then
			insert("<span class='error'>virheellinen osoite</span> [[Luokka:Sivut, joissa on virhe verkkoviitteessä]]")
		end
		
		-- jos maksullinen tai vaatii kirjautumisen
		local rajoitettu = args['pääsy'] or args['kirjautuminen'] or args['maksullinen'] or args['url-access'] or ""

		-- jos merkitty vanhentuneeksi
		local isdeadlink = args['vanhentunut'] or args['deadlink'] or args['url-status'] or ""
		if title ~= "" then
			-- don't add url if validurl == false
			insert('[')
			if (validurl == true) then
				insert(url)
			end
			insert(' ')
			insert(title)
			insert(']')
			-- rajoitettu == "registration" tai "limited" tai "subscription"
			-- pääsy == "maksullinen" tai "kirjautuminen" tai "tunnus"
			-- maksullinen == "kyllä"
			-- kirjautuminen == "kyllä"
			if rajoitettu ~= "" then
				insert(' &#128274;') -- keltainen lukkokuva
			end
			-- isdeadlink == "live", "dead" tai "pysyvästi" ..
			if isdeadlink ~= "" then
				insert('<sup>&lbrack; [[Wikiprojekti:Linkit|vanhentunut linkki]] &rbrack;</sup>[[Luokka:Artikkelit, joissa on vanhentuneita linkkejä]]')
			end
		else
			insert("<span style='color:red; font-weight:bold;'>Määritä nimeke!</span>[[Luokka:Sivut, joiden viitemallineissa on virheitä]]")
		end
	elseif archiveurl ~= "" then
		-- archived url without a live url
		if title ~= "" then
			insert(title)
		else
			insert("<span style='color:red; font-weight:bold;'>Määritä nimeke!</span>[[Luokka:Sivut, joiden viitemallineissa on virheitä]]")
		end
	else
		insert("<span style='color:red; font-weight:bold;'>Määritä osoite!</span>[[Luokka:Sivut, joiden verkkoviitemallineesta puuttuu osoite]]")
	end

	-- hyödyllinen joillakin sivuilla, esimerkiksi kun viitataan PDF-dokumenttiin
	local sivut = args['Sivut'] or args['sivut'] or args['pages'] or ""
	if sivut ~= "" then
		insert(' s. ')
		insert(sivut)
		insert('.&#32;')
	end

	local tiedostomuoto = args['Tiedostomuoto'] or args['format'] or args['tiedostomuoto'] or ""
	if tiedostomuoto ~= "" then
		insert("&#32;<small>(")
		insert(tiedostomuoto)
		insert(")</small>")
	end

	local selite = args['Selite'] or args['selite'] or ""
	if selite ~= "" then
		insert("&nbsp;(")
		insert(selite)
		insert(")")
	end

	-- same conditions as earlier
	local sitepub = args['Julkaisu'] or args['Sivusto'] or args['site'] or args['work'] or args['julkaisu'] or args['sivusto'] or ""
	local julkaisija = args['Julkaisija'] or args['publisher'] or args['julkaisija'] or ""
	if sitepub ~= "" or publisherfromurl ~= "" then
		local adddot = false
		local showurldomain = true
		if (julkaisija ~= "" or sitepub ~= "") then
			showurldomain = false
		end
		insert("&#32;<i>")
		if sitepub ~= "" then
			insert(sitepub)
			if (ends_with_punctuation(sitepub) == false) then
				adddot = true
			end
		else
			-- domainia ei haluta näyttää jos julkaisu tai julkaisija on määritelty
			if (showurldomain == true) then
				insert(publisherfromurl)
				adddot = true
			end
		end
		insert("</i>")

		if (adddot == true) then
			insert(".")
		end
	end

	local ajankohta = args['Ajankohta'] or args['date'] or args['ajankohta'] or ""
	if ajankohta ~= "" then
		if istimeinISO(ajankohta) then
			ajankohta = localizedate(ajankohta)
		end
		insert('&#32;')
		insert(ajankohta)

		-- ajankohdan perässä ei pitäisi olla pistettä mutta jos on niin ei lisätä toista
		if (ends_with_punctuation(ajankohta) == false) then			
			insert(".")
		end
	end

	local julkaisupaikka = args['Julkaisupaikka'] or args['julkaisupaikka'] or ""
	if julkaisupaikka ~= "" then
		insert("&#32;")
		insert(julkaisupaikka)

		-- semicolon if place is followed by publisher, otherwise dot
		if julkaisija ~= "" then
			insert("&#58;&#32;")
		else
			-- julkaisupaikka ilman julkaisijaa, ei lisätä pistettä jos on jo
			if (ends_with_punctuation(julkaisupaikka) == false) then			
				insert(".")
			end
		end
	end
	-- publisher
	if julkaisija ~= "" then
		insert("&#32;")
		insert(julkaisija)
		-- joissakin apumallineissa on mukana piste julkaisijan perässä:
		-- ei lisätä toista jos on jo
		if (ends_with_punctuation(julkaisija) == false) then
			insert(".")
		end
	end

	if archiveurl ~= "" then
		insert("&#32;[")
		insert(archiveurl)
		insert(' Arkistoitu]')
		local arkistoaika = args['Arkistoitu'] or args['archivedate'] or args['arkistoitu'] or args['archive-date'] or ""
		if arkistoaika ~= "" then
			if istimeinISO(arkistoaika) then
				arkistoaika = localizedate(arkistoaika)
			end
			insert("&#32;")
			insert(arkistoaika)
			if (ends_with_punctuation(arkistoaika) == false) then			
				insert(".")
			end
		end
	end

	local lainaus = args['Lainaus'] or args['quote'] or args['lainaus'] or ""
	if lainaus ~= "" then
		--<span class="citation">...</span>
		insert('&#32;”')
		insert(lainaus)
		insert('”')
	end

	local pmid = args['Pmid'] or args['pmid'] or args['PMID'] or ""
	if pmid ~= "" then
		local pubmedlink = formatpubmedid(pmid)
		if pubmedlink ~= "" then
			insert("&#32;")
			insert(pubmedlink)
			--insert('.')
			insert('&#32;')
		end
	end
	local pmc = args['PMC'] or args['Pmc'] or args['pmc'] or ""
	if pmc ~= "" then
		local pmclink = formatpubmedcentral(pmc)
		if pmclink ~= "" then
			insert("&#32;")
			insert(pmclink)
			--insert('.')
			insert('&#32;')
		end
	end
	local doi = args['Doi'] or args['doi'] or args['DOI'] or ""
	if doi ~= "" then
		local doilink = formatdoi(doi)
		if doilink ~= "" then
			insert("&#32;")
			insert(doilink)
			--insert('.')
			insert('&#32;')
		end
	end
	local hdl = args['Hdl'] or args['hdl'] or args['HDL'] or ""
	if hdl ~= "" then
		local hdllink = formathdl(hdl)
		if hdllink ~= "" then
			insert("&#32;")
			insert(hdllink)
			--insert('.')
			insert('&#32;')
		end
	end

	local bibcode = args['Bibcode'] or args['bibcode'] or ""
	if bibcode ~= "" then
		local bibcodelink = formatbibcode(bibcode)
		if bibcodelink ~= "" then
			insert("&#32;")
			insert(bibcodelink)
			--insert('.')
			insert('&#32;')
		end
	end
	local jstor = args['Jstor'] or args['jstor'] or args['JSTOR'] or ""
	if jstor ~= "" then
		local jstorlink = formatjstor(jstor)
		if jstorlink ~= "" then
			insert("&#32;")
			insert(jstorlink)
			--insert('.')
			insert('&#32;')
		end
	end
	local s2cid = args['S2CID'] or args['S2cid'] or args['s2cid'] or ""
	if s2cid ~= "" then
		local s2cidlink = formats2cid(s2cid)
		if s2cidlink ~= "" then
			insert("&#32;")
			insert(s2cidlink)
			--insert('.')
			insert('&#32;')
		end
	end
	local ssrn = args['SSRN'] or args['Ssrn'] or args['ssrn'] or ""
	if ssrn ~= "" then
		local ssrnlink = formatssrn(ssrn)
		if ssrnlink ~= "" then
			insert("&#32;")
			insert(ssrnlink)
			--insert('.')
			insert('&#32;')
		end
	end
	local arxiv = args['Arxiv'] or args['arxiv'] or args['arXiv'] or ""
	if arxiv ~= "" then
		local arxivlink = formatarxiv(arxiv)
		if arxivlink ~= "" then
			insert("&#32;")
			insert(arxivlink)
			--insert('.')
			insert('&#32;')
		end
	end
	local citeseerx = args['CiteSeerX'] or args['Citeseerx'] or args['citeseerx'] or ""
	if citeseerx ~= "" then
		local cslink = formatciteseerx(citeseerx)
		if cslink ~= "" then
			insert("&#32;")
			insert(cslink)
			--insert('.')
			insert('&#32;')
		end
	end
	
	local oclc = args['OCLC'] or args['Oclc'] or args['oclc'] or ""
	if oclc ~= "" then
		local oclclink = formatoclc(oclc)
		if oclclink ~= "" then
			insert("&#32;")
			insert(oclclink)
			--insert('.')
			insert('&#32;')
		end
	end

	local isbn = args['Isbn'] or args['ISBN'] or args['isbn'] or ""
	if isbn ~= "" then
		local isbnlink = formatisbn(isbn)
		if isbnlink ~= "" then
			insert("&#32;")
			insert(isbnlink)
			--insert('.')
			insert('&#32;')
		end
	end
	local issn = args['Issn'] or args['ISSN'] or args['issn'] or ""
	if issn ~= "" then
		local issnlink = formatissn(issn)
		if issnlink ~= "" then
			insert("&#32;")
			insert(issnlink)
			--insert('.')
			insert('&#32;')
		end
	end
	local eissn = args['Eissn'] or args['EISSN'] or args['eissn'] or ""
	if eissn ~= "" then
		local eissnlink = formateissn(eissn)
		if eissnlink ~= "" then
			insert("&#32;")
			insert(eissnlink)
			--insert('.')
			insert('&#32;')
		end
	end
	local ismn = args['Ismn'] or args['ISMN'] or args['ismn'] or ""
	if ismn ~= "" then
		local ismnlink = formatismn(ismn)
		if ismnlink ~= "" then
			insert("&#32;")
			insert(ismnlink)
			--insert('.')
			insert('&#32;')
		end
	end

	local viitattu = args['Viitattu'] or args['Luettu'] or args['accessdate'] or args['access-date'] or args['viitattu'] or args['luettu'] or ""
	if viitattu ~= "" then
		if istimeinISO(viitattu) then
			viitattu = localizedate(viitattu)
		end
		insert(' Viitattu ')
		insert(viitattu)
		insert('.')
	end

	local kieli = args['Kieli'] or args['language'] or args['kieli'] or ""
	local ietfkielikoodi = args['ietf-kielikoodi'] or ""
	if kieli ~= "" then
		-- already expanded to <span>lang</span> from a template
		local isexpanded = false
		if mw.ustring.find(kieli, "span") then
			isexpanded = true
		end
		
		if (isexpanded == true) then
			-- as-is
			insert('&#32;')
			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('&#32;')
				insert(formatlanguagecode(kielinimi))
			else
				-- language code not recognized -> can't give language name
				-- could give error of unknown language code?
				--
				--insert("<span class='error'>")
				insert('&#32;')
				insert(kieli)
				--insert("</span>")
			end
		end
	elseif ietfkielikoodi ~= "" then
		-- only use ietf-field if the normal way of giving language hasn't been used:
		-- some wiki-tools use this field instead of the normal and use different format
		
		ietfkielikoodi = ietfkielikoodi:lower()
		if ietfkielikoodi == "fi" or ietfkielikoodi == "fin" or ietfkielikoodi == "fi-fi" then
			-- |fi|fin|fi-fi =  -> no change, omitted
		else
			local kielinimi = getlanguagenamebycode(ietfkielikoodi)
			if kielinimi ~= "" then
				-- format to correct tag
				insert('&#32;')
				insert(formatlanguagecode(kielinimi))
			else
				-- language code not recognized -> can't give language name
				-- could give error of unknown language code?
				-- it might be plain name already instead of code?
				--insert("<span class='error'>Tunnistamaton kielikoodi: ")
				insert('&#32;')
				insert(ietfkielikoodi)
				--insert("</span>")
			end
		end
	end

	insert('</span>')
	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 verkkoviite( args )
end

return t;