Jump to content

Module:If in category: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
test
test
Line 1: Line 1:
local p = {}
local p = {}
local TableTools = require('Module:TableTools')


function p.main(frame)
function p.main(frame)
Line 15: Line 16:
page = mw.title.getCurrentTitle()
page = mw.title.getCurrentTitle()
end
end
local category = mw.title.new( args[1] )
local category = 'Category:' .. string.gsub( args[1], '^[Cc]ategory:', '' ) -- strip double Category: prefix
return TableTools.inArray(page.categories, category)
-- 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
end



Revision as of 03:35, 5 September 2024

local p = {}
local TableTools = require('Module:TableTools')

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 = 'Category:' .. string.gsub( args[1], '^[Cc]ategory:', '' ) -- strip double Category: prefix
	return TableTools.inArray(page.categories, category)
end

return p