Module:Sandbox/David-ri93/Timeline Fedora Linux Wikidata

-- This is a proof of concept trying to build a timeline from wikidata -- local p = {} local wd = require('Module:Wikidata')

local aliasesP = { softwareVersionIdentifier = "P348", publicationDate          = "P577", endTime                  = "P582", discontinuedDate         = "P2669", versionType              = "P548", title                    = "P1476", }

local aliasesQ = { fedora             = "Q48267", stableVersion      = "Q2804309", softwareBetaVersion = "Q3295609", }

local function recConcat(t) if type(t) ~= 'table' then return t	end local first = true local s = "("	for _, value in ipairs(t) do		s = s .. recConcat(value)		if not first then			s = s .. ", "		end		first = false	end	return s .. ")" end

local function getValueOrUnknown(object, keys) local stepper = object for _, key in ipairs(keys) do		if type(key) == 'table' then for _, testKey in ipairs(key) do				if stepper[testKey] then key = testKey break end end end if not stepper[key] then mw.logObject("Key not found " .. recConcat(key) .. 				" in order " .. recConcat(keys)) --mw.logObject(keys) --mw.logObject(stepper) return "Unknown" end stepper = stepper[key] end return stepper end

function p.hello local versions = mw.wikibase.getAllStatements(aliasesQ.fedora, 		aliasesP.softwareVersionIdentifier) -- mw.logObject(versions) local counter = 0 for k, v in pairs(versions) do		counter = counter + 1 -- there surly is a smarter way to write this local version = getValueOrUnknown(v, {"mainsnak", "datavalue", "value"}) local startTime = getValueOrUnknown(v, {"qualifiers", 			aliasesP.publicationDate, 1, "datavalue", "value", "time"}) local endTime = getValueOrUnknown(v, {"qualifiers", 			{aliasesP.discontinuedDate, aliasesP.endTime}, 1, "datavalue", "value", "time"}) mw.logObject("(Key " .. k .. "), Version " .. version .. ", start " .. startTime .. ", endTime " .. endTime) if counter == 3 then mw.logObject(v) end end return "TODO count is " .. counter end

return p