Jump to content

Module:If in category

Permanently protected module
From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by HouseBlaster (talk | contribs) at 03:14, 5 September 2024 (is this correct). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

local p = {}

function p.main(frame)
	local getArgs = require('Module:Arguments').getArgs
	local args = getArgs(frame)
	return p._main(args)
end

function p._main(args)
	local page
	-- create a title object
	if args.page then
		page = mw.title.new(args.page)
	else
		page = mw.title.getCurrentTitle()
	end
	local category = mw.title.new( args[1] )
	-- if we are not in Category: namespace, make it in category: Namespace
	-- we avoid using the namespace feature of mw.title.new because it incorrectly handles some cases (e.g. Category:Wikipedia:Foo)
	if not category:inNamespace( 14 ) then -- 14 is Category: namespace args[1]
		category = mw.title.new( "Category:" .. args[1])
	end
	return page[categories]
end

return p