„Modul:WikibaseQ“ – Versionsunterschied
Erscheinungsbild
KKeine Bearbeitungszusammenfassung |
KKeine Bearbeitungszusammenfassung |
||
| Zeile 1: | Zeile 1: | ||
local util = require('Module:Wikibase') | local util = require('Module:Wikibase') | ||
local cfg = require('Module:Wikibase/config') | |||
local p = {} | 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) | local function buildSubtitle(args, entityId) | ||
| Zeile 10: | Zeile 18: | ||
if low == 'nein' or low == '0' then return nil end | if low == 'nein' or low == '0' then return nil end | ||
if low ~= 'ja' and low ~= 'auto' then | if low ~= 'ja' and low ~= 'auto' then | ||
return util.trim(s) | return util.trim(s) -- eigener Text | ||
end | end | ||
end | end | ||
return util.getDescription(entityId) | return util.getDescription(entityId) | ||
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) | |||
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 '') | |||
return tostring(t) | |||
end | end | ||
| Zeile 20: | Zeile 67: | ||
local entityId = util.detectEntityId(args) | local entityId = util.detectEntityId(args) | ||
if not entityId then return '' end | if not entityId then return '' end | ||
local label = args.label or util.getEntityLabelOrLemma(entityId) or entityId | local label = args.label or util.getEntityLabelOrLemma(entityId) or entityId | ||
local line1 = string.format('%s %s', entityId, label) | local line1 = string.format('%s %s', entityId, label) | ||
| Zeile 34: | Zeile 82: | ||
local link = util.buildEntityLink(entityId, line1text, args.target) | local link = util.buildEntityLink(entityId, line1text, args.target) | ||
local | local desc = buildSubtitle(args, entityId) | ||
if | |||
return link .. '<br />' .. util.trim( | -- SMW immer setzen (MVP: Art/Label/Beschreibung) | ||
local smw = buildSmw(entityId, label, desc) | |||
-- 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) | |||
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 | end | ||
return link | return smw .. link | ||
end | end | ||
function p.shortdesc(frame) | function p.shortdesc(frame) | ||
-- Q: | -- Q: kein SHORTDESC-Setzen hier (Q hat Sitelink-System), daher leer | ||
return '' | return '' | ||
end | end | ||
return p | return p | ||
Version vom 16. Dezember 2025, 16:06 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
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)
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 '')
return tostring(t)
end
function p.link(frame)
local args = util.getArgs(frame)
local entityId = util.detectEntityId(args)
if not entityId 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 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)
-- SMW immer setzen (MVP: Art/Label/Beschreibung)
local smw = buildSmw(entityId, label, desc)
-- 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)
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