Modul:Wikidata

Wikidata[mi ez?] • [dokumentáció: mutat, szerkeszt] • [tesztek: sikeres: 11, sikertelen: 0, kihagyva: 0 (részletek)]

Wikidata-adatok formázott megjelenítése, a {{Wikidata}} sablon implementációja.

Wikikódból hívható függvények

formatStatements

Paraméterek

property
A Wikidatában tárolt tulajdonság azonosítója. Megadható névvel is. Például p856.
value
A Wikidatában tárolt érték helyett megjelenítendő érték.
entityId
A cikkhez kapcsolt Wikidata-elem helyett a megadott Wikidata-elemből olvassa ki a tulajdonság értékét.
pageTitle
A Wikidatához kapcsolt lap címe. Nem adható entityId-vel együtt.
qualProp
Állítás minősítőjének tulajdonságazonosítója. Példa: P548.
qualValue
A szűrésnél alkalmazott érték. Több érték is adható, vesszővel elválasztva. Példa: Q3295609,Q51930650,Q2122918,Q21727724,Q1072356.
direction
Koordináták dimenziója. Értéke latitude, longitude vagy both lehet: az első kettő a további gépi feldolgozásra alkalmas számot adja vissza, a harmadik a Modul:Coordinate segítségével formázott eredményt ad.
link
Értéke nem, ha azt szeretnénk, hogy a függvény értéke ne link legyen, hanem csak a címke; csak, ha pedig azt szeretnénk, hogy csak a kapcsolt Wikipédia-szócikk.
externalId
Helyileg megadott külső azonosító formázása Wikidata helyett. Külső azonosítóknál ezt kell megadni második paraméter helyett!
externalIdLabel
Külső azonosítóhoz tartozó hivatkozás megjelenítési szövege.
link szövege
URL típusú tulajdonság hivatkozásának megjelenő szövege. Visszamenőleges kompatibilitás miatt format=wikilink beállítást tesz szükségessé. Üres érték esetén számozott hivatkozás jelenik meg. Ha csak format van megadva, a tulajdonság neve lesz a szöveg.
lang
A címke nyelvének megadása, több nyelv esetén vesszővel elválasztva, szóköz nélkül, ekkor az első olyan nyelven jeleníti meg a címkét, amin létezik. Alapértelmezetten hu,en. Nyelvvel jelölt szövegek (monolingual text) esetén a nyelv szűrőfeltétele. all értékkel nincs szűrés.
first
Ha azt szeretnénk, hogy csak egy értéket adjon vissza, például képeknél.
showQualifiers
Összes minősítő megjelenítése, vagy megadott minősítők megjelenítése (ha a paraméterérték tulajdonságazonosítók listája, pl. P580, P582).
showReferences
Forráshivatkozások megjelenítése. Alapértelmezetten legfeljebb 5 forráshivatkozás jelenik meg; ha a paraméter értéke egy pozitív egész szám, akkor annyi a limit, ha 0, akkor pedig az összes (esetenként több tucat!) forráshivatkozás megjelenik.
rank
Értékei: preferred, normal, deprecated, all, valid. Ha nincs megadva, akkor a legmagasabb rangúakat adja vissza. A valid a preferred és a normal együttesen.
életkor
Értéke igen.
felsorolás
Az értékek felsorolásának típusa:
lista
pöttyözött lista
számozott lista
számozott lista
sorok
több érték esetén felsorolásjel nélküli lista, egy érték esetén sima szöveg (alapértelmezett)
szöveg
folyószöveg (értékek között vesszővel, utolsó érték előtt „és”-sel)
table
Lua-tömb
lenyíló
Hosszú listák megjelenítése nyitható listaként. Értéke egy szám. Ha a listának több eleme van, akkor nyitható listaként fog megjelenni. Lista, számozott lista és sorok felsorolásnál használható. Példa: Földközi-tenger.
format
raw
tárolt érték formázás nélkül
default
népesség formázása a {{Népesség}}(?) sablon alapmegjelenítése szerint
iso
dátum ISO 8601 formátumban
date-object
dátum a Modul:Time objektumával (csak modulból hívva van értelme)
percentage
számok megjelenítése százalékként
url
URL, például külső azonosító címe
wikilink
URL típusú tulajdonság formázása wikiszöveges külső hivatkozásként
sort
Rendezés több érték estén: üres vagy logikai igaz esetén címke szerint, Pxxx esetén a Pxxx minősítő szerint (a megadott minősítőket előre rendezve), egyébként a sort függvénnyel. sortDesc paraméter jelenléte esetén csökkenő sorrendben történik a rendezés.
sortDesc
Rendezés csökkenő sorrendben. A paraméter jelenléte esetén csökkenő sorrendben történik a rendezés, különben növekvő sorrendben.
dateformat
Dátumformátum a {{#time:}} értelmezőfüggvénynek (csak a népesség dátumánál működik, más helyzetben a változó pontosság – napra pontostól az évmilliárdig bármi lehet – és a függvény behatároltsága – csak 111-től 9999-ig értelmezi az éveket – miatt nincs értelme megadni egy fix formátumot).
punctuation
Központozás az utolsó érték és esetleges minősítői után, de a hozzá tartozó forráshivatkozás előtt. Általában felsorolás=lista esetén van értelme.

containsProperty

Wikidata-tulajdonság meglétének vizsgálata. Lásd {{Wikidata-f}}.

Luából hívható függvények

containsPropertyWithValue

Tulajdonág értékének vizsgálata.

withHighestRank

Tulajdonság értékeinek szűrése a legmagasabb fokozattal (rank) rendelkező értékekre.

formatStatement

Tulajdonság egy értékének formázott megjelenítése.

Használt modulok, sablonok

  • Modul:Arguments – paraméterek beolvasásához
  • Modul:Time – dátum kiírásához (formázottan)
  • {{plainlist}} – alapértelmezett kimenetnél a többelemű listák formázásához
require('strict')local p = {}local getArgs = require('Modul:Arguments').getArgslocal frame = mw.getCurrentFrame()local formatStatementslocal i18n = {['errors'] = {['property-param-not-provided'] = "Hiányzó ''property='' paraméter",['property-not-found'] = 'Érvénytelen tulajdonság: %s',['entity-not-found'] = 'Nem létező Wikidata-elem',['unknown-claim-type'] = 'Ismeretlen az állítás típusa',['unknown-snak-type'] = 'Ismeretlen a snak típusa',['unknown-datavalue-type'] = 'Ismeretlen az érték típusa',['unknown-entity-type'] = 'Ismeretlen a Wikidata-elem típusa',['unknown-value-module'] = "A ''value-module'' és ''value-function'' paramétert egyszerre kell beállítani",['value-module-not-found'] = "A ''value-module'' nem létező modulra mutat",['value-function-not-found'] = "A ''value-function'' nem létező funkcióra mutat",['globecoordinate-direction'] = "Az érték típusa ''globecoordinate:'' kell ''direction=latitude'', ''longitude'' vagy ''both''",['invalid-value'] = 'Érvénytelen érték',['unknown-unit'] = 'Ismeretlen mértékegység: %s',['excluding-arguments'] = 'Nem adható %s és %s egyidejűleg',},['somevalue'] = "''nem ismert''",['novalue'] = "''nincs''"}local function formatError(key, ...)error(i18n.errors[key]:format(...), 2)endfunction p.getUpperLevelOfType(property, typeId, entityId, item)local result, statements, visited = {}, {}, {[item and item.id or entityId] = true}local function getStatements(entityId, item)local wb_statementsif item thenwb_statements = item:getBestStatements(property)elseif entityId thenwb_statements = mw.wikibase.getBestStatements(entityId, property)elsereturnendfor _, s in ipairs(wb_statements) doif s.mainsnak.snaktype == 'value' thenlocal itemId = 'Q' .. s.mainsnak.datavalue.value['numeric-id']if not visited[itemId] thenvisited[itemId] = truelocal item = mw.wikibase.getEntity(itemId)if p.containsPropertyWithValue(item, 'P31', typeId) thenstatements[item.id] = selsegetStatements(nil, item)endendendendendgetStatements(entityId, item)for _, s in pairs(statements) dotable.insert(result, s)endreturn resultendlocal function firstValue(statements)for _, statement in ipairs(statements) doif statement.rank == 'preferred' thenreturn {statement}endendfor _, statement in ipairs(statements) doif statement.rank == 'normal' thenreturn {statement}endendreturn {}endlocal function withRank(statements, ranks)local result = {}for _i, statement in ipairs(statements) dofor _j, rank in ipairs(ranks) doif statement.rank == rank thentable.insert(result, statement)breakendendendreturn resultendfunction p.withHighestRank(statements)local preferred, normal = {}, {}for _, statement in ipairs(statements) doif statement.rank == 'preferred' thentable.insert(preferred, statement)elseif statement.rank == 'normal' thentable.insert(normal, statement)endendreturn #preferred > 0 and preferred or normalendlocal function atDate(statements, date)local result = {}local Time = require('Modul:Time')local time = Time.newFromIso8601(date, true)if not time thenreturn statementsendlocal isQualified = falsefor _, s in ipairs(statements) dolocal startDate, endDateif s.qualifiers and s.qualifiers.P580 and #s.qualifiers.P580 == 1 and s.qualifiers.P580[1].snaktype == 'value' thenstartDate = Time.newFromWikidataValue(s.qualifiers.P580[1].datavalue.value)endif s.qualifiers and s.qualifiers.P582 and #s.qualifiers.P582 == 1 and s.qualifiers.P582[1].snaktype == 'value' thenendDate = Time.newFromWikidataValue(s.qualifiers.P582[1].datavalue.value)endif startDate or endDate thenisQualified = trueendif not startDate and endDate and time <= endDate orstartDate and not endDate and startDate <= time orstartDate and endDate and startDate <= time and time <= endDate thentable.insert(result, s)endendif isQualified thenreturn resultelsereturn statementsendendlocal function getEntityFromId(id)if id and id ~= '' thenreturn mw.wikibase.getEntity(id)endreturn mw.wikibase.getEntity()endlocal function getEntityIdFromValue(value)local prefixif value['entity-type'] == 'item' thenprefix = 'Q'elseif value['entity-type'] == 'property' thenprefix = 'P'elseformatError('unknown-entity-type')endreturn prefix .. value['numeric-id']endlocal function getChrDates(chrDate, entityId)if not chrDate thenreturn {}endif chrDate:match('^P%d+$') thenlocal dates = mw.wikibase.getEntity(entityId):getBestStatements(chrDate)local ret = {}for _, v in ipairs(dates) doif v.mainsnak.snaktype == 'value' thentable.insert(ret, v.mainsnak.datavalue.value.time)endendreturn retelsereturn { chrDate }endendlocal function getChrQualifierDates(chrQualifierDate, statement)if not chrQualifierDate or not chrQualifierDate:match('^P%d+$') thenreturn {}endif not statement.qualifiers or not statement.qualifiers[chrQualifierDate] thenreturn {}endlocal ret = {}for _, v in ipairs(statement.qualifiers[chrQualifierDate]) doif v.snaktype == 'value' thentable.insert(ret, v.datavalue.value.time)endendreturn retendlocal function getDatedStatement(dates, options, dateFields, item)if not dateFields thendateFields = { 'atDate' }endlocal result, conflict = nil, falsefor _, v in ipairs(dates) dofor _, w in ipairs(dateFields) dooptions[w] = vendlocal statement = formatStatements(options, item)if statement == '' thenstatement = nilendif statement and result == nil thenresult = statementelseif statement ~= result thenconflict = trueendendif not conflict thenreturn resultelsereturn nilendendlocal function formatEntityId(entityId, options, statement)local link = mw.wikibase.sitelink(entityId)if options.link == 'csak' thenreturn linkendif link and options.link ~= 'nem' and mw.ustring.sub(link, 1, 10) == 'Kategória:' thenreturn '[[' .. link .. ']]'endlocal labelif options.lang thenfor lang in mw.text.gsplit(options.lang, ',') dolabel = mw.wikibase.getLabelByLang(entityId, lang)if label thenbreakendendelselabel = mw.wikibase.label(entityId)endif options.labelProperty and options.labelProperty ~= '' thenlocal options2 = {}for k, v in pairs(options) doif k ~= 'labelProperty' thenoptions2[k] = vendendoptions2.property = options.labelPropertyoptions2.entityId = entityIdoptions2.rank = 'valid'options2.link = 'nem'options2.lang = options.lang or 'hu'options2.firstAfter = trueoptions2['felsorolás'] = nil -- felsorolásjel nélküllocal label2 = formatStatements(options2)if label2 and label2 ~= '' thenlabel = label2endendif options.chrProperty thenlocal datesif options.chrDate thendates = getChrDates(options.chrDate, options.entityId)elseif options.chrQualifierDate and statement thendates = getChrQualifierDates(options.chrQualifierDate, statement)else-- getDatedStatement with an empty date object is a no-op-- this should not happen if the module is used correctlydates = {}endlocal chrLabel = getDatedStatement(dates, {property = options.chrProperty,entityId = entityId,rank = 'valid',lang = options.lang or 'hu',firstAfter = true,['felsorolás'] = nil -- felsorolásjel nélkül})if chrLabel thenlabel = chrLabelendendif label and options.format == 'ucfirst' thenlabel = mw.language.getContentLanguage():ucfirst(label)endif link and options.link ~= 'nem' thenif label thenif mw.ustring.sub(label, 2) == mw.ustring.sub(link, 2) and mw.ustring.lower(mw.ustring.sub(label, 1, 1)) == mw.ustring.lower(mw.ustring.sub(link, 1, 1)) thenreturn '[[' .. label .. ']]'elsereturn '[[' .. link .. '|' .. label .. ']]'endelsereturn '[[' .. link .. ']]'endelsereturn label or link  --TODO what if no links and label + fallback language?endendlocal function formatTimeValue(value, options)if options.format == 'raw' thenreturn value.timeelselocal time = require('Modul:Time').newFromWikidataValue(value)if time thenif options.format == 'iso' thenreturn tostring(time)elseif options.format == 'date-object' thenreturn timeendreturn time:formatDate(options)elseformatError('invalid-value')endendendlocal function countryOf(itemId, options, noselflink, chrDate)local function getStatement(dates, new_options, item)return getDatedStatement(dates, new_options, { 'atDate', 'chrDate' }, item) or formatStatements(new_options, item)endif not itemId thenreturn nilendlocal item = mw.wikibase.getEntity(itemId)if not item thenreturn nilendlocal dates = getChrDates(chrDate, options.entityId)local dateFields = { 'atDate', 'chrDate' }local new_options = {property = 'P17',chrProperty = options.chrProperty,format = 'raw'}if noselflink and item.id == getStatement(dates, new_options, item) thenreturn nilendnew_options.format = nilreturn getStatement(dates, new_options, item)endlocal function formatNum(amount)if amount < 10000 and -10000 < amount thenreturn tostring(amount):gsub('%.', ',')elsereturn mw.getContentLanguage():formatNum(amount)endendlocal function formatDatavalue(datavalue, options, statement)--Use the customize handler if providedif options['value-module'] or options['value-function'] thenif not options['value-module'] or not options['value-function'] thenreturn formatError( 'unknown-value-module' )endlocal formatter = require ('Module:' .. options['value-module'])if formatter == nil thenreturn formatError( 'value-module-not-found' )endlocal fun = formatter[options['value-function']]if fun == nil thenreturn formatError( 'value-function-not-found' )endreturn fun( datavalue.value, options )end--Default formattersif datavalue.type == 'wikibase-entityid' thenlocal itemId = getEntityIdFromValue(datavalue.value)if options.format == 'raw' thenreturn itemIdendlocal result = formatEntityId(itemId, options, statement)if not result thenreturn nilendlocal country = options.format == 'with_country' and countryOf(itemId, options, true, options.chrDate)return result .. (country and ', ' .. country or '')elseif datavalue.type == 'string' thenreturn datavalue.value --TODO ids + mediaelseif datavalue.type == 'time' thenreturn formatTimeValue(datavalue.value, options)elseif datavalue.type == 'globecoordinate' thenif options.format == 'geohack' thenreturn '[[Fájl:OOjs UI icon mapPin-progressive.svg|16px|link=]] ' .. require('Modul:Coordinate').coord {datavalue.value.latitude,datavalue.value.longitude,options.meta,precision = 'wikidata',format = 'dms'}endif options.direction == 'latitude' thenreturn datavalue.value.latitudeelseif options.direction == 'longitude' thenreturn datavalue.value.longitudeelsereturn formatError('globecoordinate-direction')endelseif datavalue.type == 'quantity' thenif options.format == 'raw' thenreturn datavalue.value.amountendlocal resultlocal amount = tonumber(datavalue.value.amount)if datavalue.value.unit == '1' thenif options.unit thenreturn nilendif options.format == 'percentage' thenresult = formatNum(amount * 100) .. '%'elseresult = formatNum(amount)endelselocal unitId = datavalue.value.unit:match('Q%d+')local sourceUnit = mw.loadData('Modul:Wikidata/units').wikidata_item_ids[unitId]if not sourceUnit thenif not options.unit and unitId thenlocal sym_hu, sym_mulfor _, st in ipairs(mw.wikibase.getBestStatements(unitId, 'P5061')) do  -- unit symbolsym_hu = p.formatStatement(st, { lang = 'hu' })if sym_hu thenbreakendsym_mul = sym_mul or p.formatStatement(st, { lang = 'mul' })endsym_hu = sym_hu or sym_mulresult = formatNum(amount) .. (unitId ~= 'Q28390' and ' ' or '') .. (sym_hu or mw.wikibase.getLabel(unitId) or unitId)elseformatError('unknown-unit', unitId or 'nil')endelselocal targetUnit = options.unit or sourceUnitresult = require('Modul:Convert')._convert{amount, sourceUnit, targetUnit, disp = options.showUnit and 'out' or 'number'}endendreturn resultelseif datavalue.type == 'monolingualtext' thenlocal langs = options.lang or 'hu'if langs == 'all' or langs == '~hu' and datavalue.value.language ~= 'hu' thenreturn datavalue.value.textendfor lang in mw.text.gsplit(langs, ',') doif lang:match('^%s*(.-)%s*$') == datavalue.value.language thenreturn datavalue.value.textendendreturn nilelseformatError('unknown-datavalue-type')endendlocal function formatExternalId(options, externalId)if options.format == 'raw' thenreturn externalIdendlocal formatterUrl = formatStatements {entityId = options.property,property = 'P1630',  -- formatter URLfirst = true}if not formatterUrl thenreturn externalIdendlocal url = formatterUrl:gsub('%$1', ((mw.uri.encode(externalId, 'PATH'):gsub('%%2F', '/')):gsub('%%', '%%%%')))if options.format == 'url' thenreturn urlendreturn string.format('[%s %s]', url, options.externalIdLabel ~= '' and options.externalIdLabel or externalId)endlocal function formatUrl(url, property, options)if not options or not options.format or options.format == 'raw' or options.format == 'url' thenreturn urlendif options.format == 'wikilink' thenreturn ('[%s %s]'):format(url, options['link szövege'] or mw.wikibase.getLabel(property))endreturn nilend-- Format an arbitrary snak. Parameters:--   snak: the snak to format (required)--   options: a table of formatting options (optional)--   statement: the statement of which this snak is the main snak of,--     if it’s a main snak (optional)local function formatSnak(snak, options, statement)local options = options or {}if snak.snaktype == 'somevalue' thenreturn options.somevalue or (options.format == 'raw' and 'somevalue' or i18n['somevalue'])elseif snak.snaktype == 'novalue' thenreturn options.format == 'raw' and 'novalue' or i18n['novalue']elseif snak.snaktype == 'value' thenif options['value-module'] or options['value-function'] thenreturn formatDatavalue(snak.datavalue, options, statement)endif snak.datatype == 'math' thenreturn frame:extensionTag('math', snak.datavalue.value)elseif snak.datatype == 'external-id' thenreturn formatExternalId(options, snak.datavalue.value)elseif snak.datatype == 'url' thenreturn formatUrl(snak.datavalue.value, snak.property, options)elsereturn formatDatavalue(snak.datavalue, options, statement)endelseformatError('unknown-snak-type')endend--[[Empty string result used in concatenations.  ]]local function formatSnaks(snaks, options)local formattedSnaks = {}for _, snak in ipairs(snaks) dotable.insert(formattedSnaks, formatSnak(snak, options))endreturn mw.text.listToText(formattedSnaks, options.separator, options.conjunction)endlocal function formatReference(reference, options)local statedInItemlocal function formatProperty(prop, prop2, dashSeparated, extraOptions)local localOptions = extraOptions or {}if dashSeparated thenlocalOptions['felsorolás'] = nillocalOptions.separator = '&#8201;&#8211;&#8201;'localOptions.conjunction = '&#8201;&#8211;&#8201;'elselocalOptions['felsorolás'] = 'szöveg'endlocal formatted = reference.snaks[prop] and formatSnaks(reference.snaks[prop], localOptions)if formatted and formatted ~= '' thenreturn formattedendif prop2 thenformatted = reference.snaks[prop2] and formatSnaks(reference.snaks[prop2], localOptions)if formatted and formatted ~= '' thenreturn formattedendendif statedInItem thenlocalOptions.property = propformatted = formatStatements(localOptions, statedInItem)if formatted and formatted ~= '' thenreturn formattedendif prop2 thenlocalOptions.property = prop2return formatStatements(localOptions, statedInItem)endendreturn nilendlocal args = {}local url_source = 'reference'args.url = reference.snaks['P854'] and formatSnak(reference.snaks['P854'][1])if reference.snaks.P1476 thenfor _, snak in ipairs(reference.snaks.P1476) doif not args.title or (snak.datavalue and snak.datavalue.value.language == 'hu') thenargs.title = snak.datavalue.value.textendendendstatedInItem = reference.snaks.P248 andreference.snaks.P248[1].snaktype == 'value' andmw.wikibase.getEntity(reference.snaks.P248[1].datavalue.value.id) ornilif not args.title and statedInItem thenargs.title = formatStatements({property = 'P1476',  -- title (monolingual text)lang = 'all',first = true}, statedInItem)endif not args.title and statedInItem thenargs.title = formatSnaks(reference.snaks.P248, { link = 'nem' })endif not args.url and statedInItem thenlocal id_propertyfor _, statement in ipairs(mw.wikibase.getBestStatements(statedInItem.id, 'P1687')) do  -- Wikidata propertyif statement.mainsnak.snaktype == 'value' and (reference.snaks[statement.mainsnak.datavalue.value.id] or next(mw.wikibase.getBestStatements(options.entityId, statement.mainsnak.datavalue.value.id))) thenid_property = statement.mainsnak.datavalue.value.idbreakendendif not id_property thenfor _, statement in ipairs(mw.wikibase.getBestStatements(statedInItem.id, 'P527')) doif statement.mainsnak.snaktype == 'value' thenid_property = formatStatements{entityId = statement.mainsnak.datavalue.value.id,property = 'P1687',first = true,excludespecial = true,format = 'raw'}if id_property thenbreakendendendendif id_property thenurl_source = 'external_id'local fs_options = { property = id_property, first = true, excludespecial = true, format = 'url' }if reference.snaks[id_property] thenargs.url = formatSnak(reference.snaks[id_property][1], fs_options)else-- Get property from item instead of referencefs_options.entityId = options.entityIdargs.url = formatStatements(fs_options)endendendif not args.url and statedInItem thenurl_source = 'stated_in'args.url = formatStatements({property = 'P953',first = true,excludespecial = true}, statedInItem)if not args.url thenargs.url = formatStatements({property = 'P856',first = true,excludespecial = true}, statedInItem)endendif args.url and args.title and args.title ~= '' then  -- url and titlelocal Time = {}if reference.snaks.P577 or reference.snaks.P813 or (reference.snaks.P1065 and reference.snaks.P2960) thenTime = require('Modul:Time')endif url_source ~= 'external_id' thenargs.author = formatProperty('P50', 'P2093', true)endlocal timeif reference.snaks.P577 and reference.snaks.P577[1].snaktype == 'value' thentime = Time.newFromWikidataValue(reference.snaks.P577[1].datavalue.value)elseif statedInItem thenlocal times = formatStatements({property = 'P577',first = true,excludespecial = true,format = 'date-object',['felsorolás'] = 'table'}, statedInItem)time = times[1]endif time thenif time.precision >= 11 thenargs.date = time:toIso8601()elseargs.year = tostring(time.year)endendif url_source ~= 'external_id' thenargs.publisher = formatProperty('P123', nil, true)endif not args.publisher and statedInItem thenargs.publisher = formatStatements({ property = 'P123', first = true }, statedInItem)endargs.language = formatProperty('P407', 'P364', false, {link = 'nem'})args.accessdate = reference.snaks['P813'] and Time.newFromWikidataValue(reference.snaks.P813[1].datavalue.value):toIso8601()if args.url and args.url:match('^https?://www.ksh.hu') thenargs.url = args.url:gsub('p_lang=EN', 'p_lang=HU')endif args.url and args.url:match('^https://nepszamlalas2022.ksh.hu') thenargs.url = args.url:gsub('en/database', 'adatbazis')endif reference.snaks.P1065 and reference.snaks.P2960 thenargs.archiveurl = formatSnak(reference.snaks.P1065[1])args.archivedate = Time.newFromWikidataValue(reference.snaks.P2960[1].datavalue.value):toIso8601()endreturn frame:expandTemplate{title = 'Cite web', args = args}elselocal result = {}local excluded = truefor key, referenceSnaks in pairs(reference.snaks) do-- exclude "imported from Wikimedia project", "Wikimedia import URL" and "inferred from"if key ~= 'P143' and key ~= 'P4656' and key ~= 'P3452' then-- don't show references with nothing more than an access dateif key ~= 'P813' thenexcluded = falseendfor _, snak in ipairs(referenceSnaks) dotable.insert(result, formatSnak(snak, snak.datavalue and snak.datavalue.type == 'time' and { link = 'nem' } or { property=snak.property }))endendendif excluded thenreturn ''elsereturn table.concat(result, ', ')endendendlocal function formatReferences(references, options)if not references thenreturn ''endlocal limit = tonumber(options.showReferences) or 5local formattedReferences = {}for _, reference in ipairs(references) doif limit == 0 or #formattedReferences < limit thenlocal formattedReference = formatReference(reference, options)if formattedReference and formattedReference ~= '' thentable.insert(formattedReferences, frame:extensionTag('ref', formattedReference, {name = reference.hash}))endendendreturn table.concat(formattedReferences)endlocal function populationWithPointInTime(statement, options, last)if statement.mainsnak.snaktype ~= 'value' thenreturn nilendlocal population = tonumber(statement.mainsnak.datavalue.value.amount)local text = (population < 10000 and tostring(population) or mw.getContentLanguage():formatNum(population)) .. ' fő'if statement.qualifiers and statement.qualifiers.P585 and statement.qualifiers.P585[1].snaktype == 'value' then  -- dátumlocal time, fDate = require('Modul:Time').newFromWikidataValue(statement.qualifiers.P585[1].datavalue.value)if time.precision >= 11 thenfDate = mw.getContentLanguage():formatDate(options.dateformat or 'Y. M. j.', time:toIso8601())elsefDate = tostring(time.year)endtext = text .. ' ' .. mw.text.tag('span', {style = 'font-size:90%; white-space:nowrap;'}, '(' .. fDate .. ')')endif last and options.punctuation thentext = text .. options.punctuationendtext = text .. formatReferences(statement.references, options)local qid = statement.id:match("^[Qq]%d+"):upper()if qid == mw.wikibase.getEntityIdForCurrentPage() thenreturn textendif last thentext = text .. string.format(' <small class="plainlinks noexcerpts">[https://www.wikidata.org/wiki/%s?uselang=hu#P1082 +/-]</small>', qid)endreturn textendlocal function sortAuxiliary(statements, propGenerator, sortDesc)local newlist, auxlist = {}, {}local function sort(a, b)if a.prop and b.prop and a.prop ~= b.prop thenreturn a.prop < b.propelseif a.prop and b.prop thenreturn a.i < b.ielseif a.prop or b.prop thenreturn not a.propelsereturn a.i < b.iendendfor i, v in ipairs(statements) doauxlist[i] = {i = i,prop = propGenerator(v, i)}endif sortDesc thentable.sort(auxlist, function (a, b)return not sort(a, b)end)elsetable.sort(auxlist, sort)endfor _, v in ipairs(auxlist) dotable.insert(newlist, statements[v.i])endreturn newlistendlocal function getSortableValue(snak)if not snak or snak.snaktype ~= 'value' thenreturn nilendlocal datavalue = snak.datavalueif datavalue.type == 'wikibase-entityid' thenlocal id = 'Q' .. datavalue.value['numeric-id']local key = mw.wikibase.label(id)if not key thenkey = mw.wikibase.sitelink(id)endif not key thenreturn idendreturn mw.language.getContentLanguage():caseFold(key)elseif datavalue.type == 'string' thenreturn datavalue.valueelseif datavalue.type == 'time' thenreturn require('Modul:Time').newFromWikidataValue(datavalue.value)elseif datavalue.type == 'quantity' thenreturn tonumber(datavalue.value.amount)elseif datavalue.type == 'monolingualtext' thenreturn datavalue.value.textendreturn nilendlocal function sortByValue(statements, sortDesc)local function propGenerator(v)return getSortableValue(v.mainsnak)endreturn sortAuxiliary(statements, propGenerator, sortDesc)endlocal function sortByQualifier(statements, qualifier, sortDesc)local function propGenerator(v)return v.qualifiers and v.qualifiers[qualifier] and getSortableValue(v.qualifiers[qualifier][1])endreturn sortAuxiliary(statements, propGenerator, sortDesc)endlocal function filterByQualifier(options, statements)if not options.qualProp thenreturn statementsendlocal result = {}options.qualProp = (options.qualProp):upper()for _, s in ipairs(statements) doif s.qualifiers and s.qualifiers[options.qualProp] thenif not options.qualValue thentable.insert(result, s)elsefor _, snak in ipairs(s.qualifiers[options.qualProp]) doif snak.snaktype == 'value' thenif snak.datavalue.type == 'wikibase-entityid' and ((options.qualValue):upper() .. ','):find(snak.datavalue.value.id .. ',', 1, true) orsnak.datavalue.type == 'string' and (options.qualValue .. ','):find(snak.datavalue.value .. ',', 1, true) thentable.insert(result, s)breakendendendendendendreturn resultend--[[Local function with forward declaration--]]function formatStatements(options, item)if not options.property or options.property == '' thenformatError('property-param-not-provided')endlocal property = mw.wikibase.resolvePropertyId(options.property)if not property thenformatError('property-not-found', options.property)end--Get entitylocal entity = itemlocal statements = {}if entity thenstatements = entity:getAllStatements(property)elseif options.entityId and options.pageTitle thenreturn formatError('excluding-arguments', 'entityId', 'pageTitle')endif options.pageTitle thenoptions.entityId = mw.wikibase.getEntityIdForTitle(options.pageTitle)elseif not options.entityId thenoptions.entityId = mw.wikibase.getEntityIdForCurrentPage()endif not options.entityId thenreturn options['felsorolás'] == 'table' and {} or nilendif mw.wikibase.isValidEntityId(options.entityId) thenstatements = mw.wikibase.getAllStatements(options.entityId, property)endendif #statements == 0 thenreturn options['felsorolás'] == 'table' and {} or nilendif options.atDate thenstatements = atDate(statements, options.atDate)end-- TODO Extract selection and filteringif options.rank ~= 'all' thenif not options.rank thenstatements = p.withHighestRank(statements)elseif options.rank == 'valid' thenstatements = withRank(statements, {'normal', 'preferred'})elsestatements = withRank(statements, {options.rank})endendif options.typeId thenstatements = p.getUpperLevelOfType(property, options.typeId, options.entityId, entity)endif options.excludespecial thenlocal newStatements = {}for _, s in ipairs(statements) doif s.mainsnak.snaktype == 'value' thentable.insert(newStatements, s)endendstatements = newStatementsendstatements = filterByQualifier(options, statements)if options.sort thenlocal comp = options.sortif type(comp) == 'string' and comp:match('[Pp]%d+') thenstatements = sortByQualifier(statements, string.upper(comp), options.sortDesc)elseif comp == '' or comp == true thenstatements = sortByValue(statements, options.sortDesc)elsetable.sort(statements, comp)endendif options.first thenstatements = firstValue(statements)end--Format statement and concat them cleanlylocal formattedStatements = {}-- loop variable to know if we're processing the last statementlocal i = 0for _, statement in ipairs(statements) doi = i + 1local fsif property == 'P1082' and options.format == 'default' then  -- populationfs = populationWithPointInTime(statement, options, (i == #statements))elsefs = p.formatStatement(statement, options, (i == #statements))endif fs thenif options['felsorolás'] == 'lista' thenfs = '* ' .. fselseif options['felsorolás'] == 'számozott lista' thenfs = '# ' .. fsendtable.insert(formattedStatements, fs)endendlocal function collapsibleList(frame, args, list, size)if args['lenyíló'] and size > tonumber(args['lenyíló']) thenreturn frame:expandTemplate{ title = 'Show', args = { 'Lista', list } }endreturn listendlocal function plainlist(items)if #items == 0 thenreturn nilendif #items == 1 thenreturn items[1]endreturn collapsibleList(frame, options, frame:expandTemplate{ title = 'Plainlist', args = { '\n* ' .. table.concat(items, '\n* ') .. '\n' } }, #items)endif options['felsorolás'] == 'lista' or options['felsorolás'] == 'számozott lista' thenreturn collapsibleList(frame, options, table.concat(formattedStatements, '\n'), #formattedStatements)elseif options['felsorolás'] == 'sorok' thenreturn plainlist(formattedStatements)elseif options['felsorolás'] == 'szöveg' thenreturn mw.text.listToText(formattedStatements)elseif options['felsorolás'] == 'table' thenreturn formattedStatementselseif options.separator or options.conjunction thenoptions.separator = options.separator and string.gsub(options.separator, '&#32;', ' ')options.conjunction = options.conjunction and string.gsub(options.conjunction, '&#32;', ' ')return mw.text.listToText(formattedStatements, options.separator, options.conjunction)elseif options.firstAfter thenreturn formattedStatements[1] or ''endreturn plainlist(formattedStatements)endendlocal function formatQualifiers(statement, options, qualifiers)local result, orderedResult, startDate, endDate = {}, {}local function getInterval()if startDate and startDate ~= '' or endDate and endDate ~= '' thenlocal dash = '–'if (startDate and not startDate:match('^%d+$')) or (endDate and not endDate:match('^%d+$')) thendash = ' – 'endreturn (startDate or '') .. dash .. (endDate or '')endendif type(qualifiers) == 'string' and qualifiers:find('[Pp]%d') thenqualifiers = qualifiers:upper()elsequalifiers = nilendfor key, snaks in pairs(statement.qualifiers) doif not qualifiers or qualifiers:find(key, 1, true) thenif key == 'P580' thenstartDate = formatSnak(snaks[1], {link = 'nem'})elseif key == 'P582' thenendDate = formatSnak(snaks[1], {link = 'nem'})elsefor _, snak in ipairs(snaks) dolocal formattedSnak = formatSnak(snak, { link = snak.property ~= 'P102' and 'nem' or nil, ['format'] = 'geohack', showUnit = true })if qualifiers then-- order determined by the order in parameterif orderedResult[key] thentable.insert(orderedResult[key], formattedSnak)elseorderedResult[key] = { formattedSnak }endelsetable.insert(result, formattedSnak)endendendendendif qualifiers thenfor qualifier in qualifiers:gmatch('P%d+') doif qualifier == 'P580' or qualifier == 'P582' thenlocal interval = getInterval()if interval thentable.insert(result, interval)-- prevent interval to be inserted twice (both at P580 and P582)startDate, endDate = nil, nilendelseif orderedResult[qualifier] thenfor _, v in ipairs(orderedResult[qualifier]) dotable.insert(result, v)endendendelselocal interval = getInterval()if interval thentable.insert(result, 1, interval)endendreturn table.concat(result, ', ')endfunction p.formatStatement(statement, options, last)if not statement.type or statement.type ~= 'statement' thenformatError('unknown-claim-type')endlocal options = options or {}local resultif statement.mainsnak.snaktype == 'somevalue' and statement.mainsnak.datatype == 'time' and statement.qualifiers and (statement.qualifiers.P1319 or statement.qualifiers.P1326) then-- TODO Extract methodif statement.qualifiers.P1319 thenif statement.qualifiers.P1326 thenresult = formatSnak(statement.qualifiers.P1319[1]) .. ' és ' .. formatSnak(statement.qualifiers.P1326[1]) .. ' között'elseresult = formatSnak(statement.qualifiers.P1319[1]) .. ' után'endelseresult = formatSnak(statement.qualifiers.P1326[1]) .. ' előtt'endelseresult = formatSnak(statement.mainsnak, options, statement)end--TODO reference and qualifiersif result and result ~= '' thenif options.showQualifiers and statement.qualifiers thenlocal formattedQualifiers = formatQualifiers(statement, options, options.showQualifiers)if formattedQualifiers and formattedQualifiers ~= '' thenresult = result .. ' <small>(' .. formattedQualifiers .. ')</small>'endendif last and options.punctuation thenresult = result .. options.punctuationendif options.showReferences thenresult = result .. formatReferences(statement.references, options)endendreturn resultendfunction p.formatStatements(frame, args, item)if not args thenargs = getArgs(frame, { removeBlanks = false })end--If a value if already set, use itif args.value and args.value ~= '' thenreturn args.value ~= '-' and args.value or nilendif args.externalId == '-' thenreturn nilendif args.externalId and args.externalId ~= '' thenreturn formatExternalId(args, args.externalId)endargs.entityId = args.entityId ~= '' and args.entityId or nilargs.pageTitle = args.pageTitle ~= '' and args.pageTitle or nilargs.qualProp = args.qualProp ~= '' and args.qualProp or nilargs.qualValue = args.qualValue ~= '' and args.qualValue or nilreturn formatStatements(args, item)end--[[Returns string true if connected Wikibase item contains property specified by property argument, empty string otherwise.Used by template Wikidata-f in conditional expressions.--]]function p.containsProperty(frame, args, item)if not args thenargs = getArgs(frame, { removeBlanks = false })endif not args.property thenformatError('property-param-not-provided')endif args.value == '-' or args.externalId == '-' thenreturn nilendif args.value thenreturn trueendif args.externalId and args.externalId ~= '' thenreturn trueendif not item then  -- default usage from Wikidata-f templateargs.entityId = args.entityId ~= '' and args.entityId or nilargs.pageTitle = args.pageTitle ~= '' and args.pageTitle or nillocal entityId = args.entityIdif not entityId thenif args.pageTitle thenentityId = mw.wikibase.getEntityIdForTitle(args.pageTitle)elseentityId = mw.wikibase.getEntityIdForCurrentPage()endendif not entityId thenreturn nilendif next(mw.wikibase.getBestStatements(entityId, args.property:upper())) == nil thenreturn nilendreturn trueendif not item.claims or not item.claims[args.property:upper()] thenreturn nilendif args.rank == 'all' thenreturn trueelseif args.rank == 'valid' then-- if we're just searching, it doesn't matter-- if we want all or only the better onesargs.rank = nilendfor _, claim in ipairs(item.claims[args.property:upper()]) doif(args.rank and claim.rank == args.rank or not args.rank and claim.rank ~= 'deprecated') and(not args.excludespecial or claim.mainsnak.snaktype == 'value')thenreturn trueendendreturn nilendfunction p.containsPropertyWithValue(item, property, value)if not property or not value thenreturn falseendif not item or not item.claims or not item.claims[property:upper()] thenreturn falseendfor _, statement in ipairs(item.claims[property:upper()]) doif statement.rank ~= 'deprecated' and statement.mainsnak.snaktype == 'value' thenlocal type = statement.mainsnak.datavalue.typeif type == 'wikibase-entityid' thenif 'Q' .. statement.mainsnak.datavalue.value['numeric-id'] == value thenreturn trueendendendendreturn falseendfunction p.isOfType(item, class)if not item or not item.claims or not item.claims.P31 or not class thenreturn falseendlocal isSubclass, visitedlocal level = 0local function checkProperty(item, property)-- mw.wikibase.getEntity is expensive when called with the ID of an entity not connected to the current page.if level > 15 thenreturn falseendlevel = level + 1for _, s in ipairs(item:getBestStatements(property)) doif s.mainsnak.snaktype == 'value' thenlocal itemId = 'Q' .. s.mainsnak.datavalue.value['numeric-id']if itemId == class or isSubclass(itemId) thenreturn trueendendendreturn falseendisSubclass = function (itemId)if visited[itemId] thenreturn falseendlocal item = mw.wikibase.getEntity(itemId)if not item then  -- deleted itemreturn falseendvisited[itemId] = truevisited[item.id] = truereturn checkProperty(item, 'P279')endvisited = { [item.id] = true }return checkProperty(item, 'P31')end--[[Local functions available to other modules.  ]]p.formatters = {formatDatavalue = formatDatavalue,formatSnak = formatSnak,formatSnaks = formatSnaks}return p