Jump to content

Module:Sandbox/Certes

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Certes (talk | contribs) at 14:35, 16 February 2018 (Refactor). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
local p = {}

-- Entry point for Lua callers
-- Returns a boolean value: is pagename the name of an existing page?
function p._exists(pagename)
	-- Find expiry date of edit protection on the named page
	-- If the page doesn't exist, this is an empty string
	-- If the page exists, protected or not, this is some other value
	-- Note: this check does NOT record a wikilink from the calling page to pagename
	return mw.getCurrentFrame():callParserFunction('PROTECTIONEXPIRY', "edit", pagename) ~= ""
end

-- Entry point for template callers using #invoke:
function p.exists(frame)
	-- args = { 1 = page name, 2 = text if exists, 3 = text if doesn't exist }
	-- 2 and 3 are optional; by default we return a boolean suitable for use in Lua or modules
	local args = frame.args
	if p._exists(args[1]) then
		return args[2] or true
	else
		return args[3] or nil
	end
end

return p