<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://test.zero-k.info/mediawiki/index.php?action=history&amp;feed=atom&amp;title=Module%3AHatnote_list</id>
	<title>Module:Hatnote list - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://test.zero-k.info/mediawiki/index.php?action=history&amp;feed=atom&amp;title=Module%3AHatnote_list"/>
	<link rel="alternate" type="text/html" href="https://test.zero-k.info/mediawiki/index.php?title=Module:Hatnote_list&amp;action=history"/>
	<updated>2026-04-03T19:24:29Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.34.1</generator>
	<entry>
		<id>https://test.zero-k.info/mediawiki/index.php?title=Module:Hatnote_list&amp;diff=137&amp;oldid=prev</id>
		<title>Aquanim: 1 revision imported: Added Infobox</title>
		<link rel="alternate" type="text/html" href="https://test.zero-k.info/mediawiki/index.php?title=Module:Hatnote_list&amp;diff=137&amp;oldid=prev"/>
		<updated>2016-06-25T13:20:03Z</updated>

		<summary type="html">&lt;p&gt;1 revision imported: Added Infobox&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;--------------------------------------------------------------------------------&lt;br /&gt;
--                           Module:Hatnote list                              --&lt;br /&gt;
--                                                                            --&lt;br /&gt;
-- This module produces and formats lists for use in hatnotes. In particular, --&lt;br /&gt;
-- it implements the for-see list, i.e. lists of &amp;quot;For X, see Y&amp;quot; statements,   --&lt;br /&gt;
-- as used in {{about}}, {{redirect}}, and their variants. Also introduced    --&lt;br /&gt;
-- are andList &amp;amp; orList helpers for formatting lists with those conjunctions. --&lt;br /&gt;
--------------------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
local mArguments --initialize lazily&lt;br /&gt;
local mHatnote = require('Module:Hatnote')&lt;br /&gt;
local libraryUtil = require('libraryUtil')&lt;br /&gt;
local checkType = libraryUtil.checkType&lt;br /&gt;
local p = {}&lt;br /&gt;
&lt;br /&gt;
--------------------------------------------------------------------------------&lt;br /&gt;
-- List stringification helper functions&lt;br /&gt;
--&lt;br /&gt;
-- These functions are used for stringifying lists, usually page lists inside&lt;br /&gt;
-- the &amp;quot;Y&amp;quot; portion of &amp;quot;For X, see Y&amp;quot; for-see items.&lt;br /&gt;
--------------------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
--default options table used across the list stringification functions&lt;br /&gt;
local stringifyListDefaultOptions = {&lt;br /&gt;
	conjunction = &amp;quot;and&amp;quot;,&lt;br /&gt;
	separator = &amp;quot;,&amp;quot;,&lt;br /&gt;
	altSeparator = &amp;quot;;&amp;quot;,&lt;br /&gt;
	space = &amp;quot; &amp;quot;,&lt;br /&gt;
	formatted = false&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
-- Stringifies a list generically; probably shouldn't be used directly&lt;br /&gt;
function stringifyList(list, options)&lt;br /&gt;
	-- Type-checks, defaults, and a shortcut&lt;br /&gt;
	checkType(&amp;quot;stringifyList&amp;quot;, 1, list, &amp;quot;table&amp;quot;)&lt;br /&gt;
	if #list == 0 then return nil end&lt;br /&gt;
	checkType(&amp;quot;stringifyList&amp;quot;, 2, options, &amp;quot;table&amp;quot;, true)&lt;br /&gt;
	options = options or {}&lt;br /&gt;
	for k, v in pairs(stringifyListDefaultOptions) do&lt;br /&gt;
		if options[k] == nil then options[k] = v end&lt;br /&gt;
	end&lt;br /&gt;
	local s = options.space&lt;br /&gt;
	-- Format the list if requested&lt;br /&gt;
	if options.formatted then list = mHatnote.formatPages(unpack(list)) end&lt;br /&gt;
	-- Set the separator; if any item contains it, use the alternate separator&lt;br /&gt;
	local separator = options.separator&lt;br /&gt;
	--searches display text only&lt;br /&gt;
	function searchDisp(t, f)&lt;br /&gt;
		return string.find(string.sub(t, (string.find(t, '|') or 0) + 1), f)&lt;br /&gt;
	end&lt;br /&gt;
	for k, v in pairs(list) do&lt;br /&gt;
		if searchDisp(v, separator) then&lt;br /&gt;
			separator = options.altSeparator&lt;br /&gt;
			break&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	-- Set the conjunction, apply Oxford comma, and force a comma if #1 has &amp;quot;§&amp;quot;&lt;br /&gt;
	local conjunction = s .. options.conjunction .. s&lt;br /&gt;
	if #list == 2 and searchDisp(list[1], &amp;quot;§&amp;quot;) or #list &amp;gt; 2 then&lt;br /&gt;
		conjunction = separator .. conjunction&lt;br /&gt;
	end&lt;br /&gt;
	-- Return the formatted string&lt;br /&gt;
	return mw.text.listToText(list, separator .. s, conjunction)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
--DRY function&lt;br /&gt;
function conjList (conj, list, fmt)&lt;br /&gt;
	return stringifyList(list, {conjunction = conj, formatted = fmt})&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- Stringifies lists with &amp;quot;and&amp;quot; or &amp;quot;or&amp;quot;&lt;br /&gt;
function p.andList (...) return conjList(&amp;quot;and&amp;quot;, ...) end&lt;br /&gt;
function p.orList (...) return conjList(&amp;quot;or&amp;quot;, ...) end&lt;br /&gt;
&lt;br /&gt;
--------------------------------------------------------------------------------&lt;br /&gt;
-- For see&lt;br /&gt;
--&lt;br /&gt;
-- Makes a &amp;quot;For X, see [[Y]].&amp;quot; list from raw parameters. Intended for the&lt;br /&gt;
-- {{about}} and {{redirect}} templates and their variants.&lt;br /&gt;
--------------------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
--default options table used across the forSee family of functions&lt;br /&gt;
local forSeeDefaultOptions = {&lt;br /&gt;
	andKeyword = 'and',&lt;br /&gt;
	title = mw.title.getCurrentTitle().text,&lt;br /&gt;
	otherText = 'other uses',&lt;br /&gt;
	forSeeForm = 'For %s, see %s.'&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
--Collapses duplicate punctuation&lt;br /&gt;
function punctuationCollapse (text)&lt;br /&gt;
	local replacements = {&lt;br /&gt;
		[&amp;quot;%.%.$&amp;quot;] = &amp;quot;.&amp;quot;,&lt;br /&gt;
		[&amp;quot;%?%.$&amp;quot;] = &amp;quot;?&amp;quot;,&lt;br /&gt;
		[&amp;quot;%!%.$&amp;quot;] = &amp;quot;!&amp;quot;,&lt;br /&gt;
		[&amp;quot;%.%]%]%.$&amp;quot;] = &amp;quot;.]]&amp;quot;,&lt;br /&gt;
		[&amp;quot;%?%]%]%.$&amp;quot;] = &amp;quot;?]]&amp;quot;,&lt;br /&gt;
		[&amp;quot;%!%]%]%.$&amp;quot;] = &amp;quot;!]]&amp;quot;&lt;br /&gt;
	}&lt;br /&gt;
	for k, v in pairs(replacements) do text = string.gsub(text, k, v) end&lt;br /&gt;
	return text&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- Structures arguments into a table for stringification, &amp;amp; options&lt;br /&gt;
