Content deleted Content added
Tom.Reding (talk | contribs) m --ce |
Tom.Reding (talk | contribs) 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]]
['parent1'] = '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 lastd = mw.ustring.match(s, '%d$')
elseif lastd ~= nil then return s .. 'th'
else
return ''
end
end
local p = {}
Line 18 ⟶ 35:
function p.autodetect( frame )
local currentTitle = mw.title.getCurrentTitle()
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 mw.ustring.match(currYear, '^%d%d00') then --1900 in 19th century
▲ local ord = ''
else --1901 in 20th century
if parentCent then▼
end
▲ if lastd == 1 then ord = 'st'
▲ 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
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
if description == nil then
description = map[currGroup][currYDC].description
end
if currYDC == 'year' then
if
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?
end
elseif currYDC == 'decade' then
elseif currYDC == 'century' then
if
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
categories[iparent] = '[[:Category:
else --i.e. Animals; require capital first letter?
▲ categories[iparent] = '[[:Category:' ..
end
end
Line 66 ⟶ 111:
parenti = 'parent' .. iparent
end
elseif currentTitle.namespace == 10 then --Module:/Template: sandbox/testcases/doc
end
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
|