Module:RedirectData: Difference between revisions
Appearance
Content deleted Content added
add code for detecting subpage status |
rename |
||
Line 21: | Line 21: | ||
return "Onlypage" -- just the page is a subpage, target isn't, return one |
return "Onlypage" -- just the page is a subpage, target isn't, return one |
||
else |
else |
||
return " |
return "Onlytarget" -- just the target is a subpage, the page isn't, return two |
||
end |
end |
||
else -- neither page nor target is a subpage, return zero |
else -- neither page nor target is a subpage, return zero |
Revision as of 02:34, 23 February 2021
![]() | This module is rated as ready for general use. It has reached a mature form and is thought to be relatively bug-free and ready for use wherever appropriate. It is ready to mention on help pages and other Wikipedia resources as an option for new users to learn. To reduce server load and bad output, it should be improved by sandbox testing rather than repeated trial-and-error editing. |
![]() | This module is subject to page protection. It is a highly visible module in use by a very large number of pages, or is substituted very frequently. Because vandalism or mistakes would affect many pages, and even trivial editing might cause substantial load on the servers, it is protected from editing. |
![]() | This Lua module is used on approximately 40,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.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
return p