编辑“︁
Module:Namespace
”︁
跳转到导航
跳转到搜索
File:AnonEditWarning.svg
您当前没有登录。
如果您保存任何编辑,您的
IP地址
将
公开记录
在
本页的修订历史
中。您如果
登录
或
注册一个帐号
,可以隐藏自己的IP地址并
使用更多功能
。您可以在
您的对话页
查看给您的留言。
任何侵权内容
将会删除 | 百科内容须附有来源,以
供查证
| 维基百科内容均容许他人编辑、使用和重制 | 参阅
繁简
和
地区词处理
指引。
反垃圾检查。
不要
加入这个!
local p = {} local data = mw.loadData('Module:Namespace/data') local mLan = require('Module:Lan2') local function Error(msg) return mError.error { '[[Module:Namespace]]錯誤:' .. msg } end local function ifempty(ret, val) return ret ~= '' and ret or val end local function inArray(str, arr) for i, v in ipairs(arr) do if str == v then return v end end return nil end function p._lan(args, lang) return mLan.main(args, ifempty(lang and lang:lower(), mw.getCurrentFrame():callParserFunction { name = 'int', args = { 'Lang' } }), { ['def'] = { 'en' } }) end function p._isNamespace(id) id = tostring(id) local PNS, _PNSIsTalk = p._isPseudoNamespace(id) return PNS or mw.site.namespaces[tonumber(id) or id:lower()] and mw.site.namespaces[tonumber(id) or id:lower()].id or nil end function p.namespace(frame) local args if frame == mw.getCurrentFrame() then -- We're being called via #invoke. The args are passed through to the module -- from the template page, so use the args that were passed into the template. if not getArgs then getArgs = require('Module:Arguments').getArgs end args = getArgs(frame, { parentFirst = true }) else -- We're being called from another module or from the debug console, so assume -- the args are passed in directly. args = frame if type(args) ~= type({}) then args = { frame } end end id = tostring(args.namespace or args[1]) local PNS, _PNSIsTalk = p._isPseudoNamespace() return (PNS or mw.title.getCurrentTitle().namespace) == p._isNamespace(id) and (args['then'] or args[2]) or (args['else'] or args[3]) end local MsgCallFunc = { ['NamespacesDisplay'] = (function(nsid) return data.Namespace[tostring(nsid)] end), ['NamespacesConversionDisplay'] = (function(nsid) return data.Namespace[tostring(nsid) .. '-display'] or data.Namespace[tostring(nsid)] end), } function p._PseudoNamespaceDisplay(lang, ns, isTalk) if not inArray(ns, data['PseudoNamespace']['list']) then error('Input pseudo namespace error.') end local display = p._lan(data.PseudoNamespace.messages[isTalk and 'talk' or 'main'], lang) display = mw.ustring.gsub(display, '$1', p._lan(data.PseudoNamespace[ns], lang)) return display end for key, func in pairs(MsgCallFunc) do p['_' .. key] = function(lang, ns) if type(lang) == 'table' then ns = lang[2] lang = lang[1] end local PNS, PNSIsTalk local lang = lang local nsid if ns then if ns == '' then nsid = -3 else local nsid_info = mw.site.namespaces[tonumber(ns)] or mw.site.namespaces[ns] if not nsid_info then PNS, PNSIsTalk = p._isPseudoNamespace(ns, false) nsid = -3 else nsid = nsid_info.id end end else local title = mw.title.getCurrentTitle() nsid = title.namespace if nsid == 0 or nsid == 1 then PNS, PNSIsTalk = p._isPseudoNamespace(title, true) end end if PNS then return p._pseudoNamespaceDisplay(lang, PNS, PNSIsTalk) elseif nsid < -2 then error('Input namespace error.') end return p._lan(MsgCallFunc[key](nsid), lang) end p[key] = function(frame) local args = require('Module:Arguments').getArgs(frame, { valueFunc = function(key, value) if key == 2 then return type(value) == 'string' and mw.text.trim(value) or value elseif value then value = mw.text.trim(value) if value ~= '' then return value end end return nil end }) local statue, wt = pcall(p['_' .. key], args) if statue then return wt end return tostring(mw.html.create('span'):attr('style', 'color:red;'):wikitext( p._lan({ ['en'] = 'Input namespace error', ['zh-hans'] = '输入命名空间错误', ['zh-hant'] = '輸入命名空間錯誤' }, lang) ):done()) end end function p._isPseudoNamespace(ns, isPage) if not ns then ns = mw.title.getCurrentTitle() isPage = true elseif ns == '' then return nil, false end local success, titleObj if type(ns) == type('') then if not ns:match(':') then ns = ns .. ':' end success, titleObj = pcall(mw.title.new, ns) if not success or not titleObj or not titleObj:inNamespaces(0, 1) then return nil, false end local split = mw.text.split(titleObj.text, ':') if not isPage and (#split > 2 or (split[2] ~= '' and split[2] ~= nil)) then -- isPage = false 時僅允許: -- 1. PNS -- 2. PNS: return nil, false end ns = split[1] -- 移除冒號後的東西 elseif type(ns) == type({}) and type(ns.text) == type('') and isPage then -- 如果傳入頁面物件,則 isPage 必然要是 true if not ns:inNamespaces(0, 1) then return nil, false end ns = mw.text.split(ns.text, ':')[1] -- 移除冒號後的東西 else error(string.format( 'bad argument #1 to \'_isPseudoNamespace[isPage=%s]\' (%s expected, got %s)', isPage and 'true' or 'false', isPage and 'string or mw.title object' or 'string', type(ns) )) end if inArray(ns, data['PseudoNamespace']['list']) then return ns, titleObj.namespace == 1 end return nil, false end function p.ispseudo(frame) local arg = require('Module:Arguments').getArgs(frame)['1'] local PNS, _isTalk = p._isPseudoNamespace(arg, true) return PNS or '' end p._PNSArray = data['PseudoNamespace']['list'] return p
编辑摘要
(请简要描述您所作出的修改
,或选择:
新条目
修饰语句
修正笔误
内容扩充
排版
来源
内部链接
分类
消歧义
维基化
维护清理
)
请注意,所有对Local Chinese Wikipedia的贡献均可能会被其他贡献者编辑、修改或删除。如果您不希望您的文字作品被随意编辑,请不要在此提交。
您同时也向我们承诺,您提交的内容为您自己所创作,或是复制自公共领域或类似自由来源(详情请见
Project:著作权
)。
未经许可,请勿提交受著作权保护的作品!
取消
编辑帮助
(在新窗口中打开)
导航菜单
个人工具
未登录
讨论
贡献
创建账号
登录
命名空间
模块
讨论
English
查看
阅读
编辑
查看历史
更多
搜索
导航
首页
分类索引
特色内容
新闻动态
随机条目
联络我们
关于维基百科
资助维基百科
贡献
帮助
维基社群
编辑入门
互助客栈
IRC即时聊天
最近更改
特殊页面
工具
链入页面
相关更改
特殊页面
页面信息