Modul:Benutzer:Marsupium/Object

Die Dokumentation für dieses Modul kann unter Modul:Benutzer:Marsupium/Object/Doku erstellt werden

local p = {}

local wikidata = require('Module:Wikidata')
local wikidataIB = require('Module:WikidataIB')
local coordinates = require('Module:Coordinates')
-- local wd = require('Module:Wd')
-- local mapframe = require('Module:Mapframe')

local function findLabel(qid)
	local langs = {'en', 'de'}
	local label
	local i = 0
	while not label and i <= #langs do
		i = i + 1
		label = mw.wikibase.getLabelByLang(qid, langs[i])
	end
	return label
end

function p.object(frame)
	local qid = frame.args[1] or 'Q4115189'
	
	-- name
	local sitelink = mw.wikibase.getSitelink(qid)
	local label = findLabel(qid) or qid
	local linkedLabel = sitelink and ('[[' .. sitelink .. '|' .. label .. ']]') or label
	local name = linkedLabel .. ' [[File:Wikidata-logo.svg|12px|Wikidata|link=//www.wikidata.org/wiki/'
	.. qid .. ']][[File:Wikidata-Reasonator_small_logo.svg|12px|Reasonator|link=//tools.wmflabs.org/reasonator/test/?q='
	.. qid .. ']]'
	
	-- time
	local inception = wikidata.claim({args={'P571', id=qid}})
	local startTime = wikidata.claim({args={'P580', id=qid}})
	local endTime = wikidata.claim({args={'P582', id=qid}})
	local times = ((inception and (inception .. '. ') or '')
		.. (((startTime or endTime) and ((startTime or '') .. '-' .. (endTime or ''))) or ''))
	
	-- architect
	local architect = wikidata.claim({args={'P84', id=qid, list=', ', parameter='link'}}) or ''
	-- architect sortkey
	local architectSort = ''
	local bestArchStmts = mw.wikibase.getBestStatements(qid, 'P84')
	if bestArchStmts[1] then
		local bestArchID = bestArchStmts[1].mainsnak.datavalue.value.id
		local bestFamilyNameStmts = mw.wikibase.getBestStatements(bestArchID, 'P734')
		if bestFamilyNameStmts[1] then
			local bestFamilyNameID = bestFamilyNameStmts[1].mainsnak.datavalue.value.id
			local i = 0
			while not label and i <= #langs do
				i = i + 1
				label = mw.wikibase.getLabelByLang(qid, langs[i])
			end

			local architectSortValue = findLabel(bestFamilyNameID)
			architectSort = architectSortValue and mw.ustring.format('data-sort-value="%s"|', architectSortValue) or ''
		end
	end
	
	-- image
	local image = wikidata.claim({args={'P18', id=qid}})
	local img = image and mw.ustring.format('[[File:%s|50x50px]]', image) or ''
	local catName = wikidata.claim({args={'P373', id=qid}})
	local cat = catName and mw.ustring.format('[[File:Commons-logo.svg|x16px|alt=|link=//commons.wikimedia.org/wiki/Category:%s|Commons]]', mw.uri.encode(catName, 'WIKI')) or ''
	local img = img .. cat
	
	-- location
	local coordStatements = mw.wikibase.getBestStatements(qid, 'P625')
	local coordError = false
	if not coordStatements or #coordStatements == 0 then
		coordError = true
	end
	local hasNoValue = not coordError and (coordStatements[1].mainsnak and (coordStatements[1].mainsnak.snaktype == 'novalue' or coordStatements[1].mainsnak.snaktype == 'somevalue') )
	if hasNoValue then
		coordError = true
	end
	local map
	local wdCoords = not coordError and coordStatements[1]['mainsnak']['datavalue']['value']
	if wdCoords then
		local lat, long = tonumber(wdCoords['latitude']), tonumber(wdCoords['longitude'])
		local description = image and mw.ustring.format('[[File:%s|100x100px]]', image) or '' -- TODO: implement maybe more
		local maplinkTemplate = [=[<maplink text="map" zoom=15 >
	[
	{
	  "type": "Feature",
	  "geometry": { "type": "Point", "coordinates": [%s, %s] },
	  "properties": {
	    "title": "%s",
		"description": "%s",
	    "marker-symbol": "-number"
	  }
	},
	{
		"type": "ExternalData",
		"service": "geoshape",
		"ids": "%s",
	},
	]</maplink>]=]
		local mf = mw.ustring.format(maplinkTemplate, long, lat, linkedLabel, description, qid)
		map = frame:preprocess(mf)
	end
