Editing Module:Redirect

Jump to: navigation, search

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 17: Line 17:
 
-- redirect.
 
-- redirect.
 
function p.getTargetFromText(text)
 
function p.getTargetFromText(text)
local target = string.match(
+
return string.match(
 
text,
 
text,
 
"^%s*#[Rr][Ee][Dd][Ii][Rr][Ee][Cc][Tt]%s*:?%s*%[%[([^%[%]|]-)%]%]"
 
"^%s*#[Rr][Ee][Dd][Ii][Rr][Ee][Cc][Tt]%s*:?%s*%[%[([^%[%]|]-)%]%]"
Line 24: Line 24:
 
"^%s*#[Rr][Ee][Dd][Ii][Rr][Ee][Cc][Tt]%s*:?%s*%[%[([^%[%]|]-)|[^%[%]]-%]%]"
 
"^%s*#[Rr][Ee][Dd][Ii][Rr][Ee][Cc][Tt]%s*:?%s*%[%[([^%[%]|]-)|[^%[%]]-%]%]"
 
)
 
)
return target and mw.uri.decode(target, 'PATH')
 
 
end
 
end
  
 
-- 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 53: 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 66: 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 80: 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 86: 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 104: 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 All About Ayrshire 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 All About Ayrshire:Copyrights for details). Do not submit copyrighted work without permission!

Cancel Editing help (opens in new window)

Template used on this page: