Jump to content

Module:If in page/sandbox: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
Create sandbox version of Module:If in page
(No difference)

Revision as of 13:25, 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