Module:Category described in year: Difference between revisions

Content deleted Content added
+Plants century description & nil check
Stricter current/parent category checks; implement Category:Described in year error, where sortkey = error code; allow/accept %decade% and %century% vars in description; from sandbox
Line 95:
local categories = {}
local trackingCategories = {
[1] = nil'', --placeholder for [[Category:Described in year unknown category]]
[2] = '', --placeholder for [[Category:Described in year error]]
}
local outString = nil
Line 111 ⟶ 112:
currCat = mw.ustring.gsub(parentArg, 'Category:', '')
currQID = mw.wikibase.getEntityIdForTitle('Category:' .. currCat)
else --currQID & currCat both nil
else
trackingCategories[2] = '[[Category:Described in year error|P]]' --missing a category parameter outside category-space
return --add err msg?
end
end
--find commons link(s) & produce {{Commons}} template(s)
if currQID then
local commonsLinks = {}
Line 129 ⟶ 130:
end
end
--check "Other sites" sitelink
local currSiteLinks = currEntity.sitelinks
Line 142:
end
end
--ignore duplicates
--produce {{Commons}} template(s) (ignore duplicates)
if commonsLinks[1] then
commons = frame:expandTemplate{ title = 'Commons', args = { commonsLinks[1] } }
Line 156 ⟶ 157:
if conf[currGroup] == nil then conf[currGroup] = conf['Fish'] end --'Fish' == default
local currYDC = nil --year/decade/century
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$')
local currCent = mw.ustring.match(currCat, 'described in the (%d+)[snrt][tdh] century$')
local parentDeca = nil --used with currYear (i.e. Spiders) & currDeca (i.e. Spiders)
local parentCent = nil --used with currYear (i.e. Fish) & currDeca (i.e. Spiders)
Line 185 ⟶ 186:
nextCent = currCent + 1
else
trackingCategories[2] = '[[Category:Described in year error|N]]' --invalid category name
return '' --add err msg?
end
--produce description & toc
if currYDC then
description = conf[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.ustring.match(description, '%%decade%%') then
if mw.site.stats.pagesInCategory(currCat, 'pages') >= conf['tocmin'] then --expensive
if currDeca then description = mw.ustring.gsub(description, '%%decade%%', currDeca .. 's') --2000s
local args = { numerals = 'no' }
else description = mw.ustring.gsub(description, '%%decade%%', 'this decade') end
toc = frame:expandTemplate{ title = 'Category TOC', args = args }
end
if mw.ustring.match(description, '%%century%%') then
if currCent then description = mw.ustring.gsub(description, '%%century%%', addOrd(currCent)) --21st
else description = mw.ustring.gsub(description, '%%century%%', 'this century') end
end
if mw.site.stats.pagesInCategory(currCat, 'pages') >= conf['tocmin'] then --expensive
local args = { numerals = 'no' }
toc = frame:expandTemplate{ title = 'Category TOC', args = args }
end
end
--produce cats & navs
if currYDC then
local iparent = 1
local iparent = 1
local parenti = 'parent' .. iparent
while conf[currGroup][currYDC][parenti] do
local parent = conf[currGroup][currYDC][parenti]
if currYDC == 'year' then
if nav == nil then
local args = { year = currYear, min = minYear, cat = currGroup .. ' described in' }
nav = frame:expandTemplate{ title = 'Category in year', args = args }
end
if parent == 'decade' then
categories[iparent] = '[[Category:' .. currGroup .. ' described in the ' .. parentDeca .. 's]]'
elseif parent == 'century' then
categories[iparent] = '[[Category:' .. currGroup .. ' described in the ' .. addOrd(parentCent) .. ' century]]'
else --i.e. Animals; require capital first letter?
categories[iparent] = '[[Category:' .. parent .. ' described in ' .. currYear .. ']]'
end
elseif if currYDC == 'decadeyear' then
if nav == nil then
local args = { year = currYear, min = minYear, cat = currGroup .. ' described in' }
nav = frame:expandTemplate{ title = 'Container category' }
nav = frame:expandTemplate{ title = 'Category in year', args = args }
local args = { decade = currDeca, min = minYear, cat = currGroup .. ' described in the' }
end
nav = frame:expandTemplate{ title = 'Category by decade', args = args }
if parent == 'decade' then
end
categories[iparent] = '[[Category:' .. currGroup .. ' described in the ' .. parentDeca .. 's]]'
if parent == 'century' then
elseif parent == 'century' then
categories[iparent] = '[[Category:' .. currGroup .. ' described in the ' .. addOrd(parentCent) .. ' century]]'
categories[iparent] = '[[Category:' .. currGroup .. ' described in the ' .. addOrd(parentCent) .. ' century]]'
else --i.e. Animals; require capital first letter?
elseif mw.ustring.match(parent, '^%u%l') then --i.e. Animals
categories[iparent] = '[[Category:' .. parent .. ' described in the ' .. currDeca .. 's]]'
categories[iparent] = '[[Category:' .. parent .. ' described in ' .. currYear .. ']]'
else
trackingCategories[2] = '[[Category:Described in year error|Y]]' --invalid year-parent
end
elseif currYDC == 'decade' then
if nav == nil then
nav = frame:expandTemplate{ title = 'Container category' }
local args = { decade = currDeca, min = minYear, cat = currGroup .. ' described in the' }
nav = frame:expandTemplate{ title = 'Category by decade', args = args }
end
if parent == 'century' then
categories[iparent] = '[[Category:' .. currGroup .. ' described in the ' .. addOrd(parentCent) .. ' century]]'
elseif mw.ustring.match(parent, '^%u%l') then --i.e. Animals
categories[iparent] = '[[Category:' .. parent .. ' described in the ' .. currDeca .. 's]]'
else
trackingCategories[2] = '[[Category:Described in year error|D]]' --invalid decade-parent
end
elseif currYDC == 'century' then
if nav == nil then
nav = frame:expandTemplate{ title = 'Container category' }
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 parent == 'formal' then
categories[iparent] = '[[Category:' .. currGroup .. ' by year of formal description|' .. addOrd(currCent) .. ']]'
elseif mw.ustring.match(parent, '^%u%l') then --i.e. Animals
categories[iparent] = '[[Category:' .. parent .. ' described in the ' .. addOrd(currCent) .. ' century]]'
else
trackingCategories[2] = '[[Category:Described in year error|C]]' --invalid century-parent
end
end
iparent = iparent + 1
elseif currYDC == 'century' then
ifparenti nav= =='parent' nil.. theniparent
end --while conf[currGroup][currYDC][parenti] do
nav = frame:expandTemplate{ title = 'Container category' }
end --if currYDC then
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 parent == 'formal' then
categories[iparent] = '[[Category:' .. currGroup .. ' by year of formal description|' .. addOrd(currCent) .. ']]'
else --i.e. Animals; require capital first letter?
categories[iparent] = '[[Category:' .. parent .. ' described in the ' .. addOrd(currCent) .. ' century]]'
end
end
iparent = iparent + 1
parenti = 'parent' .. iparent
end --end while conf[currGroup][currYDC][parenti]
for _, category in pairs(categories) do
Line 272 ⟶ 291:
--append cats to outString
if currentTitle.namespace == 14 then --Category:
if table.maxn(categories) > 0 then outString = outString .. table.concat(categories) .. table.concat(trackingCategories)end
outString = outString .. table.concat(trackingCategories)
else
if table.maxn(categories) > 0 then --might be 0 if there's an error before setting cats
outString = outString .. '<br />' ..
outString = outString .. '<br />' .. mw.ustring.gsub(table.concat(categories, '<br />'), '%[%[', '[[:')
if table.maxn(trackingCategories) > 0 then
outString = outString .. '<br />' ..
mw.ustring.gsub(table.concat(trackingCategories, '<br />'), '%[%[', '[[:')
end
outString = outString .. '<br />' .. mw.ustring.gsub(table.concat(trackingCategories, '<br />'), '%[%[', '[[:')
outString = mw.ustring.gsub(outString, '<br /><br />', '<br />') --produced by empty ('') first/consecutive tracking cat/s
outString = mw.ustring.gsub(outString, '<br /><br />', '<br />') --jic (use while loop if #trackingCategories >= 3 or 4 )
end