求真百科歡迎當事人提供第一手真實資料,洗刷冤屈,終結網路霸凌。

變更

前往: 導覽搜尋

模块:Redirect

增加 45 位元組, 7 年前
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*#重定向%s*:?%s*%[%[([^%[%]|]-)%]%]"
) or string.match(
text,
"^%s*#重定向%s*:?%s*%[%[([^%[%]|]-)|[^%[%]]-%]%]"
) or 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
匿名用戶