Մոդուլ:ԺամանակիԿատեգորիա

Վիքիպեդիայից՝ ազատ հանրագիտարանից

Այս կաղապարը նախատեսված է տարեթվերի/տասնամյակների/դարերի կատեգորիաների համար կաղապարներ ստեղծելու համար։ Կաղապարն օգտագործող կաղապարների ցանկը տես Վիքիպեդիա:ԺամանակիԿատեգորիա օգտագործող կաղապարներ կատեգորիայում։

«Կախարդական բառեր»[խմբագրել կոդը]

Կաղապարը աջակցում է մի շարք «կախարդական բառեր», որոնք կարելի է օգտագործել կատեգորիաների կամ վերնագրի բովանդակությունում։

  • __ԹՎԱԿԱՆ__ — վերածվում է թվականի, օրինակ՝ 1969, 2091 և այլն։
  • __ՏԱՍՆԱՄՅԱԿ__ — վերածվում է տասնամյակի (առանց «-ականների»), օրինակ՝ 1960, 2090 և այլն։
  • __ԴԱՐ__ — վերածվում է դարի (առանց «-րդի» կամ «-ինի»), օրինակ՝ 20, 21 և այլն։
  • __ՀԱԶԱՐԱՄՅԱԿ__ — վերածվում է հազարամյակի (առանց «-րդի» կամ «-ինի»), օրինակ՝ 1, 2 և այլն։
  • __ԹԵՄԱ__ — վերածվում է |topic_pattern=-ով բռված տեքստի։ Տես {{ՀիմնադրումԵրկիր}} կիրառման օրինակի համար։
  • __ՄԱՅՐՑԱՄԱՔ__ — եթե __ԹԵՄԱ__-ն որևէ երկիր է, __ՄԱՅՐՑԱՄԱՔ__-ը վերածվում է այդ երկրի մայրցամաքին։ Տես {{ՀիմնադրումԵրկիր}} կիրառման օրինակի համար։
  • ՈՒՄ(__ԹԵՄԱ__) — եթե պետք է «__ԹԵՄԱ__»-ին ավելացնել -ում, օրինակ՝ եթե «__ԹԵՄԱ__»-ն «Հայաստան», «Գերմանիա» կամ «X» է, ապա ՈՒՄ(__ԹԵՄԱ__)-ը «Հայաստանում», «Գերմանիայում» կամ «X-ում» է։
  • ՐԴ(__ԴԱՐ__) — եթե __ԴԱՐ__-ը «1» է, ապա ՐԴ(__ԴԱՐ__)-ը «1-ին» է, իսկ եթե __ԴԱՐ__-ը «2» է, ապա ՐԴ(__ԴԱՐ__)-ը «2-րդ» է։
  • ԸՆ(դար) ՈՒՄ(__ԹԵՄԱ__) — եթե __ԹԵՄԱ__-ն սկսվում է ձայնավորով (օրինակ՝ Անգլիա), ապա դառնում է «դարն Անգլիայում», հակառակ դեպքում՝ «դարը Անգլիայում։

