Module:Exists

From Coral Island Wiki
Revision as of 16:50, 3 August 2023 by Admin coral island (talk | contribs) (Created page with "-- Module copied from Genshin Impact wiki. local p = {} function p.main(frame) local args = require('Module:Arguments').getArgs(frame, { parentFirst = true, wrapper = {'Template:Exists'} }) return p._main(args) end function p._main(args) local page = args[1] or '' local trueResult = args[2] or args['then'] or '' local falseResult = args[3] or args['else'] or '' if (p.checkExists(page)) then return trueResult else return falseResu...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Documentation for this module may be created at Module:Exists/doc

-- Module copied from Genshin Impact wiki.

local p = {}

function p.main(frame)
    local args = require('Module:Arguments').getArgs(frame, {
        parentFirst = true,
        wrapper = {'Template:Exists'}
    })
    return p._main(args)
end

function p._main(args)
	local page = args[1] or ''
	local trueResult = args[2] or args['then'] or ''
	local falseResult = args[3] or args['else'] or ''
	
	if (p.checkExists(page)) then
		return trueResult
	else
		return falseResult
	end
end

function p.checkExists(page)
	page = mw.text.decode(page or '')
	local frame = mw.getCurrentFrame()
	if (page:match('[#<>%[%]%{%}]+') or page == '') then
		return false
	elseif (frame:callParserFunction('PROTECTIONEXPIRY:edit', page) ~= '') then
		return true
	else
		return false
	end
end

return p