Modul:Wikidata: Porovnání verzí

Smazaný obsah Přidaný obsah
m sup
Řádek 3:
local p = {}
 
local i18nlib = {require "Modul:Wikidata/lib"
local i18n = mw.loadData("Modul:Wikidata/i18n")
errors = {
["entity-not-found"] = "Entita nenalezena",
["invalid-datatype"] = "Nesprávný datový typ vlastnosti „%s“: „%s“; vyžadován „%s“",
["invalid-date"] = "Neplatné datum „%s“",
["invalid-field"] = "Neplatné pole „%s“",
["invalid-sort"] = "Neplatný způsob řazení „%s“",
["param-not-provided"] = "Nezadán parametr „%s“",
["unknown-claim-type"] = "Neznámý typ tvrzení: %s",
["unknown-datavalue-type"] = "Neznámý typ datové hodnoty: %s",
["unknown-entity-type"] = "Neznámý typ entity: %s",
["unknown-snak-type"] = "Neznámý typ snaku: %s",
["unknown-value-module"] = "Musíte nastavit oba parametry „value-module“ i „value-function“",
["value-function-not-found"] = "Funkce „%s“ odkazovaná parametrem „value-function“ nenalezena",
["value-module-not-found"] = "Modul „%s“ odkazovaný parametrem „value-module“ nenalezen"
},
lang = mw.language.getContentLanguage(),
more = "… více na [[d:%s#%s|Wikidatech]]",
novalue = "''bez hodnoty''",
somevalue = "''neznámá hodnota''"
}
 
local props = {
begin = { 'P569', 'P580' },
ending = { 'P570', 'P582' },
lang = { 'P407' },
point = { 'P571', 'P577', 'P585' },
}
 
local function formatError(key, ...)
return error(mw.ustring.format(i18n.errors[key], ...), 3)
end
 
local function getEntityFromId(id)
return mw.wikibase.getEntityObject(id)
end
 
function p.getEntityIdFromValue(value)
local entityType = value['entity-type']
if entityType == 'item' then
return 'Q' .. value['numeric-id']
elseif entityType == 'property' then
return 'P' .. value['numeric-id']
else
return formatError( 'unknown-entity-type', entityType )
end
end
 
