Module:RedirectData
Appearance
| This module is rated as ready for general use. It has reached a mature state, is considered relatively stable and bug-free, and may be used wherever appropriate. It can be mentioned on help pages and other Wikipedia resources as an option for new users. To minimise server load and avoid disruptive output, improvements should be developed through sandbox testing rather than repeated trial-and-error editing. |
| This module is currently protected from editing. See the protection policy and protection log for more details. Please discuss any changes on the talk page; you may submit an edit request to ask an administrator to make an edit if it is uncontroversial or supported by consensus. You may also request that this page be unprotected. |
| This Lua module is used on approximately 42,000 pages and changes may be widely noticed. Test changes in the module's /sandbox or /testcases subpages, or in your own module sandbox. Consider discussing changes on the talk page before implementing them. |
Usage
This module can be used on redirect pages to display the namespace that the page redirects to. This should generally be wrapped by templates.
{{#invoke:RedirectData|getRedirectToNamespace}}
See also
- {{Automatic redirect categories}}, a template which uses this module
- {{R from shortcut}}, another template which uses this module
local p = {}
function p.getRedirectToNamespace(frame)
titleObject = mw.title.getCurrentTitle() -- check if this is a redirect
if titleObject.redirectTarget then
targetNamespace = titleObject.redirectTarget.nsText
return targetNamespace
end
return "Notaredirect"
end
function p.getTalkPage(frame) -- this is code written to check for the criteria to apply {{R to talk page}} - essentially, whether the redirect is outside of, and going into, a talk namespace
titleObject = mw.title.getCurrentTitle() -- check if this is a redirect
if titleObject.redirectTarget then
if not titleObject.isTalkPage then -- the current page is NOT a talk page
if titleObject.redirectTarget.isTalkPage then -- the target page IS a talk page
return "Yes"
end
end
return "No"
end
return "Notaredirect"
end
function p.getSubpageStatus(frame)
titleObject = mw.title.getCurrentTitle()
if titleObject.redirectTarget then -- check if this is a redirect
pageIsSubpage = titleObject.isSubpage
targetIsSubpage = titleObject.redirectTarget.isSubpage
if (pageIsSubpage or targetIsSubpage) then
if (pageIsSubpage and targetIsSubpage) then
return "Both" -- both are subpages, return three
elseif pageIsSubpage then
return "Onlypage" -- just the page is a subpage, target isn't, return one
else
return "Onlytarget" -- just the target is a subpage, the page isn't, return two
end
else -- neither page nor target is a subpage, return zero
return "Neither"
end
end
return "Notaredirect"
end
function p.toDisambig(frame) -- this checks if the page title contains (disambiguation), as well as if it's a talkpage
titleObject = mw.title.getCurrentTitle()
if titleObject.redirectTarget then -- check if this is a redirect
if string.match(titleObject.text, "(disambiguation)") then -- title contains (disambiguation)
if titleObject.isTalkPage then -- this is a talk page ({{R from unnecessary disambiguation}})
return "Talk"
else -- this is not a talkpage ({{R to disambiguation page}})
return "Article"
end
else -- title does not contain "(disambiguation)"
return "No"
end
end
return "Notaredirect"
end
return p