한국   대만   중국   일본 
모듈:Resolve category redirect - 위키百科, 우리 모두의 百科事典 本文으로 移動

모듈 : Resolve category redirect

이 페이지는 준보호되어 있습니다.
위키百科, 우리 모두의 百科事典.

local
 p
 =
 {}


--Returns the target of {{Category redirect}}, if it exists, else returns the original cat.

--Used by catlinkfollowr(), and so indirectly by all nav_*().

function
 rtarget
(
 cat
 )

	local
 catcontent
 =
 mw
.
title
.
new
(
 cat
 or
 ''
,
 'Category'
 ):
getContent
()

	if
 string.match
(
 catcontent
 or
 ''
,
 '{{ *分類'
 )
 then

		local
 regex
 =
 {

			--the following 11 pages (7 condensed) redirect to [[Template:Category redirect]] (as of 6/2019):

			{
 '1'
,
 '{{ *分類 *넘겨주기'
 },
 --most likely match 1st

		}

		for
 k
,
 v
 in
 pairs
 (
regex
)
 do

			local
 rtarget
 =
 mw
.
ustring
.
match
(
 catcontent
,
 v
[
2
]
..
'%s*|%s*([^|}]+)'
 )

			if
 rtarget
 then

				rtarget
 =
 mw
.
ustring
.
gsub
(
rtarget
,
 '^1%s*=%s*'
,
 ''
)

				rtarget
 =
 string.gsub
(
rtarget
,
 '^分類:'
,
 ''
)

				return
 rtarget

			end

		end

	end

	return
 cat

end


function
 p
.
main
(
 frame
 )

	local
 args
 =
 frame
:
getParent
().
args

	local
 cat
  =
 args
[
1
]

	
	if
 (
cat
 ==
 ""
)
 or
 (
cat
 ==
 nil
)
 then

		return
 ""

	end

	return
 rtarget
(
 cat
 )

	
end


return
 p