-- Load the nav_hyphen function from the correct sub-module local trans = require('মডিউল:বিষয়শ্রেণী পরিভ্রমণ/trans').trans  --======================================================== local p = {} local function trackcat( key, cat ) 	if avoidself and key and cat then 		if cat ~=  then 			ttrackingcats[key] = ''..testcasecolon..'Category:'..cat..'' 		else 			ttrackingcats[key] =  		end 	end 	return end  function p.nav_hyphen( frame, start, hyph, finish, firstpart, lastpart, minseas, maxseas, testgap ) 	--Expects a PAGENAME of the form "Some sequential 2015–16 example cat", where 	--	start     = 2015 	--	hyph      = – 	--	finish    = 16 (sequential years can be abbreviated, but others should be full year, e.g. "2001–2005") 	--	firstpart = Some sequential 	--	lastpart  = example cat 	--	minseas   = 1800 ('min' starting season shown; optional; defaults to -9999) 	--	maxseas   = 2000 ('max' starting season shown; optional; defaults to 9999; 2000 will show 2000-01) 	--	testgap   = 0 (testcasegap parameter for easier testing; optional) 	 	--sterilize start 	if string.match(start or , '^%d%d?%d?%d?$') == nil then --1-4 digits, AD only 		local start_fixed = mw.ustring.match(start or , '^%s*(%d%d?%d?%d?)%D') 		if start_fixed then 			start = start_fixed 		else 			errors = p.errorclass('Function nav_hyphen can\'t recognize the number "'..(start or )..'" '.. 								  'in the first part of the "season" that was passed to it. '.. 								  'For e.g. "2015–16", "2015" is expected via "|2015|–|16|".') 			return p.failedcat(errors, 'H') 		end 	end 	local nstart = tonumber(start) 	 	--en dash check 	if hyph ~= '–' then 		trackcat(4, 'Category series navigation range not using en dash') --nav still processable, but track 	end 	 	--sterilize finish & check for weird parents 	local tgaps   = {} --table of gap sizes found b/w terms    { [<gap size found>]    = 1 } for -3 <= j <= 3 	local tgapsj4 = {} --table of gap sizes found b/w terms    { [<gap size found>]    = 1 } for j = { -4, 4 } 	local ttlens  = {} --table of term lengths found w/i terms { [<term length found>] = 1 } 	local tirregs = {} --table of ir/regular-term-length cats' "from"s & "to"s found 	local regularparent = true 	if (finish == -1) or --"Members of the Scottish Parliament 2021–present" 	   (finish == 0)	 --"Members of the Scottish Parliament 2021–" 	then 		regularparent = false 		if maxseas == nil or maxseas ==  then 			maxseas = start --hide subsequent ranges 		end 		if finish == -1 then trackcat(14, 'Category series navigation range ends (present)') 		else				 trackcat(15, 'Category series navigation range ends (blank, MOS)') end 	elseif (start == finish) and 		   (ttrackingcats[16] ~= ) --nav_year found isolated; check for surrounding hyphenated terms (e.g. UK MPs 1974) 	then 		trackcat(16, ) --reset for another check later 		trackcat(13, 'Category series navigation range irregular, 0-length') 		ttlens[0] = 1 --calc ttlens for std cases below 		regularparent = 'isolated' 	end 	if (string.match(finish or , '^%d+$') == nil) and 	   (string.match(finish or , '^%-%d+$') == nil) 	then 		local finish_fixed = mw.ustring.match(finish or , '^%s*(%d%d?%d?%d?)%D') 		if finish_fixed then 			finish = finish_fixed 		else 			errors = p.errorclass('Function nav_hyphen can\'t recognize "'..(finish or )..'" '.. 								  'in the second part of the "season" that was passed to it. '.. 								  'For e.g. "2015–16", "16" is expected via "|2015|–|16|".') 			return p.failedcat(errors, 'I') 		end 	else 		if string.len(finish) >= 5 then 			errors = p.errorclass('The second part of the season passed to function nav_hyphen should only be four or fewer digits, not "'..(finish or )..'". '.. 								  'See MOS:DATERANGE for details.') 			return p.failedcat(errors, 'J') 		end 	end 	local nfinish = tonumber(finish) 	 	--save sterilized parent range for easier lookup later 	tirregs['from0'] = nstart 	tirregs['to0']   = nfinish 	 	--sterilize min/max 	local nminseas_default = -9999 	local nmaxseas_default =  9999 	local nminseas = tonumber(minseas) or nminseas_default --same behavior as nav_year 	local nmaxseas = tonumber(maxseas) or nmaxseas_default --same behavior as nav_year 	if nminseas > nstart then nminseas = nstart end 	if nmaxseas < nstart then nmaxseas = nstart end 	 	local lspace = ' ' --assume a leading space (most common) 	local tspace = ' ' --assume a trailing space (most common) 	if string.match(firstpart, '%($') then lspace =  end --DNE for "Madrid city councillors (2007–2011)"-type cats 	if string.match(lastpart,  '^%)') then tspace =  end --DNE for "Madrid city councillors (2007–2011)"-type cats 	 	--calculate term length/intRAseason size & finishing year 	local t = 1 	while t <= term_limit and regularparent == true do 		local nish = nstart + t --use switchADBC to flip this sign to work for years BC, if/when the time comes 		if (nish == nfinish) or (string.match(nish, '%d?%d$') == finish) then 			ttlens[t] = 1 			break 		end 		if t == term_limit then 			errors = p.errorclass('Function nav_hyphen can\'t determine a reasonable term length for "'..trans(start)..hyph..trans(finish)..'".') 			return p.failedcat(errors, 'K') 		end 		t = t + 1 	end 	 	--apply MOS:DATERANGE to parent 	local lenstart = string.len(start) 	local lenfinish = string.len(finish) 	if lenstart == 4 and regularparent == true then --"2001–..." 		if t == 1 then --"2001–02" & "2001–2002" both allowed 			if lenfinish ~= 2 and lenfinish ~= 4 then 				errors = p.errorclass('The second part of the season passed to function nav_hyphen should be two or four digits, not "'..finish..'".') 				return p.failedcat(errors, 'L') 			end 		else --"2001–2005" is required for t > 1; track "2001–05"; anything else = error 			if lenfinish == 2 then 				trackcat(5, 'Category series navigation range abbreviated (MOS)') 			elseif lenfinish ~= 4 then 				errors = p.errorclass('The second part of the season passed to function nav_hyphen should be four digits, not "'..finish..'".') 				return p.failedcat(errors, 'M') 			end 		end 		if finish == '00' then --full year required regardless of term length 			trackcat(5, 'Category series navigation range abbreviated (MOS)') 		end 	end 	 	--calculate intERseason gap size 	local hgap_default     = 0 --assume & start at the most common case: 2001–02 -> 2002–03, etc. 	local hgap_limit_reg   = hgap_limit --less expensive per-increment (inc x 4) 	local hgap_limit_irreg = hgap_limit --more expensive per-increment (inc x 23 = inc x (k_bwd + k_fwd) = inc x (12 + 11)) 	local hgap_success = false 	local hgap = hgap_default 	while hgap <= hgap_limit_reg and regularparent == true do --verify 		local prevseason2 = firstpart..lspace..(nstart-t-hgap)..hyph..string.match(nstart-hgap, '%d?%d$')    ..tspace..lastpart 		local nextseason2 = firstpart..lspace..(nstart+t+hgap)..hyph..string.match(nstart+2*t+hgap, '%d?%d$')..tspace..lastpart 		local prevseason4 = firstpart..lspace..(nstart-t-hgap)..hyph..(nstart-hgap)    ..tspace..lastpart 		local nextseason4 = firstpart..lspace..(nstart+t+hgap)..hyph..(nstart+2*t+hgap)..tspace..lastpart 		if t == 1 then --test abbreviated range first, then full range, to be frugal with expensive functions 			if catexists(prevseason2) or --use 'or', in case we're at the edge of the cat structure, 			   catexists(nextseason2) or --or we hit a "–00"/"–2000" situation on one side 			   catexists(prevseason4) or 			   catexists(nextseason4) 			then 				hgap_success = true 				break 			end 		elseif t > 1 then --test full range first, then abbreviated range, to be frugal with expensive functions 			if catexists(prevseason4) or --use 'or', in case we're at the edge of the cat structure, 			   catexists(nextseason4) or --or we hit a "–00"/"–2000" situation on one side 			   catexists(prevseason2) or 			   catexists(nextseason2) 			then 				hgap_success = true 				break 			end 		end 		hgap = hgap + 1 	end 	if hgap_success == false then 		hgap = tonumber(testgap) or hgap_default --tracked via defaultgapcat() 	end 	 	--preliminary scan to determine ir/regular spacing of nearby cats; 	--to limit expensive function calls, MOS:DATERANGE-violating cats are ignored; 	--an irregular-term-length series should follow "YYYY..hyph..YYYY" throughout 	local jlimit = 4  --4-a-side if all YYYY-YY, 3-a-side if all YYYY-YYYY, with some threshold in between 	if hgap <= hgap_limit_reg then --also to isolate temp vars 		--find # of nav-visible ir/regular-term-length cats 		local bwanchor = nstart       --backward anchor/common year 		local fwanchor = bwanchor + t --forward anchor/common year 		if regularparent == 'isolated' then 			fwanchor = bwanchor 		end 		local spangreen = '[<span style="color:green">j, g, k = ' --used for/when debugging via list-all-links=yes 		local spanblue = '<span style="color:blue">' 		local spanred = ' (' 		local span = '' 		local lastg = nil --to check for run-on searches 		local lastk = nil --to check for run-on searches 		local endfound = false --switch used to stop searching forward 		local iirregs = 0 --index of tirregs[] for j < 0, since search starts from parent 		local j = -jlimit --index of tirregs[] for j > 0 & pseudo navh position 		while j <= jlimit do 			 			if j < 0 then --search backward from parent 				local gbreak = false --switch used to break out of g-loop 				local g = 0 --gap size 				while g <= hgap_limit_irreg do 					local k = 0 --term length: 0 = "0-length", 1+ = normal 					while k <= term_limit do 						local from = bwanchor - k - g 						local to   = bwanchor - g 						local full = mw.text.trim( firstpart..lspace..trans(from)..hyph..trans(to)..tspace..lastpart ) 						if k == 0 then 							if regularparent ~= 'isolated' then --+restrict to g == 0 if repeating year problems arise 								to = '0-length' 								full = mw.text.trim( firstpart..lspace..trans(from)..tspace..lastpart ) 								if catlinkfollowr( frame, full ).rtarget ~= nil then --#R followed 									table.insert( tlistallbwd, spangreen..j..', '..g..', '..k..span..'] '..full..spanred..'#R ignored'..span..')' ) 									full, to = ,  --don't use/follow 0-length cat #Rs from nav_hyphen(); otherwise gets messy 								end 							end 						end 						if (k >= 1) or		  --the normal case; only continue k = 0 if 0-length found 						   (to == '0-length') --ghetto "continue" (thx Lua) to avoid expensive searches for "UK MPs 1974-1974", etc. 						then 							table.insert( tlistallbwd, spangreen..j..', '..g..', '..k..span..'] '..full ) 							if (k == 1) and --							   (g == 0 or g == 1) and --commented to match j>0 case ("1995–96 in Federal Republic of Yugoslavia basketball") 							   (catexists(full) == false) 							then --allow bare-bones MOS:DATERANGE alternation, in case we're on a 0|1-gap, 1-year term series 								local to2 = string.match(to, '%d%d$') 								if to2 and to2 ~= '00' then --and not at a century transition (i.e. 1999–2000) 									to = to2 									full = mw.text.trim( firstpart..lspace..trans(from)..hyph..trans(to)..tspace..lastpart ) 									table.insert( tlistallbwd, spangreen..j..', '..g..', '..k..span..'] '..full ) 								end 							end 							if catexists(full) then 								if to == '0-length' then 									trackcat(13, 'Category series navigation range irregular, 0-length') 								end 								tlistallbwd[#tlistallbwd] = spanblue..tlistallbwd[#tlistallbwd]..span..' (found)' 								ttlens[ find_duration(full) ] = 1 								if j == -1 then tgapsj4[g] = 1 -- -1 since bwd search starts from parent @ -4 and ends at -1 								else tgaps[g] = 1 end 								iirregs = iirregs + 1 								tirregs['from-'..iirregs] = from 								tirregs['to-'..iirregs] = to 								bwanchor = from --ratchet down 								if to ~= '0-length' then 									gbreak = true 									break 								else 									g = 0 --soft-reset g, to keep stepping thru k 									j = j + 1 --save, but keep searching thru k 									if j > 0 then --(restore "> 3" if acts up) lest we keep searching bwd & finding 0-length cats ("MEPs for the Republic of Ireland 1973" & down) 										j = -1 --allow a normal, full search fwd after break 										gbreak = true 										break 									end 								end 							elseif (j >= 0) and 								   (lastg and lastk) and 								   ((lastg >= hgap_limit_irreg) or 									(lastk >= term_limit)) 							then --bwd search exhausted and/or done (runaway bwd search on "2018–19 FIA World Endurance Championship season") 								j = -1 --allow a normal, full search fwd after break 								gbreak = true 								break 							end 						end --ghetto "continue" 						k = k + 1 						lastk = k 					end --while k <= term_limit do 					if gbreak == true then break end 					g = g + 1 					lastg = g 				end --while g <= hgap_limit_irreg do 			end --if j < 0 			 			if j > 0 and endfound == false then --search forward from parent 				local gbreak = false --switch used to break out of g-loop 				local g = 0 --gap size 				while g <= hgap_limit_irreg do 					local k = -2 --term length: -2 = "0-length", -1 = "2020–present", 0 = "2020–", 1+ = normal 					while k <= term_limit do 						local from = fwanchor + g 						local to4  = fwanchor + k + g	--override carefully 						local to2  = nil				--last 2 digits of to4, IIF exists 						if k == -1 then to4 = 'বর্তমান'	--see if end-cat exists (present) 						elseif k == 0 then to4 =  end	--see if end-cat exists (blank) 						local full = mw.text.trim( firstpart..lspace..trans(from)..hyph..trans(to4)..tspace..lastpart ) 						if k == -2 then 							if regularparent ~= 'isolated' then --+restrict to g == 0 if repeating year problems arise 								to4 = '0-length' --see if 0-length cat exists 								full = mw.text.trim( firstpart..lspace..trans(from)..tspace..lastpart ) 								if catlinkfollowr( frame, full ).rtarget ~= nil then --#R followed 									table.insert( tlistallfwd, spangreen..j..', '..g..', '..k..span..'] '..full..spanred..'#R ignored'..span..')' ) 									full, to4 = ,  --don't use/follow 0-length cat #Rs from nav_hyphen(); otherwise gets messy 								end 							end 						end 						if (k >= -1) or		   --only continue k = -2 if 0-length found 						   (to4 == '0-length') --ghetto "continue" (thx Lua) to avoid expensive searches for "UK MPs 1974-1974", etc. 						then 							table.insert( tlistallfwd, spangreen..j..', '..g..', '..k..span..'] '..full ) 							if (k == 1) and --							   (g == 0 or g == 1) and --commented to let "2002–03 in Scottish women's football" find "2008–09 in Scottish women's football" 							   (catexists(full) == false) 							then --allow bare-bones MOS:DATERANGE alternation, in case we're on a 0|1-gap, 1-year term series 								to2 = string.match(to4, '%d%d$') 								if to2 and to2 ~= '00' then --and not at a century transition (i.e. 1999–2000) 									full = mw.text.trim( firstpart..lspace..trans(from)..hyph..trans(to2)..tspace..lastpart ) 									table.insert( tlistallfwd, spangreen..j..', '..g..', '..k..span..'] '..full ) 								end 							end 							if catexists(full) then 								if to4 == '0-length' then 									if rtarget(frame, full) == full then --only use 0-length cats that don't #R 										trackcat(13, 'Category series navigation range irregular, 0-length') 									end 								end 								tirregs['from'..j] = from 								tirregs['to'..j] = (to2 or to4) 								if (k == -1) or (k == 0) then 									endfound = true --tentative 								else --k == { -2, > 0 } 									tlistallfwd[#tlistallfwd] = spanblue..tlistallfwd[#tlistallfwd]..span..' (found)' 									ttlens[ find_duration(full) ] = 1 									if j == 4 then tgapsj4[g] = 1 									else tgaps[g] = 1 end 									endfound = false 									if to4 ~= '0-length' then --k > 0 										fwanchor = to4 --ratchet up 										gbreak = true 										break --only break on k > 0 b/c old end-cat #Rs still exist like "Members of the Scottish Parliament 2011–" 									else --k == -2 										j = j + 1 --save, but keep searching k's, in case "1974" → "1974-1979" 										if j > jlimit then --lest we keep searching & finding 0-length cats ("2018 CONCACAF Champions League" & up) 											gbreak = true 											break 										elseif g == hgap_limit_irreg then 											--keep searching, since not a runaway, just far away ("American soccer clubs 1958–59 season") 											hgap_limit_irreg = hgap_limit_irreg + 1 										end 									end 								end 							end 						end --ghetto "continue" 						k = k + 1 						lastk = k 					end --while k <= term_limit do 					if gbreak == true then break end 					g = g + 1 					lastg = g 				end --while g <= hgap_limit_irreg do 			end --if j > 0 and endfound == false then 			 			if (lastg and lastk) and 			   (lastg > hgap_limit_irreg) and 			   (lastk > term_limit) 			then --search exhausted 				if j < 0 then j = 0 --bwd search exhausted; continue fwd 				elseif j > 0 then break end --fwd search exhausted 			end 			 			j = j + 1 		end --while j <= jlimit 	end --if hgap <= hgap_limit_reg 	 	--determine # of displayed navh elements based on "YYYY-YY" vs. "YYYY-YYYY" counts 	local Ythreshold = 3.3 --((YYYY-YY x 7) + (YYYY-YYYY x 2))/18 = 3.222; ((YYYY-YY x 6) + (YYYY-YYYY x 3))/18 = 3.333 	local Ycount = 0 --"Y" count 	local ycount = 0 --tirregs counter; # of contiguous #s 	for k, v in pairs (tirregs) do 		local dummy, dunce = mw.ustring.gsub(tostring(v), '%d', ) --why can't gsub just return a table?? 		Ycount = Ycount + dunce 		ycount = ycount + 1 	end 	local ycount_limit = ((jlimit * 2) + 1) * 2 --i.e. ((4 * 2) + 1) * 2 = 18 	if ycount < ycount_limit then --fill in the blanks with Ycount_parent, since hidden/dne cats aren't in tirregs 		local dummy_finish = finish 		if not regularparent then dummy_finish = start end 		local dummy, dunce_from = mw.ustring.gsub(start,  '%d', ) 		local dummy, dunce_to   = mw.ustring.gsub(dummy_finish, '%d', '') 		local Ycount_parent_avg = (dunce_from + dunce_to)/2 --"YYYY-YYYY" = 4; "YYYY-YY" = 3 		Ycount = Ycount + (Ycount_parent_avg * (ycount_limit - ycount)) 		ycount = ycount_limit 	end 	local iwidth = 3 --default to 3-a-side, 7 total 	local Y_per_y = Ycount / ycount --normalized range: [3-4] 	if Y_per_y < Ythreshold then 		iwidth = 4 --extend to 4-a-side, 9 total 	end 	 	--begin navhyphen 	local navh = '\n' 	 	local navlist = {} 	local terminalcat = false --switch used to hide future cats 	local terminaltxt = nil 	local i = -iwidth --nav position 	while i <= iwidth do 		local from = nstart + i*(t+hgap) --the logical, but not necessarily correct, 'from' 		if tirregs['from'..i] then --prefer the irregular term table 			from = tonumber(tirregs['from'..i]) 		else --fallback to lazy/naive 'from' 			if i > 0 and 			   tirregs['from'..(i-1)] and 			   tirregs['from'..(i-1)] >= from 			then --end of the line: avoid dups/past, and create reasonable grey'd ranges 				local greyto   = tonumber(tirregs['to' .. (i-1)]) or -9999 				local greyfrom = tonumber(tirregs['from'..(i-1)]) or -9999 				local grey = greyto --prefer 'to' 				if greyfrom > greyto then grey = greyfrom end --'from' fallback, in case "1995–96", "1995-present", etc. 				if grey > -9999 then 					if grey ~= greyto then 						from = grey + t + hgap --account for missing/incomplete 'to' 					else 						from = grey + hgap 					end 					tirregs['from'..i] = from --remember 					tirregs['to' .. i] = from + t 				end 			elseif i < 0 then 				local greyfrom 				local ii = 0 				while ii < 3 do 					ii = ii + 1 					greyfrom = tonumber(tirregs['from'..(i+ii)]) 					if greyfrom then break end 				end 				from = (greyfrom or nstart) - ii*(t+hgap) 				tirregs['from'..i] = from --remember 				tirregs['to' .. i] = from + t 			end 		end 		local from2 = string.match(from, '%d?%d$') 		 		local to = tostring(from+t)	--the logical, naive range, but 		if tirregs['to'..i] then	--prefer irregular term table 			to = tirregs['to'..i] 		elseif regularparent == false and tirregs and i > 0 then 			to = tirregs['to-1']	--special treatment for parent terminal cats, since they have no natural 'to' 		end 		local to2 = string.match(to, '%d?%d$') 		local tofinal = (to2 or )    --assume t=1 and abbreviated 'to' (the most common case) 		if t > 1 or                    --per MOS:DATERANGE (e.g. 1999-2004) 		  (from2 - (to2 or from2)) > 0 --century transition exception (e.g. 1999–2000) 		then 			tofinal = (to or )       --default to the MOS-correct format, in case no fallbacks found 		end 		if to == '0-length' then 			tofinal = to 		end 		 		--check existance of 4-digit, MOS-correct range, with abbreviation fallback 		if tofinal ~= '0-length' then 			if t > 1 and string.len(from) == 4 then --e.g. 1999-2004 				--determine which link exists (full or abbr) 				local full = firstpart..lspace..trans(from)..hyph..trans(tofinal)..tspace..lastpart 				if not catexists(full) then 					local abbr = firstpart..lspace..trans(from)..hyph..trans(to2)..tspace..lastpart 					if catexists(abbr) then 						tofinal = (to2 or ) --rv to MOS-incorrect format; if full AND abbr DNE, then tofinal is still in its MOS-correct format 					end 				end 			elseif t == 1 then --full-year consecutive ranges are also allowed 				local abbr = firstpart..lspace..trans(from)..hyph..trans(tofinal)..tspace..lastpart --assume tofinal is in abbr format 				if not catexists(abbr) and tofinal ~= to then 					local full = firstpart..lspace..trans(from)..hyph..trans(to)..tspace..lastpart 					if catexists(full) then 						tofinal = (to or ) --if abbr AND full DNE, then tofinal is still in its abbr format (unless it's a century transition) 		end	end	end	end 		 		--populate navh 		if i ~= 0 then --left/right navh 			local orig = firstpart..lspace..trans(from)..hyph..trans(tofinal)..tspace..lastpart 			local disp = trans(from)..hyph..trans(tofinal) 			if tofinal == '0-length' then 				orig = firstpart..lspace..trans(from)..tspace..lastpart 				disp = trans(from) 			end 			local catlink = catlinkfollowr(frame, orig, disp, true) --force terminal cat display 			 			if terminalcat == false then 				terminaltxt = find_terminaltxt( disp ) --also sets tracking cats 				terminalcat = (terminaltxt ~= nil) 			end 			if catlink.rtarget and avoidself then --a  was followed, figure out why 				--determine new term length & gap size 				ttlens[ find_duration( catlink.rtarget ) ] = 1 				if i > -iwidth then 					local lastto = tirregs['to'..(i-1)] 					if lastto == nil then 						local lastfrom = nstart + (i-1)*(t+hgap) 						lastto = lastfrom+t --use last logical 'from' to calc lastto 					end 					if lastto then 						local gapcat = lastto..'-'..from --dummy cat to calc with 						local gap = find_duration(gapcat) or -1	--in case of nil, 						if iwidth == 4 then 							tgapsj4[ gap ] = 1 --tgapsj4[-1] are ignored later 						else 							tgaps[ gap ] = 1 --tgaps[-1] are ignored later 						end 					end 				end 				 				--display/tracking handling 				local base_regex = '%d+[–-]%d+' 				local origbase = mw.ustring.gsub(orig, base_regex, ) 				local rtarbase, rtarbase_success = mw.ustring.gsub(catlink.rtarget, base_regex, ) 				if rtarbase_success == 0 then 					local base_regex_lax = '%d%d%d%d' --in case rtarget is a year cat 					rtarbase, rtarbase_success = mw.ustring.gsub(catlink.rtarget, base_regex_lax, ) 				end 				local terminal_regex = '%d+[–-]'..(terminaltxt or )..'$' --more manual ORs bc Lua regex sux 				if mw.ustring.match(orig, terminal_regex) then 					origbase = mw.ustring.gsub(orig, terminal_regex, ) 				end 				if mw.ustring.match(catlink.rtarget, terminal_regex) then 					--finagle/overload terminalcat type to set nmaxseas on 1st occurence only 					if terminalcat == false then terminalcat = 1 end 					local dummy = find_terminaltxt( catlink.rtarget ) --also sets tracking cats 					rtarbase = mw.ustring.gsub(catlink.rtarget, terminal_regex, ) 				end 				origbase = mw.text.trim(origbase) 				rtarbase = mw.text.trim(rtarbase) 				if origbase ~= rtarbase then 					trackcat(6, 'Category series navigation range redirected (base change)') 				elseif terminalcat == 1 then 					trackcat(8, 'Category series navigation range redirected (end)') 				else --origbase == rtarbase 					local all4s_regex = '%d%d%d%d[–-]%d%d%d%d' 					local orig_all4s = mw.ustring.match(orig, all4s_regex) 					local rtar_all4s = mw.ustring.match(catlink.rtarget, all4s_regex) 					if orig_all4s and rtar_all4s then 						trackcat(10, 'Category series navigation range redirected (other)') 					else 						local year_regex1 = '%d%d%d%d$' 						local year_regex2 = '%d%d%d%d[%s%)]' 						local year_rtar = mw.ustring.match(catlink.rtarget, year_regex1) or 										  mw.ustring.match(catlink.rtarget, year_regex2) 						if orig_all4s and year_rtar then 							trackcat(7, 'Category series navigation range redirected (var change)') 						else 							trackcat(9, 'Category series navigation range redirected (MOS)') 						end 					end 				end			end 			 			if terminalcat then --true or 1 				if type(terminalcat) ~= 'boolean' then nmaxseas = from end --only want to do this once 				terminalcat = true --done finagling/overloading 			end 			if (from >= 0) and (nminseas <= from) and (from <= nmaxseas) then 				table.insert(navlist, catlink.navelement) 				if terminalcat then nmaxseas = nminseas_default end --prevent display of future ranges 			else 				local hidden = ''..disp..'' 				table.insert(navlist, hidden) 				if listall then 					tlistall[#tlistall] = tlistall[#tlistall]..' ('..hidden..')' 				end 			end 		else --center navh 			if finish == -1 then finish = 'বর্তমান' 			elseif finish == 0 then finish = ''..start..'' end 			local disp = trans(start)..hyph..trans(finish) 			if regularparent == 'isolated' then disp = trans(start) end 			table.insert(navlist, ''..disp..'') 		end 		 		i = i + 1 	end 	 	-- add the list 	navh = navh..horizontal(navlist)..'\n' 	 	--tracking cats & finalize 	if avoidself then 		local igaps  = 0 --# of diff gap sizes > 0 found 		local itlens = 0 --# of diff term lengths found 		for s = 1, hgap_limit_reg do --must loop; #tgaps, #ttlens unreliable 			igaps = igaps + (tgaps[s] or 0) 		end 		if iwidth == 4 then --only count gaps if they were displayed ("Karnataka MLAs 1957–1962") 			for s = 1, hgap_limit_reg do 				igaps = igaps + (tgapsj4[s] or 0) 			end 		end 		for s = 0, term_limit do 			itlens = itlens + (ttlens[s] or 0) 		end 		if igaps  > 0 then trackcat(11, 'Category series navigation range gaps') end 		if itlens > 1 and ttrackingcats[13] == '' then --avoid duplication in "Category series navigation range irregular, 0-length" 			trackcat(12, 'Category series navigation range irregular') 		end 	end 	isolatedcat() 	defaultgapcat(not hgap_success) 	if listall then 		return listalllinks() 	else 		return navh..'' 	end end return p