Module:Category described in year: Difference between revisions

Content deleted Content added
min=1753 for plants per current cats
Automatically place {{Category TOC}} if cat size >= 'tocmin' (initially set to 401 since each cat page displays 200); rename 'map' table to 'conf' due to expanded scope; from sandbox
Line 2:
 
--case sensitive conf/map table
local mapconf = {
--[[
Line 8:
'Spiders' use year -> decade -> century.
Any category group (i.e. Birds/Crustaceans/Molluscs/etc.) NOT explicitly outlined here in mapconf{} will follow the 'Fish' tree for that group.
To create a customized tree, like 'Spiders' below, add it to the bottom of the mapconf{} table, following the same general table format.
]]--
['tocmin'] = 401, --integer; minimum category size to place {{Category TOC}} on
['Fish'] = { --group
Line 87 ⟶ 89:
local nav = nil
local description = nil
local toc = nil
local categories = {}
local trackingCategories = {
Line 107 ⟶ 110:
--determine current/related/adjacent cats' properties/vars/etc
local currGroup = mw.ustring.match(currCat, '^%w+') --Fish/Spiders/default/etc.
if mapconf[currGroup] == nil then mapconf[currGroup] = mapconf['Fish'] end --'Fish' == default
local currYDC = nil --year/decade/century
local currYear = mw.ustring.match(currCat, 'in (%d%d%d%d)$')
Line 115 ⟶ 118:
local parentCent = nil --used with currYear (i.e. Fish) & currDeca (i.e. Spiders)
local lastCent, nextCent = nil, nil --used with currYear (i.e. Fish) & currCent (i.e. Fish)
local minYear = tonumber(mapconf[currGroup].min)
if (minYear == nil or (minYear and minYear <= 1700)) then
minYear = 1758 --default to 1758 per ICZN Art. 5
Line 141 ⟶ 144:
end
--produce description & toc
description = mapconf[currGroup][currYDC].description
if mw.ustring.match(description, '%%year%%') then
if currYear then description = mw.ustring.gsub(description, '%%year%%', currYear)
else description = mw.ustring.gsub(description, '%%year%%', 'this year') end
end
if mw.site.stats.pagesInCategory(currCat, 'pages') >= conf['tocmin'] then --expensive
toc = frame:expandTemplate{ title = 'Category TOC' }
end
Line 151 ⟶ 157:
local iparent = 1
local parenti = 'parent' .. iparent
while mapconf[currGroup][currYDC][parenti] do
local parent = mapconf[currGroup][currYDC][parenti]
if currYDC == 'year' then
Line 195 ⟶ 201:
iparent = iparent + 1
parenti = 'parent' .. iparent
end --end while mapconf[currGroup][currYDC][parenti]
for _, category in pairs(categories) do
Line 207 ⟶ 213:
--produce header
--TODO: test/see if a similar commons cat exists and, if so, include it in the header
if nav then header = nav end
if description and description ~= '' then header = header .. '<br />' .. description end
header = mw.text.trim(header)
if toc then header = header .. '<br />' .. toc end
--append header to outString