Module:Title/redirectTarget: Difference between revisions
Appearance
Template>Theknightwho No edit summary |
m 1 revision imported |
(No difference)
| |
Latest revision as of 08:44, 29 June 2025
Documentation for this module may be created at Module:Title/redirectTarget/doc
local pcall = pcall
local at_limit
local function is_redirect(title)
return title.isRedirect
end
--[==[
Returns the title object of the redirect target if title page is a redirect.
Checking {title.redirectTarget} will transclude the title page, which may be undesirable when checking large numbers of titles. To avoid this, this function will attempt to check the {title.isRedirect} key first, only checking {title.redirectTarget} if it is confirmed that the title is a redirect. However, doing so will increment the expensive function count, which has a limit of 500. Once the limit has been reached, this function reverts to checking {title.redirectTarget} directly instead.
The {force_transclusion} flag may be set to force the use of transclusion ({title.redirectTarget}) 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)
if not (force_transclusion or at_limit) then
local success, result = pcall(is_redirect, title)
if not success then
at_limit = true
elseif not result then
return false
end
end
local redirect = title.redirectTarget
if not redirect then
return false
end
-- If the original title had a fragment, carry it over to the redirect.
local fragment = title.fragment
if fragment and fragment ~= "" then
redirect.fragment = fragment
end
return redirect
end