Module:Sandbox/Marsupium/Object

local p = {}

local wd = require('Module:Wd') local wikidata = require('Module:Wikidata') -- local wikidataIB = require('Module:WikidataIB') local coordinates = require('Module:Coordinates') -- 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 args = frame:getParent.args local qid = mw.text.trim(frame.args[1]) or 'Q4115189' -- name local sitelink = mw.wikibase.getSitelink(qid) local label = findLabel(qid) or qid local linkedLabel = sitelink and ( .. label .. ) or label local nativeLabel = wd._properties( {'multilanguage', qid, 'P1705'} ) nativeLabel = (nativeLabel and nativeLabel ~=  and mw.ustring.format('/ %s ', nativeLabel)) or  local name = linkedLabel .. nativeLabel .. ' '	-- time local demolished = false local timesList = {} local demolitionDate = wd._properties({qid, 'P576'}) demolitionDate = demolitionDate ~= '' and ('demolished: ' .. demolitionDate) or nil local inception = wikidata.claim({args={'P571', id=qid}}) timesList[#timesList+1] = inception local startTime = wikidata.claim({args={'P580', id=qid}}) local endTime = wikidata.claim({args={'P582', id=qid}}) local timespan = (startTime or endTime) and ((startTime or ) .. '-' .. (endTime or )) timesList[#timesList+1] = timespan local conservationStatus = wd._properties({'raw', qid, 'P5816'}) local architecturalStyle = wikidata.claim({args={'P149', id=qid, list=', ', parameter='link'}}) timesList[#timesList+1] = (architecturalStyle and mw.ustring.format(' %s ', architecturalStyle)) if demolitionDate or (conservationStatus == 'Q56556915') then demolished = true timesList[#timesList+1] = demolitionDate timesList[#timesList+1] = 'demolished or destroyed' end local timesAndStyles = table.concat(timesList, '; ') -- creators local creatorList = {} -- architect creatorList[#creatorList+1] = wikidata.claim({args={'P84', id=qid, list=', ', parameter='link'}}) or nil -- architect sortkey local architectSort = '' local bestArchStmts = mw.wikibase.getBestStatements(qid, 'P84') if bestArchStmts[1] and bestArchStmts[1].mainsnak.datavalue then -- no "datavalue" for unknown value local bestArchID = bestArchStmts[1].mainsnak.datavalue.value.id		local bestFamilyNameStmts = mw.wikibase.getBestStatements(bestArchID, 'P734') if bestFamilyNameStmts[1] and bestFamilyNameStmts[1].mainsnak.datavalue 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 creatorList[#creatorList+1] = wikidata.claim({args={'P170', id=qid, list=', ', parameter='link'}}) or nil local creators = table.concat(creatorList, '; ') -- image local image = wikidata.claim({args={'P18', id=qid}}) local img = image and mw.ustring.format(, image) or  local catName = wikidata.claim({args={'P373', id=qid}}) local cat = catName and mw.ustring.format(, 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(, image) or  -- TODO: implement maybe more local maplinkTemplate = [=[ ]=] 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(' %s ', 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('°N, °W', coordArgs[1], coordArgs[2], label) coordTemplate2 = coordTemplate2 and frame:preprocess(coordTemplate2) coordTemplate2 = (coordTemplate2 and mw.ustring.format(' %s ', coordTemplate2)) or nil local locList = {} locList[#locList+1] = map --	locList[#locList+1] = coordTemplate locList[#locList+1] = coordTemplate2 locList[#locList+1] = wikidata.claim({args={'P276', id=qid, list=', ', parameter='link'}}) locList[#locList+1] = wikidata.claim({args={'P131', id=qid, list=', ', parameter='link'}}) locList[#locList+1] = wikidata.claim({args={'P969', id=qid, list=', ', parameter='link'}}) -- "located on street" (P669) with "street number" (P670) qualifier local street = wd._properties( {'qualifiers', qid, 'P669', 'P670'} ) locList[#locList+1] = (street and street ~= '' and street) or nil local address = wd._properties( {'multilanguage', qid, 'P6375'} ) locList[#locList+1] = (address and address ~= '' and mw.ustring.format(' %s ', address)) or nil locList[#locList+1] = args.hours local fee = wd._properties( {'qualifiers', qid, 'P2555', 'P6001'} ) locList[#locList+1] = (fee and fee ~= '' and 'fee: ' .. fee) or nil local opening = wd._properties( {['format']="%q (%p) [%s][%r]",		['sep%q']='-', 'qualifiers', 'qualifiers', 'qualifiers', qid, 'P3025', 'P8626', 'P8627', 'P1264'} ) locList[#locList+1] = ((type(opening) == 'string') and (opening ~= '') and 'open: ' .. opening) or nil local location = table.concat(locList, '; ') local osmElement = wikidata.claim({args={'P10689', id=qid}}) location = osmElement and location .. mw.ustring.format(		' ', osmElement) or location local osmRelation = wikidata.claim({args={'P402', id=qid}}) location = osmRelation and location .. mw.ustring.format(		' ', osmRelation) or location -- literature local litList = {} litList[#litList+1] = args.lit --	local describedBySourceIB = wikidataIB._getValue({'P1343', parameterset=1, qid=qid, qual='P304'}) --	litList[#litList+1] = describedBySourceIB local describedBySource2 = wd._properties( {'linked', 'qualifiers', qid, 'P1343', 'P304'} ) litList[#litList+1] = describedBySource2 -- TODO: use Module:Cite Q for the books local archnetID = wikidata.claim({args={'P7323', id=qid}}) litList[#litList+1] = archnetID and mw.ustring.format('Archnet', archnetID) local structuraeID = wikidata.claim({args={'P454', id=qid}}) litList[#litList+1] = structuraeID and mw.ustring.format('Structurae', structuraeID) local emporisID = wikidata.claim({args={'P455', id=qid}}) litList[#litList+1] = emporisID and mw.ustring.format('Emporis', emporisID) local berlinDID = wikidata.claim({args={'P2424', id=qid}}) litList[#litList+1] = berlinDID and mw.ustring.format('Berlin D', berlinDID) local bildindexID = wikidata.claim({args={'P2092', id=qid}}) litList[#litList+1] = bildindexID and mw.ustring.format('Bildindex', bildindexID) local archinformID = wikidata.claim({args={'P5383', id=qid}}) litList[#litList+1] = archinformID and mw.ustring.format('archINFORM', archinformID) local memoriademadridID = wikidata.claim({args={'P7372', id=qid}}) litList[#litList+1] = memoriademadridID and mw.ustring.format('memoriademadrid', memoriademadridID) local misasorgID = wikidata.claim({args={'P7054', id=qid}}) litList[#litList+1] = misasorgID and mw.ustring.format('misas.org', misasorgID) local coamID = wikidata.claim({args={'P2917', id=qid}}) litList[#litList+1] = coamID and mw.ustring.format('COAM', coamID) local lit = '\n* ' .. table.concat(litList, '\n* ') local demolishedStyle = demolished and ('style="background: pink;"') or '' local tablerow = mw.ustring.format('\n|-%s\n| %s \n| %s \n|%s %s \n| %s \n| %s \n| %s',		demolishedStyle, name, timesAndStyles, architectSort, creators, location, lit, img) return tablerow end

return p