<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://montepedia.com/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://montepedia.com/w/index.php?action=history&amp;feed=atom&amp;title=Module%3AMake_Wikisource_link"/>
	<link rel="alternate" type="text/html" href="https://montepedia.com/w/index.php?title=Module:Make_Wikisource_link&amp;action=history"/>
	<updated>2026-06-15T18:29:40Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.45.2</generator>
	<entry>
		<id>https://montepedia.com/w/index.php?title=Module:Make_Wikisource_link&amp;diff=5320&amp;oldid=prev</id>
		<title>Maintenance script: Sync shared ABC wiki compatibility fix from Phuketer</title>
		<link rel="alternate" type="text/html" href="https://montepedia.com/w/index.php?title=Module:Make_Wikisource_link&amp;diff=5320&amp;oldid=prev"/>
		<updated>2026-06-15T12:50:05Z</updated>

		<summary type="html">&lt;p&gt;Sync shared ABC wiki compatibility fix from Phuketer&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;
	--[[---------&lt;br /&gt;
	Variable declaration&lt;br /&gt;
	--]]---------&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 wikisourceEdition&lt;br /&gt;
	local linkTarget&lt;br /&gt;
	local displayText&lt;br /&gt;
	local toReturn&lt;br /&gt;
	local prefix&lt;br /&gt;
	&lt;br /&gt;
	--[[&lt;br /&gt;
	Create the prefix for the interwiki link&lt;br /&gt;
	It uses the lowest of:&lt;br /&gt;
	 1. &amp;#039;Special:Search/&amp;#039;, if using the enwiki pagename as the interwiki target&lt;br /&gt;
	 2. If not (1), an &amp;#039;Author:&amp;#039; prefix, localized, if given a works parameter and not under (1)&lt;br /&gt;
	 3. If not (1) or (2), the empty string&lt;br /&gt;
	We avoid &amp;#039;Special:Search/Author:&amp;#039; intentionally; this is rarely helpful&lt;br /&gt;
	Here we simply set it to (2) or (3), and override it when setting the link target if needed&lt;br /&gt;
	--]]&lt;br /&gt;
	prefix = args.works and frame:expandTemplate{ title = &amp;#039;Wikisource/Author&amp;#039;, args = { lang } } or &amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
	-- Handle multilingual Wikisource (aka old Wikisource) correctly&lt;br /&gt;
	if lang == &amp;#039;mul&amp;#039; then&lt;br /&gt;
		wikisourceEdition = &amp;#039;sourceswiki&amp;#039; -- siteid for multilingual Wikisource&lt;br /&gt;
	else&lt;br /&gt;
		wikisourceEdition = lang .. &amp;#039;wikisource&amp;#039; -- other Wikisource editions are langcode + &amp;#039;wikisource&amp;#039; (e.g. &amp;#039;enwikisource&amp;#039;)&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	-- get the Wikidata sitelink&lt;br /&gt;
	local currentEntityId = (mw.wikibase and mw.wikibase.getEntityIdForCurrentPage and mw.wikibase.getEntityIdForCurrentPage()) or &amp;#039;&amp;#039;&lt;br /&gt;
	local wikidataSitelink = (mw.wikibase and mw.wikibase.getSitelink and mw.wikibase.getSitelink(currentEntityId, wikisourceEdition)) or nil&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;
		-- we have no parameters and nothing at Wikidata, so we are flying blind&lt;br /&gt;
		-- set the linkTarget to the pagename&lt;br /&gt;
		linkTarget = pagename&lt;br /&gt;
		-- and set prefix to &amp;#039;Special:Search/&amp;#039; to find the appropriate link&lt;br /&gt;
		prefix = &amp;#039;Special:Search/&amp;#039;&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	-- clear prefixes for now; will add it back later if needed&lt;br /&gt;
	-- this prevents duplicate prefixes (Author:Author:Shakespeare; Special:Search/Special:Search/)&lt;br /&gt;
	-- and avoids displayText with any author prefix&lt;br /&gt;
	linkTarget = string.gsub(linkTarget, &amp;#039;^&amp;#039; .. prefix, &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;^Lists? of &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; .. prefix .. 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>Maintenance script</name></author>
	</entry>
</feed>