Module:Wikidata interface

local p = {}

-- functions that can only be called from another module p.fromLua = { -- manipulating a list of assertions getClaims = d.getClaims, stringTable = d.stringTable, tableToText = d.tableToText, formatStatements = d.formatStatements, formatQualifiers = d.showQualifier, formatAndCat = d.formatAndCat, wikidataDate = d.wikidataDate, addLinkback = d.addLinkBack, addtrackingcat = d.addTrackingCat, -- manipulation of individual assertions getmainid = d.getMainId, formatStatement = d.formatStatement, statementDate = d.getFormattedDate, -- retrieves qualifier date getFormattedQualifiers = d.getFormattedQualifiers, getQualifiers = d.getQualifiers, getReferences = d.getReferences,

-- snak handling getid = d.getId, formatSnak = d.formatSnak, -- using qids getEntity = d.getEntity, formatEntity = d.formatEntity, getLink = d.siteLink, getLabel = d.getLabel, --getLabel is simpler than formatEntity

-- using transitive properties isInstance = d.isInstance, isSubclass = d.isSubclass, addVals = d.addVals, transitiveVals = d.transitiveVals, inTransitiveVals = d.inTransitiveVals, findVal = d.findVal,

-- date management mainDate = d.mainDate, getDate = d.getTheDate, keyDate = d.keyDate,

-- Miscellaneous functions citeItem = d.citeitem, translate = d.translate, Dump = d.Dump, }

-- Frame functions for use from Wikitext (sometimes with options to manage less clean data) local function cleanargs(args) local newargs = {} for i, j in pairs(args) do		if j ~= '' then newargs[i] = j		end end return newargs end

function p.formatStatements( frame ) -- for Template:Wikidata local args = {} if frame == mw.getCurrentFrame then args = frame:getParent.args -- caller model settings (is this really a good idea?) for k, v in pairs(frame.args) do			args[k] = v		end else args = frame end return p.fromLua.formatStatements( args ) end

function p.addLinkBack( frame ) local args = cleanargs(frame.args) if args[1] and args[1]:match"%S" then return d.addLinkBack( '', args.entity, mw.text.trim( args[1] ) ) end end

function p.formatEntity(frame) local args = cleanargs(frame.args) local entity = args.entity or args[1] if (not entity) or (entity == '') then entity = mw.wikibase.getEntityObject end return d.formatEntity(entity, args) end

function p.formatAndCat(frame) local args = cleanargs(frame.args) return d.formatAndCat(args) end

function p.citeItem(frame) local args = cleanargs(frame.args) local item, page = args[1], args['page'] return p.fromLua.citeItem(item, page) end

function p.getLabel(frame) local args = cleanargs(frame.args) local item = args[1] local lang = args[2] or "fr" return d.getLabel(item, lang) end

function p.mainDate(frame) return d.mainDate(frame.args['entity']) end

function p.Dump(frame) return d.Dump(frame.args[1]) end

function p.formatQualifiers(frame) local args = frame.args return d.formatQualifiers(args) end

function p.getDescription(frame) -- simplistic function, but good, the Wikidata descriptions, it's not super useful either return mw.wikibase.description(frame.args[1]) end

function p.getLink(frame) local args = frame.args local link, proj, lang = p.fromLua.getLink(args[1], args[2], args[3]) return link end

function p.translate(frame) return d.translate(frame.args[1]) end

function p.findVal(frame) local args = frame.args return d.findVal(args.source, args.target, args.property, args.recursion, args.instancedepth) end

function p.transitiveVals(frame) local args = frame.args return d.transitiveVals(args.item, args, args.maxdepth, args.maxnodes, args.stopval, true) end

return p