Պարամետրեր[խմբագրել կոդը]

  • |1=, |2=, |3=, |4=, |5=, ... |n= — կատեգորիաներ, որոնք պետք է ավելացնել։ Օրինակ՝ |1=__ՏԱՍՆԱՄՅԱԿ__-ականների ֆիլմեր։ Տես {{Ֆիլմեր ըստ տարեթվի}}։
  • |title_pattern=պարտադիր, նշել, թե կատեգորիայի անվանումը ինչ տեսք ունի, օրինակ՝ |title_pattern=Ֆիլմեր, որոնց գործողությունները տեղի են ունենում __ՏԱՍՆԱՄՅԱԿ__-ականներին, որը համապատասխանում է «Ֆիլմեր, որոնց գործողությունները տեղի են ունենում 1930-ականներին» կատեգորիային։ Տես {{Ֆիլմեր ըստ գործողությունների տասնամյակի}}։
  • |decade_format= — տարեթվի կատեգորիային համապատասխանող տասնամյակի կատեգորիաների տեսքը։ Օրինակ՝ «1939 ֆիլմեր»-ին համապատասխանում է «1930-ականների ֆիլմեր» կատեգորիան, հետևաբար {{Ֆիլմեր ըստ տարեթվի}}-ում պետք է լարցնել |decade_format=__ՏԱՍՆԱՄՅԱԿ__-ականների ֆիլմեր։
  • |century_format= — տասնամյակի կատեգորիային համապատասխանող դարի կատեգորիաների տեսքը։ Օրինակ՝ «400-ականների հիմնադրումներ»-ին համապատասխանում է «5-րդ դարի հիմնադրումներ» կատեգորիան, հետևաբար {{Տասնամյակ հիմնադրումներ}}-ում պետք է լարցնել |century_format=ՐԴ(__ԴԱՐ__) դարի հիմնադրումներ։
  • |header= — կատեգորիաների նավարկման վերևում գտնվող բովանդակություն։ Կարող է լինել ցանկացած վիքիտեքստ։ Աշխատում են բոլոր կախարդական բառերը (օրինակ՝ __ԹՎԱԿԱՆ__, __ՏԱՍՆԱՄՅԱԿ__ կամ __ԴԱՐ__)։ Օրինակ՝ |header=Այս կատեգորիայում գտնվում են ֆիլմեր, որոնց գործողությունները ամբողջությամբ կամ մասմամբ տեղի են ունենում [[__ՏԱՍՆԱՄՅԱԿ__-ականներ]]ում։ {{Քույրհղումներ}}։ Տես {{Ֆիլմեր ըստ գործողությունների տասնամյակի}}։
  • |show_years=|show_years=no դեպքում ցույց չի տրվում թվականների նավարկումը, իսկ |show_years=yes դեպքում ցույց տրվում է։
  • |show_decades=|show_decades=no դեպքում ցույց չի տրվում տասնամյակների նավարկումը, իսկ |show_decades=yes դեպքում ցույց տրվում է։
  • |show_centuries=|show_centuries=no դեպքում ցույց չի տրվում դարերի նավարկումը, իսկ |show_centuries=yes դեպքում ցույց տրվում է։
  • |columns= — տարեթվերի նավարկման մեջ աջից և ձախից ցուցադրվող տարեթվերի քանակը։

local p = {}

local maxCheckRange = 100
local lang = mw.language.new('hy')
local thisFrame = nil

local yearPlaceholder = '__ԹՎԱԿԱՆ__'
local decadePlaceholder = '__ՏԱՍՆԱՄՅԱԿ__'
local centuryPlaceholder = '__ԴԱՐ__'
local millenniumPlaceholder = '__ՀԱԶԱՐԱՄՅԱԿ__'
local topicPlaceholder = '__ԹԵՄԱ__'
local continentPlaceholder = '__ՄԱՅՐՑԱՄԱՔ__'
local umPattern = 'ՈՒՄ%((.-)%)'
local iYiPattern = 'ԻՅԻ%((.-)%)'
local nThePattern = 'ԸՆ%((.-)%) (.)'
local unUmPattern = 'ՈՒՄԱՌԱՆՑ%((.-)%)'
local unIYiPattern = 'ԻՅԻԱՌԱՆՑ%((.-)%)'
local rdPattern = 'ՐԴ%((.-)%)'
local parentsResolver = nil

local function checkPageExists( title )
    local noError, titleObject = pcall(mw.title.new, title)
    if not noError then
        -- If we are over the expensive function limit then assume
        -- that the page doesn't exist.
        return false
    else
        if titleObject then
            return titleObject.exists
        else
            return false -- Return false if given a bad title.
        end
    end
end

local function getNumberArgOrDefault(arg, default)
    if arg == nil then
        return default
    end
    local parsed_value = tonumber(arg)
    if parsed_value then
        return parsed_value
    else
        return default
    end
end

local function getValueOrDefault(arg, default)
    if arg == nil then
        return default
    end
    return arg
end

local function getDecade(year)
	local year = tonumber(year)
	local isBC = year < 0
	local absD = math.floor(math.abs(year) / 10) * 10
	if isBC then
		return -absD
	else
		return absD
	end
end

local function getCentury(year)
	local year = tonumber(year)
	local isBC = year < 0 
	local absC = math.ceil(math.abs(year) / 100)
	if isBC then
		return -absC
	else
		return absC
	end
end

local function getMillenniumFromCentury(century)
    if century >= 0 then
        return math.ceil(century / 10)
    else
        return -math.ceil(math.abs(century) / 10)
    end
end

