มอดูล:Category series navigation

require('strict')
local p = {}
local horizontal = require('Module:List').horizontal
--======================================================================**
--                                Globals                                   
--======================================================================**
local currtitle = mw.title.getCurrentTitle()
local nexistingcats = 0
local errors = 
local testcasecolon = 
local testcases = string.match(currtitle.subpageText, '^testcases') or string.match(currtitle.subpageText, '^ชุดทดสอบ')
if    testcases then testcasecolon = ':' end
local navborder = true
local followRs = true
local skipgaps = false
local skipgaps_limit = 50
local term_limit = 10
local hgap_limit = 6
local ygap_limit = 5
local listall = false
local tlistall = {}
local tlistallbwd = {}
local tlistallfwd = {}
local ttrackingcats = { --when reindexing, Ctrl+H 'trackcat(13,' & 'ttrackingcats16'
	, -- 1 placeholder for 
	, -- 2 placeholder for 
	, -- 3 placeholder for 
	, -- 4 placeholder for 
	, -- 5 placeholder for 
	, -- 6 placeholder for 
	, -- 7 placeholder for 
	, -- 8 placeholder for 
	, -- 9 placeholder for 
	, --10 placeholder for 
	, --11 placeholder for 
	, --12 placeholder for 
	, --13 placeholder for 
	, --14 placeholder for 
	, --15 placeholder for 
	, --16 placeholder for 
	, --17 placeholder for 
	, --18 placeholder for 
	, --19 placeholder for 
	, --20 placeholder for 
	, --21 placeholder for 
	, --22 placeholder for 
	, --23 placeholder for 
	, --24 placeholder for 
	, --25 placeholder for 
	, --26 placeholder for หมวดหมู่:กล่องหมวดหมู่ฤดูกาลใช้พารามิเตอร์ข้ามช่องว่าง
	, --27 placeholder for 
	, --28 placeholder for หมวดหมู่:กล่องหมวดหมู่ฤดูกาลระบุปีและทศวรรษ
	, --29 placeholder for หมวดหมู่:กล่องหมวดหมู่ฤดูกาลระบุทศวรรษและศตวรรษ
	, --30 placeholder for 
	, --31 placeholder for 
}
local avoidself =  (not string.match(currtitle.text, 'Category series navigation with') and
					not string.match(currtitle.text, 'Category series navigation.*/doc') and
					not string.match(currtitle.text, 'Category series navigation.*/sandbox') and
					currtitle.text ~= 'Category series navigation' and
					currtitle.nsText:gsub('_', ' ') ~= 'คุยกับผู้ใช้' and -- phab:T369784
					currtitle.nsText:gsub('_', ' ') ~= 'คุยเรื่องแม่แบบ' and
					(currtitle.nsText ~= 'แม่แบบ' or testcases)) --avoid nested transclusion errors (i.e. )
--======================================================================**
--                      Utility & category functions                        
--======================================================================**
--Determine if a category exists (in a function for easier localization).
local function catexists( title )
	return mw.title.new( title, 'หมวดหมู่' ).exists
end
--Error message handling.
function p.errorclass( msg )
	return mw.text.tag( 'span', {class='error mw-ext-cite-error'}, 'ผิดพลาด! '..string.gsub(msg, '&#', '&#') )
end
--Failure handling.
function p.failedcat( errors, sortkey )
	if avoidself then
		return (errors or )..'***Category series navigation เกิดข้อผิดพลาดขณะสร้างกล่องนำทาง***'..
			   ..(sortkey or 'O')..'\n'
	end
	return 
end
--Tracking cat handling.
--	key: 15 (when reindexing ttrackingcats{}, Ctrl+H 'trackcat(13,' & 'ttrackingcats16')
--	cat: 'Category series navigation isolated';  to remove
--Used by main, all nav_*(), & several utility functions.
local function trackcat( key, cat )
	if avoidself and key and cat then
		if cat ~=  then
			ttrackingcatskey = ..testcasecolon..'หมวดหมู่:'..cat..
		else
			ttrackingcatskey = 
		end
	end
	return
end
--Check for unknown parameters.
--Used by main only.
local function checkforunknownparams( tbl )
	local knownparams = { --parameter whitelist
		'min' = 'min',
		'max' = 'max',
		'cat' = 'cat',
		'show' = 'show',
		'testcase' = 'testcase',
		'testcasegap' = 'testcasegap',
		'skip-gaps' = 'skip-gaps',
		'list-all-links' = 'list-all-links',
		'follow-redirects' = 'follow-redirects',
	}
	for k, _ in pairs (tbl) do
		if knownparamsk == nil then
			trackcat(3, 'Category series navigation using unknown parameter')
			break
		end
	end
end
--Check for nav_*() navigational isolation (not necessarily an error).
--Used by all nav_*().
local function isolatedcat()
	if nexistingcats == 0 then
		trackcat(16, 'Category series navigation isolated')
	end
end
--Returns the target of , if it exists, else returns the original cat.
--, etc., if found, are evaluated.
--Used by catlinkfollowr(), and so indirectly by all nav_*().
local function rtarget( frame, cat )
	local catcontent = mw.title.new( cat or , 'หมวดหมู่' ):getContent()
	if string.match( catcontent or , '