--	local coordTemplate = coordinates._coord({qid=qid, name=label})
--	coordTemplate = (not coordError and coordTemplate and mw.ustring.format('<small>%s</small>', coordTemplate)) or nil
	
	local coordArgs = {}
	local math_mod = require("Module:Math")
	local entity = mw.wikibase.getEntityObject(qid)
	if entity
		and entity.claims
		and entity.claims.P625
		and entity.claims.P625[1].mainsnak.snaktype == 'value'
	then
		local precision = entity.claims.P625[1].mainsnak.datavalue.value.precision
		coordArgs[1] = entity.claims.P625[1].mainsnak.datavalue.value.latitude
		coordArgs[2] = entity.claims.P625[1].mainsnak.datavalue.value.longitude
		if precision then
			precision = -math_mod._round(math.log(precision)/math.log(10),0)
			coordArgs[1] = math_mod._round(coordArgs[1],precision)
			coordArgs[2] = math_mod._round(coordArgs[2],precision)
		end
	end
	local coordTemplate2 = not coordError and mw.ustring.format('{{coord|%s|%s|type:landmark|name=%s}}', coordArgs[1], coordArgs[2], label)
	coordTemplate2 = coordTemplate2 and frame:preprocess(coordTemplate2)
	coordTemplate2 = (coordTemplate2 and mw.ustring.format('<small>%s</small>', coordTemplate2)) or nil
	
	local locList = {}
	locList[#locList+1] = map
--	locList[#locList+1] = coordTemplate
	locList[#locList+1] = coordTemplate2
	locList[#locList+1] = wikidata.claim({args={'P131', id=qid, list=', ', parameter='link'}})
	locList[#locList+1] = wikidata.claim({args={'P969', id=qid, list=', ', parameter='link'}})
	local address = wikidata.claim({args={'P6375', id=qid}})
	locList[#locList+1] = (address and mw.ustring.format('<small>%s</small>', address)) or nil
	local location = table.concat(locList, '; ')
	
	-- literature
	local litList = {}
	litList[#litList+1] = frame.args.lit
	local structuraeID = wikidata.claim({args={'P454', id=qid}})
	litList[#litList+1] = structuraeID and mw.ustring.format('[https://structurae.net/structures/%s Structurae]', structuraeID)
	local emporisID = wikidata.claim({args={'P455', id=qid}})
	litList[#litList+1] = emporisID and mw.ustring.format('[https://www.emporis.com/buildings/%s Emporis]', emporisID)
	local archinformID = wikidata.claim({args={'P5383', id=qid}})
	litList[#litList+1] = archinformID and mw.ustring.format('[https://www.archinform.net/projekte/%s.htm archINFORM]', archinformID)
	local berlinDID = wikidata.claim({args={'P2424', id=qid}})
	litList[#litList+1] = berlinDID and mw.ustring.format('[https://www.berlin.de/landesdenkmalamt/denkmale/liste-karte-datenbank/denkmaldatenbank/daobj.php?obj_dok_nr=%s Berlin D]', berlinDID)
	local describedBySourceIB = wikidataIB._getValue({'P1343', parameterset=1, qid=qid, qual='P304'})
	litList[#litList+1] = describedBySourceIB
	-- TODO: use [[Module:Cite Q]] for the books
	local lit = '\n* ' .. table.concat(litList, '\n* ')
	
	local tablerow = mw.ustring.format('\n|-\n| %s \n| %s \n|%s %s \n| %s \n| %s \n| %s', name, times, architectSort, architect, location, lit, img)
	return tablerow
end

return p