Module:User:QFQ/mwenv

local export = {}

function export.site_namespace(frame) function fmt(x) if type(x) == 'string' then return '"' .. x .. '"' elseif type(x) == 'table' then local t = {} for _, s in ipairs(x) do				table.insert(t, string.format('"%s"', s)) end return string.format('{%s}', table.concat(t, ', ')) else return tostring(x) end end local s = frame.args[1] local t1 = {} table.insert(t1, '{') local l = {-2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 90, 91, 92, 93, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 114, 115, 116, 117, 118, 119, 828, 829, 2300, 2301, 2302, 2303} for _, i in ipairs(l) do		local j = mw.site.namespaces[i] local t2 = {} for _, k in ipairs({"id", "name", "canonicalName", "displayName", "hasSubpages", "hasGenderDistinction", "isCapitalized", "isContent", "isIncludable", "isMovable", "isSubject", "isTalk", "defaultContentModel", "aliases"}) do			table.insert(t2, string.format('["%s"]=%s', k, fmt(j[k]))) end for _, k in ipairs({"subject", "talk", "associated"}) do			table.insert(t2, string.format('["%s"]=%s', k, j[k] and tostring(j[k].id) or "nil")) end table.insert(t1, string.format("   [%d]={ %s },", i, table.concat(t2, ", "))) end table.insert(t1, '}') return frame:extensionTag('syntaxhighlight', table.concat(t1, '\n'), { lang = 'lua' } ) end

--[===[ package.searchers[#package.searchers + 1] = function(mod) mod, cnt = mod:gsub('Module:', 'Module.') return cnt > 0 and package.searchers[2](mod) or nil end ]===]

return export