Module:Navseasoncats: Difference between revisions

replace newChild hack as Module:ConvertNumeric has now been modified to provide an API function in addition to the #invoke one
m (1 revision imported)
imported>Uzume
(replace newChild hack as Module:ConvertNumeric has now been modified to provide an API function in addition to the #invoke one)
 
Line 1: Line 1:
require[[strict]]
local p = {}
local p = {}
local horizontal = require('Module:List').horizontal
--[[==========================================================================]]
--[[                                Globals                                  ]]
--[[==========================================================================]]


local currtitle = mw.title.getCurrentTitle()
local currtitle = mw.title.getCurrentTitle()
Line 14: Line 20:
local tlistallbwd = {}
local tlistallbwd = {}
local tlistallfwd = {}
local tlistallfwd = {}
local ttrackingcats = { --when reindexing, Ctrl+H 'trackcat(1,' & 'ttrackingcats[1]'
local ttrackingcats = { --when reindexing, Ctrl+H 'trackcat(13,' & 'ttrackingcats[16]'
'', -- [1] placeholder for [[Category:Navseasoncats using cat parameter]]
'', -- [1] placeholder for [[Category:Navseasoncats using cat parameter]]
'', -- [2] placeholder for [[Category:Navseasoncats using testcase parameter]]
'', -- [2] placeholder for [[Category:Navseasoncats using testcase parameter]]
Line 21: Line 27:
'', -- [5] placeholder for [[Category:Navseasoncats range abbreviated (MOS)]]
'', -- [5] placeholder for [[Category:Navseasoncats range abbreviated (MOS)]]
'', -- [6] placeholder for [[Category:Navseasoncats range redirected (base change)]]
'', -- [6] placeholder for [[Category:Navseasoncats range redirected (base change)]]
'', -- [7] placeholder for [[Category:Navseasoncats range redirected (end)]]
'', -- [7] placeholder for [[Category:Navseasoncats range redirected (var change)]] --new
'', -- [8] placeholder for [[Category:Navseasoncats range redirected (MOS)]]
'', -- [8] placeholder for [[Category:Navseasoncats range redirected (end)]]
'', -- [9] placeholder for [[Category:Navseasoncats range redirected (other)]]
'', -- [9] placeholder for [[Category:Navseasoncats range redirected (MOS)]]
'', --[10] placeholder for [[Category:Navseasoncats range gaps]]
'', --[10] placeholder for [[Category:Navseasoncats range redirected (other)]]
'', --[11] placeholder for [[Category:Navseasoncats range irregular]]
'', --[11] placeholder for [[Category:Navseasoncats range gaps]]
'', --[12] placeholder for [[Category:Navseasoncats range irregular, 0-length]]
'', --[12] placeholder for [[Category:Navseasoncats range irregular]]
'', --[13] placeholder for [[Category:Navseasoncats range ends (present)]]
'', --[13] placeholder for [[Category:Navseasoncats range irregular, 0-length]]
'', --[14] placeholder for [[Category:Navseasoncats range ends (blank, MOS)]]
'', --[14] placeholder for [[Category:Navseasoncats range ends (present)]]
'', --[15] placeholder for [[Category:Navseasoncats isolated]]
'', --[15] placeholder for [[Category:Navseasoncats range ends (blank, MOS)]]
'', --[16] placeholder for [[Category:Navseasoncats default season gap size]]
'', --[16] placeholder for [[Category:Navseasoncats isolated]]
'', --[17] placeholder for [[Category:Navseasoncats decade redirected]]
'', --[17] placeholder for [[Category:Navseasoncats default season gap size]]
'', --[18] placeholder for [[Category:Navseasoncats year redirected (base change)]]
'', --[18] placeholder for [[Category:Navseasoncats decade redirected]]
'', --[19] placeholder for [[Category:Navseasoncats year redirected (var change)]] --new
'', --[19] placeholder for [[Category:Navseasoncats year redirected (base change)]]
'', --[20] placeholder for [[Category:Navseasoncats year redirected (other)]]
'', --[20] placeholder for [[Category:Navseasoncats year redirected (var change)]]
'', --[21] placeholder for [[Category:Navseasoncats roman numeral redirected]]
'', --[21] placeholder for [[Category:Navseasoncats year redirected (other)]]
'', --[22] placeholder for [[Category:Navseasoncats nordinal redirected]]
'', --[22] placeholder for [[Category:Navseasoncats roman numeral redirected]]
'', --[23] placeholder for [[Category:Navseasoncats wordinal redirected]]
'', --[23] placeholder for [[Category:Navseasoncats nordinal redirected]]
'', --[24] placeholder for [[Category:Navseasoncats TV season redirected]]
'', --[24] placeholder for [[Category:Navseasoncats wordinal redirected]]
'', --[25] placeholder for [[Category:Navseasoncats using skip-gaps parameter]]
'', --[25] placeholder for [[Category:Navseasoncats TV season redirected]]
'', --[26] placeholder for [[Category:Navseasoncats year and range]]
'', --[26] placeholder for [[Category:Navseasoncats using skip-gaps parameter]]
'', --[27] placeholder for [[Category:Navseasoncats year and decade]]
'', --[27] placeholder for [[Category:Navseasoncats year and range]]
'', --[28] placeholder for [[Category:Navseasoncats decade and century]]
'', --[28] placeholder for [[Category:Navseasoncats year and decade]]
'', --[29] placeholder for [[Category:Navseasoncats in mainspace]]
'', --[29] placeholder for [[Category:Navseasoncats decade and century]]
'', --[30] placeholder for [[Category:Navseasoncats redirection error]]
'', --[30] placeholder for [[Category:Navseasoncats in mainspace]]
'', --[31] placeholder for [[Category:Navseasoncats redirection error]]
}
}
local avoidself =  (not string.match(currtitle.text, 'Navseasoncats with') and
local avoidself =  (not string.match(currtitle.text, 'Navseasoncats with') and
not string.match(currtitle.text, 'Navseasoncats.*/doc') and
not string.match(currtitle.text, 'Navseasoncats.*/doc') and
not string.match(currtitle.text, 'Navseasoncats.*/sandbox') and
not string.match(currtitle.text, 'Navseasoncats.*/sandbox') and
currtitle.text ~= 'Navseasoncats' and  
currtitle.text ~= 'Navseasoncats' and
currtitle.nsText ~= 'User_talk' and
currtitle.nsText ~= 'User_talk' and
currtitle.nsText ~= 'Template_talk' and
currtitle.nsText ~= 'Template_talk' and
Line 59: Line 66:
--[[==========================================================================]]
--[[==========================================================================]]


--Error message handling
--Determine if a category exists (in a function for easier localization).
local function catexists( title )
return mw.title.new( title, 'Category' ).exists
end
 
--Error message handling.
function p.errorclass( msg )
function p.errorclass( msg )
return mw.text.tag( 'span', {class='error mw-ext-cite-error'}, '<b>Error!</b> '..string.gsub(msg, '&#', '&amp;#') )
return mw.text.tag( 'span', {class='error mw-ext-cite-error'}, '<b>Error!</b> '..string.gsub(msg, '&#', '&amp;#') )
end
end


--Failure handling
--Failure handling.
function p.failedcat( errors, sortkey )
function p.failedcat( errors, sortkey )
if avoidself then
if avoidself then
Line 71: Line 83:
end
end
return ''
return ''
end
--Tracking cat handling.
-- key: 15 (when reindexing ttrackingcats{}, Ctrl+H 'trackcat(13,' & 'ttrackingcats[16]')
-- cat: 'Navseasoncats isolated'; '' to remove
--Used by main, all nav_*(), & several utility functions.
local function trackcat( key, cat )
if avoidself and key and cat then
if cat ~= '' then
ttrackingcats[key] = '[['..testcasecolon..'Category:'..cat..']]'
else
ttrackingcats[key] = ''
end
end
return
end
end


--Check for unknown parameters.
--Check for unknown parameters.
--Used by main only.
--Used by main only.
function checkforunknownparams( tbl )
local function checkforunknownparams( tbl )
local knownparams = {
local knownparams = {
['min'] = 'min',
['min'] = 'min',
Line 89: Line 116:
if knownparams[k] == nil then
if knownparams[k] == nil then
trackcat(3, 'Navseasoncats using unknown parameter')
trackcat(3, 'Navseasoncats using unknown parameter')
break
end
end
end
end
end
end


--Tracking cat handling.
--Check for nav_*() navigational isolation (not necessarily an error).
-- key: 15 (when reindexing ttrackingcats{}, Ctrl+H 'trackcat(1,' & 'ttrackingcats[1]')
--Used by all nav_*().
-- cat: 'Navseasoncats isolated'; '' to remove
local function isolatedcat()
--Used by main, all nav_*(), & several utility functions.
if nexistingcats == 0 then
function trackcat( key, cat )
trackcat(16, 'Navseasoncats isolated')
if avoidself and key and cat then
end
if cat ~= '' then
end
ttrackingcats[key] = '[['..testcasecolon..'Category:'..cat..']]'
else
ttrackingcats[key] = ''
end
end
return
end


--Check for nav_*() navigational isolation (not necessarily an error).
--Returns the target of {{Category redirect}}, if it exists, else returns the original cat.
--Used by all nav_*().
--{{Title year}}, etc., if found, are evaluated.
function isolatedcat()
--Used by catlinkfollowr(), and so indirectly by all nav_*().
if nexistingcats == 0 then
local function rtarget( frame, cat )
trackcat(15, 'Navseasoncats isolated')
local catcontent = mw.title.new( cat or '', 'Category' ):getContent()
end
if string.match( catcontent or '', '{{ *[Cc]at' ) then --prelim test
end
local tregex = {
--the following 11 pages (6 condensed) redirect to [[Template:Category redirect]], in descending order, as of 9/2022:
--Similar to {{LinkCatIfExists2}}: make a piped link to a category, if it exists;
'{{ *[Cc]ate?g?o?r?y?[ _]*[rR]edirect', --505+312+243+1 transclusions
--if it doesn't exist, just display the greyed link title without linking.
'{{ *[Cc]atr', --21
--Follows {{Category redirect}}s.
'{{ *[Cc]at[ _]*[rR]edir', --5+3
--Returns {
'{{ *[Cc]at[ _]*[rR]ed', --3+2
-- ['cat'] = cat,
'{{ *[Cc]at[ _]*[mM]ove', --1
'{{ *[Cc]ategory[ _]*[mM]ove', --0
}
for _, v in pairs (tregex) do
local rtarget = mw.ustring.match( catcontent, v..'%s*|%s*([^|}]+)' )
if rtarget then
if string.match(rtarget, '{{') then --{{Title year}}, etc., exists; evaluate
local regex_ty = '%s*|%s*([^{}]*{{([^{|}]+)}}[^{}]-)%s*}}' --eval null-param templates only; expanded if/as needed
local rtarget_orig, ty = mw.ustring.match( catcontent, v..regex_ty )
if rtarget_orig then
local ty_eval = frame:expandTemplate{ title = ty, args = { page = cat } } --frame:newChild doesn't work, use 'page' param instead
local rtarget_eval = mw.ustring.gsub(rtarget_orig, '{{%s*'..ty..'%s*}}', ty_eval )
return rtarget_eval
else --sub-parameters present; track & return default
trackcat(31, 'Navseasoncats redirection error')
end
end
rtarget = mw.ustring.gsub(rtarget, '^1%s*=%s*', '')
rtarget = string.gsub(rtarget, '^[Cc]ategory:', '')
return rtarget
end
end --for
end --if
return cat
end
 
--Similar to {{LinkCatIfExists2}}: make a piped link to a category, if it exists;
--if it doesn't exist, just display the greyed link title without linking.
--Follows {{Category redirect}}s.
--Returns {
-- ['cat'] = cat,
-- ['catexists'] = true,
-- ['catexists'] = true,
-- ['rtarget'] = <#R target>,
-- ['rtarget'] = <#R target>,
Line 134: Line 185:
--   } otherwise.
--   } otherwise.
--Used by all nav_*().
--Used by all nav_*().
function catlinkfollowr( frame, cat, displaytext, displayend )
local function catlinkfollowr( frame, cat, displaytext, displayend )
cat        = mw.text.trim(cat or '')
cat        = mw.text.trim(cat or '')
displaytext = mw.text.trim(displaytext or '')
displaytext = mw.text.trim(displaytext or '')
Line 146: Line 197:
local link, nilorR
local link, nilorR
local exists = mw.title.new( cat, 'Category' ).exists
local exists = catexists(cat)
if exists then
if exists then
nexistingcats = nexistingcats + 1
nexistingcats = nexistingcats + 1
Line 170: Line 221:
else
else
link = '<span style="color:'..grey..'">'..disp..'</span>'
link = '<span style="color:'..grey..'">'..disp..'</span>'
--return { '[[:Category:'..cat..'|'..disp..']]', nil } --for debugging
end
end
Line 190: Line 240:
end
end


--Returns the target of {{Category redirect}}, if it exists, else returns the original cat.
--Returns a numbered list of all {{Category redirect}}s followed by catlinkfollowr() -> rtarget().
--{{Title year}}, etc., if found, are evaluated.
--For a nav_hyphen() cat, also returns a formatted list of all cats searched for & found, & all loop indices.
--Used by catlinkfollowr(), and so indirectly by all nav_*().
--Used by all nav_*().
function rtarget( frame, cat )
local function listalllinks()
local catcontent = mw.title.new( cat or '', 'Category' ):getContent()
if string.match( catcontent or '', '{{ *[Cc]at' ) then --prelim test
local regex = {
--the following 11 pages (7 condensed) redirect to [[Template:Category redirect]] (as of 6/2019):
'{{ *[Cc]ategory *[Rr]edirect', --most likely match 1st
'{{ *[Cc]at *redirect',        --444+240 transclusions
'{{ *[Cc]at *redir',            --8+3
'{{ *[Cc]ategory *move',        --6
'{{ *[Cc]at *red',              --6
'{{ *[Cc]atr',                  --4
'{{ *[Cc]at *move',            --0
}
for _, v in pairs (regex) do
local rtarget = mw.ustring.match( catcontent, v..'%s*|%s*([^|}]+)' )
if rtarget then
if string.match(rtarget, '{{') then --{{Title year}}, etc., exists; evaluate
local regex_ty = '%s*|%s*([^{}]*{{([^{|}]+)}}[^{}]-)%s*}}' --eval null-param templates only; expanded if/as needed
local rtarget_orig, ty = mw.ustring.match( catcontent, v..regex_ty )
if rtarget_orig then
local ty_eval = frame:expandTemplate{ title = ty, args = { page = cat } } --frame:newChild doesn't work, use 'page' param instead
local rtarget_eval = mw.ustring.gsub(rtarget_orig, '{{%s*'..ty..'%s*}}', ty_eval )
return rtarget_eval
else --sub-parameters present; track & return default
trackcat(30, 'Navseasoncats redirection error')
end
end
rtarget = mw.ustring.gsub(rtarget, '^1%s*=%s*', '')
rtarget = string.gsub(rtarget, '^[Cc]ategory:', '')
return rtarget
end
end --for
end --if
return cat
end
 
--Returns a numbered list of all {{Category redirect}}s followed by catlinkfollowr() -> rtarget().
--For a nav_hyphen() cat, also returns a formatted list of all cats searched for & found, & all loop indices.
--Used by all nav_*().
function listalllinks()
local nl = '\n# '
local nl = '\n# '
local out = ''
local out = ''
Line 258: Line 269:
--Returns the difference b/w 2 ints separated by endash|hyphen, nil if error.
--Returns the difference b/w 2 ints separated by endash|hyphen, nil if error.
--Used by nav_hyphen() only.
--Used by nav_hyphen() only.
function find_duration( cat )
local function find_duration( cat )
local from, to = mw.ustring.match(cat, '(%d+)[–-](%d+)')
local from, to = mw.ustring.match(cat, '(%d+)[–-](%d+)')
if from and to then
if from and to then
Line 274: Line 285:
--Returns the ending of a terminal cat, and sets the appropriate tracking cat, else nil.
--Returns the ending of a terminal cat, and sets the appropriate tracking cat, else nil.
--Used by nav_hyphen() only.
--Used by nav_hyphen() only.
function find_terminaltxt( cat )
local function find_terminaltxt( cat )
local terminaltxt = nil
local terminaltxt = nil
if mw.ustring.match(cat, '%d+[–-]present$') then
if mw.ustring.match(cat, '%d+[–-]present$') then
terminaltxt = 'present'
terminaltxt = 'present'
trackcat(13, 'Navseasoncats range ends (present)')
trackcat(14, 'Navseasoncats range ends (present)')
elseif mw.ustring.match(cat, '%d+[–-]$') then
elseif mw.ustring.match(cat, '%d+[–-]$') then
terminaltxt = ''
terminaltxt = ''
trackcat(14, 'Navseasoncats range ends (blank, MOS)')
trackcat(15, 'Navseasoncats range ends (blank, MOS)')
end
end
return terminaltxt
return terminaltxt
Line 288: Line 299:
--Returns an unsigned string of the 1-4 digit decade ending in "0", else nil.
--Returns an unsigned string of the 1-4 digit decade ending in "0", else nil.
--Used by nav_decade() only.
--Used by nav_decade() only.
function sterilizedec( decade )
local function sterilizedec( decade )
if decade == nil or decade == '' then
if decade == nil or decade == '' then
return nil
return nil
end
end
local dec = string.match(decade, '^[-%+]?(%d?%d?%d?0)$') or  
local dec = string.match(decade, '^[-%+]?(%d?%d?%d?0)$') or
string.match(decade, '^[-%+]?(%d?%d?%d?0)%D')
string.match(decade, '^[-%+]?(%d?%d?%d?0)%D')
if dec then
if dec then
Line 319: Line 330:
--Check for nav_hyphen default gap size + isolatedcat() (not necessarily an error).
--Check for nav_hyphen default gap size + isolatedcat() (not necessarily an error).
--Used by nav_hyphen() only.
--Used by nav_hyphen() only.
function defaultgapcat( bool )
local function defaultgapcat( bool )
if bool and nexistingcats == 0 then
if bool and nexistingcats == 0 then
--using "nexistingcats > 0" isn't as useful, since the default gap size obviously worked
--using "nexistingcats > 0" isn't as useful, since the default gap size obviously worked
trackcat(16, 'Navseasoncats default season gap size')
trackcat(17, 'Navseasoncats default season gap size')
end
end
end
end
Line 348: Line 359:
--Expects an integer i, and a catlinkfollowr() table.
--Expects an integer i, and a catlinkfollowr() table.
--Used by nav_decade() & nav_ordinal() only.
--Used by nav_decade() & nav_ordinal() only.
function navcenter( i, catlink )
local function navcenter( i, catlink )
if i == 0 then --center nav element
if i == 0 then --center nav element
if navborder == true then
if navborder == true then
return '*<b>'..catlink.displaytext..'</b>\n'
return '<b>'..catlink.displaytext..'</b>'
else
else
return '*<b>'..catlink.navelement..'</b>\n'
return '<b>'..catlink.navelement..'</b>'
end
end
else
else
return '*'..catlink.navelement..'\n'
return catlink.navelement
end
end
end
end
Line 362: Line 373:
--Return conditionally aligned stacked navs.
--Return conditionally aligned stacked navs.
--Used by main only.
--Used by main only.
function nav1nav2( nav1, nav2 )
local function nav1nav2( nav1, nav2 )
if avoidself then
if avoidself then
local forcealign = '<div style="display:block !important; max-width: calc(100% - 25em);">'
local forcealign = '<div style="display:block !important; max-width: calc(100% - 25em);">'
Line 379: Line 390:
--[[==========================={{  nav_hyphen  }}=============================]]
--[[==========================={{  nav_hyphen  }}=============================]]


function nav_hyphen( frame, start, hyph, finish, firstpart, lastpart, minseas, maxseas, testgap )
local function nav_hyphen( frame, start, hyph, finish, firstpart, lastpart, minseas, maxseas, testgap )
--Expects a PAGENAME of the form "Some sequential 2015–16 example cat", where  
--Expects a PAGENAME of the form "Some sequential 2015–16 example cat", where
-- start    = 2015
-- start    = 2015
-- hyph      = –
-- hyph      = –
Line 421: Line 432:
maxseas = start --hide subsequent ranges
maxseas = start --hide subsequent ranges
end
end
if finish == -1 then trackcat(13, 'Navseasoncats range ends (present)')
if finish == -1 then trackcat(14, 'Navseasoncats range ends (present)')
else trackcat(14, 'Navseasoncats range ends (blank, MOS)') end
else trackcat(15, 'Navseasoncats range ends (blank, MOS)') end
elseif (start == finish) and
elseif (start == finish) and
  (ttrackingcats[15] ~= '') --nav_year found isolated; check for surrounding hyphenated terms (e.g. UK MPs 1974)
  (ttrackingcats[16] ~= '') --nav_year found isolated; check for surrounding hyphenated terms (e.g. UK MPs 1974)
then
then
trackcat(15, '') --reset for another check later
trackcat(16, '') --reset for another check later
trackcat(12, 'Navseasoncats range irregular, 0-length')
trackcat(13, 'Navseasoncats range irregular, 0-length')
ttlens[0] = 1 --calc ttlens for std cases below
ttlens[0] = 1 --calc ttlens for std cases below
regularparent = 'isolated'
regularparent = 'isolated'
end
end
if (string.match(finish or '', '^%d+$') == nil) and
if (string.match(finish or '', '^%d+$') == nil) and
  (string.match(finish or '', '^%-%d+$') == nil)
  (string.match(finish or '', '^%-%d+$') == nil)
Line 519: Line 530:
local nextseason4 = firstpart..lspace..(nstart+t+hgap)..hyph..(nstart+2*t+hgap)..tspace..lastpart
local nextseason4 = firstpart..lspace..(nstart+t+hgap)..hyph..(nstart+2*t+hgap)..tspace..lastpart
if t == 1 then --test abbreviated range first, then full range, to be frugal with expensive functions
if t == 1 then --test abbreviated range first, then full range, to be frugal with expensive functions
if mw.title.new(prevseason2, 'Category').exists or --use 'or', in case we're at the edge of the cat structure,
if catexists(prevseason2) or --use 'or', in case we're at the edge of the cat structure,
  mw.title.new(nextseason2, 'Category').exists or --or we hit a "–00"/"–2000" situation on one side
  catexists(nextseason2) or --or we hit a "–00"/"–2000" situation on one side
  mw.title.new(prevseason4, 'Category').exists or
  catexists(prevseason4) or
  mw.title.new(nextseason4, 'Category').exists
  catexists(nextseason4)
then
then
hgap_success = true
hgap_success = true
break
break
end
end
elseif t > 1 then --test full range first, then abbreviated range
elseif t > 1 then --test full range first, then abbreviated range, to be frugal with expensive functions
if mw.title.new(prevseason4, 'Category').exists or --use 'or', in case we're at the edge of the cat structure,
if catexists(prevseason4) or --use 'or', in case we're at the edge of the cat structure,
  mw.title.new(nextseason4, 'Category').exists or --or we hit a "–00"/"–2000" situation on one side
  catexists(nextseason4) or --or we hit a "–00"/"–2000" situation on one side
  mw.title.new(prevseason2, 'Category').exists or  
  catexists(prevseason2) or
  mw.title.new(nextseason2, 'Category').exists
  catexists(nextseason2)
then
then
hgap_success = true
hgap_success = true
Line 561: Line 572:
local endfound = false --switch used to stop searching forward
local endfound = false --switch used to stop searching forward
local iirregs = 0 --index of tirregs[] for j < 0, since search starts from parent
local iirregs = 0 --index of tirregs[] for j < 0, since search starts from parent
local j = -3 --pseudo nav position & index of tirregs[] for j > 0
local j = -3 --index of tirregs[] for j > 0 & pseudo nav position
while j <= 3 do
while j <= 3 do
Line 568: Line 579:
local g = 0 --gap size
local g = 0 --gap size
while g <= hgap_limit_irreg do
while g <= hgap_limit_irreg do
local k = 0 --term length; 0 = "0-length"; 1+ = normal
local k = 0 --term length: 0 = "0-length", 1+ = normal
while k <= term_limit do
while k <= term_limit do
local from = bwanchor - k - g
local from = bwanchor - k - g
Line 589: Line 600:
if (k == 1) and
if (k == 1) and
  (g == 0 or g == 1) and
  (g == 0 or g == 1) and
  (mw.title.new( full, 'Category' ).exists == false)
  (catexists(full) == false)
then --allow bare-bones MOS:DATERANGE alternation, in case we're on a 0|1-gap, 1-year term series
then --allow bare-bones MOS:DATERANGE alternation, in case we're on a 0|1-gap, 1-year term series
local to2 = string.match(to, '%d%d$')
local to2 = string.match(to, '%d%d$')
Line 598: Line 609:
end
end
end
end
if mw.title.new( full, 'Category' ).exists then
if catexists(full) then
if to == '0-length' then
if to == '0-length' then
trackcat(12, 'Navseasoncats range irregular, 0-length')
trackcat(13, 'Navseasoncats range irregular, 0-length')
end
end
tlistallbwd[#tlistallbwd] = spanblue..tlistallbwd[#tlistallbwd]..span..' (found)'
tlistallbwd[#tlistallbwd] = spanblue..tlistallbwd[#tlistallbwd]..span..' (found)'
Line 635: Line 646:
local g = 0 --gap size
local g = 0 --gap size
while g <= hgap_limit_irreg do
while g <= hgap_limit_irreg do
local k = -2 --term length; -2 = "0-length"; -1 = "2020–present"; 0 = "2020–"; 1+ = normal
local k = -2 --term length: -2 = "0-length", -1 = "2020–present", 0 = "2020–", 1+ = normal
while k <= term_limit do
while k <= term_limit do
local from = fwanchor + g
local from = fwanchor + g
Line 659: Line 670:
if (k == 1) and
if (k == 1) and
  (g == 0 or g == 1) and
  (g == 0 or g == 1) and
  (mw.title.new( full, 'Category' ).exists == false)
  (catexists(full) == false)
then --allow bare-bones MOS:DATERANGE alternation, in case we're on a 0|1-gap, 1-year term series
then --allow bare-bones MOS:DATERANGE alternation, in case we're on a 0|1-gap, 1-year term series
to2 = string.match(to4, '%d%d$')
to2 = string.match(to4, '%d%d$')
Line 667: Line 678:
end
end
end
end
if mw.title.new( full, 'Category' ).exists then
if catexists(full) then
if to4 == '0-length' then
if to4 == '0-length' then
if rtarget(frame, full) == full then --only use 0-length cats that don't #R
if rtarget(frame, full) == full then --only use 0-length cats that don't #R
trackcat(12, 'Navseasoncats range irregular, 0-length')
trackcat(13, 'Navseasoncats range irregular, 0-length')
end
end
end
end
Line 705: Line 716:
end --if j > 0
end --if j > 0
if (lastg == (hgap_limit_irreg + 1)) and  
if (lastg == (hgap_limit_irreg + 1)) and
  (lastk == (term_limit + 1))
  (lastk == (term_limit + 1))
then --search exhausted
then --search exhausted
Line 717: Line 728:
--begin navhyphen
--begin navhyphen
local navh = '{| class="toccolours hlist" style="text-align: center; margin: auto;"\n'..'|\n'
local navh = '{| class="toccolours" style="text-align: center; margin: auto;"\n|\n'
local navlist = {}
local terminalcat = false --switch used to hide future cats
local terminalcat = false --switch used to hide future cats
local terminaltxt = nil
local terminaltxt = nil
Line 749: Line 761:
--determine which link exists (full or abbr)
--determine which link exists (full or abbr)
local full = firstpart..lspace..from..hyph..tofinal..tspace..lastpart
local full = firstpart..lspace..from..hyph..tofinal..tspace..lastpart
if not mw.title.new( full, 'Category' ).exists then
if not catexists(full) then
local abbr = firstpart..lspace..from..hyph..to2..tspace..lastpart
local abbr = firstpart..lspace..from..hyph..to2..tspace..lastpart
if mw.title.new( abbr, 'Category' ).exists then
if catexists(abbr) then
tofinal = (to2 or '') --rv to MOS-incorrect format; if full AND abbr DNE, then tofinal is still in its MOS-correct format
tofinal = (to2 or '') --rv to MOS-incorrect format; if full AND abbr DNE, then tofinal is still in its MOS-correct format
end
end
Line 757: Line 769:
elseif t == 1 then --full-year consecutive ranges are also allowed
elseif t == 1 then --full-year consecutive ranges are also allowed
local abbr = firstpart..lspace..from..hyph..tofinal..tspace..lastpart --assume tofinal is in abbr format
local abbr = firstpart..lspace..from..hyph..tofinal..tspace..lastpart --assume tofinal is in abbr format
if not mw.title.new( abbr, 'Category' ).exists and tofinal ~= to then
if not catexists(abbr) and tofinal ~= to then
local full = firstpart..lspace..from..hyph..to..tspace..lastpart
local full = firstpart..lspace..from..hyph..to..tspace..lastpart
if mw.title.new( full, 'Category' ).exists then
if catexists(full) then
tofinal = (to or '') --if abbr AND full DNE, then tofinal is still in its abbr format (unless it's a century transition)
tofinal = (to or '') --if abbr AND full DNE, then tofinal is still in its abbr format (unless it's a century transition)
end end end end
end end end end
Line 775: Line 787:
if terminalcat == false then
if terminalcat == false then
terminaltxt = find_terminaltxt( disp ) --also sets tracking cats
terminaltxt = find_terminaltxt( disp ) --also sets tracking cats
terminalcat = (terminaltxt ~= nil)  
terminalcat = (terminaltxt ~= nil)
end
end
if catlink.rtarget and avoidself then --a {{Category redirect}} was followed, figure out why
if catlink.rtarget and avoidself then --a {{Category redirect}} was followed, figure out why
Line 796: Line 808:
local base_regex = '%d+[–-]%d+'
local base_regex = '%d+[–-]%d+'
local origbase = mw.ustring.gsub(orig, base_regex, '')
local origbase = mw.ustring.gsub(orig, base_regex, '')
local rtarbase = mw.ustring.gsub(catlink.rtarget, base_regex, '')
local rtarbase, rtarbase_success = mw.ustring.gsub(catlink.rtarget, base_regex, '')
if rtarbase_success == 0 then
local base_regex_lax = '%d%d%d%d' --in case rtarget is a year cat
rtarbase, rtarbase_success = mw.ustring.gsub(catlink.rtarget, base_regex_lax, '')
end
local terminal_regex = '%d+[–-]'..(terminaltxt or '')..'$' --more manual ORs bc Lua regex sux
local terminal_regex = '%d+[–-]'..(terminaltxt or '')..'$' --more manual ORs bc Lua regex sux
if mw.ustring.match(orig, terminal_regex) then
if mw.ustring.match(orig, terminal_regex) then
Line 812: Line 828:
trackcat(6, 'Navseasoncats range redirected (base change)')
trackcat(6, 'Navseasoncats range redirected (base change)')
elseif terminalcat == 1 then
elseif terminalcat == 1 then
trackcat(7, 'Navseasoncats range redirected (end)')
trackcat(8, 'Navseasoncats range redirected (end)')
else
else --origbase == rtarbase
local all4s_regex = '%d%d%d%d[–-]%d%d%d%d'
local all4s_regex = '%d%d%d%d[–-]%d%d%d%d'
local all4s = (mw.ustring.match(orig, all4s_regex) and
local orig_all4s = mw.ustring.match(orig, all4s_regex)
  mw.ustring.match(catlink.rtarget, all4s_regex))
local rtar_all4s = mw.ustring.match(catlink.rtarget, all4s_regex)
if all4s then
if orig_all4s and rtar_all4s then
trackcat(9, 'Navseasoncats range redirected (other)')
trackcat(10, 'Navseasoncats range redirected (other)')
else
else
trackcat(8, 'Navseasoncats range redirected (MOS)')
local year_regex1 = '%d%d%d%d$'
local year_regex2 = '%d%d%d%d[%s%)]'
local year_rtar = mw.ustring.match(catlink.rtarget, year_regex1) or
  mw.ustring.match(catlink.rtarget, year_regex2)
if orig_all4s and year_rtar then
trackcat(7, 'Navseasoncats range redirected (var change)')
else
trackcat(9, 'Navseasoncats range redirected (MOS)')
end
end
end
end
end
Line 830: Line 854:
end
end
if (from >= 0) and (nminseas <= from) and (from <= nmaxseas) then
if (from >= 0) and (nminseas <= from) and (from <= nmaxseas) then
navh = navh..'*'..catlink.navelement..'\n'
table.insert(navlist, catlink.navelement)
if terminalcat then nmaxseas = nminseas_default end --prevent display of future ranges
if terminalcat then nmaxseas = nminseas_default end --prevent display of future ranges
else
else
local hidden = '<span style="visibility:hidden">'..disp..'</span>'
local hidden = '<span style="visibility:hidden">'..disp..'</span>'
navh = navh..'*'..hidden..'\n'
table.insert(navlist, hidden)
if listall then
if listall then
tlistall[#tlistall] = tlistall[#tlistall]..' ('..hidden..')'
tlistall[#tlistall] = tlistall[#tlistall]..' ('..hidden..')'
Line 844: Line 868:
local disp = start..hyph..finish
local disp = start..hyph..finish
if regularparent == 'isolated' then disp = start end
if regularparent == 'isolated' then disp = start end
navh = navh..'*<b>'..disp..'</b>\n'
table.insert(navlist, '<b>'..disp..'</b>')
end
end
i = i + 1
i = i + 1
end
end
-- add the list
navh = navh .. horizontal(navlist) .. '\n'
--tracking cats & finalize
--tracking cats & finalize
Line 860: Line 887:
itlens = itlens + (ttlens[s] or 0)
itlens = itlens + (ttlens[s] or 0)
end
end
if igaps  > 0 then trackcat(10, 'Navseasoncats range gaps') end
if igaps  > 0 then trackcat(11, 'Navseasoncats range gaps') end
if itlens > 1 and ttrackingcats[12] == '' then --avoid duplication in "Navseasoncats range irregular, 0-length"
if itlens > 1 and ttrackingcats[13] == '' then --avoid duplication in "Navseasoncats range irregular, 0-length"
trackcat(11, 'Navseasoncats range irregular')
trackcat(12, 'Navseasoncats range irregular')
end
end
end
end
Line 877: Line 904:
--[[=========================={{  nav_tvseason  }}============================]]
--[[=========================={{  nav_tvseason  }}============================]]


function nav_tvseason( frame, firstpart, tv, lastpart, maximumtv )
local function nav_tvseason( frame, firstpart, tv, lastpart, maximumtv )
--Expects a PAGENAME of the form "Futurama (season 1) episodes", where  
--Expects a PAGENAME of the form "Futurama (season 1) episodes", where
-- firstpart = Futurama (season  
-- firstpart = Futurama (season
-- tv        = 1
-- tv        = 1
-- lastpart  = ) episodes
-- lastpart  = ) episodes
Line 893: Line 920:
--begin navtvseason
--begin navtvseason
local navt = '{| class="toccolours hlist" style="text-align: center; margin: auto;"\n'..'|\n'
local navt = '{| class="toccolours" style="text-align: center; margin: auto;"\n|\n'
local navlist = {}
local i = -5 --nav position
local i = -5 --nav position
while i <= 5 do
while i <= 5 do
Line 902: Line 930:
if (t >= 1 and t <= maxtv) then --hardcode mintv
if (t >= 1 and t <= maxtv) then --hardcode mintv
if catlink.rtarget then --a {{Category redirect}} was followed
if catlink.rtarget then --a {{Category redirect}} was followed
trackcat(24, 'Navseasoncats TV season redirected')
trackcat(25, 'Navseasoncats TV season redirected')
end
end
navt = navt..'*'..catlink.navelement..'\n'
table.insert(navlist, catlink.navelement)
else
else
local hidden = '<span style="visibility:hidden">'..'0'..'</span>' --'0' to maintain dot spacing
local hidden = '<span style="visibility:hidden">'..'0'..'</span>' --'0' to maintain dot spacing
navt = navt..'*'..hidden..'\n'
table.insert(navlist, hidden)
if listall then
if listall then
tlistall[#tlistall] = tlistall[#tlistall]..' ('..hidden..')'
tlistall[#tlistall] = tlistall[#tlistall]..' ('..hidden..')'
Line 913: Line 941:
end
end
else --center navt
else --center navt
navt = navt..'*<b>'..tv..'</b>\n'
table.insert(navlist, '<b>'..tv..'</b>')
end
end
i = i + 1
i = i + 1
end
end
-- add the list
navt = navt .. horizontal(navlist) .. '\n'
isolatedcat()
isolatedcat()
if listall then
if listall then
Line 930: Line 959:
--[[==========================={{  nav_decade  }}=============================]]
--[[==========================={{  nav_decade  }}=============================]]


function nav_decade( frame, firstpart, decade, lastpart, mindecade, maxdecade )
local function nav_decade( frame, firstpart, decade, lastpart, mindecade, maxdecade )
--Expects a PAGENAME of the form "Some sequential 2000 example cat", where  
--Expects a PAGENAME of the form "Some sequential 2000 example cat", where
-- firstpart = Some sequential
-- firstpart = Some sequential
-- decade    = 2000
-- decade    = 2000
Line 951: Line 980:
local mindec = sterilizedec(mindecade) --returns a tostring(unsigned int), or nil
local mindec = sterilizedec(mindecade) --returns a tostring(unsigned int), or nil
if mindec then
if mindec then
if string.match(mindecade, '-%d') or  
if string.match(mindecade, '-%d') or
  string.match(mindecade, 'BC')
  string.match(mindecade, 'BC')
then
then
Line 968: Line 997:
local maxdec = sterilizedec(maxdecade) --returns a tostring(unsigned int), or nil + error
local maxdec = sterilizedec(maxdecade) --returns a tostring(unsigned int), or nil + error
if maxdec then
if maxdec then
if string.match(maxdecade, '-%d') or  
if string.match(maxdecade, '-%d') or
  string.match(maxdecade, 'BC')
  string.match(maxdecade, 'BC')
then                    --better +/-0 behavior with strings (0-initialized int == "-0" string...),
then                    --better +/-0 behavior with strings (0-initialized int == "-0" string...),
Line 1,015: Line 1,044:
bnb = ' border-style: none; background-color: transparent;'
bnb = ' border-style: none; background-color: transparent;'
end
end
local navd = '{| class="toccolours hlist" style="text-align: center; margin: auto;'..bnb..'"\n'..'|\n'
local navd = '{| class="toccolours" style="text-align: center; margin: auto;'..bnb..'"\n|\n'
local navlist = {}
local i = -50 --nav position x 10
local i = -50 --nav position x 10
while i <= 50 do
while i <= 50 do
Line 1,054: Line 1,084:
local catlink = catlinkfollowr( frame, firstpart..' '..d..'s'..tspace..BC..lastpart, disp )
local catlink = catlinkfollowr( frame, firstpart..' '..d..'s'..tspace..BC..lastpart, disp )
if catlink.rtarget then --a {{Category redirect}} was followed
if catlink.rtarget then --a {{Category redirect}} was followed
trackcat(17, 'Navseasoncats decade redirected')
trackcat(18, 'Navseasoncats decade redirected')
end
end
Line 1,073: Line 1,103:
if (zmin <= zsign) and (zsign <= zmax) then
if (zmin <= zsign) and (zsign <= zmax) then
navd = navd..shown
table.insert(navlist, shown)
hidden = nil
hidden = nil
else
else
navd = navd..'*'..hidden..'\n'
table.insert(navlist, hidden)
end
end
else
else
navd = navd..shown --the common case
table.insert(navlist, shown)--the common case
hidden = nil
hidden = nil
end
end
else
else
navd = navd..'*'..hidden..'\n'
table.insert(navlist, hidden)
end
end
if listall and hidden then
if listall and hidden then
Line 1,091: Line 1,121:
i = i + 10
i = i + 10
end
end
-- add the list
navd = navd .. horizontal(navlist) .. '\n'
isolatedcat()
isolatedcat()
if listall then
if listall then
Line 1,103: Line 1,134:
--[[============================{{  nav_year  }}==============================]]
--[[============================{{  nav_year  }}==============================]]


function nav_year( frame, firstpart, year, lastpart, minimumyear, maximumyear )
local function nav_year( frame, firstpart, year, lastpart, minimumyear, maximumyear )
--Expects a PAGENAME of the form "Some sequential 1760 example cat", where  
--Expects a PAGENAME of the form "Some sequential 1760 example cat", where
-- firstpart  = Some sequential
-- firstpart  = Some sequential
-- year        = 1760
-- year        = 1760
Line 1,165: Line 1,196:
while ygap1 <= 5 do --Czech Republic, Poland, Sri Lanka, etc. have 5-year terms
while ygap1 <= 5 do --Czech Republic, Poland, Sri Lanka, etc. have 5-year terms
prevseason = firstpart..lspace..(year-ygap1)..tspace..lastpart
prevseason = firstpart..lspace..(year-ygap1)..tspace..lastpart
if mw.title.new(prevseason, 'Category').exists then
if catexists(prevseason) then
ygap1_success = true
ygap1_success = true
break
break
Line 1,175: Line 1,206:
while ygap2 <= 5 do --Czech Republic, Poland, Sri Lanka, etc. have 5-year terms
while ygap2 <= 5 do --Czech Republic, Poland, Sri Lanka, etc. have 5-year terms
nextseason = firstpart..lspace..(year+ygap2)..tspace..lastpart
nextseason = firstpart..lspace..(year+ygap2)..tspace..lastpart
if mw.title.new(nextseason, 'Category').exists then
if catexists(nextseason) then
ygap2_success = true
ygap2_success = true
break
break
Line 1,214: Line 1,245:
yskipped[Yeary] = Yeary
yskipped[Yeary] = Yeary
cat = firstpart..lspace..Yeary..tspace..lastpart
cat = firstpart..lspace..Yeary..tspace..lastpart
found = mw.title.new( cat, 'Category' ).exists
found = catexists(cat)
if found then break end
if found then break end
end
end
Line 1,238: Line 1,269:
yskipped[Yeary] = Yeary
yskipped[Yeary] = Yeary
cat = firstpart..lspace..Yeary..tspace..lastpart
cat = firstpart..lspace..Yeary..tspace..lastpart
found = mw.title.new( cat, 'Category' ).exists
found = catexists(cat)
if found then break end
if found then break end
end
end
Line 1,254: Line 1,285:
--begin navyears
--begin navyears
local navy = '{| class="toccolours hlist" style="text-align: center; margin: auto;"\n'..'|\n'
local navy = '{| class="toccolours" style="text-align: center; margin: auto;"\n|\n'
local navlist = {}
local y
local y
local j = 0 --decrementor for special cases "2021 World Rugby Sevens Series" -> "2021–2022"
local i = -5 --nav position
local i = -5 --nav position
while i <= 5 do
while i <= 5 do
Line 1,262: Line 1,295:
y = ynogaps[i]
y = ynogaps[i]
else
else
y = year + i*ygap*switchADBC
y = year + i*ygap*switchADBC - j
end
end
local BCdisp = ''
local BCdisp = ''
Line 1,289: Line 1,322:
if switchADBC == -1 then --displayed y is in the BC regime
if switchADBC == -1 then --displayed y is in the BC regime
if y >= 1 then    --the common case
if y >= 1 then    --the common case
BC = BCe..' '  
BC = BCe..' '
elseif y == 0 then --switch from BC to AD regime
elseif y == 0 then --switch from BC to AD regime
switchADBC = 1
switchADBC = 1
Line 1,317: Line 1,350:
catlink = catlinkNoAD --usurp
catlink = catlinkNoAD --usurp
elseif listall then
elseif listall then
tlistall[#tlistall] = tlistall[#tlistall]..' (tried; not displayed)'
tlistall[#tlistall] = tlistall[#tlistall]..' (tried; not displayed)<sup>1</sup>'
end
end
end
end
Line 1,326: Line 1,359:
if catlinkHyph_4.catexists and catlinkHyph_4.rtarget == nil then --exists & no #Rs
if catlinkHyph_4.catexists and catlinkHyph_4.rtarget == nil then --exists & no #Rs
catlink = catlinkHyph_4 --usurp
catlink = catlinkHyph_4 --usurp
trackcat(26, 'Navseasoncats year and range')
trackcat(27, 'Navseasoncats year and range')
else
else
if listall then
if listall then
tlistall[#tlistall] = tlistall[#tlistall]..' (tried; not displayed)'
tlistall[#tlistall] = tlistall[#tlistall]..' (tried; not displayed)<sup>2</sup>'
end
end
local yHyph_2 = y..'–'..string.match(y+1, '%d%d$') --try 2010–11 type cats
local yHyph_2 = y..'–'..string.match(y+1, '%d%d$') --try 2010–11 type cats
local catlinkHyph_2 = catlinkfollowr( frame, firstpart..lspace..yHyph_2..tspace..BC..lastpart, yHyph_2 )
if i == 1 then
if catlinkHyph_2.catexists and catlinkHyph_2.rtarget == nil then --exists & no #Rs
local yHyph_2_special = (y-1)..'–'..string.match(y, '%d%d$') --try special case 2021 -> 2021–22
catlink = catlinkHyph_2 --usurp
local catlinkHyph_2_special = catlinkfollowr( frame, firstpart..lspace..yHyph_2_special..tspace..BC..lastpart, yHyph_2_special )
trackcat(26, 'Navseasoncats year and range')
if catlinkHyph_2_special.catexists and catlinkHyph_2_special.rtarget == nil then --exists & no #Rs
elseif listall then
catlink = catlinkHyph_2_special --usurp
tlistall[#tlistall] = tlistall[#tlistall]..' (tried; not displayed)'
trackcat(27, 'Navseasoncats year and range')
j = 1
elseif listall then
tlistall[#tlistall] = tlistall[#tlistall]..' (tried; not displayed)<sup>3</sup>'
end
end
if not (i == 1 and j == 1) then
local catlinkHyph_2 = catlinkfollowr( frame, firstpart..lspace..yHyph_2..tspace..BC..lastpart, yHyph_2 )
if catlinkHyph_2.catexists and catlinkHyph_2.rtarget == nil then --exists & no #Rs
catlink = catlinkHyph_2 --usurp
trackcat(27, 'Navseasoncats year and range')
elseif listall then
tlistall[#tlistall] = tlistall[#tlistall]..' (tried; not displayed)<sup>4</sup>'
end
end
end
end
end
Line 1,344: Line 1,390:
local r = catlink.rtarget
local r = catlink.rtarget
local c = catlink.cat
local c = catlink.cat
local regex_year = '%d%d%d%d[–-]?%d?%d?%d?%d?' --prioritize year/range stripping, e.g. for "2006 Super 14 season"
local year_regex = '%d%d%d%d[–-]?%d?%d?%d?%d?' --prioritize year/range stripping, e.g. for "2006 Super 14 season"
local regex_num   = '%d+' --strip any number otherwise
local hyph_regex  = '%d%d%d%d[–-]%d+' --stricter
local regex_final = nil  --best choice goes here
local num_regex   = '%d+' --strip any number otherwise
if string.match(r, regex_year) and string.match(c, regex_year) then
local final_regex = nil  --best choice goes here
regex_final = regex_year
if mw.ustring.match(r, year_regex) and mw.ustring.match(c, year_regex) then
elseif string.match(r, regex_num) and string.match(c, regex_num) then
final_regex = year_regex
regex_final = regex_num
elseif mw.ustring.match(r, num_regex) and mw.ustring.match(c, num_regex) then
final_regex = num_regex
end
end
if regex_final then
if final_regex then
local r_base = mw.ustring.gsub(r, regex_final, '')
local r_base = mw.ustring.gsub(r, final_regex, '')
local c_base = mw.ustring.gsub(c, regex_final, '')
local c_base = mw.ustring.gsub(c, final_regex, '')
if r_base ~= c_base then
if r_base ~= c_base then
trackcat(18, 'Navseasoncats year redirected (base change)') --acceptable #Rs go here
trackcat(19, 'Navseasoncats year redirected (base change)') --acceptable #R target
elseif mw.ustring.match(r, hyph_regex) then
trackcat(20, 'Navseasoncats year redirected (var change)') --e.g. "2008 in Scottish women's football" to "2008–09"
else
else
trackcat(20, 'Navseasoncats year redirected (other)') --exceptions go here
trackcat(21, 'Navseasoncats year redirected (other)') --exceptions go here
end
end
else
else
trackcat(19, 'Navseasoncats year redirected (var change)') --e.g. "V2 engines" to "V-twin engines"
trackcat(20, 'Navseasoncats year redirected (var change)') --e.g. "V2 engines" to "V-twin engines"
end
end
end
end
navy = navy..'*'..catlink.navelement..'\n'
table.insert(navlist, catlink.navelement)
else --OOB vs min/max
else --OOB vs min/max
local hidden = '<span style="visibility:hidden">'..disp..'</span>'
local hidden = '<span style="visibility:hidden">'..disp..'</span>'
navy = navy..'*'..hidden..'\n'
table.insert(navlist, hidden)
if listall then
if listall then
local dummy = catlinkfollowr( frame, firsttry, disp )
local dummy = catlinkfollowr( frame, firsttry, disp )
Line 1,375: Line 1,424:
else --center navy
else --center navy
if parentBC then BCdisp = ' '..BCe end
if parentBC then BCdisp = ' '..BCe end
navy = navy..'*<b>'..year..BCdisp..'</b>\n'
table.insert(navlist, '<b>'..year..BCdisp..'</b>')
end
end
i = i + 1
i = i + 1
end
end
--add the list
navy = navy .. horizontal(navlist) .. '\n'
isolatedcat()
isolatedcat()
Line 1,392: Line 1,444:
--[[==========================={{  nav_roman  }}==============================]]
--[[==========================={{  nav_roman  }}==============================]]


function nav_roman( frame, firstpart, roman, lastpart, minimumrom, maximumrom )
local function nav_roman( frame, firstpart, roman, lastpart, minimumrom, maximumrom )
local toarabic = require('Module:ConvertNumeric').roman_to_numeral
local toarabic = require('Module:ConvertNumeric').roman_to_numeral
local toroman  = require('Module:Roman').main
local toroman  = require('Module:Roman').main
Line 1,414: Line 1,466:
--begin navroman
--begin navroman
local navr = '{| class="toccolours hlist" style="text-align: center; margin: auto;"\n'..'|\n'
local navr = '{| class="toccolours" style="text-align: center; margin: auto;"\n|\n'
local navlist = {}
local i = -5 --nav position
local i = -5 --nav position
while i <= 5 do
while i <= 5 do
Line 1,426: Line 1,479:
if minrom <= n and n <= maxrom then
if minrom <= n and n <= maxrom then
if catlink.rtarget then --a {{Category redirect}} was followed
if catlink.rtarget then --a {{Category redirect}} was followed
trackcat(21, 'Navseasoncats roman numeral redirected')
trackcat(22, 'Navseasoncats roman numeral redirected')
end
end
navr = navr..'*'..catlink.navelement..'\n'
table.insert(navlist, catlink.navelement)
else
else
local hidden = '<span style="visibility:hidden">'..r..'</span>'
local hidden = '<span style="visibility:hidden">'..r..'</span>'
navr = navr..'*'..hidden..'\n'
table.insert(navlist, hidden)
if listall then
if listall then
tlistall[#tlistall] = tlistall[#tlistall]..' ('..hidden..')'
tlistall[#tlistall] = tlistall[#tlistall]..' ('..hidden..')'
Line 1,437: Line 1,490:
end
end
else --center navr
else --center navr
navr = navr..'*<b>'..r..'</b>\n'
table.insert(navlist, '<b>'..r..'</b>')
end
end
else
else
navr = navr..'*<span style="visibility:hidden">'..'I'..'</span>\n'
table.insert(navlist, '<span style="visibility:hidden">I</span>')
end
end
Line 1,446: Line 1,499:
end
end
-- add the list
navr = navr .. horizontal(navlist) .. '\n'
isolatedcat()
isolatedcat()
if listall then
if listall then
Line 1,457: Line 1,512:
--[[=========================={{  nav_nordinal  }}============================]]
--[[=========================={{  nav_nordinal  }}============================]]


function nav_nordinal( frame, firstpart, ord, lastpart, minimumord, maximumord )
local function nav_nordinal( frame, firstpart, ord, lastpart, minimumord, maximumord )
local nord = tonumber(ord)
local nord = tonumber(ord)
local minord = tonumber(string.match(minimumord or '', '(-?%d+)[snrt]?[tdh]?')) or -9999 --allow full ord & +/- qualifier
local minord = tonumber(string.match(minimumord or '', '(-?%d+)[snrt]?[tdh]?')) or -9999 --allow full ord & +/- qualifier
Line 1,479: Line 1,534:
['-century Judaism']      = 'BCE', --co-nominated
['-century Judaism']      = 'BCE', --co-nominated
['-century rabbis']        = 'BCE', --co-nominated
['-century rabbis']        = 'BCE', --co-nominated
['-century High Priests of Israel'] = 'BCE',
}
}
local parentBC = mw.ustring.match(lastpart, '%s(BCE?)')      --"1st-century BC" format
local parentBC = mw.ustring.match(lastpart, '%s(BCE?)')      --"1st-century BC" format
Line 1,497: Line 1,553:
bnb = ' border-style: none; background-color: transparent;'
bnb = ' border-style: none; background-color: transparent;'
end
end
local navo = '{| class="toccolours hlist" style="text-align: center; margin: auto;'..bnb..'"\n'..'|\n'
local navo = '{| class="toccolours" style="text-align: center; margin: auto;'..bnb..'"\n|\n'
local navlist = {}
local i = -5 --nav position
local i = -5 --nav position
while i <= 5 do
while i <= 5 do
Line 1,538: Line 1,595:
if (minord <= osign) and (osign <= maxord) then
if (minord <= osign) and (osign <= maxord) then
if catlink.rtarget then --a {{Category redirect}} was followed
if catlink.rtarget then --a {{Category redirect}} was followed
trackcat(22, 'Navseasoncats nordinal redirected')
trackcat(23, 'Navseasoncats nordinal redirected')
end
end
navo = navo..navcenter(i, catlink)
table.insert(navlist, navcenter(i, catlink))
else
else
navo = navo..'*'..hidden..'\n'
table.insert(navlist, hidden)
if listall then
if listall then
tlistall[#tlistall] = tlistall[#tlistall]..' ('..hidden..')'
tlistall[#tlistall] = tlistall[#tlistall]..' ('..hidden..')'
Line 1,550: Line 1,607:
local catlink = catlinkfollowr( frame, firstpart..' '..oth..tspace..lastpart, oth )
local catlink = catlinkfollowr( frame, firstpart..' '..oth..tspace..lastpart, oth )
if catlink.rtarget then --a {{Category redirect}} was followed
if catlink.rtarget then --a {{Category redirect}} was followed
trackcat(22, 'Navseasoncats nordinal redirected')
trackcat(23, 'Navseasoncats nordinal redirected')
end
end
navo = navo..navcenter(i, catlink)
table.insert(navlist, navcenter(i, catlink))
else --either out-of-range (hide), or non-temporal + BC = something might be wrong (2nd X parliament BC?); handle exceptions if/as they arise
else --either out-of-range (hide), or non-temporal + BC = something might be wrong (2nd X parliament BC?); handle exceptions if/as they arise
navo = navo..'*'..hidden..'\n'
table.insert(navlist, hidden)
end
end
i = i + 1
i = i + 1
end
end
navo = navo .. horizontal(navlist) .. '\n'
isolatedcat()
isolatedcat()
Line 1,571: Line 1,630:
--[[========================={{  nav_wordinal  }}=============================]]
--[[========================={{  nav_wordinal  }}=============================]]


function nav_wordinal( frame, firstpart, word, lastpart, minimumword, maximumword, ordinal, frame )
local function nav_wordinal( frame, firstpart, word, lastpart, minimumword, maximumword, ordinal, frame )
--Module:ConvertNumeric.numeral_to_english() flags:
--Module:ConvertNumeric.spell_number2() args:
--  ordinal == 'on': 'second' is output instead of 'two'
--  ordinal == true : 'second' is output instead of 'two'
--  ordinal ~= 'on': 'two' is output instead of 'second'
--  ordinal == false: 'two' is output instead of 'second'
local ord2eng = require('Module:ConvertNumeric').numeral_to_english
local ord2eng = require('Module:ConvertNumeric').spell_number2
local eng2ord = require('Module:ConvertNumeric').english_to_ordinal
local eng2ord = require('Module:ConvertNumeric').english_to_ordinal
local th = 'th'
local th = 'th'
if ordinal ~= 'on' then
if not ordinal then
th = ''
th = ''
eng2ord = require('Module:ConvertNumeric').english_to_numeral
eng2ord = require('Module:ConvertNumeric').english_to_numeral
end
end
local sc = string.match(word, '^%u') --sentence-case check
local capitalize = nil ~= string.match(word, '^%u') --determine capitalization
local lc = string.lower(word) --operate on/with lc, and restore any sc later
local nord = eng2ord(string.lower(word)) --operate on/with lowercase, and restore any capitalization later
local nord = eng2ord(lc)
local case = nil
if sc then case = 'U' end
local lspace = ' ' --assume a leading space (most common)
local lspace = ' ' --assume a leading space (most common)
Line 1,622: Line 1,678:
--begin navwordinal
--begin navwordinal
local navw = '{| class="toccolours hlist" style="text-align: center; margin: auto;"\n'..'|\n'
local navw = '{| class="toccolours" style="text-align: center; margin: auto;"\n|\n'
local navlist = {}
local i = -5 --nav position
local i = -5 --nav position
while i <= 5 do
while i <= 5 do
Line 1,630: Line 1,687:
if n >= 1 then
if n >= 1 then
local nth = p.addord(n)
local nth = p.addord(n)
if ordinal ~= 'on' then nth = n end
if not ordinal then nth = n end
if i ~= 0 then --left/right navw
if i ~= 0 then --left/right navw
local frame_args = frame:newChild{ args = { n, ord = ordinal, case = case } } --easier to do this than modify Module:ConvertNumeric
local w = ord2eng{ num = n, ordinal = ordinal, capitalize = capitalize }
local w = ord2eng( frame_args )
local catlink = catlinkfollowr( frame, firstpart..lspace..w..tspace..lastpart, nth )
local catlink = catlinkfollowr( frame, firstpart..lspace..w..tspace..lastpart, nth )
if minword <= n and n <= maxword then
if minword <= n and n <= maxword then
if catlink.rtarget then --a {{Category redirect}} was followed
if catlink.rtarget then --a {{Category redirect}} was followed
trackcat(23, 'Navseasoncats wordinal redirected')
trackcat(24, 'Navseasoncats wordinal redirected')
end
end
navw = navw..'*'..catlink.navelement..'\n'
table.insert(navlist, catlink.navelement)
else
else
local hidden = '<span style="visibility:hidden">'..nth..'</span>'
local hidden = '<span style="visibility:hidden">'..nth..'</span>'
navw = navw..'*'..hidden..'\n'
table.insert(navlist, hidden)
if listall then
if listall then
tlistall[#tlistall] = tlistall[#tlistall]..' ('..hidden..')'
tlistall[#tlistall] = tlistall[#tlistall]..' ('..hidden..')'
Line 1,648: Line 1,704:
end
end
else --center navw
else --center navw
navw = navw..'*<b>'..nth..'</b>\n'
table.insert(navlist, '<b>'..nth..'</b>')
end
end
else
else
navw = navw..'*<span style="visibility:hidden">'..'0'..th..'</span>\n'
table.insert(navlist, '<span style="visibility:hidden">'..'0'..th..'</span>')
end
end
i = i + 1
i = i + 1
end
end
-- Add the list
navw = navw .. horizontal(navlist) .. '\n'
isolatedcat()
isolatedcat()
Line 1,668: Line 1,726:
--[[==========================={{  find_var  }}===============================]]
--[[==========================={{  find_var  }}===============================]]


function find_var( pn )
local function find_var( pn )
--Extracts the variable text (e.g. 2015–16, 3rd, 2000s, III, etc.) from a string
--Extracts the variable text (e.g. 2015, 2015–16, 2000s, 3rd, III, etc.) from a string,
--and returns { ['vtype'] = <'year'|'season'|etc.>, <v> = <2015|2015–16|etc.> }
local pagename = currtitle.text
local pagename = currtitle.text
if pn and pn ~= '' then
if pn and pn ~= '' then
Line 1,683: Line 1,742:
local e_season = mw.ustring.match(cpagename, '%s(%d+[–-])$') or --irreg; ending unknown, e.g. "Members of the Scottish Parliament 2021–"
local e_season = mw.ustring.match(cpagename, '%s(%d+[–-])$') or --irreg; ending unknown, e.g. "Members of the Scottish Parliament 2021–"
mw.ustring.match(cpagename, '%s(%d+[–-]present)$') --e.g. "UK MPs 2019–present"
mw.ustring.match(cpagename, '%s(%d+[–-]present)$') --e.g. "UK MPs 2019–present"
local season  = mw.ustring.match(cpagename, '[:%s%(](%d+[–-]%d+)[%)%s]') or --split in 2 b/c you can't frontier '$'/eos?
local season  = mw.ustring.match(cpagename, '[:%s%(](%d+[–-]%d+)[%)%s]') or --split in 2 b/c you can't frontier '$'/eos?
mw.ustring.match(cpagename, '[:%s](%d+[–-]%d+)$')
mw.ustring.match(cpagename, '[:%s](%d+[–-]%d+)$')
local tvseason = mw.ustring.match(cpagename, 'season (%d+)') or
local tvseason = mw.ustring.match(cpagename, 'season (%d+)') or
mw.ustring.match(cpagename, 'series (%d+)')
mw.ustring.match(cpagename, 'series (%d+)')
local nordinal = mw.ustring.match(cpagename, '[:%s](%d+[snrt][tdh])[-%s]') or
local nordinal = mw.ustring.match(cpagename, '[:%s](%d+[snrt][tdh])[-%s]') or
mw.ustring.match(cpagename, '[:%s](%d+[snrt][tdh])$')
mw.ustring.match(cpagename, '[:%s](%d+[snrt][tdh])$')
local decade  = mw.ustring.match(cpagename, '[:%s](%d+s)[%s-]') or
local decade  = mw.ustring.match(cpagename, '[:%s](%d+s)[%s-]') or
mw.ustring.match(cpagename, '[:%s](%d+s)$')
mw.ustring.match(cpagename, '[:%s](%d+s)$')
local year    = mw.ustring.match(cpagename, '[:%s](%d%d%d%d)%s') or --prioritize 4-digit years
local year    = mw.ustring.match(cpagename, '[:%s](%d%d%d%d)%s') or --prioritize 4-digit years
mw.ustring.match(cpagename, '[:%s](%d%d%d%d)$') or
mw.ustring.match(cpagename, '[:%s](%d%d%d%d)$') or
Line 1,704: Line 1,763:
mw.ustring.match(cpagename, '[:%s](%d+)-cylinder') or
mw.ustring.match(cpagename, '[:%s](%d+)-cylinder') or
mw.ustring.match(cpagename, '[:%-VW](%d+)%s') --e.g. "Straight-8 engines"
mw.ustring.match(cpagename, '[:%-VW](%d+)%s') --e.g. "Straight-8 engines"
local roman    = mw.ustring.match(cpagename, '%s([IVXLCDM]+)%s')
local roman    = mw.ustring.match(cpagename, '%s([IVXLCDM]+)%s')
local found    = d_season or y_season or e_season or season or tvseason or  
local found    = d_season or y_season or e_season or season or tvseason or
nordinal or decade or year or roman
nordinal or decade or year or roman
Line 1,776: Line 1,835:
if skip_gaps and skip_gaps == 'yes' then
if skip_gaps and skip_gaps == 'yes' then
skipgaps = true
skipgaps = true
trackcat(25, 'Navseasoncats using skip-gaps parameter')
trackcat(26, 'Navseasoncats using skip-gaps parameter')
end
end
Line 1,788: Line 1,847:
end
end
elseif currtitle.nsText == '' then
elseif currtitle.nsText == '' then
trackcat(29, 'Navseasoncats in mainspace')
trackcat(30, 'Navseasoncats in mainspace')
end
end
Line 1,825: Line 1,884:
local decade = dec..'0s '
local decade = dec..'0s '
decadecat = mw.text.trim( firstpart_dec..' '..decade..lastpart )
decadecat = mw.text.trim( firstpart_dec..' '..decade..lastpart )
local exists = mw.title.new( decadecat, 'Category' ).exists
local exists = catexists(decadecat)
if exists then
if exists then
navborder = false
navborder = false
trackcat(27, 'Navseasoncats year and decade')
trackcat(28, 'Navseasoncats year and decade')
local nav2 = nav_decade( frame, firstpart_dec, decade, lastpart, minimum, maximum )..testcaseindent..table.concat(ttrackingcats)
local nav2 = nav_decade( frame, firstpart_dec, decade, lastpart, minimum, maximum )..testcaseindent..table.concat(ttrackingcats)
return nav1nav2( nav1, nav2 )
return nav1nav2( nav1, nav2 )
elseif ttrackingcats[15] ~= '' then --nav_year isolated; check nav_hyphen (e.g. UK MPs 1974, Moldovan MPs 2009, etc.)
elseif ttrackingcats[16] ~= '' then --nav_year isolated; check nav_hyphen (e.g. UK MPs 1974, Moldovan MPs 2009, etc.)
hyphen = '–'
local hyphen = '–'
finish = start
local finish = start
local nav2 = nav_hyphen( frame, start, hyphen, finish, firstpart, lastpart, minimum, maximum, testcasegap )..testcaseindent..table.concat(ttrackingcats)
local nav2 = nav_hyphen( frame, start, hyphen, finish, firstpart, lastpart, minimum, maximum, testcasegap )..testcaseindent..table.concat(ttrackingcats)
if ttrackingcats[15] ~= '' then return nav1 --still isolated; rv to nav_year
if ttrackingcats[16] ~= '' then return nav1 --still isolated; rv to nav_year
else return nav2 end
else return nav2 end
else --regular nav_year
else --regular nav_year
Line 1,852: Line 1,911:
local clastpart = ' century '..lastpart
local clastpart = ' century '..lastpart
local centurycat = mw.text.trim( firstpart..' '..p.addord(century)..clastpart )
local centurycat = mw.text.trim( firstpart..' '..p.addord(century)..clastpart )
local exists = mw.title.new( centurycat, 'Category' ).exists
local exists = catexists(centurycat)
if not exists then --check for hyphenated century
if not exists then --check for hyphenated century
clastpart = '-century '..lastpart
clastpart = '-century '..lastpart
centurycat = mw.text.trim( firstpart..' '..p.addord(century)..clastpart )
centurycat = mw.text.trim( firstpart..' '..p.addord(century)..clastpart )
exists = mw.title.new( centurycat, 'Category' ).exists
exists = catexists(centurycat)
end
end
if exists then
if exists then
navborder = false
navborder = false
trackcat(28, 'Navseasoncats decade and century')
trackcat(29, 'Navseasoncats decade and century')
local nav2 = nav_nordinal( frame, firstpart, century, clastpart, minimum, maximum )..testcaseindent..table.concat(ttrackingcats)
local nav2 = nav_nordinal( frame, firstpart, century, clastpart, minimum, maximum )..testcaseindent..table.concat(ttrackingcats)
return nav1nav2( nav1, nav2 )
return nav1nav2( nav1, nav2 )
Line 1,878: Line 1,937:
elseif findvar.vtype == 'wordinal' then --e.g. "first", "ninety-ninth"; <<1% of cats
elseif findvar.vtype == 'wordinal' then --e.g. "first", "ninety-ninth"; <<1% of cats
local ordinal = 'on'
local ordinal = true
return nav_wordinal( frame, firstpart, findvar.v, lastpart, minimum, maximum, ordinal, frame )..testcaseindent..table.concat(ttrackingcats)
return nav_wordinal( frame, firstpart, findvar.v, lastpart, minimum, maximum, ordinal, frame )..testcaseindent..table.concat(ttrackingcats)
elseif findvar.vtype == 'enumeric' then --e.g. "one", "ninety-nine"; <<1% of cats
elseif findvar.vtype == 'enumeric' then --e.g. "one", "ninety-nine"; <<1% of cats
local ordinal = 'off'
local ordinal = false
return nav_wordinal( frame, firstpart, findvar.v, lastpart, minimum, maximum, ordinal, frame )..testcaseindent..table.concat(ttrackingcats)
return nav_wordinal( frame, firstpart, findvar.v, lastpart, minimum, maximum, ordinal, frame )..testcaseindent..table.concat(ttrackingcats)
Anonymous user