<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ja">
	<id>https://wiki.akaren.club/index.php?action=history&amp;feed=atom&amp;title=%E3%83%A2%E3%82%B8%E3%83%A5%E3%83%BC%E3%83%AB%3AHatnote_list</id>
	<title>モジュール:Hatnote list - 版の履歴</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.akaren.club/index.php?action=history&amp;feed=atom&amp;title=%E3%83%A2%E3%82%B8%E3%83%A5%E3%83%BC%E3%83%AB%3AHatnote_list"/>
	<link rel="alternate" type="text/html" href="https://wiki.akaren.club/index.php?title=%E3%83%A2%E3%82%B8%E3%83%A5%E3%83%BC%E3%83%AB:Hatnote_list&amp;action=history"/>
	<updated>2026-06-06T05:11:21Z</updated>
	<subtitle>このウィキのこのページに関する変更履歴</subtitle>
	<generator>MediaWiki 1.39.3</generator>
	<entry>
		<id>https://wiki.akaren.club/index.php?title=%E3%83%A2%E3%82%B8%E3%83%A5%E3%83%BC%E3%83%AB:Hatnote_list&amp;diff=304&amp;oldid=prev</id>
		<title>Mikunyan: 1版 をインポートしました</title>
		<link rel="alternate" type="text/html" href="https://wiki.akaren.club/index.php?title=%E3%83%A2%E3%82%B8%E3%83%A5%E3%83%BC%E3%83%AB:Hatnote_list&amp;diff=304&amp;oldid=prev"/>
		<updated>2016-05-07T03:36:57Z</updated>

		<summary type="html">&lt;p&gt;1版 をインポートしました&lt;/p&gt;
&lt;p&gt;&lt;b&gt;新規ページ&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(&amp;#039;Module:Hatnote&amp;#039;)&lt;br /&gt;
local libraryUtil = require(&amp;#039;libraryUtil&amp;#039;)&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;
}&lt;br /&gt;
&lt;br /&gt;
-- Stringifies a list generically; probably shouldn&amp;#039;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;
	-- Set the separator; if any item contains it, use the alternate separator&lt;br /&gt;
	local separator = options.separator&lt;br /&gt;
	for k, v in pairs(list) do&lt;br /&gt;
		if string.find(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 string.find(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;
-- Stringifies a list with &amp;quot;and&amp;quot;&lt;br /&gt;
function p.andList (list)&lt;br /&gt;
	return stringifyList(list, {conjunction = &amp;quot;and&amp;quot;})&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- Stringifies a list with &amp;quot;or&amp;quot;&lt;br /&gt;
function p.orList (list)&lt;br /&gt;
	return stringifyList(list, {conjunction = &amp;quot;or&amp;quot;})&lt;br /&gt;
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;
	title = mw.title.getCurrentTitle().text,&lt;br /&gt;
	otherText = &amp;#039;other uses&amp;#039;,&lt;br /&gt;
	forseeForm = &amp;#039;For %s, see %s.&amp;#039;,&lt;br /&gt;
	punctuationCollapseReplacements = {&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;
}&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, &amp;#039;table&amp;#039;)&lt;br /&gt;
	checkType(&amp;quot;forSeeArgsToTable&amp;quot;, 2, from, &amp;#039;number&amp;#039;, true)&lt;br /&gt;
	from = from or 1&lt;br /&gt;
	checkType(&amp;quot;forSeeArgsToTable&amp;quot;, 3, options, &amp;#039;table&amp;#039;, 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&amp;#039;s gotten manually because getArgs() and table.maxn aren&amp;#039;t friends&lt;br /&gt;
	local maxArg = 0&lt;br /&gt;
	for k, v in pairs(args) do&lt;br /&gt;
		if type(k) == &amp;#039;number&amp;#039; 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 and a &amp;quot;pages&amp;quot; table of pagename strings&lt;br /&gt;
	local forTable = {}&lt;br /&gt;
	local i = from&lt;br /&gt;
	local terminated = false&lt;br /&gt;
	-- Repeat to generate and append each row&lt;br /&gt;
	repeat&lt;br /&gt;
		-- New empty row&lt;br /&gt;
		local forRow = {}&lt;br /&gt;
		-- If there&amp;#039;s a blank use, assume the list&amp;#039;s ended, use the default,&lt;br /&gt;
		-- and break at the end of this loop-through.&lt;br /&gt;
		forRow.use = args[i] or options.otherText&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;
		-- If there&amp;#039;s not at least one page listed, use the default.&lt;br /&gt;
		table.insert(forRow.pages, args[i + 1] or mHatnote.disambiguate(options.title))&lt;br /&gt;
		-- If the option after next is &amp;quot;and&amp;quot;, do an inner loop where we collect&lt;br /&gt;
		-- items following &amp;quot;and&amp;quot;&amp;#039;s until the &amp;quot;and&amp;quot;&amp;#039;s stop. If there&amp;#039;s a blank&lt;br /&gt;
		-- where we&amp;#039;d expect an item, ignore it: &amp;quot;1|and||and|3&amp;quot; → {1, 3}&lt;br /&gt;
		while args[i + 2] == &amp;#039;and&amp;#039; 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 the next &amp;quot;and&amp;quot;&lt;br /&gt;
			i = i + 2&lt;br /&gt;
		end&lt;br /&gt;
		-- Increment to the next use&lt;br /&gt;
		i = i + 2&lt;br /&gt;
		-- Add the row to the table&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;
-- Takes a table as formatted by forSeeArgsToTable and stringifies it&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;
	-- Format each for-see item and make a table containing them&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(mHatnote.formatPages(unpack(v.pages))) or&lt;br /&gt;
			mHatnote._formatLink(mHatnote.disambiguate(options.title))&lt;br /&gt;
		local forSeeStr = string.format(options.forseeForm, useStr, pagesStr)&lt;br /&gt;
		for k, v in pairs(options.punctuationCollapseReplacements) do&lt;br /&gt;
			forSeeStr = string.gsub(forSeeStr, k, v)&lt;br /&gt;
		end&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, &amp;#039; &amp;#039;)&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 or whitespace values; those should be filtered. Ignores&lt;br /&gt;
-- arguments less than &amp;quot;from&amp;quot;, and named arguments.&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;
-- Calls _forSee but pulls from the frame.&lt;br /&gt;
function p.forSee (frame, from, options)&lt;br /&gt;
	mArguments = require(&amp;#039;Module:Arguments&amp;#039;)&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>Mikunyan</name></author>
	</entry>
</feed>