function p.forSeeArgsToTable (args, from, options)&lt;br /&gt;
	-- Type-checks and defaults&lt;br /&gt;
	checkType(&amp;quot;forSeeArgsToTable&amp;quot;, 1, args, 'table')&lt;br /&gt;
	checkType(&amp;quot;forSeeArgsToTable&amp;quot;, 2, from, 'number', true)&lt;br /&gt;
	from = from or 1&lt;br /&gt;
	checkType(&amp;quot;forSeeArgsToTable&amp;quot;, 3, options, 'table', true)&lt;br /&gt;
	options = options or {}&lt;br /&gt;
	for k, v in pairs(forSeeDefaultOptions) do&lt;br /&gt;
		if options[k] == nil then options[k] = v end&lt;br /&gt;
	end&lt;br /&gt;
	-- maxArg's gotten manually because getArgs() and table.maxn aren't friends&lt;br /&gt;
	local maxArg = 0&lt;br /&gt;
	for k, v in pairs(args) do&lt;br /&gt;
		if type(k) == 'number' and k &amp;gt; maxArg then maxArg = k end&lt;br /&gt;
	end&lt;br /&gt;
	-- Structure the data out from the parameter list:&lt;br /&gt;
	-- * forTable is the wrapper table, with forRow rows&lt;br /&gt;
	-- * Rows are tables of a &amp;quot;use&amp;quot; string &amp;amp; a &amp;quot;pages&amp;quot; table of pagename strings&lt;br /&gt;
	-- * Blanks are left empty for defaulting elsewhere, but can terminate list&lt;br /&gt;
	local forTable = {}&lt;br /&gt;
	local i = from&lt;br /&gt;
	local terminated = false&lt;br /&gt;
	-- Loop to generate rows&lt;br /&gt;
	repeat&lt;br /&gt;
		-- New empty row&lt;br /&gt;
		local forRow = {}&lt;br /&gt;
		-- On blank use, assume list's ended &amp;amp; break at end of this loop&lt;br /&gt;
		forRow.use = args[i]&lt;br /&gt;
		if not args[i] then terminated = true end&lt;br /&gt;
		-- New empty list of pages&lt;br /&gt;
		forRow.pages = {}&lt;br /&gt;
		-- Insert first pages item if present&lt;br /&gt;
		table.insert(forRow.pages, args[i + 1])&lt;br /&gt;
		-- If the param after next is &amp;quot;and&amp;quot;, do inner loop to collect params&lt;br /&gt;
		-- until the &amp;quot;and&amp;quot;'s stop. Blanks are ignored: &amp;quot;1|and||and|3&amp;quot; → {1, 3}&lt;br /&gt;
		while args[i + 2] == options.andKeyword do&lt;br /&gt;
			if args[i + 3] then &lt;br /&gt;
				table.insert(forRow.pages, args[i + 3])&lt;br /&gt;
			end&lt;br /&gt;
			-- Increment to next &amp;quot;and&amp;quot;&lt;br /&gt;
			i = i + 2&lt;br /&gt;
		end&lt;br /&gt;
		-- Increment to next use&lt;br /&gt;
		i = i + 2&lt;br /&gt;
		-- Append the row&lt;br /&gt;
		table.insert(forTable, forRow)&lt;br /&gt;
	until terminated or i &amp;gt; maxArg&lt;br /&gt;
	&lt;br /&gt;
	return forTable&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- Stringifies a table as formatted by forSeeArgsToTable&lt;br /&gt;
