<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-GB">
	<id>https://safernicotine.wiki/mediawiki/index.php?action=history&amp;feed=atom&amp;title=Module%3AFormat_link</id>
	<title>Module:Format link - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://safernicotine.wiki/mediawiki/index.php?action=history&amp;feed=atom&amp;title=Module%3AFormat_link"/>
	<link rel="alternate" type="text/html" href="https://safernicotine.wiki/mediawiki/index.php?title=Module:Format_link&amp;action=history"/>
	<updated>2026-05-03T20:23:09Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.44.0</generator>
	<entry>
		<id>https://safernicotine.wiki/mediawiki/index.php?title=Module:Format_link&amp;diff=25238&amp;oldid=prev</id>
		<title>Richardpruen: 1 revision imported: Templates and CSS files</title>
		<link rel="alternate" type="text/html" href="https://safernicotine.wiki/mediawiki/index.php?title=Module:Format_link&amp;diff=25238&amp;oldid=prev"/>
		<updated>2022-12-04T17:27:52Z</updated>

		<summary type="html">&lt;p&gt;1 revision imported: Templates and CSS files&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&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-GB&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 18:27, 4 December 2022&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;4&quot; class=&quot;diff-notice&quot; lang=&quot;en-GB&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(No difference)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;!-- diff cache key uk_vapewiki:diff:1.41:old-25237:rev-25238 --&gt;
&lt;/table&gt;</summary>
		<author><name>Richardpruen</name></author>
	</entry>
	<entry>
		<id>https://safernicotine.wiki/mediawiki/index.php?title=Module:Format_link&amp;diff=25237&amp;oldid=prev</id>
		<title>wikipedia&gt;Pppery: Avoid Lua erroring when we run out of expensive parser function calls</title>
		<link rel="alternate" type="text/html" href="https://safernicotine.wiki/mediawiki/index.php?title=Module:Format_link&amp;diff=25237&amp;oldid=prev"/>
		<updated>2022-10-04T13:37:11Z</updated>

		<summary type="html">&lt;p&gt;Avoid Lua erroring when we run out of expensive parser function calls&lt;/p&gt;
&lt;a href=&quot;https://safernicotine.wiki/mediawiki/index.php?title=Module:Format_link&amp;amp;diff=25237&amp;amp;oldid=20675&quot;&gt;Show changes&lt;/a&gt;</summary>
		<author><name>wikipedia&gt;Pppery</name></author>
	</entry>
	<entry>
		<id>https://safernicotine.wiki/mediawiki/index.php?title=Module:Format_link&amp;diff=20675&amp;oldid=prev</id>
		<title>Richardpruen: 1 revision imported</title>
		<link rel="alternate" type="text/html" href="https://safernicotine.wiki/mediawiki/index.php?title=Module:Format_link&amp;diff=20675&amp;oldid=prev"/>
		<updated>2022-01-01T18:33:15Z</updated>

		<summary type="html">&lt;p&gt;1 revision imported&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en-GB&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 19:33, 1 January 2022&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-notice&quot; lang=&quot;en-GB&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(No difference)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
		<author><name>Richardpruen</name></author>
	</entry>
	<entry>
		<id>https://safernicotine.wiki/mediawiki/index.php?title=Module:Format_link&amp;diff=20674&amp;oldid=prev</id>
		<title>Wikipedia&gt;Nihiltres: An extra layer of nil check</title>
		<link rel="alternate" type="text/html" href="https://safernicotine.wiki/mediawiki/index.php?title=Module:Format_link&amp;diff=20674&amp;oldid=prev"/>
		<updated>2021-12-26T20:07:48Z</updated>

		<summary type="html">&lt;p&gt;An extra layer of nil check&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;--------------------------------------------------------------------------------&lt;br /&gt;
