變更
Copying change per request of AlexTheWhovian. Please revert me if this causes some sort of error
function p.getTargetFromText(text)
return string.match(
text,
"^%s*#[Rr][Ee][Dd][Ii][Rr][Ee][Cc][Tt]%s*:?%s*%[%[([^%[%]|]-)%]%]"
-- Gets the target of a redirect. If the page specified is not a redirect,
-- returns nil.
function p.getTarget(page, fulltext)
-- Get the title object. Both page names and title objects are allowed
-- as input.
local targetTitle = getTitle(target)
if targetTitle then
if fulltext then return targetTitle.fullText else return targetTitle.prefixedText end
else
return nil
error(string.format(
'could not parse redirect on page "%s"',
fulltext and titleObj.fullText or titleObj.prefixedText
))
end
-- target cannot be determined for some reason.
--]]
function p.luaMain(rname, bracket, fulltext)
if type(rname) ~= "string" or not rname:find("%S") then
return nil
bracket = bracket and "[[%s]]" or "%s"
rname = rname:match("%[%[(.+)%]%]") or rname
local target = p.getTarget(rname, fulltext)
local ret = target or rname
ret = getTitle(ret)
if ret then
if fulltext then ret = ret.fullText else ret = ret.prefixedText end
return bracket:format(ret)
else
function p.main(frame)
local args = require('Module:Arguments').getArgs(frame, {frameOnly = true})
return p.luaMain(args[1], args.bracket, args.fulltext) or ''
end