Difference between revisions of "Module:Navseasoncats/navyear/sandbox"
Jump to navigation
Jump to search
blackwiki>BrownHairedGirl (sync from live) |
blackwiki>BrownHairedGirl (add function makeCatLink(catname, disp) to avoid calls to template) |
||
| Line 1: | Line 1: | ||
local p = {} | local p = {} | ||
| + | |||
| + | -- 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 | ||
| + | local fmtlink | ||
| + | local catPage = mw.title.new( catname, "Category" ) | ||
| + | if (catPage.exists) then | ||
| + | fmtlink = "[[:Category:" .. catname .. "|" .. displaytext .. "]]" | ||
| + | blueLinkCount = blueLinkCount + 1 | ||
| + | else | ||
| + | fmtlink = '<span style="color:' .. greyLinkColor .. '">' .. displaytext .. "</span>" | ||
| + | greyLinkCount = greyLinkCount + 1 | ||
| + | end | ||
| + | |||
| + | return fmtlink | ||
| + | end | ||
function p.navyear(frame) | function p.navyear(frame) | ||
| Line 23: | Line 46: | ||
if i ~= 0 then | if i ~= 0 then | ||
if ((year >= arg4) and (year <= arg5)) then | if ((year >= arg4) and (year <= arg5)) then | ||
| − | navyear = navyear..'*'.. | + | navyear = navyear .. '*' .. makeCatLink(arg1..' '..year..' '..arg3, year) .. '\n' |
else | else | ||
navyear = navyear..'*<span style="visibility:hidden">'..year..'</span>\n' | navyear = navyear..'*<span style="visibility:hidden">'..year..'</span>\n' | ||
Revision as of 13:52, 25 February 2019
Documentation for this module may be created at Module:Navseasoncats/navyear/sandbox/doc
local p = {}
-- 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
local fmtlink
local catPage = mw.title.new( catname, "Category" )
if (catPage.exists) then
fmtlink = "[[:Category:" .. catname .. "|" .. displaytext .. "]]"
blueLinkCount = blueLinkCount + 1
else
fmtlink = '<span style="color:' .. greyLinkColor .. '">' .. displaytext .. "</span>"
greyLinkCount = greyLinkCount + 1
end
return fmtlink
end
function p.navyear(frame)
--Expects a PAGENAME of the form "Some sequential 2015 example cat", where
-- {{{1}}}=Some sequential
-- {{{2}}}=2015
-- {{{3}}}=example cat
-- {{{4}}}=1758 ('min' year parameter; optional)
-- {{{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])
local arg5 = tonumber(frame.args[5])
if arg4 == nil then arg4 = -9999 end
if arg5 == nil then arg5 = 9999 end
local navyear = '{| class="toccolours hlist" style="text-align: center; margin: auto;"\n'..'|\n'
local i = -5
while i <= 5 do
local year = arg2 + i
if i ~= 0 then
if ((year >= arg4) and (year <= arg5)) then
navyear = navyear .. '*' .. makeCatLink(arg1..' '..year..' '..arg3, year) .. '\n'
else
navyear = navyear..'*<span style="visibility:hidden">'..year..'</span>\n'
end
else
navyear = navyear..'*<b>'..arg2..'</b>\n'
end
i = i + 1
end
return navyear..'|}'
end
return p