local function getFromattedYear(year, isBC) -- isBC-ի կարքը ունենք Մ.թ.ա. 0-ականներ/0-ականներ պատճառով
	year = tonumber(year)
	if isBC == nil then
		isBC = year < 0
	end
    if isBC then
        return 'մ.թ.ա. ' .. math.abs(year)
    else
        return tostring(year)
    end
end

local function getFormattedYearOrdinal(year, isBC)
	year = tonumber(year)
	local formattedYear = getFromattedYear(year, isBC)
	if year == 1 or year == -1 then
		return formattedYear .. '-ին'
	else
		return formattedYear .. '-րդ'
	end
end

local function getCategoryAsLink(catName, displayName)
	if thisFrame == nil then
		return ''
	end
    if displayName == nil then
        return thisFrame:expandTemplate{ title = 'LinkCatIfExists2', args = {catName}}
    else
        return thisFrame:expandTemplate{ title = 'LinkCatIfExists2', args = {catName, lang:ucfirst(displayName)}}
    end
end

local function getCategory(catName, sortKey)
    if sortKey == nil then
        return '[[Կատեգորիա:' .. catName .. ']]'
    else
        return '[[Կատեգորիա:' .. catName .. '|' .. sortKey .. ']]'
    end
end

local function hyphen_Y_(name)
	local temp = mw.ustring.gsub(name, '%]%]', '')
	temp = mw.ustring.gsub(temp, "'", '')
	local lastChar = mw.ustring.sub(temp, -1)
	if lastChar == 'ա' or lastChar == 'ո' then
		return 'յ'
	end
	if mw.ustring.find(lastChar, '[բգդեզէըթժիլխծկհձղճմյնշչպջռսվտրցւփքևօֆ]') then
		return ''
	end
	return '-'
end

local function addUm(name)
	return name .. hyphen_Y_(name) .. 'ում'
end

local function addIYi(name)
	return name .. hyphen_Y_(name) .. 'ի'
end 

local function removeUm(name)
	name = mw.ustring.gsub(name, '-ում$', '')
	name = mw.ustring.gsub(name, 'յում$', '')
	name = mw.ustring.gsub(name, 'ում$', '')
	return name
end

local function removeIYi(name)
	name = mw.ustring.gsub(name, '-ի$', '')
	name = mw.ustring.gsub(name, 'յի$', '')
	name = mw.ustring.gsub(name, 'ի$', '')
	return name
end

local function addRd(name)
	if mw.ustring.lower(name) == '1' or mw.ustring.lower(name) == 'մ.թ.ա. 1' then
		return name .. '-ին'
	end
	return name .. '-րդ'
end

local function addNThe(first, nextL)
	-- սա անհրաժեշտորեն ճիշտ չէ (տես [[Վիքիպեդիա:Լեզվի կոմիտեի հորդորակներ/Ը-Ն]]), 
	-- բայց ժամանակավոր արագ լուծում է, մինչև բացառության հանդիպենք
	if mw.ustring.find(mw.ustring.lower(nextL), '[աէըիօո]') then
		return first .. 'ն ' .. nextL
	end
	return first .. 'ը ' .. nextL
end

local function replaceUm(name)
	return mw.ustring.gsub(name, umPattern, addUm)
end

local function replaceIYi(name)
	return mw.ustring.gsub(name, iYiPattern, addIYi)
end

local function replaceUnUm(name)
	return mw.ustring.gsub(name, unUmPattern, removeUm)
end

local function repalceUnIYi(name)
	return mw.ustring.gsub(name, unIYiPattern, removeIYi)
end

local function replaceRd(name)
	return mw.ustring.gsub(name, rdPattern, addRd)
end

local function replaceNThe(name)
	return mw.ustring.gsub(name, nThePattern, addNThe)
end

local function doActions(name)
	-- good enough for now, this won't always work properly for nested actions
	-- e.g. we have to start from the innermost action, not iterate over all actions in an arbitrary order
	-- likely, for now all templates first do un* actions, so we can execute those first
	local found = true
	while found do
		found = false
		if mw.ustring.find(name, unUmPattern) then
			name = replaceUnUm(name)
			found = true
		end
		if mw.ustring.find(name, unIYiPattern) then
			name = repalceUnIYi(name)
			found = true
		end
		if mw.ustring.find(name, umPattern) then
			name = replaceUm(name)
			found = true
		end
		if mw.ustring.find(name, iYiPattern) then
			name = replaceIYi(name)
			found = true
		end
		if mw.ustring.find(name, rdPattern) then
			name = replaceRd(name)
			found = true
		end
		if mw.ustring.find(name, nThePattern) then
			name = replaceNThe(name)
			found = true
		end
	end
	return name
