Module:Sandbox/RonnieV/Wikidata explained

p = -- an empty table

local function test(qid, pid) statementstbl = mw.wikibase.getBestStatements(qid, pid) local labels = "" for k, v in ipairs(statementstbl) do local dtype = v.mainsnak.datatype labels = labels .. "
" .. dtype if dtype

"time" then labels = labels .. " is a time-element with value" local time = v.mainsnak.datavalue.value.time labels = labels .. time end end return labelsend

local maanden = local function getmonthname(m) m = 1*m local s = type(maanden[m])

"function" and maanden[m] or maanden[m] or m .. m .. m return send

local function getitems(qid, pid) statementstbl = mw.wikibase.getBestStatements(qid, pid) local result = for k, v in ipairs(statementstbl) do local dtype = v.mainsnak.datatype if dtype

"wikibase-item" then local id = v.mainsnak.datavalue.value.id local label = mw.wikibase.getLabel(id) local dtype = v.mainsnak.datatype link = mw.wikibase.getSitelink(id) if link

nil or link

"" then newlabel = label else if link

label then newlabel = "" .. label .. "" else newlabel = "" .. label .. "" end end elseif dtype

"time" then local time = v.mainsnak.datavalue.value.time local prec = v.mainsnak.datavalue.value.precision local y, m, d = string.match(time, "+(%d+)-(%d+)-(%d+)") newlabel = "" if prec >= 11 then newlabel = d .. " " end if prec >= 10 then newlabel = newlabel .. getmonthname(m) .. " " end if prec >= 9 then newlabel = newlabel .. y end end table.insert(result, newlabel)-- labels = labels .. "
" .. newlabel end-- return labels return table.concat(result, "
")end

local function getlabel(pid) local label = mw.wikibase.getLabel(pid) return labelend

local function getprops local props = table.insert(props, "P735") table.insert(props, "P734") table.insert(props, "P19") table.insert(props, "P569") table.insert(props, "P106") table.insert(props, "P26") table.insert(props, "P570") return propsend

function p.getinfo(frame) local qid = frame.args.qid or "Q42" local props = getprops local htmlTable = mw.html.create("table") :addClass("wikitable") local headerRow = htmlTable :tag("tr") headerRow :tag("th") :attr("colspan", "2") :wikitext("Wikidata for " .. getlabel(qid)) for k,v in pairs(props) do local row = htmlTable:tag("tr") local cell = row:tag("td") cell:wikitext(getlabel(v)) local cell = row:tag("td") cell:wikitext(getitems(qid, v)) end return htmlTableend

function p.test(frame) local qid = frame.args.qid or "Q42" result = test(qid, "P570") return resultend

-- reizigersinformatie van een station

local function getmostrecentdate(qid) statementstbl = mw.wikibase.getAllStatements(qid, 'P1373') local maxtime = for k, v in ipairs(statementstbl) do local dtype = v.mainsnak.datatype if dtype

"quantity" then local value = v.mainsnak.datavalue.value.amount local datum = mw.wikibase.renderSnaks(v.qualifiers.P585) local jaar = string.sub(datum, string.len(datum)-4) if jaar > maxtime then maxtime = jaar end end end return maxtimeend

local function getNMBStelling(qid, gezochtjaar) statementstbl = mw.wikibase.getAllStatements(qid, 'P1373') local aantaldoordeweek = '-' local aantalzaterdag = '-' local aantalzondag = '-' local labels = "" for k, v in ipairs(statementstbl) do local dtype = v.mainsnak.datatype if dtype

"quantity" then local amount = string.sub(v.mainsnak.datavalue.value.amount,2) local tv = v.qualifiers.P585 local datum = mw.wikibase.renderSnaks(tv) local jaar = string.sub(datum, string.len(datum)-4)

if jaar

gezochtjaar then local dag = v.qualifiers.P2894 local weekdag = mw.wikibase.renderSnaks(dag) or if weekdag

'work week' then aantaldoordeweek = amount else if weekdag

'Saturday' then aantalzaterdag = amount else if weekdag

'Sunday' then aantalzondag = amount end end end end end end labels = '' return labelsend

function p.getvoyagers(frame) local qid = frame.args.qid or "Q601108" local date = getmostrecentdate(qid) local result = getNMBStelling(qid, date) return resultend

return p