打开/关闭搜索
搜索
打开/关闭菜单
34
24
11
1101
SAPedia
导航
首页
最近更改
随机页面
特殊页面
上传文件
条目
角色
物品
地点
时间线
媒介
动画
漫画
游戏
小说
站点
帮助文档
公共沙盒
站点政策
交流群组
打开/关闭外观设置菜单
无法加载偏好设置。请检查您的网络连接并重试。
重试
打开/关闭个人菜单
未登录
未登录用户的IP地址会在进行任意编辑后公开展示。
user-interface-preferences
个人工具
创建账号
登录
欢迎
注册账号
并参与编辑
欢迎加入
本站QQ群
查看“︁Module:Namespace detect”︁的源代码
来自SAPedia
查看
阅读
查看源代码
查看历史
associated-pages
模块
讨论
更多操作
←
Module:Namespace detect
因为以下原因,您没有权限编辑该页面:
您请求的操作仅限属于该用户组的用户执行:
用户
您可以查看和复制此页面的源代码。
local p = {} local lower = mw.ustring.lower local trim = mw.text.trim local getArgs = require('Module:Arguments').getArgs local namespaceKeysCache = {} -- 主命名空间的别名集合 local MAIN_NAMESPACE_ALIASES = { "main", "条目", -- 简体 "條目", -- 繁体 "主" } local function addUniqueKey(keys, seen, value) if not value or value == '' then return end value = lower(value) if seen[value] then return end seen[value] = true table.insert(keys, value) end -- 规范化参数名:小写 + 下划线转空格 + trim local function normaliseKey(s) if not s then return nil end s = tostring(s) s = lower(s) s = s:gsub('_', ' ') s = trim(s) return s end -- 规范化整个参数表 local function normaliseArgs(args) local out = {} for k, v in pairs(args) do if type(k) == 'number' then out[k] = v else out[normaliseKey(k)] = v end end return out end -- 获取 namespace 可匹配 key 列表(含 alias) local function getNamespaceKeys(nsid) if namespaceKeysCache[nsid] then return namespaceKeysCache[nsid] end local ns = mw.site.namespaces[nsid] local keys = {} local seen = {} if ns then addUniqueKey(keys, seen, ns.name) if ns.canonicalName then addUniqueKey(keys, seen, ns.canonicalName) end for _, alias in ipairs(ns.aliases or {}) do addUniqueKey(keys, seen, alias) end end -- 主命名空间 if nsid == 0 then for _, alias in ipairs(MAIN_NAMESPACE_ALIASES) do addUniqueKey(keys, seen, alias) end end namespaceKeysCache[nsid] = keys return keys end function p.main(frame) local rawArgs = getArgs(frame, { removeBlanks = false }) local args = normaliseArgs(rawArgs) local nsid = mw.title.getCurrentTitle().namespace local keys = getNamespaceKeys(nsid) -- 按 namespace alias 顺序匹配参数 for _, key in ipairs(keys) do if args[key] ~= nil then return args[key] end end -- fallback return args.other or '' end return p
此页面嵌入的页面:
Template:Documentation
(
查看源代码
)
Template:Documentation/styles.css
(
查看源代码
)
Template:FromOther
(
查看源代码
)
Template:FromOther/MGP
(
查看源代码
)
Template:Namespace detect
(
查看源代码
)
Template:Tl
(
查看源代码
)
Module:Arguments
(
查看源代码
)
Module:Namespace detect
(
查看源代码
)
Module:Namespace detect/doc
(
查看源代码
)
返回
Module:Namespace detect
。
查看“︁Module:Namespace detect”︁的源代码
来自SAPedia