Editing Module:Redirect

From MINR.ORG WIKI

Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision Your text
Line 28: Line 28:
 
-- Gets the target of a redirect. If the page specified is not a redirect,
 
-- Gets the target of a redirect. If the page specified is not a redirect,
 
-- returns nil.
 
-- returns nil.
function p.getTarget(page, fulltext)
+
function p.getTarget(page)
 
-- Get the title object. Both page names and title objects are allowed
 
-- Get the title object. Both page names and title objects are allowed
 
-- as input.
 
-- as input.
Line 52: Line 52:
 
local targetTitle = getTitle(target)
 
local targetTitle = getTitle(target)
 
if targetTitle then
 
if targetTitle then
if fulltext then
+
return targetTitle.prefixedText
return targetTitle.fullText
 
else
 
return targetTitle.prefixedText
 
end
 
 
else
 
else
 
return nil
 
return nil
Line 65: Line 61:
 
error(string.format(
 
error(string.format(
 
'could not parse redirect on page "%s"',
 
'could not parse redirect on page "%s"',
fulltext and titleObj.fullText or titleObj.prefixedText
+
titleObj.prefixedText
 
))
 
))
 
end
 
end
Line 79: Line 75:
 
-- target cannot be determined for some reason.
 
-- target cannot be determined for some reason.
 
--]]
 
--]]
function p.luaMain(rname, bracket, fulltext)
+
function p.luaMain(rname, bracket)
 
if type(rname) ~= "string" or not rname:find("%S") then
 
if type(rname) ~= "string" or not rname:find("%S") then
 
return nil
 
return nil
Line 85: Line 81:
 
bracket = bracket and "[[%s]]" or "%s"
 
bracket = bracket and "[[%s]]" or "%s"
 
rname = rname:match("%[%[(.+)%]%]") or rname
 
rname = rname:match("%[%[(.+)%]%]") or rname
local target = p.getTarget(rname, fulltext)
+
local target = p.getTarget(rname)
 
local ret = target or rname
 
local ret = target or rname
 
ret = getTitle(ret)
 
ret = getTitle(ret)
 
if ret then
 
if ret then
if fulltext then
+
ret = ret.prefixedText
ret = ret.fullText
 
else
 
ret = ret.prefixedText
 
end
 
 
return bracket:format(ret)
 
return bracket:format(ret)
 
else
 
else
Line 103: Line 95:
 
function p.main(frame)
 
function p.main(frame)
 
local args = require('Module:Arguments').getArgs(frame, {frameOnly = true})
 
local args = require('Module:Arguments').getArgs(frame, {frameOnly = true})
return p.luaMain(args[1], args.bracket, args.fulltext) or ''
+
return p.luaMain(args[1], args.bracket) or ''
 
end
 
end
  

Please note that all contributions to MINR.ORG WIKI may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see MINR.ORG WIKI:Copyrights for details). Do not submit copyrighted work without permission!

Cancel Editing help (opens in new window)