Modul:Wikidata: Unterschied zwischen den Versionen
Modul aktualisiert nach https://de.wikipedia.org/wiki/Modul:Wikidata vom 06.01.2021, 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) |
(Modul aktualisiert nach https://de.wikipedia.org/wiki/Modul:Wikidata vom 06.01.2021, Autoren siehe https://de.wikipedia.org/w/index.php?title=Modul:Wikidata&action=history) |
||
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 18: | Zeile 19: | ||
["invalid-parameters"] = "Ungültige Parameter.", | ["invalid-parameters"] = "Ungültige Parameter.", | ||
["module-not-loaded"] = "Loading of additional module failed." | ["module-not-loaded"] = "Loading of additional module failed." | ||
}, | |||
["maintenance-pages"] = | |||
{ | |||
["entity-not-found"] = "Wikidata/Wartung/Fehlendes Datenobjekt", | |||
["entity-not-valid"] = "Wikidata/Wartung/Ungültige Datenobjekt-Identifikationsnummer", | |||
["property-not-existing"] = "Wikidata/Wartung/Eigenschaft existiert nicht" | |||
}, | }, | ||
["datetime"] = | ["datetime"] = | ||
Zeile 389: | Zeile 396: | ||
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 402: | ||
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 450: | ||
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"])) | ||
end | end | ||
refFormatted, f = Zitation.format() | refFormatted, f = Zitation.format() | ||
return refFormatted | return refFormatted, f | ||
end | end | ||
Zeile 465: | Zeile 472: | ||
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 483: | Zeile 497: | ||
local function qualifierhasvalue(claim, property, value) | local function qualifierhasvalue(claim, property, value) | ||
-- TODO: not yet documented! | |||
if not claim.qualifiers then return false end | if not claim.qualifiers then return false end | ||
if not claim.qualifiers[property] then return false end | if not claim.qualifiers[property] then return false end | ||
Zeile 536: | Zeile 551: | ||
return true | return true | ||
end | |||
local function notdeprecated(claim, sourceproperty) | |||
return not (claim.rank == "deprecated") | |||
end | end | ||
Zeile 556: | Zeile 575: | ||
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 | for key, val in pairs(frame.args) do | ||
if type(key) == "number" and key > 2 and key % 2 == 1 then | if type(key) == "number" and key > 2 and key % 2 == 1 then | ||
Zeile 630: | Zeile 656: | ||
local references = frame.args["references"] | local references = frame.args["references"] | ||
local sort = frame.args["sort"] | local sort = frame.args["sort"] | ||
local sortEmptiesFirst = frame.args["sortEmptiesFirst"] | |||
local sortInItem = frame.args["sortInItem"] | local sortInItem = frame.args["sortInItem"] | ||
local inverse = frame.args["inverse"] | local inverse = frame.args["inverse"] | ||
Zeile 637: | Zeile 664: | ||
-- get wikidata entity | -- get wikidata entity | ||
if id then | |||
if not mw.wikibase.isValidEntityId(id) then | |||
if showerrors then | |||
return printError("entity-not-valid") | |||
else | |||
local temp = mw.title.new(i18n["maintenance-pages"]["entity-not-valid"], "Modul").exists | |||
return default | |||
end | |||
elseif not mw.wikibase.entityExists(id) then | |||
if showerrors then | |||
return printError("entity-not-found") | |||
else | |||
local temp = mw.title.new(i18n["maintenance-pages"]["entity-not-found"], "Modul").exists | |||
return default | |||
end | |||
end | |||
end | |||
local entity = mw.wikibase.getEntity(id) | local entity = mw.wikibase.getEntity(id) | ||
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 | ||
end | end | ||
-- check if property exists | |||
local realProp = mw.wikibase.resolvePropertyId(property) | |||
if not realProp then | |||
local temp = mw.title.new(i18n["maintenance-pages"]["property-not-existing"], "Modul").exists | |||
end | |||
-- fetch the first claim of satisfying the given property | -- fetch the first claim of satisfying the given property | ||
local claims | local claims | ||
if entity.claims then claims = entity.claims[ | if entity.claims then claims = entity.claims[realProp] end | ||
if not claims or not claims[1] then | if not claims or not claims[1] then | ||
if showerrors then return printError("property-not-found") else return default end | if showerrors then return printError("property-not-found") else return default end | ||
Zeile 660: | Zeile 712: | ||
local comparator | local comparator | ||
if sort then | if sort then | ||
comparator = function(a, b) --comparator function for sorting statements based on qualifier value | |||
comparator = function(a, b) | -- load qualifier values | ||
local | local QualifierSortValueA = getQualifierSortValue(claims[a], sort) | ||
local | local QualifierSortValueB = getQualifierSortValue(claims[b], sort) | ||
if type( | |||
if tonumber( | -- if either of the two statements does not have this qualifer: | ||
elseif tonumber( | ---- if sortEmptiesFirst=true: sort it to the beginning | ||
elseif tostring( | ---- else: always sort it to the end | ||
if inverse then return tostring( | if not QualifierSortValueB then | ||
if not QualifierSortValueA then | |||
-- if neither of the two statements has this qualifier, arbitrarily but consistently return a < b | |||
return a < b | |||
elseif sortEmptiesFirst then | |||
return false | |||
else | |||
return true | |||
end | |||
elseif not QualifierSortValueA then | |||
if sortEmptiesFirst then return true else return false end | |||
end | |||
if type(QualifierSortValueA) ~= type(QualifierSortValueB) and not (tonumber(QualifierSortValueA) and tonumber(QualifierSortValueB)) then | |||
if tonumber(QualifierSortValueA) then return true | |||
elseif tonumber(QualifierSortValueB) then return false | |||
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 | else return false end -- different types, neither numbers nor strings, no chance to compare => random result to avoid script error | ||
elseif tonumber( | elseif tonumber(QualifierSortValueA) and tonumber(QualifierSortValueB) then | ||
QualifierSortValueA = tonumber(QualifierSortValueA) | |||
QualifierSortValueB = tonumber(QualifierSortValueB) | |||
end | end | ||
if inverse then | if inverse then | ||
return | return QualifierSortValueA > QualifierSortValueB | ||
else | else | ||
return | return QualifierSortValueA < QualifierSortValueB | ||
end | end | ||
end | end | ||
Zeile 738: | Zeile 807: | ||
local claim = claims[sortindices[1]] | local claim = claims[sortindices[1]] | ||
if language and claim.mainsnak.datatype == "monolingualtext" then | if language == "Q" then | ||
result, error = "Q" .. getSnakValue(getQualifierSnak(claim), "numeric-id") | |||
elseif language and claim.mainsnak.datatype == "monolingualtext" then | |||
-- iterate over claims to find adequate language | -- iterate over claims to find adequate language | ||
for idx, claim in pairs(claims) do | for idx, claim in pairs(claims) do | ||
Zeile 853: | Zeile 924: | ||
if entity then return "<pre>" .. mw.text.jsonEncode(entity, mw.text.JSON_PRETTY) .. "</pre>" end | if entity then return "<pre>" .. mw.text.jsonEncode(entity, mw.text.JSON_PRETTY) .. "</pre>" end | ||
end | end | ||
-- formfill Template:Coordinate (NS, EW, name from WikidataEntity) and expand it | |||
-- füllt Vorlage:Coordinate (NS, EW, name mit Wikidata-Werten) + expandiert sie | |||
-- 1st frame.arg .. Q prefixed entity id (mandatory) | |||
-- named frame.arg "type", "region", "text" .. see doc of 'Coordinate' template | |||
function p.ffCoordinate(frame) | |||
local f = frame | |||
local id = f.args[1] or f.args.Q | |||
local name = f.args.name or p.labelIn{ args = { nil, id, id = id }} | |||
local coord = mw.text.split(p.claim{ args = { "P625", id, id = id }}, '/') | |||
coord[1] = tonumber(coord[1]) | |||
coord[2] = tonumber(coord[2]) | |||
local t, r = f.args.type, f.args.region | |||
if not t | |||
then t = p.claim{ args = { "P31", id, id = id, language = "Q" }} | |||
t = t and t:gsub("Q.*", { | |||
Q8502 = "mountain", | |||
Q54050 = "landmark" | |||
}) | |||
if not t or t and t:find("Q", 1, true) | |||
then t="" -- no default, let Coordinate warn about unset type= param | |||
end | |||
end | |||
if not r | |||
then r = p.claim{ args = { "P17", id, id = id, language = "Q" }} | |||
r = r and p.claim{ args = { "P297", r, id = r }} | |||
if not r | |||
then r="" -- no default, let Coordinate warn about unset region= param | |||
end | |||
end | |||
return ('<span data-sort-value="%010.6f"></span>'):format((f.args.sortkey | |||
or "EW"):find("EW", 1, true) and coord[2]+360.0 or coord[1]+180.0 | |||
) .. f:expandTemplate{ title = 'Coordinate', args = { | |||
NS = coord[1], EW = coord[2], type = t, region = r, | |||
text = f.args.text or (f.args.maplink and "ICON0" or "/"), | |||
name = name, simple = f.args.simple | |||
}} .. (not f.args.maplink and "" or (" " .. | |||
--f:callParserFunction{ name="#statements", args={ "P625", from = id } } | |||
f:callParserFunction{ name="#tag:maplink", args={ "", | |||
class = "no-icon", text = f.args.mlname and name, | |||
zoom = 12, latitude = coord[1], longitude = coord[2] | |||
}} | |||
)) | |||
end | |||
function p.ffCoordinateAndLatLonMaplink(frame) | |||
frame.args.maplink = 1 | |||
--frame.args.mlname = nil | |||
return p.ffCoordinate(frame) | |||
end | |||
function p.ffCoordinateAndMaplink(frame) | |||
frame.args.maplink = 1 | |||
frame.args.mlname = 1 | |||
return p.ffCoordinate(frame) | |||
end | |||
return p | return p |