„Modul:WikibaseQ“ – Versionsunterschied
Erscheinungsbild
KKeine Bearbeitungszusammenfassung |
KKeine Bearbeitungszusammenfassung |
||
| Zeile 22: | Zeile 22: | ||
end | end | ||
return util.getDescription(entityId) | return util.getDescription(entityId) | ||
end | |||
-- Präfixe gehören zum gespeicherten Wert, nicht zum P-Label/Attributnamen. | |||
-- Slotweise lesen, damit die Zuordnung auch bei gleichen P-Labels eindeutig ist. | |||
local function getPrefixedStatements(entityId) | |||
local c = (cfg and cfg.smw and cfg.smw.Q) or {} | |||
local rows, notices, seen = {}, {}, {} | |||
for slot = 1, 4 do | |||
local property = util.trim(tostring(c['prop' .. slot] or '')) | |||
if property ~= '' and not seen[property] then | |||
seen[property] = true | |||
if not property:match('^P[1-9]%d*$') then | |||
notices[#notices + 1] = 'Wikibase/config: prop' .. slot .. | |||
' enthält keine gültige P-ID: ' .. property | |||
else | |||
local values, warnings = util.getConfiguredQStatements( | |||
entityId, { prop1 = property }) | |||
local prefix = tostring(c['prefix' .. slot] or '') | |||
for _, entry in ipairs(values) do | |||
entry.value = prefix .. entry.value | |||
rows[#rows + 1] = entry | |||
end | |||
for _, warning in ipairs(warnings) do | |||
notices[#notices + 1] = warning | |||
end | |||
end | |||
end | |||
end | |||
return rows, notices | |||
end | end | ||
| Zeile 70: | Zeile 99: | ||
local args = util.getArgs(frame) | local args = util.getArgs(frame) | ||
local entityId = util.detectEntityId(args) | local entityId = util.detectEntityId(args) | ||
if not entityId then return '' end | if not entityId or not entityId:match('^Q%d+$') then return '' end | ||
local label = args.label or util.getEntityLabelOrLemma(entityId) or entityId | local label = args.label or util.getEntityLabelOrLemma(entityId) or entityId | ||
| Zeile 80: | Zeile 109: | ||
local args = util.getArgs(frame) | local args = util.getArgs(frame) | ||
local entityId = util.detectEntityId(args) | local entityId = util.detectEntityId(args) | ||
if not entityId then return '' end | if not entityId or not entityId:match('^Q%d+$') then return '' end | ||
local label = args.label or util.getEntityLabelOrLemma(entityId) or entityId | local label = args.label or util.getEntityLabelOrLemma(entityId) or entityId | ||
| Zeile 89: | Zeile 118: | ||
-- Bisherige Annotationen plus konfigurierte Q-Aussagen. | -- Bisherige Annotationen plus konfigurierte Q-Aussagen. | ||
local extraRows, notices = | local extraRows, notices = getPrefixedStatements(entityId) | ||
local smw = buildSmw(entityId, label, desc) .. util.smwAnnotateRows(extraRows) | local smw = buildSmw(entityId, label, desc) .. util.smwAnnotateRows(extraRows) | ||
for _, notice in ipairs(notices) do | for _, notice in ipairs(notices) do | ||
Version vom 15. Oktober 2026, 15:42 Uhr
Die Dokumentation für dieses Modul kann unter Modul:WikibaseQ/Doku erstellt werden
local util = require('Module:Wikibase')
local cfg = require('Module:Wikibase/config')
local p = {}
local function isNo(v)
if v == nil then return false end
local s = tostring(v):lower()
return (s == 'nein' or s == '0' or s == 'no' or s == 'false')
end
local function buildSubtitle(args, entityId)
-- Q: sichtbarer Untertitel = Beschreibung
local s = args.subtitle
if s and s ~= '' then
s = tostring(s)
local low = s:lower()
if low == 'nein' or low == '0' then return nil end
if low ~= 'ja' and low ~= 'auto' then
return util.trim(s) -- eigener Text
end
end
return util.getDescription(entityId)
end
-- Präfixe gehören zum gespeicherten Wert, nicht zum P-Label/Attributnamen.
-- Slotweise lesen, damit die Zuordnung auch bei gleichen P-Labels eindeutig ist.
local function getPrefixedStatements(entityId)
local c = (cfg and cfg.smw and cfg.smw.Q) or {}
local rows, notices, seen = {}, {}, {}
for slot = 1, 4 do
local property = util.trim(tostring(c['prop' .. slot] or ''))
if property ~= '' and not seen[property] then
seen[property] = true
if not property:match('^P[1-9]%d*$') then
notices[#notices + 1] = 'Wikibase/config: prop' .. slot ..
' enthält keine gültige P-ID: ' .. property
else
local values, warnings = util.getConfiguredQStatements(
entityId, { prop1 = property })
local prefix = tostring(c['prefix' .. slot] or '')
for _, entry in ipairs(values) do
entry.value = prefix .. entry.value
rows[#rows + 1] = entry
end
for _, warning in ipairs(warnings) do
notices[#notices + 1] = warning
end
end
end
end
return rows, notices
end
local function buildSmw(entityId, label, desc)
local c = cfg and cfg.smw and cfg.smw.Q
if not c then
return ''
end
return util.smwAnnotate({
[c.propArt] = c.valArt or 'Q',
[c.propLabel] = label or '',
[c.propDesc] = desc or '',
})
end
local function buildVisibleSmwTable(entityId, label, desc, extraRows)
local c = cfg and cfg.smw and cfg.smw.Q
if not c then
return ''
end
local artVal = c.valArt or 'Q'
-- HTML statt Wikitext-Tabelle (vermeidet Pipe/Parser-Kanten)
local t = mw.html.create('table')
t:addClass('aew-wb-smwtable')
local function row(k, v)
if not v or v == '' then return end
local tr = t:tag('tr')
tr:tag('th'):wikitext(k)
tr:tag('td'):wikitext(v)
end
row(c.propArt, artVal)
row(c.propLabel, label or '')
row(c.propDesc, desc or '')
for _, entry in ipairs(extraRows or {}) do
row(util.smwLiteral(entry.property), util.smwLiteral(entry.value))
end
return tostring(t)
end
function p.link(frame)
local args = util.getArgs(frame)
local entityId = util.detectEntityId(args)
if not entityId or not entityId:match('^Q%d+$') then return '' end
local label = args.label or util.getEntityLabelOrLemma(entityId) or entityId
local line1 = string.format('%s %s', entityId, label)
return util.buildEntityLink(entityId, line1, args.target)
end
function p.render(frame)
local args = util.getArgs(frame)
local entityId = util.detectEntityId(args)
if not entityId or not entityId:match('^Q%d+$') then return '' end
local label = args.label or util.getEntityLabelOrLemma(entityId) or entityId
local line1text = string.format('%s %s', entityId, label)
local link = util.buildEntityLink(entityId, line1text, args.target)
local desc = buildSubtitle(args, entityId)
-- Bisherige Annotationen plus konfigurierte Q-Aussagen.
local extraRows, notices = getPrefixedStatements(entityId)
local smw = buildSmw(entityId, label, desc) .. util.smwAnnotateRows(extraRows)
for _, notice in ipairs(notices) do
smw = smw .. '<span class="error">' .. util.smwLiteral(notice) .. '</span>'
end
-- Sichtbarkeit der SMW-Werte:
-- Default = ja, abschaltbar mit |show=nein
local show = not isNo(args.show)
-- Fallback-Anzeige (wie bisher): Link + <br/> + Beschreibung
if not show then
if desc and desc ~= '' then
return smw .. link .. '<br />' .. util.trim(desc)
end
return smw .. link
end
-- Sichtbare SMW-Anzeige: Link + (SMW-Tabelle)
local tableHtml = buildVisibleSmwTable(entityId, label, desc, extraRows)
if tableHtml ~= '' then
return smw .. link .. '<br />' .. tableHtml
end
-- Wenn config fehlt, fällt es auf die alte Anzeige zurück
if desc and desc ~= '' then
return smw .. link .. '<br />' .. util.trim(desc)
end
return smw .. link
end
function p.shortdesc(frame)
-- Q: kein SHORTDESC-Setzen hier (Q hat Sitelink-System), daher leer
return ''
end
return p