Modul:Wb: Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
imported>Juergen.Kett |
imported>Juergen.Kett |
||
Zeile 30: | Zeile 30: | ||
local value = "" | local value = "" | ||
p.entity = mw.wikibase.getEntity(id) | p.entity = mw.wikibase.getEntity(id) | ||
+ | |||
if not p.entity then | if not p.entity then | ||
return "no entity with id found: " .. id | return "no entity with id found: " .. id | ||
end | end | ||
+ | |||
p.claims = p.entity["claims"] | p.claims = p.entity["claims"] | ||
− | for | + | |
− | + | for propId, valueSnaks in pairs(p.claims) do | |
− | + | local values = "" | |
− | + | for key, valueSnak in pairs(valueSnaks) do | |
− | + | qualifiers = p.getFormatedQualifiers(valueSnak["qualifiers"]) | |
− | + | values = values .. p.renderValue(valueSnak["mainsnak"]) | |
− | + | end | |
− | + | ret = ret .. p.renderStatement(propId, values, qualifiers) | |
− | |||
end | end | ||
return ret | return ret | ||
end | end | ||
− | function p. | + | function p.getFormatedQualifiers(props) |
+ | if not props then return "" end | ||
local ret = "" | local ret = "" | ||
− | + | ||
− | + | for propId, valueSnaks in pairs(props) do | |
− | + | local values = "" | |
− | + | for key, valueSnak in pairs(valueSnaks) do | |
− | + | values = values .. p.renderValue(valueSnak) | |
− | |||
− | |||
− | |||
− | |||
− | |||
end | end | ||
+ | ret = ret .. p.renderStatement(propId, values, nil) | ||
end | end | ||
+ | |||
return ret | return ret | ||
end | end | ||
− | function p. | + | function p.renderStatement(propId, values, qualifiers) |
− | + | local propLabel = mw.wikibase.getLabel(propId) | |
− | + | if not propLabel then propLabel = "" end | |
− | + | ret = rowDelA .. colDelA .. propLabel .. colDelB .. values | |
− | + | if qualifiers then | |
− | + | ret = ret .. tableDelA .. qualifiers .. tableDelB | |
− | + | end | |
− | + | ret = ret .. rowDelB | |
− | + | return ret | |
− | + | end | |
− | + | ||
− | + | function p.renderValue(valueSnak) | |
− | + | local value = mw.wikibase.renderSnak(valueSnak) | |
+ | return rowDelA .. colDelA .. value .. colDelB .. rowDelB | ||
+ | end | ||
+ | |||
+ | p.getLabel = function (frame) | ||
+ | local id = frame.args.id | ||
+ | if id then | ||
+ | return mw.wikibase.getLabel(id) | ||
+ | end | ||
+ | return "" | ||
end | end | ||
Zeile 107: | Zeile 115: | ||
end | end | ||
− | + | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
return p | return p |
Version vom 30. Mai 2020, 19:09 Uhr
Die Dokumentation für dieses Modul kann unter Modul:Wb/Doku erstellt werden
local p = {}; p.id = nil; p.entity = nil; p.claims = nil; local rowDelA = "<tr>" local rowDelB = "</tr>\n" local colDelA = "<td>" local colDelB = "</td>" local tableDelA = "<table>" local tableDelB = "</table>" local refUrl = nil function p.getFormatedStatements(frame) id = frame.args.id rowDelA = frame.args.rowDelA rowDelB = frame.args.rowDelB colDelA = frame.args.colDelA colDelB = frame.args.colDelB tableDelA = frame.args.tableDelA tableDelB = frame.args.tableDelB return p._getFormatedStatements(id) end function p._getFormatedStatements(id) local ret = "" local qualifiers = "" local prop = "" local value = "" p.entity = mw.wikibase.getEntity(id) if not p.entity then return "no entity with id found: " .. id end p.claims = p.entity["claims"] for propId, valueSnaks in pairs(p.claims) do local values = "" for key, valueSnak in pairs(valueSnaks) do qualifiers = p.getFormatedQualifiers(valueSnak["qualifiers"]) values = values .. p.renderValue(valueSnak["mainsnak"]) end ret = ret .. p.renderStatement(propId, values, qualifiers) end return ret end function p.getFormatedQualifiers(props) if not props then return "" end local ret = "" for propId, valueSnaks in pairs(props) do local values = "" for key, valueSnak in pairs(valueSnaks) do values = values .. p.renderValue(valueSnak) end ret = ret .. p.renderStatement(propId, values, nil) end return ret end function p.renderStatement(propId, values, qualifiers) local propLabel = mw.wikibase.getLabel(propId) if not propLabel then propLabel = "" end ret = rowDelA .. colDelA .. propLabel .. colDelB .. values if qualifiers then ret = ret .. tableDelA .. qualifiers .. tableDelB end ret = ret .. rowDelB return ret end function p.renderValue(valueSnak) local value = mw.wikibase.renderSnak(valueSnak) return rowDelA .. colDelA .. value .. colDelB .. rowDelB end p.getLabel = function (frame) local id = frame.args.id if id then return mw.wikibase.getLabel(id) end return "" end -- wird nicht mehr benötigt function p.nextStatement() p.property = p.keys[p.index] mw.log(p.property) if p.property then claim = p.claims[p.property] snak = claim[1]["mainsnak"] p.value = mw.wikibase.renderSnak(snak) p.index = p.index + 1 end end -- wird nicht mehr benötigt function p.initEntity(qid) p.entity = mw.wikibase.getEntity(qid) p.claims = p.entity["claims"] -- p.i, p.v = next(p.claims, nil) -- mw.logObject(p.entity) p.keys = {} p.index=1 local i = 1 for k in pairs(p.claims) do p.keys[i]=k i = i + 1 end mw.logObject(p.keys) end return p