Module:Redirect/sandbox: Difference between revisions

Content deleted Content added
split decoding into a separate function
use title objects to canonicalise the page name
Line 16:
return nil
end
end
 
local function decode(s)
-- Decodes html entities and percent encodings.
s = mw.text.decode(s, true)
return mw.uri.decode(s, 'WIKI')
end
 
Line 49 ⟶ 43:
)
if target then
returnlocal decodetargetTitle = getTitle(target)
if targetTitle then
return targetTitle.prefixedText
else
return nil
end
else
-- The page is a redirect, but matching failed. This indicates a bug in
Line 67 ⟶ 66:
rname = rname:match("%[%[(.+)%]%]") or rname
local target = p.getTarget(rname)
iflocal ret = target thenor rname
ret = getTitle(ret)
return bracket:format(target)
if ret then
ret = ret.prefixedText
return bracket:format(targetret)
else
return nil
rname = decode(rname)
return bracket:format(rname)
end
end