Jump to content

Module:Make Wikisource link: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
save a WIP
(No difference)

Revision as of 02:46, 2 June 2025

local p = {}
local getArgs = require('Module:Arguments').getArgs

function p.getSourceName(frame)
	local args = getArgs(frame)
	local lang = args['explicit-lang-param'] or args['implicit-lang-param'] or 'en'
	
	-- if we have a language parameter, we look at the second unnamed parameter for the source title
	local checkIndex = args['implicit-lang-param'] and 2 or 1
	
	if args[checkIndex] then
		-- we have a source title parameter, so return that
		return args[checkIndex]
	else 
		-- now we check Wikidata
		-- there's probably a better way to do this
		local wikidataSitelink = mw.wikibase.getSitelink(
			wikibase.getEntityIdForCurrentPage() or '',
			lang .. 'wikisource'
			)
		if wikidataSitelink then
			return wikidataSitelink
		else
			-- if Wikidata returns nothing, search for the {{PAGENAME}}
			return 'Special:Search/' .. mw.title.getCurrentTitle().text
		end
	end
end

return p