<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="zh-Hans-CN">
	<id>https://www.wikiw.cn/index.php?action=history&amp;feed=atom&amp;title=%E6%A8%A1%E5%9D%97%3ATemplate_invocation</id>
	<title>模块:Template invocation - 版本历史</title>
	<link rel="self" type="application/atom+xml" href="https://www.wikiw.cn/index.php?action=history&amp;feed=atom&amp;title=%E6%A8%A1%E5%9D%97%3ATemplate_invocation"/>
	<link rel="alternate" type="text/html" href="https://www.wikiw.cn/index.php?title=%E6%A8%A1%E5%9D%97:Template_invocation&amp;action=history"/>
	<updated>2026-04-08T20:51:13Z</updated>
	<subtitle>本wiki上该页面的版本历史</subtitle>
	<generator>MediaWiki 1.44.0</generator>
	<entry>
		<id>https://www.wikiw.cn/index.php?title=%E6%A8%A1%E5%9D%97:Template_invocation&amp;diff=2331&amp;oldid=prev</id>
		<title>imported&gt;Xiplus-abot：​已更改“Module:Template invocation”的保护等级：高風險模板：8728引用&lt;!-- 機器人3 --&gt;（[编辑=仅允许模板编辑员和管理员]（无限期）[移动=仅允许模板编辑员和管理员]（无限期））</title>
		<link rel="alternate" type="text/html" href="https://www.wikiw.cn/index.php?title=%E6%A8%A1%E5%9D%97:Template_invocation&amp;diff=2331&amp;oldid=prev"/>
		<updated>2020-12-26T00:06:12Z</updated>

		<summary type="html">&lt;p&gt;已更改“&lt;a href=&quot;/index.php?title=%E6%A8%A1%E5%9D%97:Template_invocation&quot; title=&quot;模块:Template invocation&quot;&gt;Module:Template invocation&lt;/a&gt;”的保护等级：高風險模板：8728引用&amp;lt;!-- &lt;a href=&quot;/index.php?title=%E7%94%A8%E6%88%B7:Xiplus-abot/task/3&amp;amp;action=edit&amp;amp;redlink=1&quot; class=&quot;new&quot; title=&quot;用户:Xiplus-abot/task/3（页面不存在）&quot;&gt;機器人3&lt;/a&gt; --&amp;gt;（[编辑=仅允许模板编辑员和管理员]（无限期）[移动=仅允许模板编辑员和管理员]（无限期））&lt;/p&gt;
