Module:Category described in year/sandbox: Difference between revisions

Content deleted Content added
Place upper limit on acceptable minYear value
Further deprecate decade
Line 133:
local currYDCF = nil --possible future values: year/decade/century/formal
local currYear = mw.ustring.match(currCat, 'described in (%d%d%d%d)$')
local currDeca = mw.ustring.match(currCat, 'described in the (%d%d%d%d)s$') --deprecated
local currCent = mw.ustring.match(currCat, 'described in the (%d+)[snrt][tdh] century$')
local currFrml = mw.ustring.match(currCat, 'by year of (formal) description$')
local lastCent, nextCent = nil, nil --used with currYear & currCent
local parentDeca, parentCent = nil, nil --used with currYear & currDeca
local minYear = tonumber(conf[currGroup].minyear)
if minYear == nil or
Line 145:
if currYear then
currYDCF = 'year'
parentDeca = mw.ustring.match(currYear, '^(%d%d%d)%d$') .. '0'
if mw.ustring.match(currYear, '^%d%d00') then --1900 in 19th century
parentCent = mw.ustring.match(currYear, '^%d%d')
Line 155 ⟶ 154:
elseif currDeca then
currYDCF = 'decade'
bConfError = true
parentDeca = mw.ustring.match(currDeca, '^(%d%d%d)%d$') .. '0'
trackingCategories[2] = '[[Category:Described in year error|D]]' --invalid decade-parent (deprecated)
parentCent = mw.ustring.match(parentDeca, '^%d%d') + 1
elseif currCent then
currYDCF = 'century'
Line 177 ⟶ 176:
elseif conf[currGroup][currYDCF] == nil then
bConfError = true
trackingCategories[2] = '[[Category:Described in year error|2]]' --year/decade/century/formal key missing
else
if conf[currGroup][currYDCF].description == nil then
Line 196 ⟶ 195:
end
--produce description, evaluate %variables%
description = conf[currGroup][currYDCF].description
if mw.ustring.match(description, '%%year%%') then
if currYear then description = mw.ustring.gsub(description, '%%year%%', currYear) --"2011"
else description = mw.ustring.gsub(description, '%%year%%', 'this year') end
end
if mw.ustring.match(description, '%%decade%%') then
if currDeca then description = mw.ustring.gsub(description, '%%decade%%', currDeca .. 's') --"2010s"
else description = mw.ustring.gsub(description, '%%decade%%', 'this decade') end
end
if mw.ustring.match(description, '%%century%%') then
Line 231 ⟶ 226:
nav = frame:expandTemplate{ title = 'Navseasoncats', args = args }
end
if parent == 'decadecentury' then
if isNilOrEmpty(sortkey) then sortkey = currYear end --default to currYear
categories[iparent] = '[[Category:'..currGroup..' described in the '..parentDeca..'s|'..sortkey..']]'
elseif parent == 'century' then
if isNilOrEmpty(sortkey) then sortkey = currYear end --default to currYear
categories[iparent] = '[[Category:'..currGroup..' described in the '..addOrd(parentCent)..' century|'..sortkey..']]'
Line 260 ⟶ 252:
trackingCategories[2] = '[[Category:Described in year error|Y]]' --invalid year-parent
end
--[[================== Decade (deprecated) ===================]]
elseif currYDCF == 'decade' then
trackingCategories[2] = '[[Category:Described in year error|D]]' --invalid decade-parent (deprecated)
--[[======================== Century =========================]]