അജ്ഞാത ഉപയോക്താവ്
"ഘടകം:Redirect" എന്ന താളിന്റെ പതിപ്പുകൾ തമ്മിലുള്ള വ്യത്യാസം
ഘടകം:Redirect (മൂലരൂപം കാണുക)
02:46, 12 സെപ്റ്റംബർ 2021-നു നിലവിലുണ്ടായിരുന്ന രൂപം
, 12 സെപ്റ്റംബർ 2021en:Module:Redirect എന്നതിൽ നിന്ന് 2 പതിപ്പുകൾ ഇറക്കുമതി ചെയ്തു
(ചെ.) (ഒരു പതിപ്പ് ഇറക്കുമതി ചെയ്തു) |
en>Jacob.jose (ചെ.) (en:Module:Redirect എന്നതിൽ നിന്ന് 2 പതിപ്പുകൾ ഇറക്കുമതി ചെയ്തു) |
||
വരി 17: | വരി 17: | ||
-- redirect. | -- redirect. | ||
function p.getTargetFromText(text) | function p.getTargetFromText(text) | ||
local target = 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*%[%[([^%[%]|]-)%]%]" | ||
വരി 24: | വരി 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) | function p.getTarget(page, fulltext) | ||
-- 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. | ||
വരി 43: | വരി 44: | ||
), 2) | ), 2) | ||
end | end | ||
if not titleObj | if not titleObj then | ||
return nil | return nil | ||
end | end | ||
local targetTitle = titleObj.redirectTarget | |||
if targetTitle then | |||
local | if fulltext then | ||
if | return targetTitle.fullText | ||
else | |||
return targetTitle.prefixedText | return targetTitle.prefixedText | ||
end | end | ||
else | else | ||
return nil | |||
end | end | ||
end | end | ||
വരി 70: | വരി 63: | ||
-- target page name, or the passed page name when not a redirect. The passed | -- target page name, or the passed page name when not a redirect. The passed | ||
-- page name can be given as plain text or as a page link. | -- page name can be given as plain text or as a page link. | ||
-- | -- | ||
-- Returns page name as plain text, or when the bracket parameter is given, as a | -- Returns page name as plain text, or when the bracket parameter is given, as a | ||
-- page link. Returns an error message when page does not exist or the redirect | -- page link. Returns an error message when page does not exist or the redirect | ||
-- target cannot be determined for some reason. | -- target cannot be determined for some reason. | ||
--]] | --]] | ||
function p.luaMain(rname, bracket) | function p.luaMain(rname, bracket, fulltext) | ||
if type(rname) ~= "string" or not rname:find("%S") then | if type(rname) ~= "string" or not rname:find("%S") then | ||
return nil | return nil | ||
വരി 81: | വരി 74: | ||
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, fulltext) | ||
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 | if fulltext then | ||
ret = ret.fullText | |||
else | |||
ret = ret.prefixedText | |||
end | |||
return bracket:format(ret) | return bracket:format(ret) | ||
else | else | ||
വരി 95: | വരി 92: | ||
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) or '' | return p.luaMain(args[1], args.bracket, args.fulltext) or '' | ||
end | end | ||