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 | + | 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 | ||
− | + | return targetTitle.prefixedText | |
− | |||
− | |||
− | |||
− | |||
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"', | ||
− | + | 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 | + | 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 | + | 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 | ||
− | + | ret = ret.prefixedText | |
− | |||
− | |||
− | |||
− | |||
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 | + | return p.luaMain(args[1], args.bracket) or '' |
end | end | ||