Module:Category series navigation/navyear/sandbox: Difference between revisions

Content deleted Content added
m Undid revision 866838191 by Tom.Reding (talk) working
 
(16 intermediate revisions by 2 users not shown)
Line 1:
local p = {}
 
local greyLinkColor = "#888"
 
-- Make a piped link to a category, if it exists
-- If it doesn't exist, just display the greyed the link title without linking
function makeCatLink(catname, disp)
local displaytext
if (disp ~= "") and (disp ~= nil) then
-- use 'disp' parameter, but strip any trailing disambiguator
displaytext = mw.ustring.gsub(disp, "%s+%(.+$", "");
else
displaytext = catname
end
if 1 == 1 then return catname end -- testing
local fmtlink
local catPage = mw.title.new( catname, "Category" )
if (catPage.exists) then
fmtlink = "[[:Category:" .. catname .. "|" .. displaytext .. "]]"
else
fmtlink = '<span style="color:' .. greyLinkColor .. '">' .. displaytext .. "</span>"
end
 
return fmtlink
end
 
function p.navyear(frame)
--Expects a PAGENAME of the form "Some sequential 20151760 example cat", where
-- {{{1}}}=Some sequential,
-- {{{2}}}=2015, 1760
-- {{{3}}}=example cat,
-- {{{4}}}=1758 ('min' year parameter; optional)
--TODO: and an optional 'minumum year' parameter {{{4}}}=1758
-- {{{5}}}=1800 ('max' year parameter; optional)
local arg1 = frame.args[1]
local arg2 = tonumber(frame.args[2])
local arg3 = frame.args[3]
local arg4 = tonumber(frame.args[4])
return '{| class="toccolours hlist" style="text-align: center; margin: auto;"\n' ..
local arg5 = tonumber(frame.args[5])
'|\n' ..
if arg4 == nil then arg4 = -9999 end
'*'..frame:expandTemplate{ title = 'LinkCatIfExists2', args = { arg1..' '..(arg2-5)..' '..arg3, (arg2-5) } }..'\n' ..
if arg5 == nil then arg5 = 9999 end
'*'..frame:expandTemplate{ title = 'LinkCatIfExists2', args = { arg1..' '..(arg2-4)..' '..arg3, (arg2-4) } }..'\n' ..
'*'..frame:expandTemplate{ title = 'LinkCatIfExists2', args = { arg1..' '..(arg2-3)..' '..arg3, (arg2-3) } }..'\n' ..
returnlocal navyear = '{| class="toccolours hlist" style="text-align: center; margin: auto;"\n' ..'|\n'
'*'..frame:expandTemplate{ title = 'LinkCatIfExists2', args = { arg1..' '..(arg2-2)..' '..arg3, (arg2-2) } }..'\n' ..
'*'..frame:expandTemplate{ title = 'LinkCatIfExists2', args = { arg1..' '..(arg2-1)..' '..arg3, (arg2-1) } }..'\n' ..
local i = -5
'*<b>'..arg2..'</b>\n' ..
while i <= 5 do
'*'..frame:expandTemplate{ title = 'LinkCatIfExists2', args = { arg1..' '..(arg2+1)..' '..arg3, (arg2+1) } }..'\n' ..
local year = arg2 + i
'*'..frame:expandTemplate{ title = 'LinkCatIfExists2', args = { arg1..' '..(arg2+2)..' '..arg3, (arg2+2) } }..'\n' ..
if i ~= 0 then
'*'..frame:expandTemplate{ title = 'LinkCatIfExists2', args = { arg1..' '..(arg2+3)..' '..arg3, (arg2+3) } }..'\n' ..
if (year >= arg4) and (year <= arg5) then -- ex: 1758, 1759, 1761, 1762, 1763, 1764, 1765
'*'..frame:expandTemplate{ title = 'LinkCatIfExists2', args = { arg1..' '..(arg2+4)..' '..arg3, (arg2+4) } }..'\n' ..
navyear = navyear..'*'..frame:expandTemplate{ title = 'LinkCatIfExists2', args = {makeCatLink( arg1..' '..(arg2+5)year..' '..arg3, (arg2+5year ) } }..'\n' ..
else -- ex: 1755, 1756, 1757
'|}'
navyear = navyear..'*<span style="visibility:hidden">'..year..'</span>\n'
end
else -- ex: 1760
navyear = navyear..'*<b>'..arg2..'</b>\n' ..
end
i = i + 1
end
return navyear..'|}'
end