Modul:Wikidata: Unterschied zwischen den Versionen
Aktualisierung Modul nach https://de.wikipedia.org/wiki/Modul:Wikidata , Autoren siehe https://de.wikipedia.org/w/index.php?title=Modul:Wikidata&action=history
(Modul neu nach https://de.wikipedia.org/wiki/Modul:Wikidata , Autoren siehe https://de.wikipedia.org/w/index.php?title=Modul:Wikidata&action=history) |
(Aktualisierung Modul nach https://de.wikipedia.org/wiki/Modul:Wikidata , Autoren siehe https://de.wikipedia.org/w/index.php?title=Modul:Wikidata&action=history) |
||
Zeile 62: | Zeile 62: | ||
[14] = {"s","U"} --precision: second | [14] = {"s","U"} --precision: second | ||
} | } | ||
local function printError(code) | local function printError(code) | ||
Zeile 138: | Zeile 136: | ||
end | end | ||
do return false end | do return false end | ||
end | end | ||
Zeile 353: | Zeile 313: | ||
if qualifierId then | if qualifierId then | ||
-- search the attribute snak with the given qualifier as key | -- search the attribute snak with the given qualifier as key | ||
if claim.qualifiers then | if claim and claim.qualifiers then | ||
local qualifier = claim.qualifiers[qualifierId] | local qualifier = claim.qualifiers[qualifierId] | ||
if qualifier then return qualifier[1] end | if qualifier then return qualifier[1] end | ||
Zeile 520: | Zeile 480: | ||
if invert and claim.qualifiers[string.sub(qualifierproperty, 2)] then return false end | if invert and claim.qualifiers[string.sub(qualifierproperty, 2)] then return false end | ||
return true | return true | ||
end | |||
local function qualifierhasvalue(claim, property, value) | |||
if not claim.qualifiers then return false end | |||
if not claim.qualifiers[property] then return false end | |||
for key, snak in pairs(claim.qualifiers[property]) do | |||
if snak.snaktype == "value" then | |||
if snak.datavalue.type == "wikibase-entityid" then | |||
if snak.datavalue.value.id == value then | |||
return true | |||
end | |||
--TODO: elseif other types | |||
end | |||
end | |||
end | |||
return false | |||
end | end | ||
Zeile 580: | Zeile 556: | ||
filter('hassource', hassource) | filter('hassource', hassource) | ||
filter('atdate', atdate) | filter('atdate', atdate) | ||
for key, val in pairs(frame.args) do | |||
if type(key) == "number" and key > 2 and key % 2 == 1 then | |||
-- key = 3, 5, 7 and so on | |||
local newclaims = {} | |||
for i, claim in pairs(claims) do | |||
if qualifierhasvalue(claim, frame.args[key - 1], frame.args[key]) then | |||
table.insert(newclaims, claim) | |||
end | |||
end | |||
claims = newclaims | |||
end | |||
end | |||
return claims | |||
end | |||
local p = {} | |||
function p.isSubclass(frame) | |||
if not frame.args["parent"] then return "" end | |||
local maxDepth | |||
maxDepth = frame.args["maxDepth"] or 5 | |||
if not type(maxDepth) == "number" then maxDepth = 5 end | |||
local result | |||
result = isParent(frame.args["id"], frame.args["parent"], frame.args["exitItem"], maxDepth) | |||
if frame.args["returnInt"] then | |||
if result == true then return 1 else return "" end | |||
else | |||
if result then return result else return false end | |||
end | |||
end | |||
function p.descriptionIn(frame) | |||
local langcode = frame.args[1] | |||
local id = frame.args[2] | |||
-- return description of a Wikidata entity in the given language or the default language of this Wikipedia site | |||
local entity = mw.wikibase.getEntity(id) | |||
if entity and entity.descriptions then | |||
local desc = entity.descriptions[langcode or wiki.langcode] | |||
if desc then return desc.value end | |||
else | |||
return ""; | |||
end | |||
end | |||
return | function p.labelIn(frame) | ||
local langcode = frame.args[1] | |||
local id = frame.args[2] | |||
-- return label of a Wikidata entity in the given language or the default language of this Wikipedia site | |||
local entity = mw.wikibase.getEntity(id) | |||
if entity and entity.labels then | |||
local label = entity.labels[langcode or wiki.langcode] | |||
if label then return label.value end | |||
else | |||
return ""; | |||
end | |||
end | end | ||
Zeile 627: | Zeile 662: | ||
-- sort by time qualifier | -- sort by time qualifier | ||
comparator = function(a, b) | comparator = function(a, b) | ||
local timea = getQualifierSortValue(claims[a], sort) | local timea = getQualifierSortValue(claims[a], sort) | ||
local timeb = getQualifierSortValue(claims[b], sort) | local timeb = getQualifierSortValue(claims[b], sort) | ||
if type(timea) ~= type(timeb) and not (tonumber(timea) and tonumber(timeb)) then | if type(timea) ~= type(timeb) and not (tonumber(timea) and tonumber(timeb)) then | ||
if tonumber(timea) then return true | if tonumber(timea) then return true | ||
Zeile 734: | Zeile 769: | ||
local id = frame.args[1] | local id = frame.args[1] | ||
local entity = mw.wikibase.getEntity(id) | local entity = mw.wikibase.getEntity(id) | ||
if not entity then return | if not entity then return "" else return entity.id end | ||
end | end | ||
Zeile 806: | Zeile 841: | ||
frame.args = newargs | frame.args = newargs | ||
local status, result = pcall(p[func], frame) | local status, result = pcall(p[func], frame) | ||
-- if status then return tostring(result) or "" else return '<span class="error">' .. result .. '</span>' end -- revert | |||
if status then return result else return '<span class="error">' .. result .. '</span>' end | if status then return result else return '<span class="error">' .. result .. '</span>' end | ||
else | else |