local title_is_title_module = "Module:title/isTitle"
local title_new_title_module = "Module:title/newTitle"
local error = error
local format = string.format
local pcall = pcall
local require = require
local type = type
local at_limit
local function is_title(...)
is_title = require(title_is_title_module)
return is_title(...)
end
local function new_title(...)
new_title = require(title_new_title_module)
return new_title(...)
end
local function exists(title)
return title.exists
end
--[==[
Receives a title object or string, and returns {true} if the page for the input title exists, or {false} if not.
By default, this function checks the {title.exists} key of the relevant title object, which increments the expensive function count. Normally, attempting to exceed the expensive function limit of 500 will result in an error being thrown, but this function will instead fall back to checking {title.content}, which does not increment the count. It is, however, considerably slower to check, and (unlike {title.exists}) will register as a page transclusion.
The {force_transclusion} flag may be set to force the use of transclusion ({title.content}) in all instances, which can be used to avoid incrementing the expensive function count; this is sometimes useful when making a large number of checks, as hitting the expensive function limit can be disruptive to other modules or templates.]==]
return function(title, force_transclusion)
local title_type = type(title)
if title_type == "string" then
title = new_title(title)
-- If it's an invalid string, return false.
if not title then
return false
end
elseif not is_title(title) then
error(format("bad argument #1 to 'title/exists' (title object or string expected, got %s)", title_type), 2)
end
if not (force_transclusion or at_limit) then
local success, result = pcall(exists, title)
if success then
return result
end
at_limit = true
end
return title.content ~= false
end