-- move to submodule
local function filterStatements(entity, options)
if not options.property or options.property == '' then
return formatError( 'param-not-provided', 'property' )
else
options.property = options.property:upper()
end
if not (entity and entity.claims and entity.claims[options.property]) then
return {}
end
local Statements, oldStatements = entity.claims[options.property], {}
-- apply filter by rank
if not options.rank or options.rank ~= "all" then
oldStatements, Statements = Statements, {}
if not options.rank or options.rank == "best" or options.rank == "valid" then
if options.rank == "best" then
for _, statement in pairs(oldStatements) do
if statement.rank == "preferred" then
table.insert(Statements, statement)
end
end
if #Statements == 0 then
for _, statement in pairs(oldStatements) do
if statement.rank == "normal" then
table.insert(Statements, statement)
end
end
end
else
for _, statement in pairs(oldStatements) do
if statement.rank ~= "deprecated" then
table.insert(Statements, statement)
end
end
end
else
for _, statement in pairs(oldStatements) do
if statement.rank == options.rank then
table.insert(Statements, statement)
end
end
end
if #Statements == 0 then return {} end
end
-- apply filter by source
if options.ref and options.ref == '#any' then
oldStatements, Statements = Statements, {}
for _, statement in pairs(oldStatements) do
if statement.references then
table.insert(Statements, statement)
end
end
if #Statements == 0 then return {} end
end
-- apply filter by snak type
if not options.showspecial or tostring(options.showspecial) ~= "true" then
oldStatements, Statements = Statements, {}
for _, statement in pairs(oldStatements) do
if statement.mainsnak.snaktype == "value" then
table.insert(Statements, statement)
end
end
if #Statements == 0 then return {} end
end
-- apply filter by qualifier property
if options.withqualifier and options.withqualifier ~= '' then
oldStatements, Statements = Statements, {}
for _, statement in pairs(oldStatements) do
if statement.qualifiers and statement.qualifiers[options.withqualifier:upper()] then
table.insert(Statements, statement)
end
end
if #Statements == 0 then return {} end
end
-- apply filter by class
if options.class and options.class ~= '' then
local datatype = Statements[1].mainsnak.datatype
if datatype == 'wikibase-item' or datatype == 'wikibase-property' then
local class = options.class:upper()
oldStatements, Statements = Statements, {}
for _, statement in pairs(oldStatements) do
if statement.mainsnak.snaktype == "value" then
local function IsInClass(id)
local entity = getEntityFromId(id)
local Classes = entity:getBestStatements('P279')
if Classes then
for _, class in pairs(Classes) do
if class.mainsnak.snaktype == 'value' then
local id = p.getEntityIdFromValue(class.mainsnak.datavalue.value)
if class == id or IsInClass(id) then
return true
end
end
end
end
return false
end
local entity = getEntityFromId(p.getEntityIdFromValue(statement.mainsnak.datavalue.value))
local Instances = entity:getBestStatements('P31')
if Instances then
for _, instance in pairs(Instances) do
if instance.mainsnak.snaktype == 'value' then
local id = p.getEntityIdFromValue(instance.mainsnak.datavalue.value)
if class == id or IsInClass(id) then
table.insert(Statements, statement)
break
end
end
end
end
end
end
if #Statements == 0 then return {} end
else
return formatError('invalid-datatype', options.property, datatype, 'wikibase-item/wikibase-property')
end
end
-- apply filter by language
if options.withlang and options.withlang ~= '' then
local datatype = Statements[1].mainsnak.datatype
if datatype == 'monolingualtext' then
oldStatements, Statements = Statements, {}
for _, statement in pairs(oldStatements) do
if statement.mainsnak.snaktype == "value" then
if statement.mainsnak.datavalue.value.language == options.withlang then
table.insert(Statements, statement)
end
end
end
if #Statements == 0 then return {} end
else
return formatError('invalid-datatype', options.property, datatype, 'monolingualtext')
end
end
-- apply filter by time
if options.date and options.date ~= '' then
local date
local Time = require 'Modul:Time'
if type(options.date) == 'table' then
date = options.date
-- elseif mw.ustring.find(options.date, '^[Pp][1-9]%d-$') then
elseif options.date == '#now' then
date = Time.new( os.date('!*t') )
else
date = Time.newFromIso8601( options.date )
end
if date then
oldStatements, Statements = Statements, {}
local temp_value
local Date = require 'Modul:Wikidata/datum'
for _, statement in pairs(oldStatements) do
if statement.qualifiers then
local Values = {}
for key, array in pairs(props) do
for _, prop in pairs(array) do
if statement.qualifiers[prop] then
for _, qualData in pairs(statement.qualifiers[prop]) do
if qualData.snaktype == "value" then
Values[key] = Time.newFromWikidataValue(qualData.datavalue.value)
break
end
end
end
end
end
if Values.point then
if not Date.IsSecondLaterThanFirst(date, Values.point) then
if not temp_value then
Statements = { statement }
temp_value = Values.point
else
if Date.IsSecondLaterThanFirst(Values.point, temp_value) then
Statements = { statement }
temp_value = Values.point
elseif Date.IsSecondSameAsFirst(temp_value, Values.point) then
table.insert(Statements, statement)
end
end
end
else
if Values.begin then
if Date.IsSecondLaterThanFirst(Values.begin, date) then
if not Values.ending then
table.insert(Statements, statement)
elseif Date.IsSecondLaterThanFirst(date, Values.ending) then
table.insert(Statements, statement)
end
end
elseif Values.ending then
if Date.IsSecondLaterThanFirst(date, Values.ending) then
if not Values.begin then
table.insert(Statements, statement)
elseif Date.IsSecondLaterThanFirst(Values.begin, date) then
table.insert(Statements, statement)
end
end
end
end
end
end
if #Statements == 0 then return {} end
else
return formatError('invalid-date', options.date)
end
end
-- sort statements if needed
if options.sort and options.sort ~= '' then
local function checkInvert(value)
if options.invert and tostring(options.invert) == 'true' then
return not value
end
return value and true
end
if options.sort == 'rank' then
table.sort(Statements, function(first, second)
if first.rank == 'preferred' and second.rank ~= 'preferred' then
return checkInvert(true)
elseif first.rank == 'normal' and second.rank == 'deprecated' then
return checkInvert(true)
end
return checkInvert(false)
end)
elseif options.sort == 'date' then
table.sort(Statements, function(first, second)
local FirstValues, SecondValues
local Date = require 'Modul:Wikidata/datum'
if first and first.qualifiers then
FirstValues = {}
local Time = require 'Modul:Time'
for key, array in pairs(props) do
for _, prop in pairs(array) do
if first.qualifiers[prop] then
for _, qualData in pairs(first.qualifiers[prop]) do
if qualData.snaktype == "value" then
FirstValues[key] = Time.newFromWikidataValue(qualData.datavalue.value)
break
end
end
end
end
end
end
if second and second.qualifiers then
SecondValues = {}
local Time = require 'Modul:Time'
for key, array in pairs(props) do
for _, prop in pairs(array) do
if second.qualifiers[prop] then
for _, qualData in pairs(second.qualifiers[prop]) do
if qualData.snaktype == "value" then
SecondValues[key] = Time.newFromWikidataValue(qualData.datavalue.value)
break
end
end
end
end
end
end
if not FirstValues or not SecondValues then
if not FirstValues and not SecondValues then
return checkInvert(false)
else
return checkInvert(not SecondValues)
end
end
if FirstValues.point or SecondValues.point then
if FirstValues.point and SecondValues.point then
return checkInvert(Date.IsSecondLaterThanFirst(FirstValues.point, SecondValues.point))
else
return checkInvert(not FirstValues.point)
end
else
if FirstValues.begin or SecondValues.begin then
if FirstValues.begin and SecondValues.begin then
return checkInvert(Date.IsSecondLaterThanFirst(FirstValues.begin, SecondValues.begin))
else
return checkInvert(not FirstValues.begin)
end
elseif FirstValues.ending or SecondValues.ending then
if FirstValues.ending and SecondValues.ending then
return checkInvert(Date.IsSecondLaterThanFirst(FirstValues.ending, SecondValues.ending))
else
return checkInvert(not FirstValues.ending)
end
end
end
return checkInvert(false)
end)
elseif options.sort == 'alfa' then
if Statements[1].mainsnak.datatype == 'wikibase-item' or Statements[1].mainsnak.datatype == 'wikibase-property' then
table.sort(Statements, function(first, second)
if not (first and second) then
return checkInvert(second)
end
if not (first.mainsnak.snaktype == "value" and second.mainsnak.snaktype == "value") then
return checkInvert(second.mainsnak.snaktype == "value")
end
local first_label = mw.wikibase.label(p.getEntityIdFromValue(first.mainsnak.datavalue.value))
local second_label = mw.wikibase.label(p.getEntityIdFromValue(second.mainsnak.datavalue.value))
if not (first_label and second_label) then
return checkInvert(second_label)
end
local min_length = mw.ustring.len(first_label)
if mw.ustring.len(second_label) < mw.ustring.len(first_label) then
min_length = mw.ustring.len(second_label)
end
local chars = ' -0123456789aábcčdďeéěfghiíjklmnňoópqrřsštťuúůvwxyýzž'
local function charValue(char)
return mw.ustring.match(chars, '()' .. char) or (mw.ustring.len(chars) + 1)
end
local i = 1
while i <= min_length do
local first_char = mw.ustring.sub(mw.ustring.lower(first_label), i, i)
local second_char = mw.ustring.sub(mw.ustring.lower(second_label), i, i)
if charValue(first_char) ~= charValue(second_char) then
return checkInvert(charValue(first_char) < charValue(second_char))
end
i = i + 1
end
return checkInvert(mw.ustring.len(second_label) == min_length)
end)
end
elseif options.sort == 'number' then
if Statements[1].mainsnak.datatype == 'quantity' then
table.sort(Statements, function(first, second)
if not (first and second) then
return checkInvert(second)
end
if not (first.mainsnak.snaktype == "value" and second.mainsnak.snaktype == "value") then
return checkInvert(second.mainsnak.snaktype == "value")
end
local first_quantity = tonumber(first.mainsnak.datavalue.value.amount)
local second_quantity = tonumber(second.mainsnak.datavalue.value.amount)
return checkInvert(first_quantity > second_quantity)
end)
end
else
return formatError('invalid-sort', options.sort)
end
end
-- apply filter by limit
local limit = options.limit
if limit then
while #Statements > limit do
table.remove(Statements)
end
end
return Statements
end
 
