Content deleted Content added
No edit summary |
No edit summary |
||
(9 intermediate revisions by 3 users not shown) | |||
Line 3:
--]]
require('
local getArgs = require ('Module:Arguments').getArgs;
Line 30:
end
--[[--------------------------< I S _ L E A P >----------------------------------------------------------------
returns true when <year> is a leapyear
]]
local function is_leap (year)
return '1' == lang_obj:formatDate ('L', tostring(year));
end
--[[--------------------------< D A Y _ O F _ W E E K >--------------------------------------------------------
returns 1 to 7; 1 == Sunday; 1 == Monday when iso true
local function day_of_week (year, month, day, iso)
return
iso and lang_obj:formatDate ('N', year .. '-' .. month .. '-' .. day) or -- ISO: 1 = monday
lang_obj:formatDate ('w', year .. '-' .. month .. '-' .. day) + 1; -- 1 = sunday
end
Line 84 ⟶ 89:
--[[--------------------------< G E T _ D I S P L A Y _ Y E A R >----------------------------------------------
and stand-alone calendars
]]
Line 93 ⟶ 96:
local function get_display_year (props)
local year_text = props.year;
local lk_prefix = props.lk_pref_y or props.lk_pref;
local lk_suffix = props.lk_suff_y or props.lk_suff;
if props.lk_y then -- if to be linked
if lk_prefix or lk_suffix then -- when prefix or suffix, [[prefix .. link .. suffix|label]]
year_text = make_wikilink ((lk_prefix or '') .. year_text .. (lk_suffix or ''), year_text);
else
year_text = make_wikilink (year_text); -- just year
end
end
return year_text;
end
Line 104 ⟶ 113:
--[[--------------------------< G E T _ D I S P L A Y _ M O N T H >--------------------------------------------
returns month from
argument mnum is nil when rendering stand-alone calendar
]]
Line 112 ⟶ 123:
month_text = monthname[month_text];
local lk_prefix = props.lk_pref_m or props.lk_pref;
if props['lk_m&y'] then -- stand-alone month calendars only
month_text = month_text .. ' ' .. props.year; -- composite month and year link
end
if props.lk_m or props['lk_m&y'] then
if lk_prefix or lk_suffix then -- when prefix or suffix, [[prefix .. link .. suffix|label]]
month_text = make_wikilink ((lk_prefix or '') .. month_text .. (lk_suffix or ''), month_text);
else
month_text = make_wikilink (month_text); -- just month name or composite month/year
end
end
Line 131 ⟶ 149:
local function get_display_day (day_text, mnum, props)
local lk_prefix = props.lk_pref_d or props.lk_pref;
local lk_suffix = props.lk_suff_d or props.lk_suff;
if props.lk_d then
local link_text = (
day_text = make_wikilink (link_text, day_text);
end
Line 162 ⟶ 183:
:attr (opt_attr)
:css (css_opts)
:wikitext (item) --
:done() -- close <td>
table.insert (tags, tostring (repeat_tag)); -- make a string of this object
end
return table.concat (tags); -- concatenate them all together
end
Line 182 ⟶ 204:
local result = {};
local hilite;
local hilite_two;
for col = 1, 7 do
Line 203 ⟶ 226:
if (props.year == props.this_ynum) and (mnum == props.this_mnum) and (dom == props.this_dnum) then
hilite = col;
end
end
if props.aday then -- highlight arbitrary date when displayed
if (props.year == props.this_ynum) and (mnum == props.this_mnum) and (dom == props.this_dnum) then
hilite_two = col;
end
end
Line 213 ⟶ 241:
table.insert (result, repeat_tags ('td', {td_item}, {['class']='mcal', ['css'] = {['background-color'] = props.today_color or '#cfc'}}));
else
if i == hilite_two then
table.insert (result, repeat_tags ('td', {td_item}, {['class']='mcal', ['css'] = {['background-color'] = props.aday_color or '#cfc'}}));
end
table.insert (result, repeat_tags ('td', {td_item}, options));
end
Line 231 ⟶ 262:
local css_opts = props.week_color and {['background'] = props.week_color} or {}
if props.iso_wk or props.iso then
if props.iso_wk then
table.insert (headers, repeat_tags ('th', {'Wk'}, {['class']='mcal', ['attr']={['title'] = 'ISO week number'}, ['css'] = css_opts})); -- iso week header
end
for i, abbr in ipairs (iso_dayabbr) do
table.insert (headers, repeat_tags ('th', {iso_dayabbr[i]}, {['class']='mcal', ['attr']={['title'] = iso_dayname[i]}, ['css'] = css_opts}));
Line 259 ⟶ 292:
local col_span = (props.iso_wk and 8) or 7; -- assume no prev/next
if not props.hide_year and props.month_num then -- props.month_num has value only for stand-alone month calendars
hdr_year = get_display_year (props); -- if to be shown, add wikilink, etc when required
end
if props.prevnext then
next = monthname[(13 > mnum+1) and mnum+1 or 1];
if is_set (hdr_year) then
prev = prev .. ' ' .. ((0 < mnum-1) and hdr_year or hdr_year-1); -- january-1 = december previous year
next = next .. ' ' .. ((13 > mnum+1) and hdr_year or hdr_year+1); -- december+1 = january next year
end
local link_text = (props.lk_pref_mprev or '') .. prev .. (props.lk_suff_mprev or '')
prev = make_wikilink (link_text, '<<');
link_text = (
next = make_wikilink (link_text, '>>');
Line 274 ⟶ 315:
end
if props['lk_m&y'] then -- for composite links
table.insert (result, repeat_tags ('th', {get_display_month (mnum, props)}, {['class']='mcal', ['attr']={['colspan']=col_span}}));
else
table.insert (result, repeat_tags ('th', {get_display_month (mnum, props) .. ' ' .. hdr_year}, {['class']='mcal', ['attr']={['colspan']=col_span}}));
end
if props.prevnext then
Line 303 ⟶ 348:
end
if props.month_num then -- month_num only set when doing
table_css.border = '1px solid grey'; -- put this is styles.css as a separate class?
end
Line 329 ⟶ 374:
end
month_cal:done() -- close <table>
--mw.log (tostring (month_cal))
return tostring (month_cal)
end
Line 351 ⟶ 396:
end
end
return repeat_tags ('td', td_items, options)
end
Line 364 ⟶ 410:
local css_opts = {};
if props.hide_year
css_opts['display'] = 'none'; -- use css to hide the year header (but not when |title= has a value)
end
Line 375 ⟶ 421:
:css(css_opts)
:attr ('colspan', props.cols)
:wikitext (props.title or get_display_year (props
return tostring (header)
end
Line 412 ⟶ 458:
--[[--------------------------< _ C A L E N D A R >------------------------------------------------------------
module entry point. args is the parent frame args table
]]
local function _calendar (args)
local props = {}; -- separate calendar properties table to preserve arguments as originally provided
local this_year_num = tonumber (lang_obj:formatDate ('Y'));
local this_month_num = tonumber (lang_obj:formatDate ('n'));
if (1583 > props.year) or (1582 == props.year and 10 > props.month_num) then -- gregorian calendar only (1583 for yearly calendar because gregorian started in October of 1582)
props.year = this_year_num; -- so use this year
end
props.leap = is_leap (props.year)
if 1 >
end
if args.month then
local mnum = tonumber(args.month)
if not mnum then -- month provided as some sort of text string
if args.month == "current" then
elseif args.month == "last" then
mnum = this_month_num - 1
if mnum == 0 then
else
end
elseif args.month == "next" then
mnum = this_month_num + 1
if mnum == 13 then
else
end
else
local good
good,
if not good then
else
end
end
else
end
if args.lk_pref_mprev or args.lk_suff_mprev then
props.lk_suff_mprev = args.lk_suff_mprev;
props.prevnext = true;
end
if args.lk_pref_mnext or args.lk_suff_mnext then
props.lk_suff_mnext = args.lk_suff_mnext;
props.prevnext = true;
end
end
args.lk = args.lk and args.lk:lower();
if args.lk and ({['yes']=1, ['m&y']=1, ['dm&y']=1, ['dm']=1, ['my']=1, ['dy']=1, ['d']=1, ['m']=1, ['y']=1})[args.lk] then -- if valid keywords
if 'yes' == args.lk then -- all date components are individually linked
props.lk_d = true;
elseif 'm&y' == args.lk and props.month_num then -- stand-alone month calendars only; month and year as a single composite link
props['lk_m&y'] = true;
elseif 'dm&y' == args.lk and props.month_num then -- stand-alone month calendars only; month and year as a single composite link
props['lk_m&y'] = true;
props.lk_d = true;
else
end
end
if not (props.title or props.lk_y or props['lk_m&y']) then
props.hide_year = ('yes' == args.hide_year) or ('off' == args.show_year); -- year normally displayed; this hides year display but not when linked or replaced with title
end
props.lk_pref = args.lk_pref; -- prefix for all links except previous and next
props.lk_suff = args.lk_suff; -- suffix for all links except previous and next
for _, v in ipairs ({'y', 'm', 'd'}) do -- loop through calendar parts for link prefix and suffix parameters
if
end
end
if not (
end
props.today = 'yes' == (args.show_today and args.show_today:lower()); -- highlight today's date in calendars where it is displayed
props.today_color = args.today_color or args.today_colour;
-- TODO: add all other args{} from template or invoke to
if props.month_num then -- set only when rendering stand-alone month calendar
return display_month (props.month_num, props);
else
return display_year (props);
end
end
--[[--------------------------< C A L E N D A R >--------------------------------------------------------------
template entry point. All parameters are template parameters; there are no special invoke parameters
]]
local function calendar (frame)
local args=getArgs (frame);
return _calendar (args);
end
Line 580 ⟶ 617:
return {
calendar = calendar,
}
|