Module:Sandbox

local p = {} function p.hello return "Hello, world!" end

function p.check(frame) return entityCheck(frame.args[1]) end

function entityCheck(entityId) if string.match(entityId, '^[PQ]%d+$') == nil then return entityId .. ': Invalid entity id' end

if mw.wikibase.getEntity(entityId) then return entityId .. ': Does exist' else return entityId .. ': Does not exist' end end

function p.pcall_check(frame) return pcall_entityCheck(frame.args[1]) end

function pcall_entityCheck(entityId) if string.match(entityId, '^[PQ]%d+$') == nil then return entityId .. ': Invalid entity id' end

local test, result test, result = pcall(mw.wikibase.getEntity, entityId) if test then return entityId .. ': Does exist' else return entityId .. ': Does not exist' end end

function p.xpcall_check(frame) return xpcall_entityCheck(frame.args[1]) end

function xpcall_entityCheck(entityId) if string.match(entityId, '^[PQ]%d+$') == nil then return entityId .. ': Invalid entity id' end

local test, result test, message = xpcall(mw.wikibase.getEntity, entityId) if test then return entityId .. ': Does exist' else return entityId .. ': Does not exist' end end return p