Řádek 419 ⟶ 28:
if options.of and options.of ~= '' then
if entity then
local Statements = filterStatements(entity, { property = :getBestStatements(options.of, rank = 'best' })
for _, statement in pairs(Statements) do
if statement.mainsnak.datavalue.type == 'wikibase-entityid' then
local id = plib.getEntityIdFromValue(statement.mainsnak.datavalue.value)
entity = getEntityFromId(id)
if entity and entity.id ~= id then
Řádek 429 ⟶ 38:
return entity
else
return error(lib.formatError('invalid-datatype', options.of:upper(), statement.mainsnak.datatype, 'wikibase-item/wikibase-property'))
end
end
Řádek 436 ⟶ 45:
end
return entity
end
 
local function formatFromPattern( str, options )
return mw.ustring.gsub( options.pattern, '$1', str ) .. '' --Hack to get only the first result of the function
end
 
local function getSitelink(options)
local options = lib.common.cleanArgs(options)
local site
if options.site and options.site ~= '' then
site = options.site
elseif options[1] and options[1] ~= '' then
site = mw.text.trim(options[1])
end
 
local entity = findEntity(options)
 
if not entity or not entity.sitelinks then
return nil
end
 
local site = options.site or options[1]
 
local sitelink = entity:getSitelink(site)
 
if not sitelink then
return nil
end
 
if options.pattern and options.pattern ~= '' then
if options.pattern then
sitelink = formatFromPattern(sitelink, options)
sitelink = lib.formatFromPattern(sitelink, options.pattern)
end
return sitelink
end
 
-- @deprecated
local function fastConvertDdToDms(ddValue)
local dmsArr = {
degrees = 0,
minutes = 0,
seconds = 0.0
}
 
if ddValue then
dmsArr["degrees"] = math.floor(tonumber(ddValue))
dmsArr["minutes"] = math.floor((tonumber(ddValue) - dmsArr["degrees"]) * 60)
dmsArr["seconds"] = (tonumber(ddValue) - dmsArr["degrees"] - dmsArr["minutes"]/60) * 3600
end
 
return dmsArr
end
 
local function formatCoordinateValue(datavalue, typeOfValue, field)
-- type bude nepovinny - tj. "nil"
-- priklad pouze -- je tam asi X chyb (mimo jine N vs S a podobne)
local value = ""
local latdmsText, londmsText
if typeOfValue == 'dms' then
local latDms = fastConvertDdToDms(datavalue.value.latitude)
local lonDms = fastConvertDdToDms(datavalue.value.longitude)
latdmsText = "N " .. latDms["degrees"] .. "° " .. latDms["minutes"] .. "' " .. latDms["seconds"] .. '"'
londmsText = "E " .. lonDms["degrees"] .. "° " .. lonDms["minutes"] .. "' " .. lonDms["seconds"] .. '"'
if field then
if field == 'latitude' then
value = latdmsText
elseif field == 'longitude' then
value = londmsText
end
else
value = latdmsText .. " " .. londmsText
end
elseif typeOfValue == 'dd' then
latdmsText = tonumber(datavalue.value.latitude)
londmsText = tonumber(datavalue.value.longitude)
if field then
if field == 'latitude' then
value = latdmsText
elseif field == 'longitude' then
value = londmsText
end
else
value = latdmsText .. " " .. londmsText
end
else
value = datavalue.value.latitude .. ' / ' .. datavalue.value.longitude .. ' (přesnost: ' .. datavalue.value.precision .. ')'
end
 
return value
end
 
local function formatEntityId(entityId, options)
local formatter = require 'Modul:Wikidata/item'
Řádek 526 ⟶ 74:
end
 
local function findPatternformatStatement(propertystatement, options)
if not statement.type or statement.type ~= 'statement' then
local entity = getEntityFromId(property:upper())
return error(lib.formatError('unknown-claim-type', statement.type))
if entity then
local Statements = filterStatements(entity, { limit = 1, property = 'P1630', rank = 'best' })
if Statements[1] then
return Statements[1].mainsnak.datavalue.value
end
end
return nil
end
 
local functionoptions formatDatavalue= lib.common.cleanArgs( datavalue, options )
local Filterers = require 'Modul:Wikidata/Filterers'
--Use the customize handler if provided
local Formatters = require 'Modul:Wikidata/Formatters'
if options['value-module'] or options['value-function'] then
if not options['value-module'] or not options['value-function'] then
return formatError( 'unknown-value-module' )
end
local formatter = require ('Module:' .. options['value-module'])
if not formatter then
return formatError( 'value-module-not-found', options['value-module'] )
end
local fun = formatter[options['value-function']]
if not fun then
return formatError( 'value-function-not-found', options['value-function'] )
end
return fun( datavalue.value, options )
end
 
local mainsnak, qualifiers, targetdata, references
--Default formatters
if not lib.IsOptionTrue(options, 'qualifiersOnly') then
if datavalue.type == 'wikibase-entityid' then
returnmainsnak formatEntityId(p= Formatters.getEntityIdFromValuegetFormattedValue(datavaluestatement.value)mainsnak, options)
elseif datavalue.type == 'string' then
if options.pattern and options.pattern ~= '' then
return formatFromPattern( datavalue.value, options )
elseif options.autoformat and tostring(options.autoformat) == 'true' then
local pattern = findPattern(options.property)
if pattern then
return formatFromPattern( datavalue.value, { pattern = '[' .. pattern .. ' $1]' } )
end
else
return datavalue.value
end
elseif datavalue.type == 'time' then
local Time = require 'Modul:Time'
return Time.newFromWikidataValue( datavalue.value ):toString()
elseif datavalue.type == 'globecoordinate' then
if not options.field or options.field == '' then
-- return formatError( 'param-not-provided', 'field' )
return formatCoordinateValue(datavalue, 'dms')
elseif options.field == "latitude" or options.field == "longitude" then
return formatCoordinateValue(datavalue, options.typeOfCoordinates, options.field)
elseif options.field == "precision" or options.field == "globe" then
return datavalue.value[options.field]
else
return formatError( 'invalid-field', options.field )
end
elseif datavalue.type == 'monolingualtext' then
return '<span lang="' .. datavalue.value.language .. '">' .. datavalue.value.text .. '</span>'
elseif datavalue.type == 'quantity' then
local value = tonumber(datavalue.value.amount)
local margin
if tostring(options.showmargin) == 'true' then
margin = value - tonumber(datavalue.value.lowerBound)
if margin == 0 then
margin = nil
end
end
local prefix
if value < 0 then
value = tonumber(mw.ustring.sub(value, 2))
prefix = '−'
end
if tostring(options.formatted) == 'true' then
local function formatNumber(number)
local integer, decimal
if mw.ustring.find(number, '%.') then
integer, decimal = mw.ustring.match(number, '^(.+)%.(.+)$')
else
integer = number
end
local length = mw.ustring.len(integer)
local i = length % 3
if i == 0 then
i = 3
end
local formatted_num = mw.ustring.sub(integer, 1, i)
while i < length do
formatted_num = formatted_num .. '&nbsp;' .. mw.ustring.sub(integer, i + 1, i + 3)
i = i + 3
end
if decimal then
local length = mw.ustring.len(decimal)
local i = 3
formatted_num = formatted_num .. ',' .. mw.ustring.sub(decimal, 1, 3)
while i < length do
formatted_num = formatted_num .. '&nbsp;' .. mw.ustring.sub(decimal, i + 1, i + 3)
i = i + 3
end
end
return formatted_num
end
value = formatNumber(value)
if margin then
margin = formatNumber(margin)
end
end
if margin then
value = value .. '±' .. margin
end
if prefix then
value = prefix .. value
end
local unit = datavalue.value.unit
if unit ~= '1' and tostring(options.showunit) ~= 'false' then
unit = mw.ustring.match(unit, '(Q%d+)')
unit = formatEntityId(unit, {})
value = value .. '&nbsp;' .. unit
end
return value
else
return formatError( 'unknown-datavalue-type', datavalue.type )
end
if statement.qualifiers and options.showqualifier then
end
local PropList = lib.textToTable(options.showqualifier)
 
local function formatSnak( snak, options )
if snak.snaktype == 'value' then
return formatDatavalue( snak.datavalue, options )
elseif snak.snaktype == 'somevalue' or snak.snaktype == 'novalue' then
return i18n[snak.snaktype]
else
return formatError( 'unknown-snak-type', snak.snaktype )
end
end
 
local function formatStatement( statement, options )
if not statement.type or statement.type ~= 'statement' then
return formatError( 'unknown-claim-type', statement.type )
end
local mainsnak = formatSnak(statement.mainsnak, options)
local qualifiers, targetdata, references
if statement.qualifiers and options.showqualifier and options.showqualifier ~= '' then
local Snaks = {}
local PropList = {}
if type(options.showqualifier) == "table" then
PropList = options.showqualifier
else
PropList = mw.text.split(tostring(options.showqualifier):upper(), "%s*,%s*")
end
for _, property in pairs(PropList) do
local Values = {}
local optionsproperty = {mw.ustring.upper(property)
local format_options = {
autoformat = true,
entityprecision = options.entity9,
property = property,
}
if statement.qualifiers[property] then
forlocal _,Qualifiers snakData= in pairsFilterers.filterQualifiers(statement.qualifiers[property]), dooptions)
for _, snak in pairs(Qualifiers) do
if snakData.snaktype == "value" then
if snakDatalib.datatype == "time"IsSnakValue(snak) then
table.insert(Values, Formatters.getFormattedValue(snak, format_options))
options["value-module"] = "Wikidata/datum"
options["value-function"] = "formatDate"
options.precision = 9
end
table.insert(Values, formatDatavalue(snakData.datavalue, options))
end
end
elseif property == "TIME" then
local Data = {}
options["value-module"] = "Wikidata/datum"
for key, array in pairs(lib.props) do
options["value-function"] = "formatDate"
options.precision = 9
local Datavalues = {}
for key, array in pairs(props) do
for _, prop in pairs(array) do
if statement.qualifiers[prop] then
for _, snakDatasnak in pairs(statement.qualifiers[prop]) do
if snakDatalib.snaktype == "value"IsSnakValue(snak) then
DatavaluesData[key] = snakDataFormatters.datavaluegetRawValue(snak)
break
end
Řádek 709 ⟶ 119:
end
end
local Date = require 'Modul:Wikidata/datum'
if Datavalues.point then
if Data.point then
table.insert(Values, formatDatavalue(Datavalues.point, options))
table.insert(Values, Date.formatDateFromTimevalue(Data.point, options))
elseif Datavalues.begin or Datavalues.ending then
elseif Data.begin or Data.ending then
local Date = require 'Modul:Wikidata/datum'
table.insert(Values, Date.formatDateRange(optionsData, Datavalues.begin, Datavalues.endingoptions))
end
end
Řádek 724 ⟶ 134:
end
end
if not qualifiers and options.showtargetdata and options.showtargetdata ~= '' then
local Snaks = {}
local entity
if lib.IsSnakValue(statement.mainsnak.snaktype == "value") then
if statement.mainsnak.datavalue.type == 'wikibase-entityid' then
entity = getEntityFromId(pFormatters.getEntityIdFromValuegetRawValue(statement.mainsnak.datavalue.value))
else
return error(lib.formatError('invalid-datatype', statement.mainsnak.property, statement.mainsnak.datatype, 'wikibase-item/wikibase-property'))
end
end
if entity and entity.claims then
local PropList = {}lib.textToTable(options.showtargetdata)
iflocal type(options.showtargetdata) == "table" then{
autoformat = true,
PropList = options.showtargetdata
date = options.targetdate,
else
entity = entity,
PropList = mw.text.split(tostring(options.showtargetdata):upper(), "%s*,%s*")
precision = 9,
end
rank = (options.targetdate and 'valid') or 'best',
sort = 'date'
}
local Snaks = {}
for _, property in pairs(PropList) do
local Values = {}result
if mw.ustring.lower(property) == 'time' then
local options = {
autoformatlocal Data = true,{}
for key, array in pairs(lib.props) do
date = options.targetdate,
entity = entity,
property = property,
rank = (options.targetdate and 'valid') or 'best',
sort = 'date'
}
if entity.claims[property] then
local Statements = filterStatements(entity, options)
for _, statement in pairs(Statements) do
if statement.mainsnak.datatype == "time" then
options["value-module"] = "Wikidata/datum"
options["value-function"] = "formatDate"
end
table.insert(Values, formatDatavalue(statement.mainsnak.datavalue, options))
end
elseif property == "TIME" then
options["value-module"] = "Wikidata/datum"
options["value-function"] = "formatDate"
local Datavalues = {}
for key, array in pairs(props) do
for _, prop in pairs(array) do
options.property = prop
local Statements = filterStatementsFilterers.filterStatementsFromEntity(entity, options)
for _, statement in pairs(Statements) do
DatavaluesData[key] = Formatters.getRawValue(statement.mainsnak.datavalue)
break
end
end
end
local Date = require 'Modul:Wikidata/datum'
if Datavalues.point then
if Data.point then
table.insert(Values, formatDatavalue(Datavalues.point, options))
result = Date.formatDateFromTimevalue(Data.point, options)
elseif Datavalues.begin or Datavalues.ending then
elseif Data.begin or Data.ending then
local Date = require 'Modul:Wikidata/datum'
table.insert(Values,result = Date.formatDateRange(optionsData, Datavalues.begin, Datavalues.ending)options)
end
else
options.property = property
result = p.formatStatementsFromLua(options)
end
if #Values > 0result then
table.insert(Snaks, mw.text.listToText(Values)result)
end
end
Řádek 790 ⟶ 187:
end
end
if statement.references and optionslib.showsource and tostringIsOptionTrue(options.showsource) ==, 'trueshowsource') then
local Module = require 'Module:Wikidata/cite' --TODO
references = Module.formatSource(statement.references, options)
end
 
