Jump to content

Module:If in category/sandbox: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
Create sandbox version of Module:If in category
 
clean
Line 1: Line 1:
local p = {}
local p = {}
local TableTools = require('Module:TableTools')


function p.main(frame)
function p.main(frame)
local getArgs = require('Module:Arguments').getArgs
local args = getArgs(frame)
local args = getArgs(frame)
return p._main(args)
return p._main(args)
Line 10: Line 8:
function p._main(args)
function p._main(args)
-- create a title object
-- create a title object
local page = mw.title.new((args.page or '')) or mw.title.getCurrentTitle()
local page = (args.page and mw.title.new(args.page)) or mw.title.getCurrentTitle()
if TableTools.inArray(page.categories, string.gsub( args[1], '^[Cc]ategory:', '' )) then
if require('Module:TableTools').inArray(page.categories, string.gsub( args[1], '^[Cc]ategory:', '' )) then
if not args[3] then
if not args[3] then
-- if we are are not given anything to return, return 'yes' if it evalulates to true
-- if we are are not given anything to return, return 'yes' if it evalulates to true
return args[2] or 'yes'
return args[2] or 'yes'
else
else

Revision as of 20:17, 5 March 2025

local p = {}

function p.main(frame)
	local args = getArgs(frame)
	return p._main(args)
end

function p._main(args)
	-- create a title object
	local page = (args.page and mw.title.new(args.page)) or mw.title.getCurrentTitle()
	if require('Module:TableTools').inArray(page.categories, string.gsub( args[1], '^[Cc]ategory:', '' )) then
		if not args[3] then
			-- if we are are not given anything to return, return 'yes' if it evalulates to true
    		return args[2] or 'yes'
    	else 
    		return args[2]
		end
	else
		return args[3]
	end
end

return p