Jump to content

Module:If in page

Permanently protected module
From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Danski454 (talk | contribs) at 11:53, 1 July 2019 (test). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

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 mw.text.nowiki( content )
	else
		return args["3"] or ""
	end
end

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

return p