if qualifiers or targetdata then
if lib.IsOptionTrue(options., 'qualifiersOnly and qualifiers') then
mainsnak = (qualifiers or targetdata)
else
if options.delimiter and options.delimiter ~= '' then
mainsnak = mainsnak .. options.delimiter .. (qualifiers or targetdata)
else
Řádek 805 ⟶ 202:
end
end
end
if options.qualifiersOnly and not qualifiers then
return ""
end
if references then
Řádek 819 ⟶ 212:
local value = options.value
if value then
if value == '' and tostringlib.IsOptionTrue(options.over) ==, 'trueover') then
value = nil
end
if value and not (tostringlib.IsOptionTrue(options.compare) ==, 'truecompare') then
return value
end
Řádek 832 ⟶ 225:
options.limit = tonumber(options.limit) --TODO default
local add_more = false
if not (tostringlib.IsOptionTrue(options.compare) ==, 'truecompare') then
if options.limit and optionslib.showmore and tostringIsOptionTrue(options.showmore) ==, 'trueshowmore') then
options.limit = options.limit + 1
add_more = true
Řádek 839 ⟶ 232:
end
 
local Filterers = require 'Modul:Wikidata/Filterers'
local Statements = filterStatements(entity, options)
local Statements = Filterers.filterStatementsFromEntity(entity, options)
 
