打开/关闭搜索
搜索
打开/关闭菜单
28
6680
50
1.4万
OGAS数据中枢
导航
首页
最近更改
随机页面
特殊页面
上传文件
少女前线
简介
战术人形
装备图鉴
BGM
任务
少前2:追放
逆向坍塌:面包房行动
打开/关闭外观设置菜单
通知
打开/关闭个人菜单
未登录
未登录用户的IP地址会在进行任意编辑后公开展示。
user-interface-preferences
个人工具
注册
登录
查看“︁Module:GFLCalc/check”︁的源代码
来自OGAS数据中枢
更多操作
←
Module:GFLCalc/check
因为以下原因,您没有权限编辑该页面:
您请求的操作仅限属于该用户组的用户执行:
管理员
您可以查看和复制此页面的源代码。
--[[ Module:GFLCalc/check —— 部署自检 用法: {{#invoke:GFLCalc/check|report}} -- 只查核心页面 {{#invoke:GFLCalc/check|report|M4A1|TT33}} -- 顺便查这几个单位的数据页 {{#invoke:GFLCalc/check|index}} -- 只看索引页能否被 mw.loadData 读取 输出一张表:页面 / 是否存在 / 实际内容模型 / 期望模型 / 状态。 ]] local p = {} local CORE = { { "Module:GFLCalc", "Scribunto" }, { "Module:GFLCalc/index", "json" }, { "Module:GFLCalc/panel", "Scribunto" }, { "Template:GFLCalc", "wikitext" }, { "Template:GFLCalc/styles.css", "sanitized-css" }, { "Widget:GFLCalcPanel", "wikitext" }, } local function probe(title) local ok, t = pcall(mw.title.new, title) if not ok or not t then return { exists = false, model = "?" } end return { exists = t.exists, model = t.contentModel } end local function esc(s) return (tostring(s):gsub("&", "&"):gsub("<", "<"):gsub(">", ">")) end function p.report(frame) local rows, bad = {}, 0 local function add(title, want) local i = probe(title) local okk = i.exists and i.model == want if not okk then bad = bad + 1 end rows[#rows + 1] = { title = title, want = want, got = i.model, exists = i.exists, ok = okk } end for _, c in ipairs(CORE) do add(c[1], c[2]) end for _, code in ipairs(frame.args) do add("Module:GFLCalc/data/" .. code, "json") add("Module:GFLCalc/brief/" .. code, "json") end local tbl = mw.html.create("table"):addClass("wikitable"):addClass("gfl-check") local hr = tbl:tag("tr") for _, h in ipairs({ "页面", "存在", "实际模型", "期望模型", "状态" }) do hr:tag("th"):wikitext(h) end for _, r in ipairs(rows) do local tr = tbl:tag("tr") tr:tag("td"):wikitext(esc(r.title)) tr:tag("td"):wikitext(r.exists and "是" or "否") tr:tag("td"):wikitext(esc(r.got or "-")) tr:tag("td"):wikitext(esc(r.want)) tr:tag("td"):wikitext(r.ok and "OK" or '<span class="gfl-error">✗</span>') end return tostring(tbl) .. string.format("\n共 %d 项,异常 %d 项。", #rows, bad) end --- 单个数据页诊断:{{#invoke:GFLCalc/check|probe|M4A1}} function p.probe(frame) local code = frame.args[1] or "M4A1" local title = "Module:GFLCalc/data/" .. code local t = mw.title.new(title) local ok, res = pcall(mw.loadData, title) local parts = { "标题 = " .. title, "存在 = " .. tostring(t and t.exists), "模型 = " .. tostring(t and t.contentModel or "?"), "loadData = " .. (ok and (res ~= nil and "成功" or "返回 nil") or ("报错:" .. tostring(res))), } return table.concat(parts, "<br>") end --- 对比三条读取路径:{{#invoke:GFLCalc/check|load|Module:GFLCalc/data/M4A1}} function p.load(frame) local title = mw.text.trim(frame.args[1] or "") if title == "" then title = "Module:GFLCalc/data/M4A1" end local t = mw.title.new(title) local out = { "标题 = " .. title } if type(mw.loadJsonData) == "function" then local ok, data = pcall(mw.loadJsonData, title) out[#out + 1] = "loadJsonData = " .. (ok and (type(data) == "table" and "成功" or "返回 " .. type(data)) or ("报错:" .. tostring(data))) else out[#out + 1] = "loadJsonData = 不存在" end local ok, data = pcall(mw.loadData, title) out[#out + 1] = "loadData = " .. (ok and (type(data) == "table" and "成功" or "返回 " .. type(data)) or ("报错:" .. tostring(data))) local text = t and t:getContent() out[#out + 1] = "getContent = " .. (text and ("成功,长度 " .. #text) or "返回 nil") if text then local ok2, parsed = pcall(mw.text.jsonDecode, text) out[#out + 1] = "jsonDecode = " .. (ok2 and (type(parsed) == "table" and "成功" or "返回 " .. type(parsed)) or ("报错:" .. tostring(parsed))) end return table.concat(out, "<br>") end --- 数据页顶层/改造表的键类型:{{#invoke:GFLCalc/check|mods|M4A1}} function p.mods(frame) local code = frame.args[1] or "M4A1" local title = "Module:GFLCalc/data/" .. code local ok, d = pcall(mw.loadJsonData, title) if not ok or type(d) ~= "table" then return "loadJsonData 失败:" .. tostring(d) end local keys = {} for k in pairs(d) do keys[#keys + 1] = type(k) .. ":" .. tostring(k) end table.sort(keys) local out = { "顶层键 = " .. table.concat(keys, ", ") } if type(d.mods) == "table" then local mk = {} for k in pairs(d.mods) do mk[#mk + 1] = type(k) .. ":" .. tostring(k) end table.sort(mk) out[#out + 1] = "mods 键 = " .. table.concat(mk, ", ") for _, k in ipairs({ "0", "3", 0, 3, 1, 2 }) do local v = d.mods[k] out[#out + 1] = string.format("mods[%s(%s)] = %s", tostring(k), type(k), type(v)) end else out[#out + 1] = "mods 类型 = " .. type(d.mods) end return table.concat(out, "<br>") end --- 打印数据页开头:{{#invoke:GFLCalc/check|raw|M4A1}} function p.raw(frame) local code = frame.args[1] or "M4A1" local t = mw.title.new("Module:GFLCalc/data/" .. code) if not t or not t.exists then return '<span class="gfl-error">页面不存在</span>' end local text = t:getContent() or "" local head = text:sub(1, 160) local ok, err = pcall(mw.text.jsonDecode, text) return string.format("长度 %d<br>JSON 解析:%s<br><br><code>%s</code>", #text, ok and "成功" or ("失败:" .. tostring(err)), mw.text.nowiki(head)) end --- 列出索引里的键(诊断用):{{#invoke:GFLCalc/check|keys}} function p.keys(frame) local ok, idx = pcall(mw.loadData, "Module:GFLCalc/index") if not ok or type(idx) ~= "table" then return '<span class="gfl-error">index 读取失败</span>' end local ks = {} for k in pairs(idx) do ks[#ks + 1] = tostring(k) end table.sort(ks) local show = {} for i = 1, math.min(#ks, 40) do show[#show + 1] = ks[i] end return string.format("索引共 %d 键;前 %d 个:\n%s", #ks, #show, table.concat(show, ", ")) end function p.index() local ok, idx = pcall(mw.loadData, "Module:GFLCalc/index") if not ok then return '<span class="gfl-error">Module:GFLCalc/index 读取失败:' .. esc(idx) .. "</span>" end if type(idx) ~= "table" then return '<span class="gfl-error">index 不是表</span>' end local n = 0 for _ in pairs(idx) do n = n + 1 end return string.format("index 正常:%d 条,数据版本 %s", n, tostring(idx.__dv__ or "?")) end return p
该页面嵌入的页面:
Module:GFLCalc/check/doc
(
查看源代码
)
返回
Module:GFLCalc/check
。
查看“︁Module:GFLCalc/check”︁的源代码
来自OGAS数据中枢