-- Format link&lt;br /&gt;
--&lt;br /&gt;
-- Makes a wikilink from the given link and display values. Links are escaped&lt;br /&gt;
-- with colons if necessary, and links to sections are detected and displayed&lt;br /&gt;
-- with &amp;quot; § &amp;quot; as a separator rather than the standard MediaWiki &amp;quot;#&amp;quot;. Used in&lt;br /&gt;
-- the {{format link}} template.&lt;br /&gt;
--------------------------------------------------------------------------------&lt;br /&gt;
local libraryUtil = require(&amp;#039;libraryUtil&amp;#039;)&lt;br /&gt;
local checkType = libraryUtil.checkType&lt;br /&gt;
local checkTypeForNamedArg = libraryUtil.checkTypeForNamedArg&lt;br /&gt;
local mArguments -- lazily initialise [[Module:Arguments]]&lt;br /&gt;
local yesno -- lazily initialise [[Module:Yesno]]&lt;br /&gt;
&lt;br /&gt;
local p = {}&lt;br /&gt;
&lt;br /&gt;
--------------------------------------------------------------------------------&lt;br /&gt;
-- Helper functions&lt;br /&gt;
--------------------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
local function getArgs(frame)&lt;br /&gt;
	-- Fetches the arguments from the parent frame. Whitespace is trimmed and&lt;br /&gt;
	-- blanks are removed.&lt;br /&gt;
	mArguments = require(&amp;#039;Module:Arguments&amp;#039;)&lt;br /&gt;
	return mArguments.getArgs(frame, {parentOnly = true})&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function removeInitialColon(s)&lt;br /&gt;
	-- Removes the initial colon from a string, if present.&lt;br /&gt;
	return s:match(&amp;#039;^:?(.*)&amp;#039;)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function italicize(s)&lt;br /&gt;
	-- Italicize a string.&lt;br /&gt;
	return &amp;#039;&amp;lt;i&amp;gt;&amp;#039; .. s .. &amp;#039;&amp;lt;/i&amp;gt;&amp;#039;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function maybeItalicize(s, shouldItalicize)&lt;br /&gt;
	-- italicize s if s is a string and the shouldItalicize parameter is true.&lt;br /&gt;
	if s and shouldItalicize then&lt;br /&gt;
		return italicize(s)&lt;br /&gt;
	else&lt;br /&gt;
		return s&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function parseLink(link)&lt;br /&gt;
	-- Parse a link and return a table with the link&amp;#039;s components.&lt;br /&gt;
	-- These components are:&lt;br /&gt;
	-- - link: the link, stripped of any initial colon (always present)&lt;br /&gt;
	-- - page: the page name (always present)&lt;br /&gt;
	-- - section: the page name (may be nil)&lt;br /&gt;
	-- - display: the display text, if manually entered after a pipe (may be nil)&lt;br /&gt;
	link = removeInitialColon(link)&lt;br /&gt;
&lt;br /&gt;
	-- Find whether a faux display value has been added with the {{!}} magic&lt;br /&gt;
	-- word.&lt;br /&gt;
	local prePipe, display = link:match(&amp;#039;^(.-)|(.*)$&amp;#039;)&lt;br /&gt;
	link = prePipe or link&lt;br /&gt;
&lt;br /&gt;
	-- Find the page, if it exists.&lt;br /&gt;
	-- For links like [[#Bar]], the page will be nil.&lt;br /&gt;
	local preHash, postHash = link:match(&amp;#039;^(.-)#(.*)$&amp;#039;)&lt;br /&gt;
	local page&lt;br /&gt;
	if not preHash then&lt;br /&gt;
		-- We have a link like [[Foo]].&lt;br /&gt;
		page = link&lt;br /&gt;
	elseif preHash ~= &amp;#039;&amp;#039; then&lt;br /&gt;
		-- We have a link like [[Foo#Bar]].&lt;br /&gt;
		page = preHash&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	-- Find the section, if it exists.&lt;br /&gt;
	local section&lt;br /&gt;
	if postHash and postHash ~= &amp;#039;&amp;#039; then&lt;br /&gt;
		section = postHash&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	return {&lt;br /&gt;
		link = link,&lt;br /&gt;
		page = page,&lt;br /&gt;
		section = section,&lt;br /&gt;
		display = display,&lt;br /&gt;
	}&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
--------------------------------------------------------------------------------&lt;br /&gt;
-- Main functions&lt;br /&gt;
--------------------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
function p.formatLink(frame)&lt;br /&gt;
	-- The formatLink export function, for use in templates.&lt;br /&gt;
	yesno = require(&amp;#039;Module:Yesno&amp;#039;)&lt;br /&gt;
	local args = getArgs(frame)&lt;br /&gt;
	local link = args[1]&lt;br /&gt;
	if not link then&lt;br /&gt;
		return&lt;br /&gt;
			&amp;#039;&amp;lt;strong class=&amp;quot;error&amp;quot;&amp;gt;&amp;#039;..&lt;br /&gt;
			&amp;#039;Error: no link specified ([[Template:Format link#Errors|help]]).&amp;#039;..&lt;br /&gt;
			&amp;#039;&amp;lt;/strong&amp;gt;&amp;#039;&lt;br /&gt;
	end&lt;br /&gt;
	return p._formatLink{&lt;br /&gt;
		link = link,&lt;br /&gt;
		display = args[2],&lt;br /&gt;
		italicizePage = yesno(args.italicizepage),&lt;br /&gt;
		italicizeSection = yesno(args.italicizesection),&lt;br /&gt;
		categorizeMissing = args.categorizemissing&lt;br /&gt;
	}&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function p._formatLink(options)&lt;br /&gt;
	-- The formatLink export function, for use in modules.&lt;br /&gt;
	checkType(&amp;#039;_formatLink&amp;#039;, 1, options, &amp;#039;table&amp;#039;)&lt;br /&gt;
	checkTypeForNamedArg(&amp;#039;_formatLink&amp;#039;, &amp;#039;link&amp;#039;, options.link, &amp;#039;string&amp;#039;, false)&lt;br /&gt;
	checkTypeForNamedArg(&lt;br /&gt;
		&amp;#039;_formatLink&amp;#039;,&lt;br /&gt;
		&amp;#039;display&amp;#039;,&lt;br /&gt;
		options.display,&lt;br /&gt;
		&amp;#039;string&amp;#039;,&lt;br /&gt;
		true&lt;br /&gt;
	)&lt;br /&gt;
	checkTypeForNamedArg(&lt;br /&gt;
		&amp;#039;_formatLink&amp;#039;,&lt;br /&gt;
		&amp;#039;italicizePage&amp;#039;,&lt;br /&gt;
		options.italicizePage,&lt;br /&gt;
		&amp;#039;boolean&amp;#039;,&lt;br /&gt;
		true&lt;br /&gt;
	)&lt;br /&gt;
	checkTypeForNamedArg(&lt;br /&gt;
		&amp;#039;_formatLink&amp;#039;,&lt;br /&gt;
		&amp;#039;italicizeSection&amp;#039;,&lt;br /&gt;
		options.italicizeSection,&lt;br /&gt;
		&amp;#039;boolean&amp;#039;,&lt;br /&gt;
		true&lt;br /&gt;
	)&lt;br /&gt;
	checkTypeForNamedArg(&lt;br /&gt;
		&amp;#039;_formatLink&amp;#039;,&lt;br /&gt;
		&amp;#039;categorizeMissing&amp;#039;,&lt;br /&gt;
		options.categorizeMissing,&lt;br /&gt;
		&amp;#039;string&amp;#039;,&lt;br /&gt;
		true&lt;br /&gt;
	)&lt;br /&gt;
&lt;br /&gt;
	local parsed = parseLink(options.link)&lt;br /&gt;
	local display = options.display or parsed.display&lt;br /&gt;
	local catMissing = options.categorizeMissing&lt;br /&gt;
	local category = &amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
	--Test if page exists if a diagnostic category is specified&lt;br /&gt;
	if catMissing and (mw.ustring.len(catMissing) &amp;gt; 0) then&lt;br /&gt;
		local title = nil&lt;br /&gt;
		if parsed.page then title = mw.title.new(parsed.page) end&lt;br /&gt;
		if title and (not title.isExternal) and (not title.exists) then&lt;br /&gt;
			category = mw.ustring.format(&amp;#039;[[Category:%s]]&amp;#039;, catMissing)&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	-- Deal with the case where we don&amp;#039;t have to pipe the link&lt;br /&gt;
	if not display and not parsed.section and not options.italicizePage then&lt;br /&gt;
		return mw.ustring.format(&amp;#039;[[:%s]]%s&amp;#039;, parsed.link, category)&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	-- Find the display text for piped links&lt;br /&gt;
	if not display then&lt;br /&gt;
		local page = maybeItalicize(parsed.page, options.italicizePage)&lt;br /&gt;
		local section = maybeItalicize(parsed.section, options.italicizeSection)&lt;br /&gt;
		if not page then&lt;br /&gt;
			display = mw.ustring.format(&amp;#039;§&amp;amp;nbsp;%s&amp;#039;, section)&lt;br /&gt;
		elseif section then&lt;br /&gt;
			display = mw.ustring.format(&amp;#039;%s §&amp;amp;nbsp;%s&amp;#039;, page, section)&lt;br /&gt;
		else&lt;br /&gt;
			display = page&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	return mw.ustring.format(&amp;#039;[[:%s|%s]]%s&amp;#039;, parsed.link, display, category)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
--------------------------------------------------------------------------------&lt;br /&gt;
-- Derived convenience functions&lt;br /&gt;
--------------------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
function p.formatPages(options, pages)&lt;br /&gt;
	-- Formats an array of pages using formatLink and the given options table,&lt;br /&gt;
	-- and returns it as an array. Nil values are not allowed.&lt;br /&gt;
	local ret = {}&lt;br /&gt;
	for i, page in ipairs(pages) do&lt;br /&gt;
		ret[i] = p._formatLink{&lt;br /&gt;
			link = page,&lt;br /&gt;
			categorizeMissing = options.categorizeMissing,&lt;br /&gt;
			italicizePage = options.italicizePage,&lt;br /&gt;
			italicizeSection = options.italicizeSection&lt;br /&gt;
		}&lt;br /&gt;
	end&lt;br /&gt;
	return ret&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
return p&lt;/div&gt;</summary>
		<author><name>Wikipedia&gt;Nihiltres</name></author>
	</entry>
</feed>