打开/关闭菜单
打开/关闭外观设置菜单
打开/关闭个人菜单
未登录
未登录用户的IP地址会在进行任意编辑后公开展示。

Module:SafeCate

来自OGAS数据中枢
秋绘君留言 | 贡献2026年1月22日 (四) 13:42的版本 (创建页面,内容为“local module = {} local function _isvalid(value) return value ~= nil and type(value) == "string" and mw.text.trim(value) ~= "" end function module.main(frame) local strict = frame local parent = frame:getParent() if not _isvalid(frame.args[1]) then if not (parent and _isvalid(parent.args[1])) then return end local title = parent:getTitle() if title == "Template:SafeCate" then strict, frame = parent, parent elseif mw.title.new(title).namespace =…”)
(差异) ←上一版本 | 最后版本 (差异) | 下一版本→ (差异)

此模块的文档可以在Module:SafeCate/doc创建

local module = {}

local function _isvalid(value)
	return value ~= nil and type(value) == "string" and mw.text.trim(value) ~= ""
end

function module.main(frame)
	local strict = frame
	local parent = frame:getParent()
	if not _isvalid(frame.args[1]) then
		if not (parent and _isvalid(parent.args[1])) then return end
		local title = parent:getTitle()
		if title == "Template:SafeCate" then
			strict, frame = parent, parent
		elseif mw.title.new(title).namespace == 10 and frame.args["strict"]=="1" then
			frame = parent
		else return end
	end
	local cate = frame.args[1]
	local mod = frame.args[2]
	local nsMap = { }
	local bExclude, nsids = false, nil
	if strict.args["nsid"] then
		nsids = mw.text.split(strict.args["nsid"], ",", true)
	elseif strict.args["nsidExclude"] then
		bExclude = true
		nsids = mw.text.split(strict.args["nsidExclude"], ",", true)
	end
	if nsids then
		for _, value in ipairs(nsids) do
			nsMap[tonumber(value)] = true
		end
	else
		nsMap[0] = true
	end
	local noSubpage = (strict).args["noSubpage"]=="1"
	local title = mw.title.getCurrentTitle()
	local curNsid = title.namespace
	if ((nsMap[curNsid] and (not bExclude)) or ((not nsMap[curNsid]) and bExclude)) and ((not noSubpage) or (not title.isSubpage)) then
		if curNsid == 10 and title.isSubpage and title.subpageText == "doc" then return end
		if mod then
			return "[[Category:"..cate.."|"..mod.."]]"
		else
			return "[[Category:"..cate.."]]"
		end
	end
end

return module