Module:RedirectData: Difference between revisions
Appearance
rename |
add toDisambig function |
||
| Line 25: | Line 25: | ||
else -- neither page nor target is a subpage, return zero | else -- neither page nor target is a subpage, return zero | ||
return "Neither" | 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 | ||
end | end | ||
Revision as of 02:51, 23 February 2021
Documentation for this module may be created at Module:RedirectData/doc
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
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