Modul:FBMVerlagTable

Die Dokumentation für dieses Modul kann unter Modul:FBMVerlagTable/Doku erstellt werden

-- Modul:FBMVerlagTable
-- Kompakte Arbeitsübersicht für WP:FBM-Verlagsseiten
-- Verwendung:
-- {{#invoke:FBMVerlagTable|table|Q16009958|Q42298814|Q1379034}}

local p = {}

local coreLangs = { 'de', 'en', 'fr', 'es' }

local langIcons = {
de = '[[Datei:Germany-orb.png|15px]]<br />de',
en = '[[Datei:United-Kingdom-orb.png|15px]]<br />en',
fr = '[[Datei:France-orb.png|15px]]<br />fr',
es = '[[Datei:Spain-orb.png|15px]]<br />es'
}

local function yes()
return '<span style="color:green; font-weight:bold;" title="vorhanden">✓</span>'
end

local function no()
return '<span style="color:#b00020; font-weight:bold;" title="nicht vorhanden">✗</span>'
end

local function dash()
return '<span style="color:#777;">–</span>'
end

local function hasClaim(entity, prop)
if entity and entity.claims and entity.claims[prop] then
return true
end
return false
end

local function getFirstStatementValue(entity, prop)
if not entity or not entity.claims or not entity.claims[prop] then
return nil
end

local statement = entity.claims[prop][1]
if not statement or not statement.mainsnak or statement.mainsnak.snaktype ~= 'value' then
	return nil
end

if not statement.mainsnak.datavalue then
	return nil
end

return statement.mainsnak.datavalue.value

end

local function getYear(entity, prop)
local value = getFirstStatementValue(entity, prop)
if not value or not value.time then
return nil
end

local year = value.time:match('^%+?(%d%d%d%d)')
if year then
	return year
end

return nil

end

local function isHuman(entity)
local value = getFirstStatementValue(entity, 'P31')
if value and value['numeric-id'] == 5 then
return true
end
return false
end

local function getLifeDates(entity)
if not isHuman(entity) then
return ''
end

local birth = getYear(entity, 'P569')
local death = getYear(entity, 'P570')

if birth and death then
	return '<br /><span style="font-size:smaller;">(' .. birth .. '–' .. death .. ')</span>'
elseif birth then
	return '<br /><span style="font-size:smaller;">(geb. ' .. birth .. ')</span>'
elseif death then
	return '<br /><span style="font-size:smaller;">(gest. ' .. death .. ')</span>'
end

return '<br /><span style="font-size:smaller;">(Lebensdaten prüfen)</span>'

end

local function getLabel(entity, id)
local label = entity:getLabel('de') or entity:getLabel('en')
if label and label ~= '' then
return label
end

local deSitelink = entity:getSitelink('dewiki')
if deSitelink then
	return deSitelink
end

local enSitelink = entity:getSitelink('enwiki')
if enSitelink then
	return enSitelink
end

return id

end

local function getDescription(entity)
local description = entity:getDescription('de') or entity:getDescription('en')
if description and description ~= '' then
return description
end

return '<span style="color:#777;">Beschreibung fehlt</span>'

end

local function getImageCell(entity)
local image = entity:formatPropertyValues('P18').value
if image and image ~= '' then
return '[[Datei:' .. image .. '|center|90px]]'
end

return dash()

end

local function makeArticleLink(entity, label, id)
local deSitelink = entity:getSitelink('dewiki')
if deSitelink then
return '[[' .. deSitelink .. '|' .. label .. ']]'
end

local enSitelink = entity:getSitelink('enwiki')
if enSitelink then
	return '[[:en:' .. enSitelink .. '|' .. label .. ']]'
end

local frSitelink = entity:getSitelink('frwiki')
if frSitelink then
	return '[[:fr:' .. frSitelink .. '|' .. label .. ']]'
end

local esSitelink = entity:getSitelink('eswiki')
if esSitelink then
	return '[[:es:' .. esSitelink .. '|' .. label .. ']]'
end

return '[[d:' .. id .. '|' .. label .. ']]'

end

local function makeLangCell(entity, lang)
local sitelink = entity:getSitelink(lang .. 'wiki')
if sitelink then
return '| style="background:#cfc; text-align:center;" | [[:' .. lang .. ':' .. sitelink .. '|+]]'
end

return '| style="text-align:center;" | –'

end

local function countWikipediaSitelinks(entity)
local count = 0
if not entity or not entity.sitelinks then
return 0
end

for key, _ in pairs(entity.sitelinks) do
	if key:match('wiki$') and key ~= 'commonswiki' then
		count = count + 1
	end
end

return count

end

local function countWdStatements(entity)
local count = 0

if not entity or not entity.claims then
	return 0
end

for _, statements in pairs(entity.claims) do
	if statements and statements[1] and statements[1].mainsnak then
		if statements[1].mainsnak.datatype ~= 'external-id' then
			count = count + 1
		end
	end
end

return count

end

local function getCommonsCell(entity)
local hasImage = hasClaim(entity, 'P18')
local hasCommonsCategory = hasClaim(entity, 'P373')
local hasCommonsSitelink = entity:getSitelink('commonswiki')

if hasImage and (hasCommonsCategory or hasCommonsSitelink) then
	return 'Bild ' .. yes() .. '<br />Kat. ' .. yes()
elseif hasImage then
	return 'Bild ' .. yes() .. '<br />Kat. ' .. no()
elseif hasCommonsCategory or hasCommonsSitelink then
	return 'Bild ' .. no() .. '<br />Kat. ' .. yes()
end

return 'Bild ' .. no() .. '<br />Kat. ' .. no()

end

local function normLine(entity, label, prop)
if hasClaim(entity, prop) then
return label .. ' ' .. yes()
end

return label .. ' ' .. no()

end

local function getNormdataCell(entity)
local parts = {}

table.insert(parts, normLine(entity, 'GND', 'P227'))
table.insert(parts, normLine(entity, 'VIAF', 'P214'))
table.insert(parts, normLine(entity, 'ORCID', 'P496'))
table.insert(parts, normLine(entity, 'ISNI', 'P213'))

return table.concat(parts, '<br />')

end

local function hasAllCoreNormdata(entity)
return hasClaim(entity, 'P227')
and hasClaim(entity, 'P214')
and hasClaim(entity, 'P496')
and hasClaim(entity, 'P213')
end

local function getTodoCell(entity)
local todos = {}

if not entity:getSitelink('dewiki') then
	table.insert(todos, 'dewiki prüfen')
end

if not hasClaim(entity, 'P18') then
	table.insert(todos, 'Bild prüfen')
end

if not hasClaim(entity, 'P373') and not entity:getSitelink('commonswiki') then
	table.insert(todos, 'Commons-Kat. prüfen')
end

if not hasAllCoreNormdata(entity) then
	table.insert(todos, 'Normdaten prüfen')
end

local deDescription = entity:getDescription('de')
if not deDescription or deDescription == '' then
	table.insert(todos, 'Beschreibung ergänzen')
end

if #todos == 0 then
	return dash()
end

return table.concat(todos, '<br />')

end

local function getClaimCount(entity, prop)
	if not entity or not entity.claims or not entity.claims[prop] then
		return 0
	end

	return #entity.claims[prop]
end

local function makeWorksQueryLink(id)
	local query =
		'SELECT ?work ?workLabel ?date WHERE {\n' ..
		'  ?work wdt:P50 wd:' .. id .. ' .\n' ..
		'  OPTIONAL { ?work wdt:P577 ?date . }\n' ..
		'  SERVICE wikibase:label { bd:serviceParam wikibase:language "de,en,fr,es". }\n' ..
		'}\n' ..
		'ORDER BY ?date ?workLabel'

	return '[https://query.wikidata.org/#' .. mw.uri.encode(query, 'PATH') .. ' Werke ↗]'
end

local function getWorksCell(entity, id)
	local p800Count = getClaimCount(entity, 'P800')
	local p800Status

	if p800Count > 0 then
		p800Status = 'P800 ' .. yes()
	else
		p800Status = 'P800 ' .. no()
	end

	return p800Status .. '<br />' .. makeWorksQueryLink(id)
end

function p.table(frame)
local result = {}

table.insert(result, '{| class="wikitable sortable" style="width:100%;"')
table.insert(result, '|-')
table.insert(result, '! Nr.')
table.insert(result, '! style="width:95px;" | Bild')
table.insert(result, '! Autorin / Autor')
table.insert(result, '! Kurzbeschreibung')

for _, lang in ipairs(coreLangs) do
	table.insert(result, '! class="unsortable" | ' .. langIcons[lang])
end

table.insert(result, '! <span title="Anzahl der vorhandenen Wikipedia-Sprachversionen">Σ</span>')
table.insert(result, '! Wikidata')
table.insert(result, '! <span title="Anzahl der Wikidata-Aussagen ohne externe Identifikatoren">WD-Items</span>')
table.insert(result, '! Commons')
table.insert(result, '! Normdaten')
table.insert(result, '! Werkdaten')
table.insert(result, '! Hinweis / To-do')

local index = 1

while frame.args[index] do
	local id = mw.text.trim(frame.args[index])
	local entity = mw.wikibase.getEntityObject(id)

	if entity then
		local label = getLabel(entity, id)
		local articleLink = makeArticleLink(entity, label, id)
		local description = getDescription(entity)
		local lifeDates = getLifeDates(entity)
		local languageCount = countWikipediaSitelinks(entity)
		local statementCount = countWdStatements(entity)

		table.insert(result, '|-')
		table.insert(result, '| style="text-align:right;" | ' .. index)
		table.insert(result, '| ' .. getImageCell(entity))
		table.insert(result, '| ' .. articleLink .. lifeDates)
		table.insert(result, '| ' .. description)

		for _, lang in ipairs(coreLangs) do
			table.insert(result, makeLangCell(entity, lang))
		end

		table.insert(result, '| style="text-align:right;" | ' .. languageCount)
		table.insert(result, '| data-sort-value="' .. string.sub(id, 2) .. '" | [[d:' .. id .. '|' .. id .. ']]')
		table.insert(result, '| style="text-align:right;" | ' .. statementCount)
        table.insert(result, '| ' .. getCommonsCell(entity))
        table.insert(result, '| ' .. getNormdataCell(entity))
        table.insert(result, '| ' .. getWorksCell(entity, id))
        table.insert(result, '| ' .. getTodoCell(entity))
	else
		table.insert(result, '|-')
		table.insert(result, '| style="text-align:right;" | ' .. index)
		table.insert(result, '| colspan="13" | <span style="color:red;">Wikidata-Objekt nicht gefunden: ' .. id .. '</span>')
	end

	index = index + 1
end

table.insert(result, '|}')

return table.concat(result, '\n')

end

return p

Content Disclaimer

Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.

  1. The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
  2. There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
  3. It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
  4. Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
  5. Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.