Modul:Test
Dokumentaci tohoto modulu lze vytvořit na stránce Modul:Test/Dokumentace
local p = {
}
function p.trace(c, dbgInfo, s)
table.insert(c.r, "{p." .. dbgInfo.name .. (s and s or "") .. "}")
end
function p.citaceInit(c)
c.r = {} -- result
c.state = {}
if type(c.frame.callParserFunction) == 'function' then
-- running as wiki module
local aModule = require('Modul:Arguments')
c.args = aModule.getArgs(c.frame)
c.parentArgs = aModule.getArgs(c.frame:getParent())
p.frame = c.frame -- zmena reseni, 30.12.2017 12:30:06
else
-- running in console
c.localTest = 1
c.args = c.frame
c.parentArgs = {}
-- makety vybranych fci pro lokalni testovani
mw = {
uri = {
encode = p.identity
}
}
-- debugging options
c.noCoins = 1
c.trace = 1
-- c.dbg = 1
end
if c.trace then p.trace(c, debug.getinfo(1, "n"), ':' .. c.type) end
-- zpětná kompatibilita
c.args = p.convertUnderscoreArgs(c.args)
p.provideArgs(c.args, {
-- ["SRC"] = "DEST",
["příjmení"] = "příjmení1",
["jméno"] = "jméno1",
["autor"] = "autor1",
["odkaz na autora"] = "odkaz na autora1",
["příjmení sestavitele"] = "příjmení sestavitele1",
["jméno sestavitele"] = "jméno sestavitele1",
["sestavitel"] = "sestavitel1",
["odkaz na sestavitele"] = "odkaz na sestavitele1",
["noviny"] = "periodikum",
["časopis"] = "periodikum",
["odkaz na noviny"] = "odkaz na periodikum",
["odkaz na časopis"] = "odkaz na periodikum",
["datum vydání"] = "datum",
["den vydání"] = "den",
["měsíc vydání"] = "měsíc",
["rok vydání"] = "rok",
["stránky"] = "strany",
["poznámka"] = "poznámky",
["titulorig"] = "titul původní",
["url alt"] = "url2",
["ISBN"] = "isbn",
["ISSN"] = "issn",
})
c.printAnchor = not p.empty(c.args.ref)
c.useHarvardFormat = c.printAnchor and c.args["typ refu"] ~= "normální"
if c.dbg then
table.insert(c.r, "((DBG: ")
for k, v in pairs(c.args) do
table.insert(c.r, k .. ' = ' .. v .. ';')
end
table.insert(c.r, "((PARENT)): ")
for k, v in pairs(c.parentArgs) do
table.insert(c.r, k .. ' = ' .. v .. ';')
end
table.insert(c.r, " DBG_END))\n")
end
end
function p.citace(frame)
local c = {
frame = frame
}
p.citaceInit(c)
if not p.empty(c.args["contribution"]) then
c.args["sborník"] = c.args["title"];
c.args["titul"] = c.args["contribution"];
return p.citaceSborniku(frame)
elseif not p.empty(c.args["periodikum"]) then
return p.citacePeriodika(frame)
else
return p.citaceMonografie(frame)
end
end
function p.citaceMonografie(frame)
local c = {
frame = frame
}
c.type = 'citaceMonografie'
p.citaceInit(c)
local t = {} -- temp
local i
table.insert(c.r, '<cite class="book" style="font-style:normal;' .. p.style(c) .. '"')
p.citAnchorId(c)
table.insert(c.r, '>')
p.citAuthors(c, { maxAuthors = 7, honorCorporation = true })
p.citTitle(c)
p.citOtherPersons(c)
p.citEdition(c)
p.citVolume(c)
--p.citPlacePublisher prepare
if not p.empty(c.args["qid"]) then
local PlaceOfPublicationFromWikidata=p.getPlaceOfPublicationFromWikidata(c)
if PlaceOfPublicationFromWikidata~=false and not p.empty(PlaceOfPublicationFromWikidata) then
c.args["místo"]=PlaceOfPublicationFromWikidata
end
end
p.citPlacePublisher(c)
--p.citDate prepare
if not p.empty(c.args["qid"]) then
local RokVydaniFromWikidata,MesicVydaniFromWikidata,DenVydaniFromWikidata=p.getRokMesicDenVydaniFromWikidata(c)
if RokVydaniFromWikidata~=nil and RokVydaniFromWikidata~=false and RokVydaniFromWikidata~=0 then
c.args["rok"]=tostring(RokVydaniFromWikidata) --needs to be string as citDate expects string afterwards for this parameter
end
if MesicVydaniFromWikidata~=nil and MesicVydaniFromWikidata~=0 then
c.args["měsíc"]=tostring(MesicVydaniFromWikidata)
end
if DenVydaniFromWikidata~=nil and DenVydaniFromWikidata~=0 then
c.args["den"]=tostring(DenVydaniFromWikidata)
end
end
p.citDate(c)
p.citNumberOfVolumesPagesAppendices(c)
p.citBookSeries(c)
--p.citUrl prepare
if not p.empty(c.args["qid"]) then
local urlFromWikidata=p.getUrlFromWikidata(c)
if urlFromWikidata~=false then
c.args["url"]=urlFromWikidata
else --url not found, but will try to erase wikidata link if exists!
local lookForWikidataLink=string.find(c.args["url"], "https://www.wikidata.org") --unwanted link to qid in url
if lookForWikidataLink~=nil then --unwanted link found, erase url parameter
c.args["url"]=""
end
end
end
p.citUrl(c)
p.citIsbn(c)
p.citDoi(c)
p.citPmid(c)
p.citBibcode(c)
p.citArxiv(c)
p.citOclc(c)
p.citQID(c) --counting currently only with citaceMonografie
p.citId(c)
p.citChapterPage(c)
-- p.citLanguage(c) --rewrited specifically for citaceMonografie
p.citLanguageMonografieStyle(c)
p.citNotes(c)
table.insert(c.r, '</cite>')
p.citCoinsMonografie(c)
return table.concat(c.r)
end
function p.citaceElMonografie(frame)
local c = {
frame = frame
}
c.type = 'citaceElMonografie'
p.citaceInit(c)
local t = {} -- temp
local i
table.insert(c.r, '<cite class="book" style="font-style:normal;' .. p.style(c) .. '"')
p.citAnchorId(c)
table.insert(c.r, '>')
p.citAuthors(c, { maxAuthors = 7, honorCorporation = true })
p.citTitle(c)
p.citOtherPersons(c)
p.citEdition(c)
-- p.citVolume(c)
p.citPlacePublisher(c)
p.citDate(c)
-- p.citNumberOfVolumesPagesAppendices(c)
p.citBookSeries(c)
p.citChapterPage(c)
p.citNotes(c)
p.citUrl(c)
p.citIsbn(c)
p.citDoi(c)
p.citPmid(c)
p.citBibcode(c)
p.citArxiv(c)
p.citOclc(c)
p.citId(c)
p.citLanguage(c)
table.insert(c.r, '</cite>')
p.citCoinsMonografie(c)
return table.concat(c.r)
end
function p.citacePeriodika(frame)
local c = {
frame = frame
}
c.type = 'citacePeriodika'
p.citaceInit(c)
local t = {} -- temp
local i
p.supplyPeriodical(c)
table.insert(c.r, '<cite style="font-style:normal;' .. p.style(c) .. '"')
p.citAnchorId(c)
table.insert(c.r, '>')
p.citAuthors(c, { maxAuthors = 7, honorCorporation = false })
p.citTitle(c)
p.citOtherPersons(c)
-- table.insert(c.r, " ")
p.citPeriodical(c)
-- table.insert(c.r, " ")
p.citPlacePublisher(c)
p.citDate(c)
p.citYearNumberPage(c)
-- table.insert(c.r, ".")
p.citNotes(c)
p.citUrl(c)
p.citIssn(c)
p.citIsbn(c)
p.citDoi(c)
p.citPmid(c)
p.citBibcode(c)
p.citArxiv(c)
p.citId(c)
p.citLanguage(c)
p.checkPeriodical(c)
table.insert(c.r, '</cite>')
p.citCoinsPeriodikum(c)
return table.concat(c.r)
end
function p.citaceElPeriodika(frame)
local c = {
frame = frame
}
c.type = 'citaceElPeriodika'
p.citaceInit(c)
local t = {} -- temp
local i
p.supplyPeriodical(c)
table.insert(c.r, '<cite style="font-style:normal;' .. p.style(c) .. '"')
p.citAnchorId(c)
table.insert(c.r, '>')
p.citAuthors(c, { maxAuthors = 7, honorCorporation = false })
p.citTitle(c)
p.citOtherPersons(c)
-- table.insert(c.r, " ")
p.citPeriodical(c)
-- table.insert(c.r, " ")
p.citPlacePublisher(c)
p.citDate(c)
p.citYearNumberPage(c)
-- table.insert(c.r, ".")
p.citNotes(c)
p.citUrl(c)
p.citIssn(c)
p.citIsbn(c)
p.citArxiv(c)
p.citDoi(c)
p.citBibcode(c)
p.citPmid(c)
p.citId(c)
p.citLanguage(c)
p.checkPeriodical(c)
table.insert(c.r, '</cite>')
p.citCoinsPeriodikum(c)
return table.concat(c.r)
end
function p.citaceSborniku(frame)
local c = {
frame = frame
}
c.type = 'citaceSborniku'
p.citaceInit(c)
local t = {}
local i
table.insert(c.r, '<cite style="font-style:normal;' .. p.style(c) .. '"')
p.citAnchorId(c)
table.insert(c.r, '>')
p.citAuthors(c, { maxAuthors = 3, honorCorporation = true })
p.citTitle(c)
table.insert(c.r, ' In: ')
p.citCompilers(c, { maxAuthors = 3, honorCorporation = true })
p.citCompilation(c)
p.citEdition(c)
p.citPlacePublisher(c)
p.citDate(c)
p.citNotes(c)
p.citUrl(c)
p.citIsbn(c)
p.citIssn(c)
p.citDoi(c)
p.citId(c)
p.citVolume(c)
p.citChapterPage(c)
p.citLanguage(c)
table.insert(c.r, '</cite>')
-- p.citCoinsSbornik(c)
return table.concat(c.r)
end
function p.debug(frame)
--[[
if frame.callParserFunction ~= nil and type(callParserFunction) == 'function' then
local aModule = require('Modul:Arguments')
local args = aModule.getArgs(frame)
end
--]]
-- local a = '';
-- return 'Titul: ' .. args.titul .. ';'
result = {}
table.insert(result, type(frame))
for k, v in pairs(frame) do
table.insert(result, k .. ' = ' .. type(v) .. '; ')
end
return table.concat(result)
end
function p.nowiki(c, txt)
if type(c.frame.extensionTag) == 'function' then
return c.frame:extensionTag('nowiki', (txt and txt or ''), {})
else
if not p.empty(txt) then
return "<nowiki>" .. txt .. "</nowiki>"
else
return "<nowiki/>"
end
end
end
function p.identity(x)
return x
end
function p.empty(x)
-- return x == nil or x == 0 or x == ""
return x == nil or x == ""
end
-- vrátí první neprázdný argument
function p.coalesce(x, y)
return ((x and x ~= "") and x or ((y and y ~= "") and y or ""))
end
function p.coalesceN(len, args)
for i = 1, len do
local v = args[i]
if v ~= nil and v ~= "" then
return v
end
end
return ""
end
function p.provideArg(args, x, y)
if args[x] == nil then
args[x] = args[y]
end
end
function p.convertUnderscoreArgs(args)
local t = {}
t.args = {}
for k, v in pairs(args) do
k = tostring(k)
t.k, t.count = k:gsub('_', ' ')
t.args[t.k] = v
end
return t.args
end
function p.provideArgs(args, map)
for src, dest in pairs(map) do
if (args[dest] == nil or args[dest] == "") and (args[src] ~= nil and args[src] ~= "") then
args[dest] = args[src]
end
end
end
function p.plural(num, s1, s2, s3)
num = tonumber(num) or 0
return (num == 1 and s1) or (1 < num and num < 5 and s2 or s3)
end
function p.lastChar(s)
if p.frame then
return mw.ustring.sub(s, -1)
else
return string.sub(s, -1)
end
end
-- nevim, zda lze nejak nastavit locale pro systemovy upper
function p.upper(s)
-- return "<span style='text-transform: uppercase'>" .. s .. "</span>"
if p.frame then
-- return p.frame:callParserFunction('uc', s)
return mw.ustring.upper(s)
else
return s:upper()
end
end
function p.upperFirst(s)
if p.frame then
return p.upper(mw.ustring.sub(s, 1, 1)) .. mw.ustring.sub(s, 2)
else
return p.upper(s:sub(1, 1)) .. s:sub(2)
end
end
function p.wikilink(odkaz, popis)
if not p.empty(odkaz) then
if not p.empty(popis) then
return "[[" .. odkaz .. "|" .. popis .. "]]"
else
return "[[" .. odkaz .. "]]"
end
else
return popis
end
end
function p.wikiextlink(odkaz, popis)
if not p.empty(odkaz) then
if not p.empty(popis) then
return "[" .. odkaz .. " " .. popis .. "]"
else
return "[" .. odkaz .. "]"
end
else
return popis
end
end
function p.date(args, params)
local r = {}
local postfix = ""
if (params and params.postfix) then
postfix = params.postfix
end
if not p.empty(args["datum" .. postfix]) then
table.insert(r, ""
.. args["datum" .. postfix]
)
elseif not p.empty(args["rok" .. postfix]) then
table.insert(r, ""
.. args["rok" .. postfix]
.. (not p.empty(args["měsíc" .. postfix])
and "-" .. args["měsíc" .. postfix] .. (not p.empty(args["den" .. postfix]) and "-" .. args["den" .. postfix] or "")
or ""
)
)
end
return table.concat(r)
end
function p.dateCs(args, params)
local r = {}
if not p.empty(args["datum"]) then
table.insert(r, ""
.. args["datum"]
)
elseif not p.empty(args["rok"]) then
table.insert(r, ""
.. (not p.empty(args["měsíc"])
and (not p.empty(args["den"]) and args["den"] .. ". " or "")
-- za měsícem vyjádřeným číslem uvedeme tečku
.. args["měsíc"] .. (string.match(args["měsíc"], "^[0-9]+$") and "." or "") .. " "
or ""
)
.. args["rok"]
)
end
return table.concat(r)
end
-- normalizace data, aby se dalo použít jako vstup pro #time
-- existuje take mw.ustring.gsub
-- https://www.lua.org/pil/20.2.html
-- '%.' matches a dot
function p.normDate(d)
return d:gsub('%. ', '.')
end
function p.style(c)
return (not p.empty(c.args['background']) and "background:" .. c.args['background'] .. ";" or "")
end
function p.supplyPeriodical(c)
local t = {}
if p.empty(c.args["periodikum"]) and not p.empty(c.args["url"]) then
t.urlRegex = "^https?://([^/]*)"
if p.frame then
t.periodikum = mw.ustring.match(c.args["url"], t.urlRegex)
else
t.periodikum = string.match(c.args["url"], t.urlRegex)
end
if t.periodikum then
c.args["periodikum"] = t.periodikum
end
end
end
-- *** Pomocné funkce přidávající výstup do pole c.r ***
-- Odkazy pro harvardské citace
-- Srovnej cs:Modul:Footnotes / core() / grep CITEREF
-- Srovnej en:Module:Citation/CS1 fce / anchor_id() -- tam je trochu jiné řešení, bere v úvahu více polí
function p.citAnchorId(c)
local t = {}
if c.printAnchor then
if c.args.ref == "harv" then
t.r = {}
if not p.empty(c.args["příjmení1"]) then
for i = 1, 4 do
if not p.empty(c.args["příjmení" .. i]) then
table.insert(t.r, c.args["příjmení" .. i])
end
end
if not p.empty(c.args["rok"]) then
table.insert(t.r, c.args["rok"])
end
end
t.ref = "CITEREF" .. table.concat(t.r)
else
t.ref = "CITEREF" .. c.args.ref
end
table.insert(c.r, ' id="' .. t.ref .. '"')
end
end
function p.citAuthors(c, params)
if c.trace then p.trace(c, debug.getinfo(1, "n")) end
local t = {}, i
if params.honorCorporation and not p.empty(c.args["korporace"]) then
c.state.lastAuthor = c.args["korporace"]
table.insert(c.r, ""
.. p.wikilink(c.args["odkaz na korporaci"], c.args["korporace"])
)
else
for i = 1, params.maxAuthors do
p.citAuthor(t, c, i)
end
end
-- if not p.empty(c.args["korporace"]) or not p.empty(c.args["autor1"]) or not p.empty(c.args["příjmení1"]) then
if not p.empty(c.state.lastAuthor) then
if not p.empty(c.args["spoluautoři"]) then
c.state.lastAuthor = c.args["spoluautoři"]
table.insert(c.r, ", " .. c.args["spoluautoři"])
end
end
if c.useHarvardFormat and not p.empty(c.args["rok"]) then
c.state.lastAuthor = c.args["rok"]
table.insert(c.r, ", " .. c.args["rok"])
end
-- pokud posledni jmeno nekonci teckou, pak ji vlozime
-- DBG
if nil and c.state.lastAuthor then
table.insert(c.r, "[" .. c.state.lastAuthor .. "/" .. p.lastChar(c.state.lastAuthor) .. "]")
end
if c.state.lastAuthor and p.lastChar(c.state.lastAuthor) ~= '.' then
table.insert(c.r, ".")
end
end
function p.citAuthor(t, c, i)
if c.trace then p.trace(c, debug.getinfo(1, "n")) end
local t = {}
t["autor"] = nil
if not p.empty(c.args["autor" .. i]) then
t["autor"] = c.args["autor" .. i]
elseif not p.empty(c.args["příjmení" .. i]) then
t["autor"] = p.upper(c.args["příjmení" .. i])
.. (not p.empty(c.args["jméno" .. i]) and (', ' .. c.args["jméno" .. i]) or "")
;
end
if t["autor"] ~= nil then
c.state.lastAuthor = t.autor
table.insert(c.r, ""
.. (i == 1 and "" or "; ")
.. p.wikilink(c.args["odkaz na autora" .. i], t.autor)
)
end
end
function p.citCompilers(c, params)
if c.trace then p.trace(c, debug.getinfo(1, "n")) end
local t = {}, i
if params.honorCorporation and not p.empty(c.args["sestavující korporace"]) then
c.state.lastCompiler = c.args["sestavující korporace"]
table.insert(c.r, ""
.. p.wikilink(c.args["odkaz na sestavující korporaci"], c.args["sestavující korporace"])
)
else
for i = 1, 1 do
p.citCompiler(c, t, i)
end
end
if not p.empty(c.state.lastCompiler) then
if not p.empty(c.args["spolusestavitelé"]) then
c.state.lastCompiler = c.args["spolusestavitelé"]
table.insert(c.r, ", " .. c.args["spolusestavitelé"])
else
for i = 2, params.maxAuthors do
p.citCompiler(c, t, i)
end
end
end
-- pokud posledni jmeno nekonci teckou, pak ji vlozime
if c.state.lastCompiler ~= nil and p.lastChar(c.state.lastCompiler) ~= '.' then
table.insert(c.r, ".")
end
end
function p.citCompiler(c, t, i)
if c.trace then p.trace(c, debug.getinfo(1, "n")) end
local t = {}
t["sestavitel"] = nil
if not p.empty(c.args["sestavitel" .. i]) then
t["sestavitel"] = c.args["sestavitel" .. i]
elseif not p.empty(c.args["příjmení sestavitele" .. i]) then
t["sestavitel"] = p.upper(c.args["příjmení sestavitele" .. i])
.. (not p.empty(c.args["jméno sestavitele" .. i]) and (', ' .. c.args["jméno sestavitele" .. i]) or "")
;
end
if t["sestavitel"] ~= nil then
c.state.lastCompiler = t.sestavitel
table.insert(c.r, ""
.. (i == 1 and "" or "; ")
.. p.wikilink(c.args["odkaz na sestavitele" .. i], t.sestavitel)
)
end
end
-- editor, preklad apod.
-- NOTE: texty převzaty ze šablony "citace monografie" V š. "citace periodika" byly drobné rozdíly ve std. textech.
function p.citOtherPersons(c)
if c.trace then p.trace(c, debug.getinfo(1, "n")) end
local t = {}, i
t.dalsi = {}
if not p.empty(c.args["editoři"]) then
table.insert(t.dalsi, "příprava vydání " .. c.args["editoři"])
end
if not p.empty(c.args["redaktoři"]) then
table.insert(t.dalsi, "redakce " .. c.args["redaktoři"])
end
if not p.empty(c.args["překladatelé"]) then
table.insert(t.dalsi, "překlad " .. c.args["překladatelé"])
end
if not p.empty(c.args["ilustrátoři"]) then
table.insert(t.dalsi, "ilustrace " .. c.args["ilustrátoři"])
end
if not p.empty(c.args["fotografové"]) then
table.insert(t.dalsi, "fotografie " .. c.args["fotografové"])
end
if not p.empty(c.args["další"]) then
table.insert(t.dalsi, c.args["další"])
end
i = 0
for k, v in pairs(t.dalsi) do
t.v = i == 0 and " " .. p.upperFirst(v) or "; " .. v
table.insert(c.r, t.v)
i = i + 1
end
if i > 0 then
table.insert(c.r, ".")
end
end
function p.citTitle(c)
if c.trace then p.trace(c, debug.getinfo(1, "n")) end
if not p.empty(c.args["titul"]) then
table.insert(c.r, " ")
if c.type == 'citaceMonografie' then
table.insert(c.r, ""
.. "''" .. p.nowiki(c)
.. p.wikilink(c.args["odkaz na titul"], c.args["titul"])
.. p.nowiki(c) .. "''"
.. (not p.empty(c.args["titul původní"]) and " (původním názvem: ''" .. p.nowiki(c) .. c.args["titul původní"] .. p.nowiki(c) .. "'')" or "")
.. "."
)
elseif c.type == 'citaceElMonografie' then
table.insert(c.r, ""
.. "''" .. p.nowiki(c)
.. p.wikilink(c.args["odkaz na titul"], c.args["titul"])
.. p.nowiki(c) .. "''"
.. " " .. p.nowiki(c, "[") .. p.coalesceN(3, { c.args["druh nosiče"], c.args["formát"], "online" }) .. p.nowiki(c, "]")
.. "."
)
else
table.insert(c.r, ""
.. p.wikilink(c.args["odkaz na titul"], c.args["titul"])
.. "."
)
end
end
end
function p.citCompilation(c)
if c.trace then p.trace(c, debug.getinfo(1, "n")) end
if not p.empty(c.args["sborník"]) then
table.insert(c.r, " "
.. "''" .. p.nowiki(c)
.. p.wikilink(c.args["odkaz na sborník"], c.args["sborník"])
.. p.nowiki(c) .. "''"
.. "."
)
end
end
function p.citPeriodical(c)
if c.trace then p.trace(c, debug.getinfo(1, "n")) end
if not p.empty(c.args["periodikum"]) then
table.insert(c.r, " "
.. "''" .. p.nowiki(c)
.. p.wikilink(c.args["odkaz na periodikum"], c.args["periodikum"])
.. p.nowiki(c) .. "''"
.. (c.type == "citaceElPeriodika"
and " " .. p.nowiki(c, "[") .. p.coalesceN(3, { c.args["druh nosiče"], c.args["formát"], "online" }) .. p.nowiki(c, "]")
or ""
)
.. "."
)
else
table.insert(c.r, '<small>Chybí název periodika!</small>')
end
end
function p.citEdition(c)
if c.trace then p.trace(c, debug.getinfo(1, "n")) end
if not p.empty(c.args["vydání"]) then
local getNumberOnly = string.match(c.args["vydání"],"%d+") --will output only number
table.insert(c.r, " "
.. getNumberOnly .. "."
.. (not p.empty(c.args["typ vydání"]) and ", " .. c.args["typ vydání"] or "")
.. " vyd."
)
end
end
function p.citVolume(c)
if c.trace then p.trace(c, debug.getinfo(1, "n")) end
if not p.empty(c.args["svazek"]) then
table.insert(c.r, " "
.. (not p.empty(c.args["typ svazku"]) and p.upperFirst(c.args["typ svazku"]) or "Svazek")
.. " " .. c.args["svazek"] .. "."
)
end
end
-- dle ISO 690 platne od dubna 2011 uz neni vyzadovana mezera pred ":"
function p.citPlacePublisher(c)
if c.trace then p.trace(c, debug.getinfo(1, "n")) end
if c.type == 'citacePeriodika' or c.type == 'citaceElMonografie' or c.type == 'citaceElPeriodika' then
table.insert(c.r, ""
.. ((not p.empty(c.args["místo"]) or not p.empty(c.args["vydavatel"])) and " " or "")
.. "" .. (not p.empty(c.args["místo"]) and " " .. c.args["místo"] .. ": " or "")
.. "" .. (not p.empty(c.args["vydavatel"]) and p.wikilink(c.args["odkaz na vydavatele"], c.args["vydavatel"]) or "")
)
else
table.insert(c.r, ""
.. " " .. (not p.empty(c.args["místo"]) and c.args["místo"] or "[s.l.]")
.. ": " .. (not p.empty(c.args["vydavatel"]) and p.wikilink(c.args["odkaz na vydavatele"], c.args["vydavatel"]) or "[s.n.]")
)
end
end
-- NOTE: Neprehledny kod. Pokud mozno zjednodusit, pripadne take sjednotit format data.
function p.citDate(c)
if c.trace then p.trace(c, debug.getinfo(1, "n")) end
local t = {}
t.datum = not p.empty(c.args["datum"]) and c.args["datum"] or p.dateCs(c.args)
if c.type == 'citaceElMonografie' or c.type == 'citaceElPeriodika' then
if not p.empty(c.args["vydavatel"]) then
t.finalDot = true;
end
if not p.empty(t.datum) then
t.finalDot = true;
table.insert(c.r, ""
.. (not p.empty(c.args["vydavatel"]) and ", " .. t.datum or " " .. p.upperFirst(t.datum))
)
end
if not p.empty(c.args["datum aktualizace"]) then
t.finalDot = true;
if not p.empty(c.args["vydavatel"]) or not p.empty(t.datum) then
table.insert(c.r, ", " .. p.coalesce(c.args["typ aktualizace"], "rev."))
elseif not p.empty(c.args["místo"]) then
table.insert(c.r, " " .. p.coalesce(c.args["typ aktualizace"], "rev."))
else
table.insert(c.r, " " .. p.upperFirst(p.coalesce(c.args["typ aktualizace"], "rev.")))
end
table.insert(c.r, " " .. c.args["datum aktualizace"])
end
if not p.empty(c.args["datum přístupu"]) then
t.finalDot = true;
table.insert(c.r, " ")
if not c.localTest and c.type == 'citaceElMonografie' then
table.insert(c.r, "[cit. " .. p.frame:callParserFunction('#time', 'Y-m-d', p.normDate(c.args["datum přístupu"])) .. "]")
else
table.insert(c.r, "[cit. " .. p.normDate(c.args["datum přístupu"]) .. "]")
end
end
if (t.finalDot) then
table.insert(c.r, ".")
end
elseif c.type == "citacePeriodika" then
if not p.empty(c.args["vydavatel"]) then
t.finalDot = true;
end
t.datum = p.dateCs(c.args)
if c.useHarvardFormat and t.datum == c.args["rok"] then
t.datum = ""
end
if not p.empty(t.datum) then
c.state.isDatum = true
if not p.empty(c.args["vydavatel"]) then
table.insert(c.r, ", " .. t.datum)
else
table.insert(c.r, " " .. p.upperFirst(t.datum))
end
else
if t.finalDot then
table.insert(c.r, ".")
end
end
else
t.datum = p.dateCs(c.args) -- was p.date
if c.useHarvardFormat and t.datum == c.args["rok"] then
t.datum = ""
t.finalDot = true
end
if t.datum ~= "" then
table.insert(c.r, ", " .. t.datum)
elseif not p.empty(c.args["rok copyrightu"]) then
table.insert(c.r, ", c" .. c.args["rok copyrightu"])
end
if not p.empty(c.args["rok tisku"]) then
if not p.empty(c.args["rok"]) or not p.empty(c.args["rok copyrightu"]) then
table.insert(c.r, " (")
else
table.insert(c.r, ", ")
end
table.insert(c.r, p.dateCs(c.args, { postfix = " tisku" }) .. " tisk") -- was p.date
if not p.empty(c.args["rok"]) or not p.empty(c.args["rok copyrightu"]) then
table.insert(c.r, ")")
end
end
if t.datum ~= "" or not p.empty(c.args["rok tisku"]) or t.finalDot then
table.insert(c.r, ".")
end
end
end
-- refact/fix 1.6.2018
function p.citYearNumberPage(c)
if c.trace then p.trace(c, debug.getinfo(1, "n")) end
local t = {}
t.ar = {}
if not p.empty(c.args["ročník"]) then
table.insert(t.ar, (not p.empty(c.args["typ ročníku"]) and c.args["typ ročníku"] or "roč.") .. " " .. c.args["ročník"])
end
if not p.empty(c.args["číslo"]) then
table.insert(t.ar, (not p.empty(c.args["typ čísla"]) and c.args["typ čísla"] or "čís.") .. " " .. c.args["číslo"])
end
if not p.empty(c.args["strany"]) then
table.insert(t.ar, "s. " .. c.args["strany"])
end
-- test array length
if #t.ar > 0 then
if c.state.isDatum then
table.insert(c.r, ", " .. table.concat(t.ar, ", ") .. ".")
else
table.insert(c.r, " " .. p.upperFirst(table.concat(t.ar, ", ")) .. ".")
end
elseif c.state.isDatum then
table.insert(c.r, ".")
end
end
-- refact 8.5.2018
function p.citChapterPage(c)
if c.trace then p.trace(c, debug.getinfo(1, "n")) end
local t = {}
t.ar = {}
if not p.empty(c.args["kapitola"]) then
table.insert(t.ar, ""
.. (not p.empty(c.args["typ kapitoly"]) and p.upperFirst(c.args["typ kapitoly"]) or "Kapitola")
.. " "
.. p.wikiextlink(c.args["url kapitoly"], c.args["kapitola"])
)
end;
if not p.empty(c.args["číslování"]) then
table.insert(t.ar, c.args["číslování"])
end
if not p.empty(c.args["strany"]) then
table.insert(t.ar, "s. " .. c.args["strany"])
end
if not p.empty(c.args["lokace"]) then
table.insert(t.ar, c.args["lokace"])
end
-- test array length
if #t.ar > 0 then
table.insert(c.r, " " .. p.upperFirst(table.concat(t.ar, ", ")) .. ".")
end
end
-- pocetSvazku, pocetStranPlusPrilohy
function p.citNumberOfVolumesPagesAppendices(c)
if c.trace then p.trace(c, debug.getinfo(1, "n")) end
local t = {}
t.pocetSvazku = ""
if not p.empty(c.args["počet svazků"]) and (tonumber(c.args["počet svazků"]) or 0) > 1 then
t.pocetSvazku = " "
.. c.args["počet svazků"]
.. " "
.. p.plural(c.args["počet svazků"], "svazek", "svazky", "svazků")
;
end
if c.type == "citaceMonografie" then
if not p.empty(c.args["qid"]) then
local pocetStranFromWikidata=p.getNumberOfPagesFromWikidata(c)
if pocetStranFromWikidata ~= false then
c.args["počet stran"]=pocetStranFromWikidata
end
end
end
if not p.empty(c.args["počet stran"]) then --will get only first number (in case the input contains text or other unwanted characters)
local makePocetStranNumberOnly = c.args["počet stran"]:gsub(" ", "")
makePocetStranNumberOnly = string.match(makePocetStranNumberOnly,"%d+")
c.args["počet stran"]=makePocetStranNumberOnly
end
if not p.empty(c.args["počet stran"]) then
t.pocetStranPlusPrilohy = ""
.. c.args["počet stran"] .. " s."
.. (not p.empty(c.args["přílohy"]) and ", " .. c.args["přílohy"] or "")
;
else
t.pocetStranPlusPrilohy = ""
.. (not p.empty(c.args["přílohy"]) and c.args["přílohy"] or "")
;
end
if t.pocetSvazku ~= "" then
if (t.pocetStranPlusPrilohy ~= "") then
table.insert(c.r, t.pocetSvazku .. " (" .. t.pocetStranPlusPrilohy .. ").")
else
table.insert(c.r, t.pocetSvazku .. ".")
end
else
if (t.pocetStranPlusPrilohy ~= "") then
table.insert(c.r, " " .. t.pocetStranPlusPrilohy)
if p.lastChar(t.pocetStranPlusPrilohy) ~= "." then
table.insert(c.r, ".")
end
end
end
end
function p.citBookSeries(c)
if c.trace then p.trace(c, debug.getinfo(1, "n")) end
if not p.empty(c.args["edice"]) then
table.insert(c.r, " "
.. "("
.. p.upperFirst(c.args["edice"])
.. (not p.empty(c.args["subedice"]) and ". " .. p.upperFirst(c.args["subedice"]) or "")
.. (not p.empty(c.args["svazek edice"]) and p.nowiki(c, ';') .. " sv. " .. c.args["svazek edice"] or "")
.. ")."
)
end
end
function p.citUrl(c)
if c.trace then p.trace(c, debug.getinfo(1, "n")) end
local t = {}
if c.type == 'citacePeriodika' then
if not p.empty(c.args["url"]) then
t.afterUrl = {}
if not p.empty(c.args["formát"]) then
table.insert(t.afterUrl, c.args["formát"])
end
if not p.empty(c.args["datum přístupu"]) then
table.insert(t.afterUrl, "cit. " .. c.args["datum přístupu"])
elseif not p.empty(c.args["rok přístupu"]) then
table.insert(t.afterUrl, "cit. " .. c.args["rok přístupu"]
.. (not p.empty(c.args["měsíc přístupu"])
and "-" .. c.args["měsíc přístupu"] .. (not p.empty(c.args["den přístupu"]) and "-" .. c.args["den přístupu"] or "")
or ""
))
;
end
t.afterUrlStr = table.concat(t.afterUrl, ", ");
if t.afterUrlStr ~= "" then
t.afterUrlStr = " " .. p.nowiki(c, "[") .. t.afterUrlStr .. "]"
end
c.state.afterUrlStr = t.afterUrlStr
p.citUrlInnerFn(c)
end
else
if not p.empty(c.args["url"]) then
p.citUrlInnerFn(c)
end
end
-- citacePeriodika
--if not p.empty(c.args["url alt"]) then
--table.insert(c.r, " [" .. c.args["url alt"] .. " (Alternativní odkaz)]")
--end
-- citaceElMonografie, citaceElPeriodika
if not p.empty(c.args["url2"]) then
table.insert(c.r, " "
.. p.coalesce(c.args["dostupnost2"], "Dostupné také na:")
.. " "
.. p.wikiextlink(c.args["url2"])
.. "."
)
end
if not p.empty(c.args["url3"]) then
table.insert(c.r, " "
.. p.coalesce(c.args["dostupnost3"], "Dále dostupné na:")
.. " "
.. p.wikiextlink(c.args["url3"])
.. "."
)
end
end
function p.citUrlInnerFn(c)
local t = {}
if not p.empty(c.args["url archivu"]) then
t.liveUrl = c.args["nedostupné"] ~= "ano" and c.args["dead-url"] ~= "yes" and c.args["deadurl"] ~= "yes"
table.insert(c.r, " "
.. p.wikiextlink(c.args["url archivu"], p.coalesce(c.args["dostupnost"], "Dostupné v archivu"))
.. ((t.liveUrl or not p.empty(c.args["datum archivace"])) and " pořízeném" or "")
.. (t.liveUrl and " z " .. p.wikiextlink(c.args["url"], "originálu") or "")
.. (not p.empty(c.args["datum archivace"]) and " dne " .. c.args["datum archivace"] or "")
.. "."
)
else
table.insert(c.r, " "
.. p.wikiextlink(c.args["url"], p.coalesce(c.args["dostupnost"], "Dostupné online"))
.. (c.state.afterUrlStr and c.state.afterUrlStr or "")
.. "."
)
end
end
function p.citIsbn(c)
if c.trace then p.trace(c, debug.getinfo(1, "n")) end
if not p.empty(c.args["isbn"]) then
-- OLD
-- table.insert(c.r, " [.[International Standard Book Number|ISBN].] [https://worldcat.org/isbn/" .. c.args["isbn"] .. " " .. c.args["isbn"] .. "].")
-- NEW
if c.localTest then
table.insert(c.r, " "
.. "{{ISBN|{{{isbn}}}}}"
.. (not p.empty(c.args["isbn2"]) and ", {{ISBN|{{{isbn2}}}}}" or "")
.. "."
)
else
table.insert(c.r, " "
.. c.frame:expandTemplate{title = 'ISBN', args = { c.args["isbn"] }}
.. (not p.empty(c.args["isbn2"]) and ", " .. c.frame:expandTemplate{title = 'ISBN', args = { c.args["isbn2"] }} or "")
.. "."
)
end
end
end
function p.citIssn(c)
if c.trace then p.trace(c, debug.getinfo(1, "n")) end
if not p.empty(c.args["issn"]) then
table.insert(c.r, " [[w:International Standard Serial Number|ISSN]] [https://worldcat.org/issn/" .. c.args["issn"] .. " " .. c.args["issn"] .. "].")
end;
end
function p.citDoi(c)
if c.trace then p.trace(c, debug.getinfo(1, "n")) end
if not p.empty(c.args["doi"]) then
table.insert(c.r, " [[w:Digital object identifier|DOI]]:[http://dx.doi.org/" .. mw.uri.encode(c.args["doi"]) .. " " .. c.args["doi"] .. "].")
end;
end
function p.citOclc(c)
if c.trace then p.trace(c, debug.getinfo(1, "n")) end
if not p.empty(c.args["oclc"]) then
table.insert(c.r, " [[w:Online Computer Library Center|OCLC]] [https://worldcat.org/oclc/" .. mw.uri.encode(c.args["oclc"]) .. " " .. c.args["oclc"] .. "]")
end;
end
function p.citPmid(c)
if c.trace then p.trace(c, debug.getinfo(1, "n")) end
if not p.empty(c.args["pmid"]) then
table.insert(c.r, " [[w:PubMed|PMID]] [https://www.ncbi.nlm.nih.gov/pubmed/" .. c.args["pmid"] .. " <span class='PMID'>" .. c.args["pmid"] .. "</span>].")
end;
end
function p.citBibcode(c)
if c.trace then p.trace(c, debug.getinfo(1, "n")) end
if not p.empty(c.args["bibcode"]) then
table.insert(c.r, " [[w:Bibcode]]:[http://adsabs.harvard.edu/abs/" .. mw.uri.encode(c.args["bibcode"]) .. " " .. c.args["bibcode"] .. "].")
end;
end
function p.citArxiv(c)
if c.trace then p.trace(c, debug.getinfo(1, "n")) end
if not p.empty(c.args["arxiv"]) then
table.insert(c.r, " [[w:arXiv]]:[http://arxiv.org/abs/" .. mw.uri.encode(c.args["arxiv"]) .. " " .. c.args["arxiv"] .. "].")
end;
end
function p.citId(c)
if c.trace then p.trace(c, debug.getinfo(1, "n")) end
if not p.empty(c.args["id"]) then
table.insert(c.r, " " .. c.args["id"] .. ".")
end;
end
function p.citNotes(c)
if c.trace then p.trace(c, debug.getinfo(1, "n")) end
if not p.empty(c.args["poznámky"]) then
table.insert(c.r, " " .. p.upperFirst(c.args["poznámky"]) .. ".")
end;
end
function p.checkPeriodical(c)
if c.trace then p.trace(c, debug.getinfo(1, "n")) end
local t = {}
if p.empty(c.args["periodikum"]) then
if c.localTest then
t.chyba = '{{chyba|Chybí povinný parametr: V šabloně {{šablona|Citace periodika}} je nutno určit zdrojové "<code>periodikum</code>" odkazu!|kategorie=Stránky s chybným voláním citačních šablon|skrytý=skrytý}}'
else
t.chyba = c.frame:expandTemplate{title = 'chyba', args = {
'Chybí povinný parametr: V šabloně '
.. c.frame:expandTemplate{title = 'šablona', args = {'Citace periodika'}}
.. ' je nutno určit zdrojové "<code>periodikum</code>" odkazu!',
['kategorie'] = 'Stránky s chybným voláním citačních šablon',
['skrytý'] = 'skrytý'
}}
end
table.insert(c.r, t.chyba)
end;
end
-- Return only primary language subtag from IETF language tag
function p.sanitizeLang(s)
if type(s) ~= 'string' then return s end
return mw.ustring.match(s, "^([a-z][a-z][a-z]?)-[A-Za-z][A-Za-z][A-Za-z]?$") or s
end
function p.citLanguage(c)
if c.trace then p.trace(c, debug.getinfo(1, "n")) end
local t = {}
if not p.empty(c.args["jazyk"]) then
if c.localTest then
t.jazykem = c.args["jazyk"]
else
t.jazykem = c.frame:expandTemplate{title = 'jazykem', args = { p.sanitizeLang(c.args["jazyk"]), toleruj = 'toleruj'}}
end
table.insert(c.r, " (" .. t.jazykem .. ")")
end;
end
function p.citCoinsMonografie(c)
if c.noCoins then return end
if c.trace then p.trace(c, debug.getinfo(1, "n")) end
local t = {}
if c.type == 'citaceElMonografie' then
t.tplName = 'citaceelmonografie'
else
t.tplName = 'citacemonografie'
end
t.coins = 'ctx_ver=Z39.88-2004&rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Abook&rfr_id=info:sid/cs.wikipedia.org:template' .. t.tplName
.. '&rft.btitle=' .. mw.uri.encode(p.coalesce(c.args["titul"]))
.. (not p.empty(c.args["doi"]) and "&rft_id=info:doi/" .. mw.uri.encode(c.args["doi"]) or "")
.. (not p.empty(c.args["url"]) and "&rft_id=" .. mw.uri.encode(c.args["url"]) or "")
.. (not p.empty(c.args["isbn"]) and "&rft.isbn=" .. mw.uri.encode(c.args["isbn"]) or "")
.. (not p.empty(c.args["příjmení1"]) and "&rft.aulast=" .. mw.uri.encode(c.args["příjmení1"]) or "")
.. (not p.empty(c.args["jméno1"]) and "&rft.aufirst=" .. mw.uri.encode(c.args["jméno1"]) or "")
.. (not p.empty(c.args["autor1"]) and "&rft.au=" .. mw.uri.encode(c.args["autor1"]) or "")
.. (not p.empty(c.args["příjmení2"]) and "&rft.au=" .. mw.uri.encode(c.args["příjmení2"] .. ", " .. p.coalesce(c.args["jméno2"])) or "")
.. (not p.empty(c.args["autor2"]) and "&rft.au=" .. mw.uri.encode(c.args["autor2"]) or "")
.. (not p.empty(c.args["příjmení3"]) and "&rft.au=" .. mw.uri.encode(c.args["příjmení3"] .. ", " .. p.coalesce(c.args["jméno3"])) or "")
.. (not p.empty(c.args["autor3"]) and "&rft.au=" .. mw.uri.encode(c.args["autor3"]) or "")
.. (not p.empty(c.args["korporace"]) and "&rft.aucorp=" .. mw.uri.encode(c.args["korporace"]) or "")
.. (not p.empty(c.args["kapitola"]) and "&rft.atitle=" .. mw.uri.encode(c.args["kapitola"]) or "")
.. (not p.empty(c.args["místo"]) and "&rft.place=" .. mw.uri.encode(c.args["místo"]) or "")
.. (not p.empty(c.args["vydavatel"]) and "&rft.pub=" .. mw.uri.encode(c.args["vydavatel"]) or "")
.. (not p.empty(c.args["rok"]) and "&rft.date=" .. mw.uri.encode(c.args["rok"]) or "")
.. (not p.empty(c.args["vydání"]) and "&rft.edition=" .. mw.uri.encode(c.args["vydání"]) or "")
.. (not p.empty(c.args["počet stran"]) and "&rft.tpages=" .. mw.uri.encode(c.args["počet stran"]) or "")
.. (not p.empty(c.args["edice"]) and "&rft.series=" .. mw.uri.encode(c.args["edice"]) or "")
.. (not p.empty(c.args["strany"]) and "&rft.pages=" .. mw.uri.encode(c.args["strany"]) or "")
;
if c.localTest then
t.coins = "(COinS:" .. t.coins .. ")"
else
t.coins = c.frame:expandTemplate{title = 'COinS', args = { obj = t.coins }}
end
table.insert(c.r, t.coins)
end
function p.citCoinsPeriodikum(c)
if c.noCoins then return end
if c.trace then p.trace(c, debug.getinfo(1, "n")) end
local t = {}
if c.type == 'citaceElPeriodika' then
t.tplName = 'citaceelperiodika'
else
t.tplName = 'citaceperiodika'
end
t.coins = 'ctx_ver=Z39.88-2004&rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Ajournal&rfr_id=info:sid/cs.wikipedia.org:template' .. t.tplName
.. '&rft.jtitle=' .. mw.uri.encode(p.coalesce(c.args["periodikum"]))
.. (not p.empty(c.args["doi"]) and "&rft_id=info:doi/" .. mw.uri.encode(c.args["doi"]) or "")
.. (not p.empty(c.args["url"]) and "&rft_id=" .. mw.uri.encode(c.args["url"]) or "")
.. (not p.empty(c.args["titul"]) and "&rft.atitle=" .. mw.uri.encode(c.args["titul"]) or "")
.. (not p.empty(c.args["datum"])
and "&rft.date=" .. mw.uri.encode(c.args["datum"])
or (not p.empty(c.args["rok"])
and "&rft.date=" .. mw.uri.encode(c.args["rok"])
.. (not p.empty(c.args["měsíc"])
and "&rft.chron=" .. (not p.empty(c.args["den"])
and mw.uri.encode(c.args["den"]) .. ". "
or ""
) .. mw.uri.encode(c.args["měsíc"])
or ""
)
or ""
)
)
.. (not p.empty(c.args["ročník"]) and "&rft.volume=" .. mw.uri.encode(c.args["ročník"]) or "")
.. (not p.empty(c.args["číslo"]) and "&rft.issue=" .. mw.uri.encode(c.args["číslo"]) or "")
.. (not p.empty(c.args["strany"]) and "&rft.pages=" .. mw.uri.encode(c.args["strany"]) or "")
.. (not p.empty(c.args["issn"]) and "&rft.issn=" .. mw.uri.encode(c.args["issn"]) or "")
.. (not p.empty(c.args["příjmení1"]) and "&rft.aulast=" .. mw.uri.encode(c.args["příjmení1"]) or "")
.. (not p.empty(c.args["jméno1"]) and "&rft.aufirst=" .. mw.uri.encode(c.args["jméno1"]) or "")
.. (not p.empty(c.args["autor1"]) and "&rft.au=" .. mw.uri.encode(c.args["autor1"]) or "")
.. (not p.empty(c.args["příjmení2"]) and "&rft.au=" .. mw.uri.encode(c.args["příjmení2"] .. ", " .. p.coalesce(c.args["jméno2"])) or "")
.. (not p.empty(c.args["autor2"]) and "&rft.au=" .. mw.uri.encode(c.args["autor2"]) or "")
.. (not p.empty(c.args["příjmení3"]) and "&rft.au=" .. mw.uri.encode(c.args["příjmení3"] .. ", " .. p.coalesce(c.args["jméno3"])) or "")
.. (not p.empty(c.args["autor3"]) and "&rft.au=" .. mw.uri.encode(c.args["autor3"]) or "")
.. (not p.empty(c.args["korporace"]) and "&rft.aucorp=" .. mw.uri.encode(c.args["korporace"]) or "")
.. (not p.empty(c.args["místo"]) and "&rft.place=" .. mw.uri.encode(c.args["místo"]) or "")
.. (not p.empty(c.args["vydavatel"]) and "&rft.pub=" .. mw.uri.encode(c.args["vydavatel"]) or "")
.. (not p.empty(c.args["počet stran"]) and "&rft.tpages=" .. mw.uri.encode(c.args["počet stran"]) or "")
;
if c.localTest then
t.coins = "(COinS:" .. t.coins .. ")"
else
t.coins = c.frame:expandTemplate{title = 'COinS', args = { obj = t.coins }}
end
table.insert(c.r, t.coins)
end
-------------------------------------
-- Fetches QID from text and returns it
-- If not found, returns "false"
-- in case the templatedata adjustment is not working, otherwise CAN BE DELETED
-------------------------------------
-- @param notes - Text generated by citation tool and taken from arg "poznámky"
-------------------------------------
function p.getQID(notes)
if p.empty(notes) then
return false
end
local qidStringIdentifier = "qid:"
local qidStringIdentifierLen = string.len(qidStringIdentifier)
local notesLowerCase = notes:lower() --in case qiD would be like ThIs
local search = string.find(notesLowerCase, qidStringIdentifier)
if search == nil then
return false --QID not found
else
local notesStripBeginning = notes:sub(search + qidStringIdentifierLen) --get only string after "qid:"
local QID = notesStripBeginning:match("(%w+)") --get first word
if p.empty(QID) then
return false
end
return QID
end
end
-------------------------------------
-- Returns value of property for wikidata id, defaultly searches for current item QID
-- If no QID exists or no id specified, returns "false"
-------------------------------------
-- Uses submodule Modul:Wikidata
-------------------------------------
-- @param property - Property to get value from
-- @param limit - How many values return (in case there are multiple values within 1 property), Default: 1
-- @param includeLinks - If links should be included in output of this func, Default: false => suppress
-- @param formatterType - fill as parameter "value-formatter" in Wikidata.formatStatements, optional parameter
-- @param separator - fill as parameter "separator" + "conjunction" in Wikidata.formatStatements, optional parameter
-- @param id - fill as parameter "id" in Wikidata.formatStatements, optional parameter
-- @param precision - fill as parameter "precision" in Wikidata.formatStatements, optional parameter (0-15; 9 = years, 10 = months, 11 = days)
-------------------------------------
function p.getWikidataPropertyValue(c, property, limit, includeLinks, formatterType, separator, id, precision)
if p.empty(property) then
return false
end
limit = limit or 1 --default value
if includeLinks == nil then
includeLinks = false --default value
end
local submoduleWikidata = require("Modul:Wikidata")
local qid = ""
if not p.empty(id) then --prioritizing id parameter
qid = id
end
if p.empty(qid) and not p.empty(c.args["qid"]) then --if not inputed, will try to take argument "qid"
qid = c.args["qid"]
end
if p.empty(qid) then -- we don't have any id, terminate here
return false
end
local arrayOfAttributesFormatStatements = {}
arrayOfAttributesFormatStatements.id = qid
arrayOfAttributesFormatStatements.property = property
arrayOfAttributesFormatStatements.limit = limit
arrayOfAttributesFormatStatements.addclass = includeLinks --do not include links in the output of this function
if not p.empty(formatterType) then
arrayOfAttributesFormatStatements["value-formatter"] = formatterType
end
if not p.empty(separator) then
arrayOfAttributesFormatStatements.conjunction = separator
arrayOfAttributesFormatStatements.separator = separator
end
if not p.empty(precision) then
arrayOfAttributesFormatStatements.precision = precision
end
local output = submoduleWikidata.formatStatements(arrayOfAttributesFormatStatements)
if p.empty(output) then
return false
end
return output
end
-------------------------------------
-- Returns value of property for wikidata id, defaultly searches for current item QID
-- If no QID exists or no id specified, returns "false"
-- Needed function, because unfortunately Wikidata.formatStatements returns object with CSS+link for "years" even when called with "addclass" set to false
-- This Wikidata submodule does not currently respect limit parameter and always returns max 1 value...
-- This Wikidata submodule does not currently respect precision parameter as well....
-------------------------------------
-- Uses submodule Modul:Wikidata
-------------------------------------
-- @param property - Property to get value from
-- @param formatterType - fill as parameter "value-formatter" in Wikidata.formatStatements, optional parameter
-- @param id - fill as parameter "id" in Wikidata.formatStatements, optional parameter
-- @param precision - fill as parameter "precision" in Wikidata.formatStatements, optional parameter (0-15; 9 = years, 10 = months, 11 = days)
-------------------------------------
function p.getWikidataPropertyRAWValue(c, property, formatterType, id, precision)
if p.empty(property) then
return false
end
local submoduleWikidata = require("Modul:Wikidata")
local qid = ""
if not p.empty(id) then --prioritizing id parameter
qid = id
end
if p.empty(qid) and not p.empty(c.args["qid"]) then --if not inputed, will try to take argument "qid"
qid = c.args["qid"]
end
if p.empty(qid) then -- we don't have any id, terminate here
return false
end
local arrayOfAttributesFormatStatements = {}
arrayOfAttributesFormatStatements.id = qid
arrayOfAttributesFormatStatements.property = property
if not p.empty(formatterType) then
arrayOfAttributesFormatStatements["value-formatter"] = formatterType
end
if not p.empty(precision) then
arrayOfAttributesFormatStatements.precision = precision
end
local output = submoduleWikidata.getRawValue(arrayOfAttributesFormatStatements)
if p.empty(output) then
return false
end
return output
end
-------------------------------------
-- Returns label of property
-- if parameter property is empty, return false
-------------------------------------
-- Uses submodule Modul:Wikidata
-------------------------------------
-- @param property - Property to get label of
-------------------------------------
function p.getWikidataPropertyLabel(c, property)
if p.empty(property) then
return false
end
local submoduleWikidata = require("Modul:Wikidata")
local arrayOfAttributesLabel = {}
arrayOfAttributesLabel.id = property
return submoduleWikidata.getLabel(arrayOfAttributesLabel)
end
-------------------------------------
-- Returns url from wikidata for current item's QID
-- uses hardcoded property p953 from Wikidata for URL output
-- if not found, return false
-------------------------------------
function p.getUrlFromWikidata(c)
if p.empty(c.args["qid"]) then
return false
end
local property = "p953" --hardcoded property of source data
--local label = p.getWikidataPropertyLabel(c, property)
--label = label:sub(1,1):upper()..label:sub(2)..": " --uppercase first letter
--not needed anymore, using the standard function for outputting
local url =
p.getWikidataPropertyValue(
c,
property, --p953
1, --limit
false --includeLinks
)
if p.empty(url) or url == false then
return false
end
return url
end
-------------------------------------
-- Replaces p.Language for p.citaceMonografie
-- if QID is empty, return false
-------------------------------------
function p.citLanguageMonografieStyle(c)
if p.empty(c.args["qid"]) then
return false
end
local formatterType = "wikibase-entityrawids" --new formatter which gets only QID of returned values
local separator = ";"
local csLangSkip = "Q9056" -- =skip czech language, do not output it...
local output = ""
local LanguageOfWorkOrNameProperty = "p407" -- language of work or name
local LanguageOfWorkOrNameOutputPropertyValue = "p218" --value of this property will be used for output
local LanguageOfWorkOrNameIds =
p.getWikidataPropertyValue(
c,
LanguageOfWorkOrNameProperty, --p407
5, --limit - fetch up to 5 languages, can be increased if needed
false, --includeLinks
formatterType, --formatter type "wikibase-entityrawids"
separator --separator ";"
)
if LanguageOfWorkOrNameIds == false then --p407 not found for this QID
return false
end
local currentOutputValue = ""
for getId in LanguageOfWorkOrNameIds:gmatch("([^" .. separator .. "]+)") do --go through all returned ids
if string.upper(getId) ~= csLangSkip then --if it is Q9056, skip it (no "continue" in Lua?), upper just in case...
currentOutputValue =
p.getWikidataPropertyValue(
c,
LanguageOfWorkOrNameOutputPropertyValue, --p218 = ISO 639-1 code
1, --limit - fetch first value, not expecting there will be more anyway
false, --includeLinks
nil, --formatter type
nil, --separator
getId -- id of wikidata value
)
if currentOutputValue ~= false then --we have iso code for this language
if not p.empty(output) then --add separator between multiple languages
output = output .. ", "
end
output = output .. currentOutputValue
end
end
end
if p.empty(output) then
return false
end
--output not empty, can add to final table
table.insert(c.r, " (" .. output .. ") ")
return true -- in case we would otherwise wanted to call former function
end
-------------------------------------
-- returns "year, month, day" for current item from Wikidata
-- if QID is empty or nothing found, return false
-------------------------------------
function p.getRokMesicDenVydaniFromWikidata(c)
if p.empty(c.args["qid"]) then
return false --checked in getWikidataPropertyRAWValue as well, but for performance and safety reasons
end
local precision = "11" --set precision to days...not working anyway..
local property = "p577" --publication date
local output =
p.getWikidataPropertyRAWValue(
c,
property, --p577 = publication date
nil, --formatter type
nil, -- id of wikidata value-will use QID
precision -- 11 = days, not respected by submodule anyway
)
if output == false then
return false
end
return output["year"], output["month"], output["day"]
end
-------------------------------------
-- returns place of publication for current item from Wikidata
-- if QID is empty or nothing found, return false
-------------------------------------
function p.getPlaceOfPublicationFromWikidata(c)
if p.empty(c.args["qid"]) then
return false --checked in getWikidataPropertyValue as well, but for performance and safety reasons
end
local property = "p291" --place of publication
local separator = ", "
local placeOfPublicationValues =
p.getWikidataPropertyValue(
c,
property, --"p291" --place of publication
5, --limit - fetch up to 5 places, can be increased
false, --includeLinks
nil, --formatter type
separator --separator ", "
)
return placeOfPublicationValues
end
-------------------------------------
-- returns number of pages from Wikidata for current item
-- if QID is empty, return false (if called for some other reason)
-------------------------------------
function p.getNumberOfPagesFromWikidata(c)
if p.empty(c.args["qid"]) then
return false --checked in getWikidataPropertyValue as well, but for performance and safety reasons
end
local property = "p1104" --number of pages
local limit = "1" --take only first record
local numberOfPages =
p.getWikidataPropertyValue(
c,
property, --"p1104" --place of publication
limit, --limit - fetch only first
false, --includeLinks
nil, --formatter type
nil --separator
)
if numberOfPages == false then
return false
end
return numberOfPages
end
-------------------------------------
-- formatting QID output + inserting straight to citation output
-- deletes qid from "poznámky"
-------------------------------------
function p.citQID(c)
if p.empty(c.args["qid"]) then
local qid = p.getQID(c.args["poznámky"])
if qid ~= false then
c.args["qid"] = qid
end
end
if not p.empty(c.args["qid"]) then
table.insert(c.r, " QID [[d:" .. c.args["qid"] .. "|" .. c.args["qid"] .. "]]") --output current qid
--tries to delete qid from poznámky
if not p.empty(c.args["poznámky"]) then
local poznamkyCut = string.gsub(c.args["poznámky"], "QID: " .. c.args["qid"], "")
c.args["poznámky"] = poznamkyCut
end
end
end
return p