मोड्युल:Navseasoncats/navyear
मोड्युल कागजात[हेर्नुहोस्] [सम्पादन गर्नुहोस्] [इतिहास] [ताजा गर्नुहोस्]
This Lua module is used on approximately १५१,००० pages. To avoid major disruption and server load, any changes should be tested in the module's /sandbox or /testcases subpages, or in your own module sandbox. The tested changes can be added to this page in a single edit. Consider discussing changes on the talk page before implementing them. |
About
सम्पादन गर्नुहोस्This is a former submodule to {{Navseasoncats}}. Due to minimal error checking and limited scope, it should not be used on its own except in controlled situations. It should not be used in category sequences which extend below AD 6, to simplify maintenance for that sequence and to limit the potential for error.
local p = {}
local grey = "#888"
-- Make a piped link to a category, if it exists
-- If it doesn't exist, just display the greyed unlinked title
function makeCatLink(catname, disp)
local displaytext = catname
if disp and disp ~= '' then
-- use 'disp' parameter, but strip any trailing disambiguator
displaytext = mw.ustring.gsub(disp, '%s+%(.+$', '');
end
local catPage = mw.title.new( catname, 'Category' )
if (catPage and catPage.exists) then
return '[[:Category:'..catname..'|'..displaytext..']]'
else
return '<span style="color:'..grey..'">'..displaytext.."</span>"
end
end
function p.navyear(frame)
--Expects a PAGENAME of the form "Some sequential 1760 example cat", where
-- {{{1}}}=Some sequential
-- {{{2}}}=1760
-- {{{3}}}=example cat
-- {{{4}}}=1758 ('min' year parameter; optional)
-- {{{5}}}=1800 ('max' year parameter; optional)
local firsthalf = frame.args[1]
local year = tonumber(frame.args[2])
local lasthalf = frame.args[3]
local minyear = tonumber(frame.args[4]) or -9999
local maxyear = tonumber(frame.args[5]) or 9999
local navyear = '{| class="toccolours hlist" style="text-align: center; margin: auto;"\n'..'|\n'
local i = -5
while i <= 5 do
local y = year + i
if i ~= 0 then
if (y >= minyear) and (y <= maxyear) then -- ex: 1758, 1759, 1761, 1762, 1763, 1764, 1765
navyear = navyear..'*'..makeCatLink( firsthalf..' '..y..' '..lasthalf, y )..'\n'
else -- ex: 1755, 1756, 1757
navyear = navyear..'*<span style="visibility:hidden">'..y..'</span>\n'
end
else -- ex: 1760
navyear = navyear..'*<b>'..year..'</b>\n'
end
i = i + 1
end
return navyear..'|}'
end
return p