<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.tiffa.net/w/index.php?action=history&amp;feed=atom&amp;title=Module%3AMake_Wikisource_link</id>
	<title>Module:Make Wikisource link - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.tiffa.net/w/index.php?action=history&amp;feed=atom&amp;title=Module%3AMake_Wikisource_link"/>
	<link rel="alternate" type="text/html" href="https://wiki.tiffa.net/w/index.php?title=Module:Make_Wikisource_link&amp;action=history"/>
	<updated>2026-06-11T12:40:08Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.0</generator>
	<entry>
		<id>https://wiki.tiffa.net/w/index.php?title=Module:Make_Wikisource_link&amp;diff=162524&amp;oldid=prev</id>
		<title>Fire: Created page with &quot;local p = {} local getArgs = require(&#039;Module:Arguments&#039;).getArgs local yesno = require(&#039;Module:Yesno&#039;)  function p.makeLink(frame) 	local args = getArgs(frame) 	local lang = args[&#039;explicit_lang_param&#039;] or args[&#039;implicit_lang_param&#039;] or &#039;en&#039; 	local page = mw.title.getCurrentTitle() 	local pagename = page.text 	local authorPrefix = args.works and frame:expandTemplate{ title = &#039;Wikisource/Author&#039;, args = { lang } } or &#039;&#039; 	local linkTarget 	local displayText 	local toReturn...&quot;</title>
		<link rel="alternate" type="text/html" href="https://wiki.tiffa.net/w/index.php?title=Module:Make_Wikisource_link&amp;diff=162524&amp;oldid=prev"/>
		<updated>2025-07-14T07:33:33Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;local p = {} local getArgs = require(&amp;#039;Module:Arguments&amp;#039;).getArgs local yesno = require(&amp;#039;Module:Yesno&amp;#039;)  function p.makeLink(frame) 	local args = getArgs(frame) 	local lang = args[&amp;#039;explicit_lang_param&amp;#039;] or args[&amp;#039;implicit_lang_param&amp;#039;] or &amp;#039;en&amp;#039; 	local page = mw.title.getCurrentTitle() 	local pagename = page.text 	local authorPrefix = args.works and frame:expandTemplate{ title = &amp;#039;Wikisource/Author&amp;#039;, args = { lang } } or &amp;#039;&amp;#039; 	local linkTarget 	local displayText 	local toReturn...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;local p = {}&lt;br /&gt;
local getArgs = require(&amp;#039;Module:Arguments&amp;#039;).getArgs&lt;br /&gt;
local yesno = require(&amp;#039;Module:Yesno&amp;#039;)&lt;br /&gt;
&lt;br /&gt;
function p.makeLink(frame)&lt;br /&gt;
	local args = getArgs(frame)&lt;br /&gt;
	local lang = args[&amp;#039;explicit_lang_param&amp;#039;] or args[&amp;#039;implicit_lang_param&amp;#039;] or &amp;#039;en&amp;#039;&lt;br /&gt;
	local page = mw.title.getCurrentTitle()&lt;br /&gt;
	local pagename = page.text&lt;br /&gt;
	local authorPrefix = args.works and frame:expandTemplate{ title = &amp;#039;Wikisource/Author&amp;#039;, args = { lang } } or &amp;#039;&amp;#039;&lt;br /&gt;
	local linkTarget&lt;br /&gt;
	local displayText&lt;br /&gt;
	local toReturn&lt;br /&gt;
	&lt;br /&gt;
	-- get the Wikidata sitelink&lt;br /&gt;
	local wikidataSitelink = mw.wikibase.getSitelink(&lt;br /&gt;
		mw.wikibase.getEntityIdForCurrentPage() or &amp;#039;&amp;#039;,&lt;br /&gt;
		lang .. &amp;#039;wikisource&amp;#039;&lt;br /&gt;
	)&lt;br /&gt;
		&lt;br /&gt;
	-- if we have a language parameter, we look at the second unnamed parameter for the source title&lt;br /&gt;
	local checkIndexForTarget = args[&amp;#039;implicit_lang_param&amp;#039;] and 2 or 1&lt;br /&gt;
	-- and then use the next index for display&lt;br /&gt;
	local checkIndexForDisplay = checkIndexForTarget + 1&lt;br /&gt;
	&lt;br /&gt;
	--[[---------&lt;br /&gt;
	Set the link target&lt;br /&gt;
	--]]---------&lt;br /&gt;
	if args[&amp;#039;wslink&amp;#039;] then&lt;br /&gt;
		linkTarget = args[&amp;#039;wslink&amp;#039;]&lt;br /&gt;
	elseif args[checkIndexForTarget] then&lt;br /&gt;
		-- we have a source title parameter, so return that&lt;br /&gt;
		linkTarget = args[checkIndexForTarget]&lt;br /&gt;
	elseif wikidataSitelink then&lt;br /&gt;
		-- use Wikidata&lt;br /&gt;
		linkTarget = wikidataSitelink&lt;br /&gt;
	else&lt;br /&gt;
		-- if Wikidata returns nothing, search for the {{PAGENAME}}&lt;br /&gt;
		linkTarget = &amp;#039;Special:Search/&amp;#039; .. pagename&lt;br /&gt;
		-- we have no parameters and nothing at Wikidata, so we are flying blind&lt;br /&gt;
		-- We set displayText now to avoid including the Special:Search in the display text&lt;br /&gt;
		displayText = pagename&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	-- clear the Author: prefix for now; will add it back later if needed&lt;br /&gt;
	-- this prevents duplicate prefixes (Author:Author:Shakespeare)&lt;br /&gt;
	-- and avoids displayText with any author prefix&lt;br /&gt;
	linkTarget = string.gsub(linkTarget, &amp;#039;^&amp;#039; .. authorPrefix, &amp;#039;&amp;#039;)&lt;br /&gt;
	&lt;br /&gt;
	--[[---------	&lt;br /&gt;
	Now build the displayText&lt;br /&gt;
	--]]---------&lt;br /&gt;
	&lt;br /&gt;
	if not displayText then&lt;br /&gt;
		-- we did not set displayText in the above steps, so set it now&lt;br /&gt;
		-- first we check for an explicit display text, or else we set it to be the link target&lt;br /&gt;
		displayText = args[&amp;#039;title&amp;#039;] or args[checkIndexForDisplay] or linkTarget&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	--[[---------	&lt;br /&gt;
	Now we check whether we should categorize in Category:Wikisource templates with missing id&lt;br /&gt;
	--]]---------&lt;br /&gt;
	&lt;br /&gt;
	-- initialize errorCategory as true&lt;br /&gt;
	local errorCategory = true&lt;br /&gt;
	&lt;br /&gt;
	-- helper to set errorCategory = false&lt;br /&gt;
	local function setFalse() errorCategory = false end&lt;br /&gt;
	&lt;br /&gt;
	if wikidataSitelink then&lt;br /&gt;
		-- we do have a sitelink at Wikidata&lt;br /&gt;
		setFalse()&lt;br /&gt;
	elseif yesno(args.nocat, true) then&lt;br /&gt;
		-- we have a |nocat parameter&lt;br /&gt;
		setFalse()&lt;br /&gt;
	elseif page.namespace ~= 0 then&lt;br /&gt;
		-- only care about mainspace&lt;br /&gt;
		setFalse()&lt;br /&gt;
	elseif string.match(pagename, &amp;#039;^List&amp;#039;) then&lt;br /&gt;
		-- we are on a list page, and those should not have Wikisource links&lt;br /&gt;
		setFalse()&lt;br /&gt;
	elseif string.match(pagename, &amp;#039;^%d%d?%d?%d?s? in&amp;#039;) then&lt;br /&gt;
		-- we are in a YEAR/DECADE in FOO page, and those also should not have anything else&lt;br /&gt;
		setFalse()&lt;br /&gt;
	else&lt;br /&gt;
		-- Now we check categories and determine whether this is something which does not need a Wikisource links&lt;br /&gt;
		-- Currently, we avoid categorizing:&lt;br /&gt;
		-- 1. Disambiguation pages&lt;br /&gt;
		-- 2. Set index articles&lt;br /&gt;
		-- 3. Articles about species. There is no universal category; [[Category:Articles with &amp;#039;species&amp;#039; microformats]] is a proxy&lt;br /&gt;
		-- we do this check last to avoid using [[WP:EXPENSIVE]] parser calls if possible&lt;br /&gt;
		for _, cat in ipairs(page.categories) do&lt;br /&gt;
			if cat == &amp;quot;All disambiguation pages&amp;quot; or cat == &amp;quot;All set index articles&amp;quot; or cat == &amp;quot;Articles with &amp;#039;species&amp;#039; microformats&amp;quot; then&lt;br /&gt;
				setFalse()&lt;br /&gt;
				break&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	-- build the link&lt;br /&gt;
	toReturn = &amp;#039;[[:s:&amp;#039; .. lang .. &amp;#039;:&amp;#039; .. authorPrefix .. linkTarget .. &amp;#039;|&amp;#039; .. displayText .. &amp;#039;]]&amp;#039;&lt;br /&gt;
	&lt;br /&gt;
	-- append the error category if needed&lt;br /&gt;
	if errorCategory then&lt;br /&gt;
		toReturn = toReturn .. &amp;#039;[[Category:Wikisource templates with missing id|&amp;#039; .. pagename .. &amp;#039;]]&amp;#039; &lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	return toReturn&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
return p&lt;/div&gt;</summary>
		<author><name>Fire</name></author>
	</entry>
</feed>