Editing
Module:TemplateArgPassingTool
Jump to navigation
Jump to search
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
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
Summary:
Please note that all contributions to wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Wiki:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Navigation menu
Personal tools
Not logged in
Talk
Contributions
Create account
Log in
Namespaces
Page
Discussion
English
Views
Read
Edit
View history
More
Search
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Tools
What links here
Related changes
Special pages
Page information