&lt;p&gt;&lt;b&gt;新页面&lt;/b&gt;&lt;/p&gt;&lt;div&gt;-- This module provides functions for making MediaWiki template invocations.&lt;br /&gt;
&lt;br /&gt;
local checkType = require(&amp;#039;libraryUtil&amp;#039;).checkType&lt;br /&gt;
&lt;br /&gt;
local p = {}&lt;br /&gt;
&lt;br /&gt;
------------------------------------------------------------------------&lt;br /&gt;
--         Name:  p.name&lt;br /&gt;
--      Purpose:  Find a template invocation name from a page name or a&lt;br /&gt;
--                mw.title object.&lt;br /&gt;
--  Description:  This function detects whether a string or a mw.title&lt;br /&gt;
--                object has been passed in, and uses that to find a&lt;br /&gt;
--                template name as it is used in template invocations.&lt;br /&gt;
--   Parameters:  title - full page name or mw.title object for the&lt;br /&gt;
--                template (string or mw.title object)&lt;br /&gt;
--      Returns:  String&lt;br /&gt;
------------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
function p.name(title)&lt;br /&gt;
	if type(title) == &amp;#039;string&amp;#039; then&lt;br /&gt;
		title = mw.title.new(title)&lt;br /&gt;
		if not title then&lt;br /&gt;
			error(&amp;quot;invalid title in parameter #1 of function &amp;#039;name&amp;#039;&amp;quot;, 2)&lt;br /&gt;
		end&lt;br /&gt;
	elseif type(title) ~= &amp;#039;table&amp;#039; or type(title.getContent) ~= &amp;#039;function&amp;#039; then&lt;br /&gt;
		error(&amp;quot;parameter #1 of function &amp;#039;name&amp;#039; must be a string or a mw.title object&amp;quot;, 2)&lt;br /&gt;
	end&lt;br /&gt;
	if title.namespace == 10 then&lt;br /&gt;
		return title.text&lt;br /&gt;
	elseif title.namespace == 0 then&lt;br /&gt;
		return &amp;#039;:&amp;#039; .. title.prefixedText&lt;br /&gt;
	else&lt;br /&gt;
		return title.prefixedText&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
------------------------------------------------------------------------&lt;br /&gt;
--         Name:  p.invocation&lt;br /&gt;
--      Purpose:  Construct a MediaWiki template invocation.&lt;br /&gt;
--  Description:  This function makes a template invocation from the&lt;br /&gt;
--                name and the arguments given. Note that it isn&amp;#039;t&lt;br /&gt;
--                perfect: we have no way of knowing what whitespace was&lt;br /&gt;
--                in the original invocation, the order of the parameters&lt;br /&gt;
--                may be changed, and any parameters with duplicate keys&lt;br /&gt;
--                will be removed.&lt;br /&gt;
--   Parameters:  name - the template name, formatted as it will appear&lt;br /&gt;
--                    in the invocation. (string)&lt;br /&gt;
--                args - a table of template arguments. (table)&lt;br /&gt;
--                format - formatting options. (string, optional)&lt;br /&gt;
--                    Set to &amp;quot;nowiki&amp;quot; to escape, curly braces, pipes and&lt;br /&gt;
--                    equals signs with their HTML entities. The default&lt;br /&gt;
--                    is unescaped.&lt;br /&gt;
--      Returns:  String&lt;br /&gt;
------------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
function p.invocation(name, args, format)&lt;br /&gt;
	checkType(&amp;#039;invocation&amp;#039;, 1, name, &amp;#039;string&amp;#039;)&lt;br /&gt;
	checkType(&amp;#039;invocation&amp;#039;, 2, args, &amp;#039;table&amp;#039;)&lt;br /&gt;
	checkType(&amp;#039;invocation&amp;#039;, 3, format, &amp;#039;string&amp;#039;, true)&lt;br /&gt;
&lt;br /&gt;
	-- Validate the args table and make a copy to work from. We need to&lt;br /&gt;
	-- make a copy of the table rather than just using the original, as&lt;br /&gt;
	-- some of the values may be erased when building the invocation.&lt;br /&gt;
	local invArgs = {}&lt;br /&gt;
	for k, v in pairs(args) do&lt;br /&gt;
		local typek = type(k)&lt;br /&gt;
		local typev = type(v)&lt;br /&gt;
		if typek ~= &amp;#039;string&amp;#039; and typek ~= &amp;#039;number&amp;#039;&lt;br /&gt;
			or typev ~= &amp;#039;string&amp;#039; and typev ~= &amp;#039;number&amp;#039;&lt;br /&gt;
		then&lt;br /&gt;
			error(&amp;quot;invalid arguments table in parameter #2 of &amp;quot; ..&lt;br /&gt;
			&amp;quot;&amp;#039;invocation&amp;#039; (keys and values must be strings or numbers)&amp;quot;, 2)&lt;br /&gt;
		end&lt;br /&gt;
		invArgs[k] = v&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	-- Get the separators to use.&lt;br /&gt;
	local seps = {&lt;br /&gt;
		openb = &amp;#039;{{&amp;#039;,&lt;br /&gt;
		closeb = &amp;#039;}}&amp;#039;,&lt;br /&gt;
		pipe = &amp;#039;|&amp;#039;,&lt;br /&gt;
		equals = &amp;#039;=&amp;#039;&lt;br /&gt;
	}&lt;br /&gt;
	if format == &amp;#039;nowiki&amp;#039; then&lt;br /&gt;
		for k, v in pairs(seps) do&lt;br /&gt;
			seps[k] = mw.text.nowiki(v)&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	-- Build the invocation body with numbered args first, then named.&lt;br /&gt;
	local ret = {}&lt;br /&gt;
	ret[#ret + 1] = seps.openb&lt;br /&gt;
	ret[#ret + 1] = name&lt;br /&gt;
	for k, v in ipairs(invArgs) do&lt;br /&gt;
		if v:find(&amp;#039;=&amp;#039;, 1, true) then&lt;br /&gt;
			-- Likely something like 1=foo=bar, we need to do it as a named arg&lt;br /&gt;
			break&lt;br /&gt;
		end&lt;br /&gt;
		ret[#ret + 1] = seps.pipe&lt;br /&gt;
		ret[#ret + 1] = v&lt;br /&gt;
		invArgs[k] = nil -- Erase the key so that we don&amp;#039;t add the value twice&lt;br /&gt;
	end&lt;br /&gt;
	for k, v in pairs(invArgs) do&lt;br /&gt;
		ret[#ret + 1] = seps.pipe&lt;br /&gt;
		ret[#ret + 1] = k&lt;br /&gt;
		ret[#ret + 1] = seps.equals&lt;br /&gt;
		ret[#ret + 1] = v&lt;br /&gt;
	end&lt;br /&gt;
	ret[#ret + 1] = seps.closeb&lt;br /&gt;
&lt;br /&gt;
	return table.concat(ret)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
return p&lt;/div&gt;</summary>
		<author><name>imported&gt;Xiplus-abot</name></author>
	</entry>
</feed>