Jump to content

Module:RedirectData: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
add code for detecting subpage status
rename
Line 21: Line 21:
return "Onlypage" -- just the page is a subpage, target isn't, return one
return "Onlypage" -- just the page is a subpage, target isn't, return one
else
else
return "Onlysubpage" -- just the target is a subpage, the page isn't, return two
return "Onlytarget" -- just the target is a subpage, the page isn't, return two
end
end
else -- neither page nor target is a subpage, return zero
else -- neither page nor target is a subpage, return zero

Revision as of 02:34, 23 February 2021

local p = {}

function p.getRedirectToNamespace(frame)
	titleObject = mw.title.getCurrentTitle() -- check if this is a redirect
	if titleObject.redirectTarget then
		targetNamespace = titleObject.redirectTarget.nsText
		return targetNamespace
	end
	return "Notaredirect"
end

function p.getSubpageStatus(frame)
	titleObject = mw.title.getCurrentTitle()
	if titleObject.redirectTarget then -- check if this is a redirect
		pageIsSubpage = titleObject.isSubpage
		targetIsSubpage = titleObject.redirectTarget.isSubpage
		if (pageIsSubpage or targetIsSubpage) then
			if (pageIsSubpage and targetIsSubpage) then
				return "Both" -- both are subpages, return three
			elseif pageIsSubpage then
				return "Onlypage" -- just the page is a subpage, target isn't, return one
			else
				return "Onlytarget" -- just the target is a subpage, the page isn't, return two
			end
		else -- neither page nor target is a subpage, return zero
			return "Neither"
		end
	end
	return "Notaredirect"
end

return p