Jump to content

Module:If in category: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
test
test
Line 21: Line 21:
category = mw.title.new( "Category:" .. args[1])
category = mw.title.new( "Category:" .. args[1])
end
end
if page.categories then
return page.categories
return 'yes'
else
return 'no'
end
end
end



Revision as of 03:28, 5 September 2024

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