options.property = mw.ustring.upper(options.property)
if value then
local Check = require 'Modul:Wikidata/compare'
Řádek 865 ⟶ 260:
end
if add_more then
table.insert(formattedStatements, mw.ustring.format(i18n.["more-on-Wikidata"], entity.id, options.property))
end
value = mw.text.listToText(formattedStatements, options.separator, options.conjunction)
if tostringlib.IsOptionTrue(options.addcat) ==, 'trueaddcat') then
value = value .. lib.category('used-property', options.catbase or options.property)
local Cat = require 'Modul:Kategorie'
value = value .. Cat.makeCategory('Údržba:Použití vlastnosti ' .. options.catbase or options.property)
end
if tostringlib.IsOptionTrue(options.infobox) ==, 'trueaddlink') then
value = value .. ' <sup class="wd-link">([[d:' .. entity.id .. '#' .. options.property .. '|e]])</sup>'
end
value = '<span class="wd">' .. value .. '</span>'
if lib.IsOptionTrue(options, 'addclass') then
value = lib.addWdClass(value)
end
return value
Řádek 889 ⟶ 285:
local site = args.site or nil
if not site or site == '' then
return error(lib.formatError( 'param-not-provided', 'site' ))
end
local entity = findEntity( args )
Řádek 898 ⟶ 294:
end
end
return table.concat( Badges, ', ' ) or ''
end
 
