跳转到内容
打开/关闭搜索
搜索
打开/关闭菜单
397
文件
1978
用户
1.2万
编辑
Gal中文百科
导航
首页
最近更改
随机页面
MediaWiki帮助
特殊页面
在其他项目中
打开/关闭外观设置菜单
无法加载偏好设置。请检查您的网络连接并重试。
重试
打开/关闭个人菜单
未登录
未登录用户的IP地址会在进行任意编辑后公开展示。
user-interface-preferences
个人工具
讨论
贡献
创建账号
登录
编辑“︁
Module
:
TemplateArgPassingTool
”︁
来自Gal中文百科
查看
阅读
编辑源代码
查看历史
associated-pages
模块
讨论
更多操作
更多
工具
链入页面
相关更改
页面信息
警告:
您没有登录。如果您进行任何编辑,您的IP地址会公开展示。如果您
登录
或
创建账号
,您的编辑会以您的用户名署名,此外还有其他益处。
反垃圾检查。
不要
加入这个!
local p={} local lib_arg={} local module_pattern = "#%s*[Ii][Nn][Vv][Oo][Kk][Ee]%s*:%s*(.+)%s*%|%s*(.+)" function p.passArgs(frame) return p.passNArgs(frame, true) end function p.passEscapeArgs(frame) local args, working_frame 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 lib_arg.getArgs == nil then lib_arg = require('Module:Arguments') end args = lib_arg.getArgs(frame, {parentFirst=true}) working_frame = frame else -- We're being called from another module or from the debug console, so assume -- the args are passed in directly. args = frame working_frame = mw.getCurrentFrame() if type(args) ~= type({}) then args = {frame} end end local template_name = '' .. (args.template_name or 'void') local module_name, function_name = nil,nil if mw.ustring.find(template_name, module_pattern) then mw.ustring.gsub(template_name, module_pattern, function(str, fun)module_name, function_name = str, fun return str end) end local escape_args = {} for key, value in pairs(args) do local arg_value = value if mw.isSubsting() then arg_value = mw.ustring.gsub(value, "[=%|%{%}]", function(esc_str) local mapping = {} mapping['|']='!' mapping['=']='=' mapping['{']='(' mapping['}']=')' if mapping[esc_str] then return "{{" .. mapping[esc_str] .. "}}" end return esc_str end) end escape_args[key] = mw.text.encode(arg_value) end local body_frame = working_frame:newChild{ title = module_name or template_name, args = escape_args } if module_name ~= nil then module_body = require("Module:"..module_name) if module_body ~= nil then func_body = module_body[function_name] if func_body ~= nil then return func_body(body_frame) end end return '' end return body_frame:expandTemplate{ title = template_name, args = escape_args } end function p.passNArgs(frame, no_skip) local args, working_frame 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 lib_arg.getArgs == nil then lib_arg = require('Module:Arguments') end args = lib_arg.getArgs(frame, {parentFirst=true}) working_frame = frame else -- We're being called from another module or from the debug console, so assume -- the args are passed in directly. args = frame working_frame = mw.getCurrentFrame() if type(args) ~= type({}) then args = {frame} end end local skip_args = no_skip and 0 or (tonumber(args.skip) or 1) local template_name = '' .. (args.template_name or 'void') local module_name, function_name = nil,nil if mw.ustring.find(template_name, module_pattern) then mw.ustring.gsub(template_name, module_pattern, function(str, fun)module_name, function_name = str, fun return str end) end local sikp_args = {} for key, value in pairs(args) do local i = tonumber(key) local new_key = key local skip_flag = false if i ~= nil then if i > 0 then if i <= skip_args then skip_flag = true end new_key = i - skip_args end end if not skip_flag then sikp_args[new_key] = value end end local body_frame = working_frame:newChild{ title = module_name or template_name, args = sikp_args } if module_name ~= nil then module_body = require("Module:"..module_name) if module_body ~= nil then func_body = module_body[function_name] if func_body ~= nil then return func_body(body_frame) end end return '' end return body_frame:expandTemplate{ title = template_name, args = sikp_args } end return p
摘要:
请注意,所有对Gal中文百科的贡献均可能会被其他贡献者编辑、修改或删除。如果您不希望您的文字作品被随意编辑,请不要在此提交。
您同时也向我们承诺,您提交的内容为您自己所创作,或是复制自公共领域或类似自由来源(详情请见
Gal中文百科:著作权
)。
未经许可,请勿提交受著作权保护的作品!
取消
编辑帮助
(在新窗口中打开)
此页面嵌入的页面:
Module:TemplateArgPassingTool/doc
(
编辑
)
编辑“︁
Module
:
TemplateArgPassingTool
”︁
来自Gal中文百科