Module:User/JsonProbe: Difference between revisions
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 |
||
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 |
|||
⚫ | |||
return 'JsonConfig Lua: OK' |
|||
else |
|||
return 'JsonConfig Lua: MISSING (no mw.ext.data.get)' |
|||
end |
|||
end |
|||
function p.fetch() |
|||
if not hasLuaJson() then |
|||
return 'JsonConfig Lua: MISSING (no mw.ext.data.get)' |
|||
end |
|||
-- Try both title forms (spaces vs underscores) |
|||
local name1 = 'CS1/Identifier limits.tab' |
|||
local name2 = 'CS1/Identifier_limits.tab' |
|||
local function tryGet(name) |
|||
return pcall(function() |
|||
return mw.ext.data.get(name) |
|||
end) |
|||
end |
|||
-- First attempt |
|||
local ok, res = tryGet(name1) |
|||
if not ok or type(res) ~= 'table' or type(res.data) ~= 'table' then |
|||
-- Second attempt |
|||
ok, res = tryGet(name2) |
|||
end |
|||
if not ok then |
|||
return 'pcall error: ' .. tostring(res) |
|||
end |
|||
⚫ | |||
return 'Commons Data reachable: rows=' .. tostring(#res.data) |
|||
else |
|||
return 'mw.ext.data.get returned type: ' .. tostring(type(res)) |
|||
end |
|||
end |
end |
||
return p |
return p |
Revision as of 03:18, 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() if not hasLuaJson() then return 'JsonConfig Lua: MISSING (no mw.ext.data.get)' end -- Try both title forms (spaces vs underscores) local name1 = 'CS1/Identifier limits.tab' local name2 = 'CS1/Identifier_limits.tab' local function tryGet(name) return pcall(function() return mw.ext.data.get(name) end) end -- First attempt local ok, res = tryGet(name1) if not ok or type(res) ~= 'table' or type(res.data) ~= 'table' then -- Second attempt ok, res = tryGet(name2) end if not ok then return 'pcall error: ' .. tostring(res) end if type(res) == 'table' and type(res.data) == 'table' then return 'Commons Data reachable: rows=' .. tostring(#res.data) else return 'mw.ext.data.get returned type: ' .. tostring(type(res)) end end return p