end

local function replacePlaceholders(text, data)
	local result = {}
	if mw.ustring.find(text, yearPlaceholder) then
		text = mw.ustring.gsub(text, yearPlaceholder, getFromattedYear(data.year))
	end
	if mw.ustring.find(text, decadePlaceholder) then
		text = mw.ustring.gsub(text, decadePlaceholder, getFromattedYear(data.decade, data.isBC))
	end
	if mw.ustring.find(text, centuryPlaceholder) then
		text = mw.ustring.gsub(text, centuryPlaceholder, getFromattedYear(data.century, data.isBC))
	end
	if mw.ustring.find(text, millenniumPlaceholder) then
		text = mw.ustring.gsub(text, millenniumPlaceholder, getFromattedYear(data.millennium, data.isBC))
	end
	if mw.ustring.find(text, topicPlaceholder) and data.topic then
		text = mw.ustring.gsub(text, topicPlaceholder, data.topic)
	end
	if mw.ustring.find(text, continentPlaceholder) and data.topic then
		if parentsResolver == nil then
			parentsResolver = require('Մոդուլ:ԵրկիրՄաս')
		end
		local parents = parentsResolver.getParents(data.topic, data.year)
		for i, v in ipairs(parents) do
			local temp = mw.ustring.gsub(text, continentPlaceholder, v)
			table.insert(result, doActions(temp))
		end
	else
		table.insert(result, doActions(text))
	end
	return result
end

local function getYearCategoryIfExists(y, data)
	if y == 0 then
		return nil, nil
	end
	local formatted = getFromattedYear(y)
	local cat = data.yearFormat
	if mw.ustring.find(cat, yearPlaceholder) then
		cat = mw.ustring.gsub(cat, yearPlaceholder, formatted)
	end
	local catName = replacePlaceholders(cat, data)[1]
	if data.showRedYears or checkPageExists('Category:' .. catName) then
		return catName, formatted
	end
	return nil, nil
end

local function getCenturyOrMillenniumLink(num, data, isCentury)
	local linkTextSuffix = 'հազարամյակ'
	local format = data.millenniumFormat
	local placeholder = millenniumPlaceholder
	if isCentury then
		linkTextSuffix = 'դար'
		format = data.centuryFormat
		placeholder = centuryPlaceholder
	end
	local formattedNum = getFromattedYear(num) -- ավելացնել մ.թ.ա.
	local formatted = mw.ustring.gsub(format, placeholder, formattedNum)
	formatted = replacePlaceholders(formatted, data)[1]
	local value = nil
	if num == 1 or num == -1 then
		value = getCategoryAsLink(formatted, formattedNum .. '-ին ' .. linkTextSuffix)
	else
		value = getCategoryAsLink(formatted, formattedNum .. '-րդ ' .. linkTextSuffix)
	end
	return value
end

local function getMillenniumLink(num, data)
	return getCenturyOrMillenniumLink(num, data, false)
end

local function getCenturyLink(num, data)
	return getCenturyOrMillenniumLink(num, data, true)
end

local function getDecadeLink(num, data, isBC)
	local formattedDecade = getFromattedYear(num)
	if num == 0 and isBC then
		formattedDecade = 'Մ.թ.ա. ' .. formattedDecade
	end
	local formatted = mw.ustring.gsub(data.decadeFormat, decadePlaceholder, formattedDecade)
	formatted = replacePlaceholders(formatted, data)[1]
	local value = getCategoryAsLink(formatted, formattedDecade .. '-ականներ' )
	return value
end

local function getYearLink(num, data)
	local formatted = getFromattedYear(num)
	local cat = data.yearFormat
	if mw.ustring.find(cat, yearPlaceholder) then
		cat = mw.ustring.gsub(cat, yearPlaceholder, formatted)
	end
	local catName = replacePlaceholders(cat, data)[1]
	return getCategoryAsLink(catName, formatted)
end

