Jump to content

Module:R from sort name

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Tol (talk | contribs) at 03:03, 12 January 2022 (if page doesn't exist, default to unambiguous instead of throwing error). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
local c = {
	disambig_magic_word = '__DISAMBIG__',
	template_ambiguous = 'R from sort name/ambiguous',
	template_unambiguous = 'R from sort name/unambiguous',
	err_not_redirect = '[[Template:R from sort name]] error: page is not a redirect',
}

local p = {}

p.core = function(title, frame)
	if title.exists then
		if title.isRedirect then
			if mw.ustring.find(
				frame:preprocess(
					title.redirectTarget:getContent()
				),
				c.disambig_magic_word,
				1,
				true
			) then
				return frame:expandTemplate{
					title = c.template_ambiguous
				}
			else
				return frame:expandTemplate{
					title = c.template_unambiguous
				}
			end
		else
			return error(c.err_not_redirect)
		end
	else
		return frame:expandTemplate{
			title = c.template_unambiguous
		}
	end
end

p.main = function(frame)
	return p.core(mw.title.getCurrentTitle(), frame)
end

return p