Module:User/JsonProbe: Difference between revisions

From Foxopedia
Jump to navigation Jump to search
(Created page with "local p = {} function p.run() if type(mw.ext) == 'table' and type(mw.ext.data) == 'table' and type(mw.ext.data.get) == 'function' then return 'JsonConfig Lua: OK' else return 'JsonConfig Lua: MISSING' end end return p")
 
No edit summary
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
local p = {}
local p = {}

local function hasLuaJson()
return type(mw.ext) == 'table'
and type(mw.ext.data) == 'table'
and type(mw.ext.data.get) == 'function'
end

function p.run()
function p.run()
if hasLuaJson() then
if type(mw.ext) == 'table' and type(mw.ext.data) == 'table' and type(mw.ext.data.get) == 'function' then
return 'JsonConfig Lua: OK'
return 'JsonConfig Lua: OK'
else
else
return 'JsonConfig Lua: MISSING'
return 'JsonConfig Lua: MISSING (no mw.ext.data.get)'
end
end

function p.fetch()
local function hasLuaJson()
return type(mw.ext) == 'table'
and type(mw.ext.data) == 'table'
and type(mw.ext.data.get) == 'function'
end
if not hasLuaJson() then
return 'JsonConfig Lua: MISSING (no mw.ext.data.get)'
end

-- Try both space and underscore versions, WITH the Data: namespace
local names = {
'Data:CS1/Identifier limits.tab',
'Data:CS1/Identifier_limits.tab',
}

local ok, res
for _, name in ipairs(names) do
ok, res = pcall(function() return mw.ext.data.get(name) end)
if ok and type(res) == 'table' and type(res.data) == 'table' then
return 'Commons Data reachable: rows=' .. tostring(#res.data) .. ' (' .. name .. ')'
end
end

if not ok then
return 'pcall error: ' .. tostring(res)
end
end
return 'mw.ext.data.get returned non-table; likely no access to remote Data:'
end
end

return p
return p

Latest revision as of 03:20, 12 August 2025

Documentation for this module may be created at Module:User/JsonProbe/doc

local p = {}

local function hasLuaJson()
	return type(mw.ext) == 'table'
		and type(mw.ext.data) == 'table'
		and type(mw.ext.data.get) == 'function'
end

function p.run()
	if hasLuaJson() then
		return 'JsonConfig Lua: OK'
	else
		return 'JsonConfig Lua: MISSING (no mw.ext.data.get)'
	end
end

function p.fetch()
  local function hasLuaJson()
    return type(mw.ext) == 'table'
      and type(mw.ext.data) == 'table'
      and type(mw.ext.data.get) == 'function'
  end
  if not hasLuaJson() then
    return 'JsonConfig Lua: MISSING (no mw.ext.data.get)'
  end

  -- Try both space and underscore versions, WITH the Data: namespace
  local names = {
    'Data:CS1/Identifier limits.tab',
    'Data:CS1/Identifier_limits.tab',
  }

  local ok, res
  for _, name in ipairs(names) do
    ok, res = pcall(function() return mw.ext.data.get(name) end)
    if ok and type(res) == 'table' and type(res.data) == 'table' then
      return 'Commons Data reachable: rows=' .. tostring(#res.data) .. ' (' .. name .. ')'
    end
  end

  if not ok then
    return 'pcall error: ' .. tostring(res)
  end
  return 'mw.ext.data.get returned non-table; likely no access to remote Data:'
end

return p