local function getExistingRow(center, leftColumns, rightColumns, data)
	local years = {}
	for i = 1, maxCheckRange do
		if #years >= leftColumns then
			break
		end
		local y = center - i
		local catName, formatted = getYearCategoryIfExists(y, data)
		if catName ~= nil then
			table.insert(years, 1, getCategoryAsLink(catName, formatted))
		end
	end
	local catName, formatted = getYearCategoryIfExists(center, data)
	if catName ~= nil then
		table.insert(years, getCategoryAsLink(catName, formatted))
	end
	local rightItems = 0
	for i = 1, maxCheckRange do
		if rightItems >= rightColumns then
			break
		end
		local y = center + i
		local catName, formatted = getYearCategoryIfExists(y, data)
		if catName ~= nil then
			table.insert(years, getCategoryAsLink(catName, formatted))
			rightItems = rightItems + 1
		end
	end
	return '<center>' .. table.concat(years, ' • ') .. '</center>'
end

local function getZeroDecades(data)
	local result = {}
	table.insert(result, getCategoryAsLink(
		replacePlaceholders(
			mw.ustring.gsub(data.decadeFormat, decadePlaceholder, 'մ.թ.ա. 0'), 
			data)[1], 'Մ.թ.ա. 0-ականներ' ))
	table.insert(result, getCategoryAsLink(
		replacePlaceholders(
			mw.ustring.gsub(data.decadeFormat, decadePlaceholder, '0'), 
			data)[1], '0-ականներ' ))
	return result
end

local function getDecadeRow(data)
	local function insertFormattedDecades(_decade, _data, _table, first)
		if _decade == 0 then
			local zeros = getZeroDecades(_data)
			table.insert(_table, zeros[1])
			table.insert(_table, zeros[2])
		else
			local formattedDecade = getFromattedYear(_decade)
			local formatted = mw.ustring.gsub(_data.decadeFormat, decadePlaceholder, formattedDecade)
			formatted = replacePlaceholders(formatted, _data)[1]
			local value = getCategoryAsLink(formatted, formattedDecade .. '-ականներ')
			if first then 
				table.insert(_table, 1, value)
			else
				table.insert(_table, value)
			end
		end
	end
	local years = {}
	local thisDecade = data.decade
	for i = 1, data.decadeRadius do
		local decade = thisDecade - 10 * i
		insertFormattedDecades(decade, data, years, true)
	end
	insertFormattedDecades(thisDecade, data, years)
	for i = 1, data.decadeRadius do
		local decade = thisDecade + 10 * i
		insertFormattedDecades(decade, data, years)
	end
	return '<center>' .. table.concat(years, ' • ') .. '</center>'
end

local function makeYearsNavigation(data)
    return getExistingRow(data.year, data.leftColumns, data.rightColumns, data)
end

local function makeDecadesNavigation(data)
    return getDecadeRow(data)
end

local function makeCenturiesOrMillenniaNavigation(data, num, isCentury)
	local function insertFormattedNum(_num, _data, _table, first)
		local value = ''
		if isCentury then
			value = getCenturyLink(_num, _data)
		else
			value = getMillenniumLink(_num, _data)
		end
		if first then 
			table.insert(_table, 1, value)
		else
			table.insert(_table, value)
		end
	end
	local nums = {}
	local thisNum = num
	local num = thisNum - 1
	local done = 0
	local radius = data.millenniumRadius
	if isCentury then
		radius = data.centuryRadius
	end
	while done < radius do
		if num == 0 then
			num = -1
		end
		insertFormattedNum(num, data, nums, true)
		done = done + 1
		num = num - 1
	end
	insertFormattedNum(thisNum, data, nums)
	num = thisNum + 1
	done = 0
	for i = 1, radius do
		if num == 0 then
			num = 1
		end
		insertFormattedNum(num, data, nums)
		done = done + 1
		num = num + 1
	end
	return '<center>' .. table.concat(nums, ' • ') .. '</center>'
end

local function makeCenturiesNavigation(data)
	return makeCenturiesOrMillenniaNavigation(data, data.century, true)
end

local function makeMillenniaNavigation(data)
	return makeCenturiesOrMillenniaNavigation(data, data.millennium, false)
end

local function makeMillenniumBox(data)
	local result = '\n{| id="toc" align=center'
	result = result .. '\n|-'

	for centIndex = 1, 10 do
		local century = (data.millennium - 1) * 10 + centIndex
		result = result .. '\n|-'
		result = result .. '\n|' .. getCenturyLink(century, data) .. ' &mdash; '
		for decadeIndex = 0, 9 do
			local decade = (century - 1) * 100 + 10 * decadeIndex
			result = result .. getDecadeLink(decade, data, data.isBC)
			if decadeIndex ~= 9 then
				result = result .. ' • '
			end
		end
	end

	result = result .. '\n|}\n'
	return result
