Jump to content

Module:If in page: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
test
Reverted to revision 904323487 by Danski454 (talk): I am stupid (TW)
Line 15: Line 15:
end
end
if mw.ustring.match(content, args["1"] or "") then
if mw.ustring.match(content, args["1"] or "") then
return mw.text.nowiki( content )
return args["2"] or ""
else
else
return args["3"] or ""
return args["3"] or ""

Revision as of 11:54, 1 July 2019

local p = {}
local getArgs = require('Module:Arguments').getArgs

--args: 1 - ustring pattern, 2 - value if present, 3 - value if absent, 
--      page - page to test if not this page

function p._main(args)
	if not args["page"] then
		args.page = mw.title.getCurrentTitle().fullText
	end
	local content = mw.title.new(args.page):getContent()
	if not content then
		--page does not exist
		return args["3"] or ""
	end
	if mw.ustring.match(content, args["1"] or "") then
		return args["2"] or ""
	else
		return args["3"] or ""
	end
end

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

return p