From English Wikipedia @ Freddythechick
local m = {}
function m.dump(x, maxDepth, hangingIndent)
if type(maxDepth) == 'nil' then
elseif maxDepth <= 0 then
return ''
else
maxDepth = maxDepth - 1
end
if type(hangingIndent) ~= 'string' then
hangingIndent = ''
end
if type(x) == 'number' then
return tostring(x)
elseif type(x) == 'string' then
return '"' .. x .. '"'
elseif type(x) == 'table' then
local numEntries = 0
for k,v in pairs(x) do
numEntries = numEntries + 1
end
if numEntries == 0 then
return '[empty table]'
end
local s = "\n"
local i = 1
for k,v in pairs(x) do
local thisIndent = hangingIndent
local subIndent = hangingIndent
if i < numEntries then
thisIndent = thisIndent .. '├─'
subIndent = subIndent .. '│ '
else
thisIndent = thisIndent .. '└─'
subIndent = subIndent .. ' '
end
s = s .. thisIndent .. k .. ': ' .. m.dump(v, maxDepth, subIndent)
if i < numEntries then
s = s .. "\n"
end
i = i + 1
end
return s
else
return "[value of type " .. type(x) .. "]"
end
end
function m.dumpEntity(frame)
if frame == nil or frame.args == nil or frame.args.entityId == nil or frame.args.entityId == '' then
return "<span class='error'>Please specify 'entityId' parameter.</span>"
end
local entityId = frame.args.entityId
local entity = mw.wikibase.getEntity( entityId )
return m.dump(entity)
end
return m