<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.pttlink.org/index.php?action=history&amp;feed=atom&amp;title=Module%3ATemplate_invocation</id>
	<title>Module:Template invocation - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.pttlink.org/index.php?action=history&amp;feed=atom&amp;title=Module%3ATemplate_invocation"/>
	<link rel="alternate" type="text/html" href="https://wiki.pttlink.org/index.php?title=Module:Template_invocation&amp;action=history"/>
	<updated>2026-04-06T10:59:09Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.35.5</generator>
	<entry>
		<id>https://wiki.pttlink.org/index.php?title=Module:Template_invocation&amp;diff=11909&amp;oldid=prev</id>
		<title>Kg7qin: 1 revision imported</title>
		<link rel="alternate" type="text/html" href="https://wiki.pttlink.org/index.php?title=Module:Template_invocation&amp;diff=11909&amp;oldid=prev"/>
		<updated>2022-01-24T15:14:20Z</updated>

		<summary type="html">&lt;p&gt;1 revision imported&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left diff-editfont-monospace&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 15:14, 24 January 2022&lt;/td&gt;
				&lt;/tr&gt;
&lt;!-- diff cache key mediawiki:diff::1.12:old-11908:rev-11909 --&gt;
&lt;/table&gt;</summary>
		<author><name>Kg7qin</name></author>
	</entry>
	<entry>
		<id>https://wiki.pttlink.org/index.php?title=Module:Template_invocation&amp;diff=11908&amp;oldid=prev</id>
		<title>Mediawiki&gt;Johnuniq: fixes requested at Module talk:Template invocation: keys of parameters may be numbers or strings so need a custom sort; that break was wrong as more could be following</title>
		<link rel="alternate" type="text/html" href="https://wiki.pttlink.org/index.php?title=Module:Template_invocation&amp;diff=11908&amp;oldid=prev"/>
		<updated>2020-05-20T04:03:53Z</updated>

		<summary type="html">&lt;p&gt;fixes requested at &lt;a href=&quot;/index.php?title=Module_talk:Template_invocation&amp;amp;action=edit&amp;amp;redlink=1&quot; class=&quot;new&quot; title=&quot;Module talk:Template invocation (page does not exist)&quot;&gt;Module talk:Template invocation&lt;/a&gt;: keys of parameters may be numbers or strings so need a custom sort; that break was wrong as more could be following&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&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('libraryUtil').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) == 'string' 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 'name'&amp;quot;, 2)&lt;br /&gt;
		end&lt;br /&gt;
	elseif type(title) ~= 'table' or type(title.getContent) ~= 'function' then&lt;br /&gt;
		error(&amp;quot;parameter #1 of function 'name' 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 ':' .. 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't&lt;br /&gt;
--                perfect: we have no way of knowing what whitespace was&lt;br /&gt;
--                in the original invocation, the named parameters will be&lt;br /&gt;
--                alphabetically sorted, 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('invocation', 1, name, 'string')&lt;br /&gt;
	checkType('invocation', 2, args, 'table')&lt;br /&gt;
	checkType('invocation', 3, format, 'string', 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 ~= 'string' and typek ~= 'number'&lt;br /&gt;
			or typev ~= 'string' and typev ~= 'number'&lt;br /&gt;
		then&lt;br /&gt;
			error(&amp;quot;invalid arguments table in parameter #2 of &amp;quot; ..&lt;br /&gt;
			&amp;quot;'invocation' (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 = '{{',&lt;br /&gt;
		closeb = '}}',&lt;br /&gt;
		pipe = '|',&lt;br /&gt;
		equals = '='&lt;br /&gt;
	}&lt;br /&gt;
	if format == 'nowiki' 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 type(v) == 'string' and v:find('=', 1, true) then&lt;br /&gt;
			-- Likely something like 1=foo=bar which needs to be displayed as a named arg.&lt;br /&gt;
		else&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't add the value twice&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	local keys = {} -- sort parameter list; better than arbitrary order&lt;br /&gt;
	for k, _ in pairs(invArgs) do&lt;br /&gt;
		keys[#keys + 1] = k&lt;br /&gt;
	end&lt;br /&gt;
	table.sort(keys, function (a, b)&lt;br /&gt;
			-- Sort with keys of type number first, then string.&lt;br /&gt;
			if type(a) == type(b) then&lt;br /&gt;
				return a &amp;lt; b&lt;br /&gt;
			elseif type(a) == 'number' then&lt;br /&gt;
				return true&lt;br /&gt;
			end&lt;br /&gt;
		end)&lt;br /&gt;
	for _, v in ipairs(keys) do -- Add named args based on sorted parameter list&lt;br /&gt;
		ret[#ret + 1] = seps.pipe&lt;br /&gt;
		ret[#ret + 1] = tostring(v)&lt;br /&gt;
		ret[#ret + 1] = seps.equals&lt;br /&gt;
		ret[#ret + 1] = invArgs[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>Mediawiki&gt;Johnuniq</name></author>
	</entry>
</feed>