Jump to content

Module:Sandbox/Jackmcbarn

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Jackmcbarn (talk | contribs) at 01:25, 13 January 2016 (test cross-namespace redirects). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

local getTarget = require('Module:Redirect').getTarget
local p = {}

local function pagetype(nsText)
	return nsText == '' and 'articles' or (mw.ustring.lower(nsText) .. ' pages')
end

function p.main(frame)
	local currentTitle = mw.title.getCurrentTitle()
	local target = getTarget(currentTitle)
	if target then
		local currentNsText, targetNsText = currentTitle.nsText, mw.title.new(target).nsText
		if currentNsText ~= targetNsText then
			return string.format('[[Category:Cross-namespace redirects from %s]][[Category:Cross-namespace redirects to %s]]', pagetype(currentNsText), pagetype(targetNsText))
		end
	end
	return '[[Category:Pages incorrectly tagged as cross-namespace redirects]]'
end

return p