function p.forSeeTableToString (forSeeTable, options)&lt;br /&gt;
	-- Type-checks and defaults&lt;br /&gt;
	checkType(&amp;quot;forSeeTableToString&amp;quot;, 1, forSeeTable, &amp;quot;table&amp;quot;)&lt;br /&gt;
	checkType(&amp;quot;forSeeTableToString&amp;quot;, 2, options, &amp;quot;table&amp;quot;, true)&lt;br /&gt;
	options = options or {}&lt;br /&gt;
	for k, v in pairs(forSeeDefaultOptions) do&lt;br /&gt;
		if options[k] == nil then options[k] = v end&lt;br /&gt;
	end&lt;br /&gt;
	-- Stringify each for-see item into a list&lt;br /&gt;
	local strList = {}&lt;br /&gt;
	for k, v in pairs(forSeeTable) do&lt;br /&gt;
		local useStr = v.use or options.otherText&lt;br /&gt;
		local pagesStr = p.andList(v.pages, true) or&lt;br /&gt;
			mHatnote._formatLink(mHatnote.disambiguate(options.title))&lt;br /&gt;
		local forSeeStr = string.format(options.forSeeForm, useStr, pagesStr)&lt;br /&gt;
		forSeeStr = punctuationCollapse(forSeeStr)&lt;br /&gt;
		table.insert(strList, forSeeStr)&lt;br /&gt;
	end&lt;br /&gt;
	-- Return the concatenated list&lt;br /&gt;
	return table.concat(strList, ' ')&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- Produces a &amp;quot;For X, see [[Y]]&amp;quot; string from arguments. Expects index gaps&lt;br /&gt;
-- but not blank/whitespace values. Ignores named args and args &amp;lt; &amp;quot;from&amp;quot;.&lt;br /&gt;
function p._forSee (args, from, options)&lt;br /&gt;
	local forSeeTable = p.forSeeArgsToTable(args, from, options)&lt;br /&gt;
	return p.forSeeTableToString(forSeeTable, options)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- As _forSee, but uses the frame.&lt;br /&gt;
function p.forSee (frame, from, options)&lt;br /&gt;
	mArguments = require('Module:Arguments')&lt;br /&gt;
	return p._forSee(mArguments.getArgs(frame), from, options)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
return p&lt;/div&gt;</summary>
		<author><name>Aquanim</name></author>
		
	</entry>
</feed>