Zeile 12: |
Zeile 12: |
| ["property-not-found"] = "Eigenschaft nicht gefunden.", | | ["property-not-found"] = "Eigenschaft nicht gefunden.", |
| ["entity-not-found"] = "Wikidata-Eintrag nicht gefunden.", | | ["entity-not-found"] = "Wikidata-Eintrag nicht gefunden.", |
| + | ["entity-not-valid"] = "Die an die Wikidata-Schnittstelle übergebene Item-ID ist nicht gültig.", |
| ["unknown-claim-type"] = "Unbekannter Aussagentyp.", | | ["unknown-claim-type"] = "Unbekannter Aussagentyp.", |
| ["unknown-entity-type"] = "Unbekannter Entity-Typ.", | | ["unknown-entity-type"] = "Unbekannter Entity-Typ.", |
Zeile 313: |
Zeile 314: |
| 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 389: |
Zeile 390: |
| function formatReference(ref) | | function formatReference(ref) |
| -- "imported from"-references are useless, skip them: | | -- "imported from"-references are useless, skip them: |
− | if ref["P143"] then return nil end | + | if ref["P143"] or ref["P4656"] then return nil end |
| | | |
| -- load [[Modul:Zitation]] | | -- load [[Modul:Zitation]] |
Zeile 395: |
Zeile 396: |
| if type(r) == "table" then | | if type(r) == "table" then |
| Zitation = r.Zitation() | | Zitation = r.Zitation() |
| + | -- clear Zitation state from previous invocations |
| + | Zitation.o = nil |
| end | | end |
| -- assert (ZitationSuccess, i18n["errors"]["module-not-loaded"]) | | -- assert (ZitationSuccess, i18n["errors"]["module-not-loaded"]) |
Zeile 441: |
Zeile 444: |
| local URLutil = Zitation.fetch("URLutil") | | local URLutil = Zitation.fetch("URLutil") |
| Zitation.fill("bas", "Titel", URLutil.getHost(ref["P854"])) | | Zitation.fill("bas", "Titel", URLutil.getHost(ref["P854"])) |
− | elseif not (ref["P1476"]) then
| |
− | Zitation.fill("bas", "Titel", ref["P854"])
| |
| end | | end |
| refFormatted, f = Zitation.format() | | refFormatted, f = Zitation.format() |
− | return refFormatted | + | return refFormatted, f |
| end | | end |
| | | |
Zeile 465: |
Zeile 466: |
| end | | end |
| end | | end |
− | local formattedRef = formatReference(refTable) | + | local formattedRef, f = formatReference(refTable) |
− | if formattedRef then result = result .. frame:extensionTag("ref", formattedRef) end | + | -- log errors that occur during formatting |
| + | if f then |
| + | mw.log(f) |
| + | end |
| + | if formattedRef and formattedRef ~= "" then |
| + | local hash = mw.hash.hashValue('fnv164', formattedRef) |
| + | result = result .. frame:extensionTag("ref", formattedRef, { name = '_' .. hash }) |
| + | end |
| end | | end |
| return result | | return result |
Zeile 480: |
Zeile 488: |
| 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) |
| + | -- TODO: not yet documented! |
| + | 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 520: |
Zeile 545: |
| | | |
| return true | | return true |
| + | end |
| + | |
| + | local function notdeprecated(claim, sourceproperty) |
| + | return not (claim.rank == "deprecated") |
| end | | end |
| | | |
Zeile 540: |
Zeile 569: |
| filter('hassource', hassource) | | filter('hassource', hassource) |
| filter('atdate', atdate) | | filter('atdate', atdate) |
− | | + | if not frame.args.includedeprecated then |
| + | frame.args.notdeprecated = true |
| + | filter('notdeprecated', notdeprecated) |
| + | end |
| + | |
| + | -- use additional unnamed parameters as qualifier conditions (in pairs) |
| + | -- not yet documented! |
| + | -- TODO: not sure if this is good approach. Maybe use named parameter that has pairs split by semicolon |
| + | 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 | | return claims |
| end | | end |
Zeile 555: |
Zeile 604: |
| local result | | local result |
| result = isParent(frame.args["id"], frame.args["parent"], frame.args["exitItem"], maxDepth) | | result = isParent(frame.args["id"], frame.args["parent"], frame.args["exitItem"], maxDepth) |
| + | |
| if frame.args["returnInt"] then | | if frame.args["returnInt"] then |
− | if result == true then return 1 else return 0 end | + | if result == true then return 1 else return "" end |
| else | | else |
− | if result then return result else return "" end | + | if result then return result else return false end |
| end | | end |
| + | |
| end | | end |
| | | |
Zeile 579: |
Zeile 630: |
| local id = frame.args[2] | | local id = frame.args[2] |
| -- return label of a Wikidata entity in the given language or the default language of this Wikipedia site | | -- 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 mw.wikibase then |
| + | local entity = mw.wikibase.getEntity(id) |
| + | end |
| if entity and entity.labels then | | if entity and entity.labels then |
| local label = entity.labels[langcode or wiki.langcode] | | local label = entity.labels[langcode or wiki.langcode] |
Zeile 602: |
Zeile 655: |
| local inverse = frame.args["inverse"] | | local inverse = frame.args["inverse"] |
| local showerrors = frame.args["showerrors"] | | local showerrors = frame.args["showerrors"] |
− | local default = frame.args["default"] or "" | + | local default = frame.args["default"] |
− | if default ~="" then showerrors = nil end | + | if default then showerrors = nil end |
| | | |
| -- get wikidata entity | | -- get wikidata entity |
− | local entity = mw.wikibase.getEntity(id) | + | if id then |
| + | if not mw.wikibase.isValidEntityId(id) then |
| + | if showerrors then return printError("entity-not-valid") else return default end |
| + | elseif not mw.wikibase.entityExists(id) then |
| + | if showerrors then return printError("entity-not-found") else return default end |
| + | end |
| + | end |
| + | |
| + | if mw.wikibase then |
| + | local entity = mw.wikibase.getEntity(id) |
| + | end |
| if not entity then | | if not entity then |
| if showerrors then return printError("entity-not-found") else return default end | | if showerrors then return printError("entity-not-found") else return default end |
Zeile 629: |
Zeile 692: |
| local comparator | | local comparator |
| if sort then | | if sort then |
− | -- sort by time qualifier
| + | comparator = function(a, b) --comparator function for sorting statements based on qualifier value |
− | comparator = function(a, b) | + | -- load qualifier values |
− | local timea = getQualifierSortValue(claims[a], sort) or '' | + | local QualifierSortValueA = getQualifierSortValue(claims[a], sort) |
− | local timeb = getQualifierSortValue(claims[b], sort) or '' | + | local QualifierSortValueB = getQualifierSortValue(claims[b], sort) |
− | if type(timea) ~= type(timeb) and not (tonumber(timea) and tonumber(timeb)) then | + | |
− | if tonumber(timea) then return true | + | -- if either of the two statements does not have this qualifer, always sort it to the end. If neither of the two statements has this qualifier, statement A is ordered first |
− | elseif tonumber(timeb) then return "" | + | if not QualifierSortValueB then return true end |
− | elseif tostring(timea) and tostring(timeb) then | + | if not QualifierSortValueA then return false end |
− | if inverse then return tostring(timea) > tostring(timeb) else return tostring(timea) < tostring(timeb) end | + | |
− | else return "" end -- different types, neither numbers nor strings, no chance to compare => random result to avoid script error | + | if type(QualifierSortValueA) ~= type(QualifierSortValueB) and not (tonumber(QualifierSortValueA) and tonumber(QualifierSortValueB)) then |
− | elseif tonumber(timea) and tonumber(timeb) then | + | if tonumber(QualifierSortValueA) then return true |
− | timea = tonumber(timea) | + | elseif tonumber(QualifierSortValueB) then return false |
− | timeb = tonumber(timeb) | + | elseif tostring(QualifierSortValueA) and tostring(QualifierSortValueB) then |
| + | if inverse then return tostring(QualifierSortValueA) > tostring(QualifierSortValueB) else return tostring(QualifierSortValueA) < tostring(QualifierSortValueB) end |
| + | else return false end -- different types, neither numbers nor strings, no chance to compare => random result to avoid script error |
| + | elseif tonumber(QualifierSortValueA) and tonumber(QualifierSortValueB) then |
| + | QualifierSortValueA = tonumber(QualifierSortValueA) |
| + | QualifierSortValueB = tonumber(QualifierSortValueB) |
| end | | end |
| if inverse then | | if inverse then |
− | return tostring(timea > timeb) or "" | + | return QualifierSortValueA > QualifierSortValueB |
| else | | else |
− | return tostring(timea < timeb) or "" | + | return QualifierSortValueA < QualifierSortValueB |
| end | | end |
| end | | end |
Zeile 667: |
Zeile 735: |
| comparator = function(a, b) | | comparator = function(a, b) |
| if inverse then | | if inverse then |
− | return tostring(sortkeys[a] > sortkeys [b]) or "" | + | return sortkeys[a] > sortkeys [b] |
| else | | else |
− | return tostring(sortkeys[a] < sortkeys [b]) or "" | + | return sortkeys[a] < sortkeys [b] |
| end | | end |
| end | | end |
Zeile 726: |
Zeile 794: |
| | | |
| if result then return result else | | if result then return result else |
− | if showerrors then return error else return tostring(default) or "" end | + | if showerrors then return error else return default end |
| end | | end |
| end | | end |
Zeile 732: |
Zeile 800: |
| function p.getValue(frame) | | function p.getValue(frame) |
| local param = frame.args[2] | | local param = frame.args[2] |
− | if param == "FETCH_WIKIDATA" or param == i18n["FETCH_WIKIDATA"] then return tostring(p.claim(frame)) or "" else return tostring(param) or "" end | + | if param == "FETCH_WIKIDATA" or param == i18n["FETCH_WIKIDATA"] then return p.claim(frame) else return param end |
| end | | end |
| | | |
Zeile 777: |
Zeile 845: |
| if result then result = result .. "/" .. badges[idx] else result = badges[idx] end | | if result then result = result .. "/" .. badges[idx] else result = badges[idx] end |
| end | | end |
− | return tostring(result) or "" | + | return result |
| end | | end |
| end | | end |
Zeile 792: |
Zeile 860: |
| end | | end |
| end | | end |
− | return tostring(count) or "" | + | return count |
| end | | end |
| | | |
Zeile 810: |
Zeile 878: |
| 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 | + | -- 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 |
| else | | else |
| return printError("invalid-parameters") | | return printError("invalid-parameters") |
Zeile 819: |
Zeile 888: |
| local id = frame.args[1] | | local id = frame.args[1] |
| local entity = mw.wikibase.getEntity(id) | | local entity = mw.wikibase.getEntity(id) |
− | if entity then | + | if entity then return "<pre>" .. mw.text.jsonEncode(entity, mw.text.JSON_PRETTY) .. "</pre>" end |
− | return "<pre>" .. mw.text.jsonEncode(entity, mw.text.JSON_PRETTY) .. "</pre>"
| |
− | else
| |
− | return ""
| |
− | end
| |
| end | | end |
| | | |
| return p | | return p |