Module:Category described in year: Difference between revisions

Content deleted Content added
m --ce
Add description field to year/decade/century cats, add header & nav template(s) from current fish cats
Line 1:
require('Module:No globals')
 
--case sensitive conf/map table
local map = {
['Fish'] = { --group
['year'] = { --[[Category:Fish described in 1901]]
local header ['description'] = 'tbd year; This category should only contain species articles, etc....',
['parent1'] = 'century', --'year', '/decade'/century, i.e. 'century' for [[Category:Fish described in the 20th century]]
['parent2'] = 'Animals', --[[Category:Animals described in the 20th century]]
},
['century'] = { --[[Category:Fish described in the 20th century]]
['description'] = 'tbd century; container category, etc....',
['parent1'] = 'formal', --[[Category:Fish by year of formal description]]
['parent2'] = 'Animals', --[[Category:Animals described in the 20th century]]
Line 13 ⟶ 16:
},
}
 
local function addOrd( i ) --20 -> 20th, etc.
if i and tonumber(i) then
local ords = ''tostring(i)
local lastd = mw.ustring.match(s, '%d$')
if lastd == '1' then ordreturn =s .. 'st'
elseif lastd == '2' then ordreturn =s .. 'nd'
elseif lastd == '3' then ordreturn =s .. 'rd'
elseif lastd ~= nil then return s .. 'th'
else ord =return 'th' end
else
return ''
end
end
 
local p = {}
Line 18 ⟶ 35:
function p.autodetect( frame )
local currentTitle = mw.title.getCurrentTitle()
local outStringnav = ''nil
local description = nil
local header = ' ' --will contain header template(s), nav bar, and category description text
local categories = {}
local outString = nil
local header = 'tbd; This category should only contain species articles, etc....'
local outString = ''
if currentTitle.namespace == 14 then --Category:
Line 29 ⟶ 48:
local currYear = mw.ustring.match(currCat, '%d%d%d%d$')
local currCent = mw.ustring.match(currCat, 'the (%d+)[snrt][tdh] century')
local parentCent = nil --only used when currYear
if currYear then currYDC = 'year' end
local lastCent, nextCent = nil, nil --used with currYear and currCent
if currCent then currYDC = 'century' end
if currYear then currYDC = 'year' end
local parentCent currYDC = 'year'
if mw.ustring.match(currYear, '^%d%d00') then --1900 in 19th century
local ord = ''
if currYear then parentCent = 1 + mw.ustring.match(currYear, '^%d%d') end
else --1901 in 20th century
if parentCent then
local lastd parentCent = 1 + mw.ustring.match(parentCentcurrYear, '^%d%d$')
end
if lastd == 1 then ord = 'st'
if lastCent = parentCent then- 1
elseif lastd == 2 then ord = 'nd'
nextCent = parentCent + 1
elseif lastd == 3 then ord = 'rd'
elseif currDeca then
else ord = 'th' end
elseif currCent then
if currCent then currYDC = 'century' end
lastCent = currCent - 1
nextCent = currCent + 1
else
return '' --add err msg?
end
--produce cats
local iparent = 1
local parenti = 'parent' .. iparent
while currYDC and map[currGroup][currYDC][parenti] do
iflocal parent = map[currGroup][currYDC][parenti] == 'Animals' then
if description == nil then
description = map[currGroup][currYDC].description
end
if currYDC == 'year' then
if map[currGroup][currYDC][parenti]nav == 'century'nil then
categories[iparent]local args = '[[:Category:'{ ..year = currYear, cat = currGroup .. ' described in the ' .. parentCent .. ord .. ' century]]'}
nav = frame:expandTemplate{ title = 'Category in year', args = args }
end
if map[currGroup][currYDC][parenti] == 'Animals' then
if parent == 'century' then
categories[iparent] = '[[:Category:Animals described in ' .. currYear .. ']]'
categories[iparent] = '[[:Category:' .. currGroup .. ' described in the ' .. addOrd(parentCent) .. ' century]]'
elseif parent == 'decade' then
else --i.e. Animals; require capital first letter?
categories[iparent] = '[[:Category:Animals' .. parent .. ' described in ' .. currYear .. ']]'
end
elseif currYDC == 'decade' then
elseif currYDC == 'century' then
if map[currGroup][currYDC][parenti]nav == 'formal'nil then
nav = frame:expandTemplate{ title = 'Container category' }
categories[iparent] = '[[:Category:' .. currGroup .. ' by year of formal description|' .. currCent .. ord .. ']]'
local args = { currGroup .. ' described in the ' .. addOrd(lastCent) .. ' century',
currGroup .. ' described in the ' .. addOrd(nextCent) .. ' century' }
nav = nav .. frame:expandTemplate{ title = 'Category pair', args = args }
end
if map[currGroup][currYDC][parenti]parent == 'Animalsformal' then
categories[iparent] = '[[:Category:Animals' described.. incurrGroup the.. ' ..by currCentyear of formal description|' .. ordaddOrd(currCent) .. ' century]]'
else --i.e. Animals; require capital first letter?
categories[iparent] = '[[:Category:' .. currGroupparent .. ' bydescribed yearin ofthe formal description|' .. addOrd(currCent) .. ord' .. 'century]]'
end
end
Line 66 ⟶ 111:
parenti = 'parent' .. iparent
end
 
elseif currentTitle.namespace == 10 then --Module:/Template: sandbox/testcases/doc
end
outString =--produce header .. outString
if nav then header = nav end
if description then header = header .. '\n\n' .. description end
header = mw.text.trim(header)
if outString then outString = outString .. header
else outString = header end
if string.sub(currentTitle.subpageText,1,9) == 'testcases' then