Řádek 904 ⟶ 300:
local args = frame and frame.args or {}
local lang = args.lang or nil
if not lang or lang == '' or lang == i18nmw.langlanguage.codegetContentLanguage():getCode() then
return mw.wikibase.label(args.id or nil)
end
Řádek 911 ⟶ 307:
return entity.labels[lang].value
end
return ''nil
end
 
Řádek 917 ⟶ 313:
local args = frame and frame.args or {}
local lang = args.lang or nil
if not lang or lang == '' or lang == i18nmw.langlanguage.codegetContentLanguage():getCode() then
return mw.wikibase.description(args.id or nil)
end
Řádek 924 ⟶ 320:
return entity.descriptions[lang].value
end
return ''nil
end
 
Řádek 932 ⟶ 328:
local entity = findEntity( args )
if not lang or lang == '' then
lang = i18nmw.langlanguage.codegetContentLanguage():getCode()
end
if not entity or not entity.aliases or not entity.aliases[lang] then
return ''nil
end
 
Řádek 952 ⟶ 348:
local args = frame and frame.args or {}
if not args.property or args.property == '' then
return error(lib.formatError( 'param-not-provided', 'property' ))
end
 
Řádek 976 ⟶ 372:
end
 
-- @deprecated
-- move to submodule
function p.filterStatementsFromLua(entity, options...)
local Filterers = require 'Modul:Wikidata/Filterers'
return filterStatements(entity, options)
return Filterers.filterStatementsFromEntity(...)
end