end

local function makeCenturyBox(data)
	local result = '\n{| id="toc" align=center'
	result = result .. '\n|-'

	for centIndex = 0, 9 do
		local decade = (data.century - data.dir) * 100 + data.dir * centIndex * 10
		result = result .. '\n|-'
		result = result .. '\n|' .. getDecadeLink(decade, data, data.isBC) .. ' &mdash; '
		for yearIndex = 1, 10 do
			local year = decade + data.dir * yearIndex
			result = result .. getYearLink(year, data)
			if yearIndex ~= 10 then
				result = result .. ' • '
			end
		end
	end

	result = result .. '\n|}\n'
	return result
end

local catData = {}

local function prepareCategoryData(args)
	local function getTimeValueFromTitle(_title, _isBC)
		local result = tonumber(mw.ustring.match(_title, '(%d%d?%d?%d?)'))
		if _isBC then
			result = -result
		end
		return result
	end

    catData.titleFormat = args['title_format']
    catData.yearFormat = args['year_format']
    if args['title'] == nil then
        local title = mw.title.getCurrentTitle()
        if title.namespace ~= 14 then
            catData.aborted = true
            catData.namespace = title.namespace
            return
        end
        catData.title = title.text
    else
        catData.title = args['title']
    end
    catData.isBC = mw.ustring.find(catData.title, '[Մմ].թ.ա.')
	if catData.isBC then
		catData.dir = -1 -- լիքը ստուգումներից խուսափելու համար
	else
		catData.dir = 1
	end
	local timeValue = getTimeValueFromTitle(catData.title, catData.isBC)
    if catData.isYear then
		catData.year = timeValue
		catData.decade = getDecade(catData.year)
		catData.century = getCentury(catData.year)
		if catData.yearFormat == nil then
			catData.yearFormat = catData.titleFormat
		end
    elseif catData.isDecade then
		catData.year = timeValue
		catData.decade = timeValue
		catData.century = getCentury(catData.decade + catData.dir * 5)
	elseif catData.isCentury then
		catData.century = timeValue
    elseif catData.isMillennium then
		catData.millennium = timeValue
    end
    if not catData.isMillennium then
        catData.millennium = getMillenniumFromCentury(catData.century)
    end

    if args['topic_pattern'] ~= nil and mw.text.trim(args['topic_pattern']) then
		catData.topic = mw.ustring.match(catData.title, mw.text.trim(args['topic_pattern']))
	end
    if args['header'] then
		catData.header = mw.getCurrentFrame():preprocess(replacePlaceholders(mw.text.unstripNoWiki(args['header']), catData)[1])
    else
        catData.header = ''
	end
    catData.leftColumns = getNumberArgOrDefault(args['left_columns'], 5)
    catData.rightColumns = getNumberArgOrDefault(args['right_columns'], 5)
    catData.leftColumns = getNumberArgOrDefault(args['columns'], catData.leftColumns)
    catData.rightColumns = getNumberArgOrDefault(args['columns'], catData.rightColumns)
    catData.cats = ''
    for i, v in ipairs(args) do
		local cats = replacePlaceholders(v, catData)
		for _, catName in ipairs(cats) do
            if catName ~= nil then
                local trimed = mw.text.trim(catName)
                if trimed ~= '' then
                    catData.cats = catData.cats .. getCategory(trimed, nil)
                end
            end
		end
	end
    catData.showDecades = args['show_decades'] == 'yes'
    catData.showYears = args['show_years'] == 'yes'
    catData.showCenturies = args['show_centuries'] == 'yes'
    catData.showMillennia = args['show_millennia'] == 'yes'
    catData.showRedYears = args['show_red_years'] == 'yes'
    catData.showMillenniumBox = args['show_millennium_box'] == 'yes'
	catData.showCenturyBox = args['show_century_box'] == 'yes'
    catData.decadeRadius = getNumberArgOrDefault(args['decade_radius'], 2)
    catData.decadeFormat = args['decade_format']
    if catData.decadeFormat == nil and not catData.isYear then
        catData.decadeFormat = catData.titleFormat
    end
    if catData.decadeFormat == nil then
    	catData.decadeFormat = mw.ustring.gsub(catData.titleFormat, yearPlaceholder, decadePlaceholder .. '-ականներ')
    end
    if catData.decadeFormat == nil then
    	catData.showDecades = 'no'
    end
    catData.centuryRadius = getNumberArgOrDefault(args['century_radius'], 2)
    catData.centuryFormat = args['century_format']
    if catData.centuryFormat == nil and catData.isCentury then
    	catData.centuryFormat = catData.titleFormat
    end
    catData.millenniumRadius = getNumberArgOrDefault(args['millennium_radius'], 2)
    catData.millenniumFormat = args['millennium_format']
    if catData.millenniumFormat == nil and catData.isMillennium then
    	catData.millenniumFormat = catData.titleFormat
    end
