Jump to content

Module:Make Wikisource link

Permanently protected module
From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by HouseBlaster (talk | contribs) at 02:46, 2 June 2025 (save a WIP). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)

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