Module:Resolve category redirect/sandbox

විකිපීඩියා වෙතින්
local p = {}

--Returns the target of {{Category redirect}}, if it exists, else returns the original cat.
function rtarget( cat )
	local catcontent = mw.title.new( cat or '', 'Category' ):getContent()
	if string.match( catcontent or '', '{{ *[Cc]at' ) then --preliminary test
		local regex = {
			--the following 11 pages (7 condensed) redirect to [[Template:Category redirect]] (as of 6/2019):
			'{{ *[Cc]ategory *[Rr]edirect', --most likely match 1st
			'{{ *[Cc]at *redirect',         --444+240 transclusions
			'{{ *[Cc]at *redir',            --8+3
			'{{ *[Cc]ategory *move',        --6
			'{{ *[Cc]at *red',              --6
			'{{ *[Cc]atr',                  --4
			'{{ *[Cc]at *move',             --0
		}
		for _, v in pairs (regex) do
			local rtarget = mw.ustring.match( catcontent, v..'%s*|%s*([^|}]+)' )
			if rtarget then
				rtarget = mw.ustring.gsub(rtarget, '^1%s*=%s*', '')
				rtarget = string.gsub(rtarget, '^[Cc]ategory:', '')
				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
"https://si.wikipedia.org/w/index.php?title=Module:Resolve_category_redirect/sandbox&oldid=519893" වෙතින් සම්ප්‍රවේශනය කෙරිණි