end

local function main(args)
    local result = ''
    prepareCategoryData(args)
    if catData.aborted then
        if catData.namespace == 10 then
        	local key = mw.title.getCurrentTitle().text
        				:gsub('^Տասնամյակ ', '')
        				:gsub('^Տարեթիվ ', '')
        				:gsub('^Դար ', '')
        				:gsub('^Հազարամյակ ', '')
        				:gsub('^ըստ ', '')
            return '[[Կատեգորիա:Վիքիպեդիա:ԺամանակիԿատեգորիա օգտագործող կաղապարներ|' .. key ..']][[Կատեգորիա:Կաղապարներ:Կատեգորիաների համար|' .. key ..']]'
        end
        return ''
    end
    result = result .. catData.header
    if catData.showYears then
        result = result .. makeYearsNavigation(catData)
    end
    if catData.showDecades then
        result = result .. makeDecadesNavigation(catData)
    end
    if catData.showCenturies then
    	result = result .. makeCenturiesNavigation(catData)
    end
    if catData.showMillennia then
    	result = result .. makeMillenniaNavigation(catData)
    end
	if catData.showMillenniumBox then
		result = result .. makeMillenniumBox(catData)
	end
	if catData.showCenturyBox then
		result = result .. makeCenturyBox(catData)
	end
    if not args['nocat'] then
    	result = result .. catData.cats
    end
    if args['debug'] ~= nil then
        return mw.getCurrentFrame():preprocess('<pre>\n' .. result .. '\n</pre>')
    end
    return result
end

function p.yearCategory(frame)
	thisFrame = frame
    catData.isYear = true
    catData.isDecade = false
    catData.isCentury = false
    catData.isMillennium = false
    local args = frame:getParent().args
    args['show_years'] = getValueOrDefault(args['show_years'], 'yes')
    args['show_decades'] = getValueOrDefault(args['show_decades'], 'yes')
    args['show_centuries'] = getValueOrDefault(args['show_centuries'], 'no')
    args['show_millennia'] = getValueOrDefault(args['show_millennia'], 'no')
    return main(args)
end

function p.decadeCategory(frame)
	thisFrame = frame
    catData.isYear = false
    catData.isDecade = true
    catData.isCentury = false
    catData.isMillennium = false
    local args = frame:getParent().args
    args['show_years'] = getValueOrDefault(args['show_years'], 'no')
    args['show_decades'] = getValueOrDefault(args['show_decades'], 'yes')
    args['show_centuries'] = getValueOrDefault(args['show_centuries'], 'no')
    args['show_millennia'] = getValueOrDefault(args['show_millennia'], 'no')
    return main(args)
end

function p.centuryCategory(frame)
	thisFrame = frame
    catData.isYear = false
    catData.isDecade = false
    catData.isCentury = true
    catData.isMillennium = false
    local args = frame:getParent().args
    args['show_years'] = getValueOrDefault(args['show_years'], 'no')
    args['show_decades'] = getValueOrDefault(args['show_decades'], 'no')
    args['show_centuries'] = getValueOrDefault(args['show_centuries'], 'yes')
    args['show_millennia'] = getValueOrDefault(args['show_millennia'], 'no')
    return main(args)
end

function p.millenniumCategory(frame)
	thisFrame = frame
    catData.isYear = false
    catData.isDecade = false
    catData.isCentury = false
    catData.isMillennium = true
    local args = frame:getParent().args
    args['show_years'] = getValueOrDefault(args['show_years'], 'no')
    args['show_decades'] = getValueOrDefault(args['show_decades'], 'no')
    args['show_centuries'] = getValueOrDefault(args['show_centuries'], 'no')
    args['show_millennia'] = getValueOrDefault(args['show_millennia'], 'yes')
    return main(args)
end
return p