Module:Category described in year: Difference between revisions

Content deleted Content added
add line breaks to stop lint issues
m -spaces for readability; -old toc code; var/ce/condense
Line 1:
require('Module:No globals')
local commonsLink = require('Module:Commons link')
 
local conf = require( 'Module:Category described in year/conf' ) --configuration module
 
--[[==========================================================================]]
Line 34 ⟶ 31:
 
function p.autodetect( frame )
local conf = require( 'Module:Category described in year/conf' ) --configuration module
local commonsLink = require('Module:Commons link')
local currentTitle = mw.title.getCurrentTitle()
local parentArg = frame:getParent().args[1] --accept 1 unnamed category parameter if not in category namespace; required for testing/doc/etc. purposes
Line 44 ⟶ 43:
local toc = nil
local categories = {}
local trackingCategoriestrackingCats = {
[1] = '', --placeholder for [[Category:Described in year unknown category]]
[2] = '', --placeholder for [[Category:Described in year error]]
Line 60 ⟶ 59:
if parentArg then
currCat = mw.ustring.gsub(parentArg, 'Category:', '')
currQID = mw.wikibase.getEntityIdForTitle('Category:' .. currCat)
else --currQID & currCat both nil
if currentTitle.fullText ~= 'Template:Category described in year' then --ignore self...
trackingCategoriestrackingCats[2] = '[[Category:Described in year error|P]]' --missing a category parameter outside category namespace
end
end
Line 83 ⟶ 82:
if currSpeciesWikiTitle then
wikispecies = frame:expandTemplate{ title = 'Wikispecies', args = { currSpeciesWikiTitle } }
end end end end end
end
end
end
end --if currQID then
--[[======================================================================]]
Line 119 ⟶ 114:
currYDCF = 'decade'
bConfError = true
trackingCategoriestrackingCats[2] = '[[Category:Described in year error|D]]' --invalid decade-parent (deprecated)
elseif currCent then
currYDCF = 'century'
Line 126 ⟶ 121:
else
bConfError = true
trackingCategoriestrackingCats[2] = '[[Category:Described in year error|N]]' --invalid category name
end
Line 135 ⟶ 130:
if conf[currGroup] == nil then
bConfError = true
trackingCategoriestrackingCats[2] = '[[Category:Described in year error|1]]' --group (Bacteria/Plants/etc.) key missing from conf
elseif conf[currGroup][currYDCF] == nil then
bConfError = true
trackingCategoriestrackingCats[2] = '[[Category:Described in year error|2]]' --year/century/formal key missing
else
if conf[currGroup][currYDCF].description == nil then
bConfError = true
trackingCategoriestrackingCats[2] = '[[Category:Described in year error|3]]' --description key missing
end
if conf[currGroup][currYDCF].parent1 == nil then
bConfError = true
trackingCategoriestrackingCats[2] = '[[Category:Described in year error|4]]' --parent key missing
end
end
Line 168 ⟶ 163:
end
--produce toc
-- {{CatAutoTOC}} now provided via [[Template:Category described in year]]
--[[
if mw.site.stats.pagesInCategory(currCat, 'pages') >= conf['tocmin'] then --expensive
local args = { numerals = 'no' }
toc = frame:expandTemplate{ title = 'Category TOC', args = args }
end
--]]
 
--produce cats & navs
local iparent = 1
local parenti = 'parent' .. iparent
local sortkeyi = 'sortkey' .. iparent
while conf[currGroup][currYDCF][parenti] do
local parent = conf[currGroup][currYDCF][parenti]
Line 218 ⟶ 204:
categories[iparent] = '[[Category:'..parent..' described in '..currYear..sortkey..']]'
else
trackingCategoriestrackingCats[2] = '[[Category:Described in year error|Y]]' --invalid year-parent
end
Line 255 ⟶ 241:
categories[iparent] = '[[Category:'..parent..' described in the '..addOrd(currCent)..' century'..sortkey..']]'
else
trackingCategoriestrackingCats[2] = '[[Category:Described in year error|C]]' --invalid century-parent
end
Line 277 ⟶ 263:
categories[iparent] = '[[Category:Paleontology by year|'..sortkey..']]'
else
trackingCategoriestrackingCats[2] = '[[Category:Described in year error|F]]' --invalid formal-parent
end
--[[========================= Error ==========================]]
else
trackingCategoriestrackingCats[2] = '[[Category:Described in year error|U]]' --unknown configuration
end
iparent = iparent + 1
parenti = 'parent' .. iparent
sortkeyi = 'sortkey' .. iparent
end --while conf[currGroup][currYDCF][parenti] do
end --if bConfError == false then
Line 295 ⟶ 281:
local cat = mw.ustring.match(category, '%[%[Category:([%w%s]+)')
if mw.title.new(cat, 14).exists == false then
trackingCategoriestrackingCats[1] = '[[Category:Described in year unknown category]]'
break
end
Line 303 ⟶ 289:
--build header & rem surrounding whitespace
local br = '<br />'
if nav then header = nav end
if portal then header = header .. '\n' .. portal end
if commons then header = header .. '\n' .. commons end
if wikispecies then header = header .. '\n' .. wikispecies end
if description and description ~= '' then
header = header .. description
elseif portal or commons or wikispecies then
header = mw.ustring.gsub(header, '<br ?/?>', '')
end
if toc then header = header .. '<br />' .. toc end
header = mw.text.trim(header)
header = mw.ustring.gsub(header, '^<br />', '')
Line 318 ⟶ 305:
--append header to outString
if outString then outString = outString .. header
else outString = header end
--append cats to outString
if currentTitle.namespace == 14 then --category namespace
if table.maxn(categories) > 0 then outString = outString .. table.concat(categories) end
outString = outString .. table.concat(trackingCategoriestrackingCats)
else
if table.maxn(categories) > 0 then --might be 0 if there's an error before setting cats
outString = outString .. '<br />' .. mw.ustring.gsub(table.concat(categories, '<br />'), '%[%[', '[[:')
end
outString = outString .. '<br />' .. mw.ustring.gsub(table.concat(trackingCategoriestrackingCats, '<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 #trackingCategoriestrackingCats >= 3 or 4)
end