Modul:Navseasoncats: Perbedaan antara revisi
Konten dihapus Konten ditambahkan
k using skip-gaps parameter → dengan parameter skip-gaps |
k uji coba |
||
Baris 1:
require[[strict]]
local p = {}
local horizontal = require('
--[[==========================================================================]]
Baris 36:
'', --[14] placeholder for [[Category:Navseasoncats range ends (present)]]
'', --[15] placeholder for [[Category:Navseasoncats range ends (blank, MOS)]]
'', --[16] placeholder for [[Category:Navseasoncats
'', --[17] placeholder for [[Category:Navseasoncats default season gap size]]
'', --[18] placeholder for [[Category:Navseasoncats decade redirected]]
Baris 46:
'', --[24] placeholder for [[Category:Navseasoncats wordinal redirected]]
'', --[25] placeholder for [[Category:Navseasoncats TV season redirected]]
'', --[26] placeholder for [[Category:Navseasoncats
'', --[27] placeholder for [[Category:Navseasoncats year and range]]
'', --[28] placeholder for [[Category:Navseasoncats year and decade]]
Baris 68:
--Determine if a category exists (in a function for easier localization).
local function catexists( title )
return mw.title.new( title, '
end
--Error message handling.
function p.errorclass( msg )
return mw.text.tag( 'span', {class='error mw-ext-cite-error'}, '<b>
end
Baris 92:
if avoidself and key and cat then
if cat ~= '' then
ttrackingcats[key] = '[['..testcasecolon..'
else
ttrackingcats[key] = ''
Baris 115:
for k, _ in pairs (tbl) do
if knownparams[k] == nil then
trackcat(3, 'Navseasoncats
break
end
Baris 133:
--Used by catlinkfollowr(), and so indirectly by all nav_*().
local function rtarget( frame, cat )
local catcontent = mw.title.new( cat or '', '
if string.match( catcontent or '', '{{ *[Cc]at' ) then --prelim test
local
--the following 11 pages (6 condensed) redirect to [[Template:Category redirect]], in descending order, as of 9/2022:
'{{ *[Cc]ate?g?o?r?y?[ _]*[rR]edirect', --505+312+243+1 transclusions
Baris 144:
'{{ *[Cc]ategory[ _]*[mM]ove', --0
}
for _, v in pairs (
local rtarget = mw.ustring.match( catcontent, v..'%s*|%s*([^|}]+)' )
if rtarget then
Baris 208:
if displayend then
local y, hyph, ending = mw.ustring.match(R, '^.-(%d+)([–-])(.*)$')
if ending == '
disp = y..hyph..ending
elseif ending == '' then
Baris 246:
local nl = '\n# '
local out = ''
if currtitle.nsText == '
errors = p.errorclass('The <b><code>|list-all-links=yes</code></b> parameter/utility '..
'should not be saved in category space, only previewed.')
Baris 287:
local function find_terminaltxt( cat )
local terminaltxt = nil
if mw.ustring.match(cat, '%d+[–-]
terminaltxt = '
trackcat(14, 'Navseasoncats range ends (
elseif mw.ustring.match(cat, '%d+[–-]$') then
terminaltxt = ''
Baris 362:
if i == 0 then --center nav element
if navborder == true then
return '
else
return '
end
else
return
end
end
Baris 728:
--begin navhyphen
local navh = '{| class="toccolours
local terminalcat = false --switch used to hide future cats
local terminaltxt = nil
Baris 853 ⟶ 854:
end
if (from >= 0) and (nminseas <= from) and (from <= nmaxseas) then
if terminalcat then nmaxseas = nminseas_default end --prevent display of future ranges
else
local hidden = '<span style="visibility:hidden">'..disp..'</span>'
if listall then
tlistall[#tlistall] = tlistall[#tlistall]..' ('..hidden..')'
Baris 863 ⟶ 864:
end
else --center navh
if finish == -1 then finish = '
elseif finish == 0 then finish = '<span style="visibility:hidden">'..start..'</span>' end
local disp = start..hyph..finish
if regularparent == 'isolated' then disp = start end
end
i = i + 1
end
-- add the list
navh = navh .. horizontal(navlist) .. '\n'
--tracking cats & finalize
Baris 916 ⟶ 920:
--begin navtvseason
local navt = '{| class="toccolours
local navlist = {}
local i = -5 --nav position
while i <= 5 do
Baris 927 ⟶ 932:
trackcat(25, 'Navseasoncats TV season redirected')
end
else
local hidden = '<span style="visibility:hidden">'..'0'..'</span>' --'0' to maintain dot spacing
if listall then
tlistall[#tlistall] = tlistall[#tlistall]..' ('..hidden..')'
Baris 936 ⟶ 941:
end
else --center navt
end
i = i + 1
end
-- add the list
navt = navt .. horizontal(navlist) .. '\n'
isolatedcat()
if listall then
Baris 975 ⟶ 981:
if mindec then
if string.match(mindecade, '-%d') or
string.match(mindecade, '
then
mindec = '-'..mindec --better +/-0 behavior with strings (0-initialized int == "-0" string...)
Baris 992 ⟶ 998:
if maxdec then
if string.match(maxdecade, '-%d') or
string.match(maxdecade, '
then --better +/-0 behavior with strings (0-initialized int == "-0" string...),
maxdec = '-'..maxdec --but a "-0" string -> tonumber() -> tostring() = "-0",
Baris 1.009 ⟶ 1.015:
--AD/BC switches & vars
local parentBC = string.match(lastpart, '^
lastpart = mw.ustring.gsub(lastpart, '^
--TODO?: handle BCE, but only if it exists in the wild
Baris 1.038 ⟶ 1.044:
bnb = ' border-style: none; background-color: transparent;'
end
local navd = '{| class="toccolours
local navlist = {}
local i = -50 --nav position x 10
while i <= 50 do
Baris 1.049 ⟶ 1.056:
if D < -10 then
d = math.abs(d + 10) --b/c 2 "0s" decades exist: "0s BC" & "0s" (AD)
BC = '
if d == 0 then
D = -10 --track 1st d = 0 use (BC)
Baris 1.059 ⟶ 1.066:
elseif parentBC then
if switchADBC == -1 then --parentBC looking at the BC side (the common case)
BC = '
if d == 0 then --prepare to switch to the AD side on the next iteration
switchADBC = 1 --1st d = 0 use (BC)
Baris 1.070 ⟶ 1.077:
end
if BC ~= '' and ndec <= 50 then
BCdisp = '
end
--determine target cat
local disp = d..'
local catlink = catlinkfollowr( frame, firstpart..' '..d..'s'..tspace..BC..lastpart, disp )
if catlink.rtarget then --a {{Category redirect}} was followed
Baris 1.096 ⟶ 1.103:
if (zmin <= zsign) and (zsign <= zmax) then
hidden = nil
else
end
else
hidden = nil
end
else
table.insert(navlist, hidden)
navd = navd..'*'..hidden..'\n'▼
end
if listall and hidden then
Baris 1.114 ⟶ 1.121:
i = i + 10
end
-- add the list
isolatedcat()
if listall then
Baris 1.138 ⟶ 1.146:
local minyear = tonumber(string.match(minimumyear or '', '-?%d+')) or minyear_default --allow +/- qualifier
local maxyear = tonumber(string.match(maximumyear or '', '-?%d+')) or maxyear_default --allow +/- qualifier
if string.match(minimumyear or '', '
if string.match(maximumyear or '', '
if year == nil then
Baris 1.150 ⟶ 1.158:
local yearBCElastparts = { --needed for parent = AD 1-5, when the BC/E format is unknown
--"BCE" removed to match both AD & BCE cats; easier & faster than multiple string.match()s
['example_Hebrew people_example'] = '
}
local parentAD = string.match(firstpart, '
local parentBC = string.match(lastpart, '^
firstpart = mw.ustring.gsub(firstpart, '%s*
lastpart = mw.ustring.gsub(lastpart, '^
local BCe = parentBC or yearBCElastparts[lastpart] or '
local year1to10 = (year >= 1 and year <= 10)
Baris 1.181 ⟶ 1.189:
local ygapdefault = 1 --assume/start at the most common case: 2001, 2002, etc.
local ygap = ygapdefault
if string.match(lastpart, '
local ygap1, ygap2 = ygapdefault, ygapdefault --need to determine previous & next year gaps indepedently
local ygap1_success, ygap2_success = false, false
Baris 1.277 ⟶ 1.285:
--begin navyears
local navy = '{| class="toccolours
local navlist = {}
local y
local j = 0 --decrementor for special cases "2021 World Rugby Sevens Series" -> "2021–2022"
local i = -5 --nav position
while i <= 5 do
Baris 1.285 ⟶ 1.295:
y = ynogaps[i]
else
y = year + i*ygap*switchADBC - j
end
local BCdisp = ''
Baris 1.297 ⟶ 1.307:
if year >= 11 then --parent = AD 11-15
if y <= 10 then --prepend AD on y = 1-10 cats only, per existing cats
AD = '
end
Baris 1.305 ⟶ 1.315:
y = math.abs(y - 1) --skip y = 0 (DNE)
elseif y >= 1 and y <= 10 then --prepend AD on y = 1-10 cats only, per existing cats
AD = '
end
end
Baris 1.320 ⟶ 1.330:
Y = Y + 1 --skip y = 0 (DNE)
y = Y --easiest solution: start another iterator for these AD y's displayed on a BC year parent
AD = '
end
end
Baris 1.340 ⟶ 1.350:
catlink = catlinkNoAD --usurp
elseif listall then
tlistall[#tlistall] = tlistall[#tlistall]..' (tried; not displayed)<sup>1</sup>'
end
end
Baris 1.352 ⟶ 1.362:
else
if listall then
tlistall[#tlistall] = tlistall[#tlistall]..' (tried; not displayed)<sup>2</sup>'
end
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 )▼
local yHyph_2_special = (y-1)..'–'..string.match(y, '%d%d$') --try special case 2021 -> 2021–22
if catlinkHyph_2.catexists and catlinkHyph_2.rtarget == nil then --exists & no #Rs▼
local catlinkHyph_2_special = catlinkfollowr( frame, firstpart..lspace..yHyph_2_special..tspace..BC..lastpart, yHyph_2_special )
catlink = catlinkHyph_2 --usurp▼
if catlinkHyph_2_special.catexists and catlinkHyph_2_special.rtarget == nil then --exists & no #Rs
trackcat(27, 'Navseasoncats year and range')▼
catlink = catlinkHyph_2_special --usurp
▲ elseif listall then
▲ trackcat(27, 'Navseasoncats year and range')
tlistall[#tlistall] = tlistall[#tlistall]..' (tried; not displayed)'▼
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
Baris 1.367 ⟶ 1.390:
local r = catlink.rtarget
local c = catlink.cat
local
local
local
local
if mw.ustring.match(r,
elseif mw.ustring.match(r,
end
if
local r_base = mw.ustring.gsub(r,
local c_base = mw.ustring.gsub(c,
if r_base ~= c_base then
trackcat(19, 'Navseasoncats year redirected (base change)') --acceptable #R target
elseif mw.ustring.match(r,
trackcat(20, 'Navseasoncats year redirected (var change)') --e.g. "2008 in Scottish women's football" to "2008–09"
else
Baris 1.390 ⟶ 1.413:
end
end
else --OOB vs min/max
local hidden = '<span style="visibility:hidden">'..disp..'</span>'
if listall then
local dummy = catlinkfollowr( frame, firsttry, disp )
Baris 1.401 ⟶ 1.424:
else --center navy
if parentBC then BCdisp = ' '..BCe end
end
i = i + 1
end
--add the list
navy = navy .. horizontal(navlist) .. '\n'
isolatedcat()
Baris 1.419 ⟶ 1.445:
local function nav_roman( frame, firstpart, roman, lastpart, minimumrom, maximumrom )
local toarabic = require('
local toroman = require('
--sterilize/convert rom/num
Baris 1.427 ⟶ 1.453:
if num == nil or rom == nil then --out of range or some other error
errors = p.errorclass('Function nav_roman can\'t recognize one or more of "'..(num or 'nil')..'" & "'..
(rom or 'nil')..'"
return p.failedcat(errors, 'R')
end
Baris 1.440 ⟶ 1.466:
--begin navroman
local navr = '{| class="toccolours
local navlist = {}
local i = -5 --nav position
while i <= 5 do
Baris 1.454 ⟶ 1.481:
trackcat(22, 'Navseasoncats roman numeral redirected')
end
else
local hidden = '<span style="visibility:hidden">'..r..'</span>'
if listall then
tlistall[#tlistall] = tlistall[#tlistall]..' ('..hidden..')'
Baris 1.463 ⟶ 1.490:
end
else --center navr
end
else
end
Baris 1.472 ⟶ 1.499:
end
-- add the list
navr = navr .. horizontal(navlist) .. '\n'
isolatedcat()
if listall then
Baris 1.487 ⟶ 1.516:
local minord = tonumber(string.match(minimumord or '', '(-?%d+)[snrt]?[tdh]?')) or -9999 --allow full ord & +/- qualifier
local maxord = tonumber(string.match(maximumord or '', '(-?%d+)[snrt]?[tdh]?')) or 9999 --allow full ord & +/- qualifier
if string.match(minimumord or '', '
if string.match(maximumord or '', '
local temporal = string.match(lastpart, '
string.match(lastpart, '
local tspace = ' ' --assume a trailing space after ordinal
Baris 1.501 ⟶ 1.530:
--lists the lastpart of valid BCE cats
--"BCE" removed to match both AD & BCE cats; easier & faster than multiple string.match()s
['-century Hebrew people'] = '
['-century Jews'] = '
['-century Judaism'] = '
['-century rabbis'] = '
['-century High Priests of Israel'] = '
}
local parentBC = mw.ustring.match(lastpart, '%s(
local lastpartNoBC = mw.ustring.gsub(lastpart, '%
local BCe = parentBC or ordBCElastparts[lastpartNoBC] or '
local switchADBC = 1 -- 1=AD parent
Baris 1.524 ⟶ 1.553:
bnb = ' border-style: none; background-color: transparent;'
end
local navo = '{| class="toccolours
local navlist = {}
local i = -5 --nav position
while i <= 5 do
Baris 1.567 ⟶ 1.597:
trackcat(23, 'Navseasoncats nordinal redirected')
end
else
if listall then
tlistall[#tlistall] = tlistall[#tlistall]..' ('..hidden..')'
Baris 1.579 ⟶ 1.609:
trackcat(23, 'Navseasoncats nordinal redirected')
end
else --either out-of-range (hide), or non-temporal + BC = something might be wrong (2nd X parliament BC?); handle exceptions if/as they arise
table.insert(navlist, hidden)
navo = navo..'*'..hidden..'\n'▼
end
i = i + 1
end
isolatedcat()
Baris 1.599 ⟶ 1.631:
local function nav_wordinal( frame, firstpart, word, lastpart, minimumword, maximumword, ordinal, frame )
--Module:ConvertNumeric.
-- ordinal ==
-- ordinal
local
local
local th = 'th'
if not ordinal
th = ''
end
local
local
▲ local case = nil
local lspace = ' ' --assume a leading space (most common)
Baris 1.628 ⟶ 1.657:
minword = num
else
local ord =
if 0 < ord and ord < maxword then
minword = ord
Baris 1.639 ⟶ 1.668:
maxword = num
else
local ord =
if 0 < ord and ord < maxword then
maxword = ord
Baris 1.649 ⟶ 1.678:
--begin navwordinal
local navw = '{| class="toccolours
local navlist = {}
local i = -5 --nav position
while i <= 5 do
Baris 1.657 ⟶ 1.687:
if n >= 1 then
local nth = p.addord(n)
if not ordinal
if i ~= 0 then --left/right navw
local
local catlink = catlinkfollowr( frame, firstpart..lspace..w..tspace..lastpart, nth )
if minword <= n and n <= maxword then
Baris 1.666 ⟶ 1.695:
trackcat(24, 'Navseasoncats wordinal redirected')
end
else
local hidden = '<span style="visibility:hidden">'..nth..'</span>'
if listall then
tlistall[#tlistall] = tlistall[#tlistall]..' ('..hidden..')'
Baris 1.675 ⟶ 1.704:
end
else --center navw
end
else
end
i = i + 1
end
-- Add the list
navw = navw .. horizontal(navlist) .. '\n'
isolatedcat()
Baris 1.703 ⟶ 1.734:
end
local cpagename = '
local d_season = mw.ustring.match(cpagename, ':(%d+
local y_season = mw.ustring.match(cpagename, ':(%d+) .+%(%d+[–-]%d+%)') --i.e. "1763 establishments in the Province of Quebec (1763–1791)"
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+[–-]
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+)$')
local tvseason = mw.ustring.match(cpagename, '
mw.ustring.match(cpagename, '
local nordinal = mw.ustring.match(cpagename, '
mw.ustring.match(cpagename, '
local decade = mw.ustring.match(cpagename, '[:%s](%d+s)[%s-
mw.ustring.match(cpagename, '[:%s](%d+
local year = mw.ustring.match(cpagename, '[:%s](%d%d%d%d)%s') or --prioritize 4-digit years
Baris 1.755 ⟶ 1.786:
else
--try wordinals ('zeroth' to 'ninety-ninth' only)
local
local split = mw.text.split(pagename, ' ')
for i=1, #split do
if
return { ['vtype'] = 'wordinal', ['v'] = split[i] }
end
Baris 1.764 ⟶ 1.795:
--try English numerics ('one'/'single' to 'ninety-nine' only)
local eng2num = require('
local split = mw.text.split(pagename, '[%s%-]') --e.g. "Nine-cylinder engines"
for i=1, #split do
Baris 1.804 ⟶ 1.835:
if skip_gaps and skip_gaps == 'yes' then
skipgaps = true
trackcat(26, 'Navseasoncats
end
--ns checks
if currtitle.nsText == '
if cat and cat ~= '' then
trackcat(1, 'Navseasoncats using cat parameter')
Baris 1.830 ⟶ 1.861:
local firstpart, lastpart = string.match(pagename, '^(.-)'..findvar_escaped..'(.*)$')
if findvar.vtype == 'tvseason' then --double check for cases like '30 Rock (season 3) episodes'
firstpart, lastpart = string.match(pagename, '^(.-
if firstpart == nil then
firstpart, lastpart = string.match(pagename, '^(.-
end
end
Baris 1.846 ⟶ 1.877:
local firstpart_dec = firstpart
if firstpart_dec ~= '' then
firstpart_dec = firstpart_dec..' the'
elseif firstpart_dec == '
firstpart_dec = ''
if dec == 0 then dec = '' end
end
local decade = dec..'
decadecat = mw.text.trim( firstpart_dec..' '..decade..lastpart )
local exists = catexists(decadecat)
Baris 1.872 ⟶ 1.903:
local nav1 = nav_decade( frame, firstpart, start, lastpart, minimum, maximum )..testcaseindent..table.concat(ttrackingcats)
local decade = tonumber(string.match(findvar.v, '^(%d+)
local century = math.floor( ((decade-1)/100) + 1 ) --from {{CENTURY}}
if century == 0 then century = 1 end --no 0th century
Baris 1.878 ⟶ 1.909:
century = century + 1 --'2000' is in the 20th, but the rest of the 2000s is in the 21st
end
local clastpart = '
local centurycat = mw.text.trim( firstpart..' '..p.addord(century)..clastpart )
local exists = catexists(centurycat)
if not exists then --check for hyphenated century
clastpart = '-
centurycat = mw.text.trim( firstpart..' '..p.addord(century)..clastpart )
exists = catexists(centurycat)
Baris 1.906 ⟶ 1.937:
elseif findvar.vtype == 'wordinal' then --e.g. "first", "ninety-ninth"; <<1% of cats
local ordinal =
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
local ordinal =
return nav_wordinal( frame, firstpart, findvar.v, lastpart, minimum, maximum, ordinal, frame )..testcaseindent..table.concat(ttrackingcats)
Baris 1.917 ⟶ 1.948:
elseif findvar.vtype == 'ending' then --e.g. "2021–" (irregular; ending unknown); <<<1% of cats
local hyphen, finish = mw.ustring.match(findvar.v, '%d([–-])
if hyphen == nil then
hyphen, finish = mw.ustring.match(findvar.v, '%d([–-])$'), 0 --0/-1 are hardcoded switches for nav_hyphen()
|