fbpx
วิกิพีเดีย

มอดูล:Current events calendar

คู่มือการใช้งานมอดูล[สร้าง]
-- This module renders the calendar seen on [[Portal:Current events]].  local config = {  monthAndYearFormat = 'F พ.ศ. xkY',  yearFormat = 'xkY',  dayLinkFormat = "'''[[#$3 $2 $1|$3]]'''", } local p = {}  local function makeWikilink(link, display)  if display then  return string.format('[[%s|%s]]', link, display)  else  return string.format('[[%s]]', link)  end end  function p.main()  local dateStuff = p.getDateStuff()  local dayStrings = p.makeDayStrings(dateStuff)  return p.export(dayStrings, dateStuff) end  function p.getDateStuff()  -- Gets date data.  local dateStuff = {}  local lang = mw.language.getContentLanguage()  --Year  local year = lang:formatDate(config.yearFormat)  year = tonumber(year)  dateStuff.year = year  -- Month  local month = lang:formatDate('F')  dateStuff.month = month  -- Month and year  local monthAndYear = lang:formatDate(config.monthAndYearFormat)  local firstOfMonth = lang:formatDate('01-m-Y')  dateStuff.monthAndYear = monthAndYear  -- Previous month and year  dateStuff.previousMonthAndYear = lang:formatDate(config.monthAndYearFormat, firstOfMonth .. ' -1 month')  -- Next month and year  dateStuff.nextMonthAndYear = lang:formatDate(config.monthAndYearFormat, firstOfMonth .. ' +1 month')  -- Day  local day = lang:formatDate('j')  day = tonumber(day)  dateStuff.day = day  -- Days in month  local daysInMonth = lang:formatDate('j', firstOfMonth .. ' +1 month -1 day')  daysInMonth = tonumber(daysInMonth)  dateStuff.daysInMonth = daysInMonth  -- Weekday of the first day of the month  local firstWeekday = lang:formatDate('w', firstOfMonth) -- Sunday = 0, Saturday = 6  firstWeekday = tonumber(firstWeekday)  firstWeekday = firstWeekday + 1 -- Make compatible with Lua tables. Sunday = 1, Saturday = 7.  dateStuff.firstWeekday = firstWeekday  return dateStuff end  function p.makeDayStrings(dateStuff)  local calStrings = {}  local currentDay = dateStuff.day  local isLinkworthy = p.isLinkworthy  local currentMonth = dateStuff.month  local currentYear = dateStuff.year  local makeDayLink = p.makeDayLink  for day = 1, dateStuff.daysInMonth do  if isLinkworthy(day, currentDay) then  calStrings[#calStrings + 1] = makeDayLink(day, currentMonth, currentYear)  else  calStrings[#calStrings + 1] = tostring(day)  end  end  return calStrings end  function p.isLinkworthy(day, currentDay)  -- Returns true if the calendar day should be linked, and false if not.  -- Days should be linked if they are the current day or if they are within the six  -- preceding days, as that is the number of items on the current events page.  if currentDay - 6 <= day and day <= currentDay then  return true  else  return false  end end  function p.makeDayLink(day, month, year)  return mw.message.newRawMessage(config.dayLinkFormat):params(year, month, day):plain() end  function p.export(dayStrings, dateStuff)  -- Generates the calendar HTML.  local monthAndYear = dateStuff.monthAndYear  local root = mw.html.create('table')  root  :addClass('infobox')  :css{width = '250px', ['text-align'] = 'center', ['background-color'] = '#f5faff', border = '1px solid #cedff2'}   -- Headings  :tag('tr')  :css('background-color', '#cedff2')  :tag('td')  :css{['padding-top'] = '1px', ['padding-bottom'] = '3px'}  :wikitext(makeWikilink(dateStuff.previousMonthAndYear, '<<'))  :done()  :tag('td')  :attr('colspan', '5')  :css{padding = '1px 4px', ['font-weight'] = 'bold'}  :wikitext(makeWikilink(monthAndYear))  :done()  :tag('td')  :css{['padding-top'] = '1px', ['padding-bottom'] = '3px'}  :wikitext(makeWikilink(dateStuff.nextMonthAndYear, '>>'))   -- Day of week headings  local dayHeadingRow = root:tag('tr')  local weekdays = {'อา', 'จ', 'อ', 'พ', 'พฤ', 'ศ', 'ส'}  for i, weekday in ipairs(weekdays) do  dayHeadingRow:tag('td')  :wikitext(weekday)  end   -- Days  local colspan = dateStuff.firstWeekday - 1  local cellCount = 0 -- Tracks the number of day cells.  local firstDayRow = root:tag('tr')  if colspan > 1 then  firstDayRow:tag('td')  :attr('colspan', tostring(colspan))  elseif colspan == 1 then  firstDayRow:tag('td')  end  for i = colspan + 1, 7 do -- Finish the first row  cellCount = cellCount + 1  firstDayRow:tag('td')  :wikitext(dayStrings[cellCount])  end  while cellCount < #dayStrings do -- Second day row onwards  local otherDayRow = root:tag('tr')  for i = 1, 7 do  cellCount = cellCount + 1  local dayString = dayStrings[cellCount]  if not dayString then  break  end  otherDayRow:tag('td')  :wikitext(dayString)  end  end   -- Footer  root:tag('tr')  :tag('td')  :attr('colspan', '7')  :css{['padding-top'] = '3px', ['padding-bottom'] = '5px', ['font-size'] = '78%', ['text-align'] = 'left'}  :wikitext('&nbsp;&nbsp; ' .. makeWikilink(monthAndYear, 'ดูเพิ่มเกี่ยวกับเหตุการณ์ใน' .. monthAndYear))   return tostring(root) end  return p 

มอด, current, events, calendar, เป, นมอด, ลท, กป, องก, นถาวรเน, องจากม, ความเส, ยงส, งกร, ณาอภ, ปรายการเปล, ยนแปลงใด, ทางหน, าค, ณอาจส, งคำขอแก, ไข, ไปย, งผ, แลระบบเพ, อให, แก, ไขได, หากเป, นการแก, ไขท, ไม, การค, ดค, านหร, อม, ความเห, นพ, องสน, บสน, ณย, งสามาร. niepnmxdulthithukpxngknthawrenuxngcakmikhwamesiyngsungkrunaxphipraykarepliynaeplngid thanghnakhuy khunxacsngkhakhxaekikh ipyngphuduaelrabbephuxihaekikhidhakepnkaraekikhthiimmikarkhdkhanhruxmikhwamehnphxngsnbsnun khunyngsamarthkhxihelikpxngknhnaidkhumuxkarichnganmxdul srang khunxaccatxngkarsrangkhumuxkarichngankhxngmxdulniphuekhiynsamarththakarthdlxngidthikrabathray srang khdlxk aelachudthdsxb srang khxngmxdulnioprdephimhmwdhmuipthihnayxy doc hnayxykhxngmxdulni This module renders the calendar seen on Portal Current events local config monthAndYearFormat F ph s xkY yearFormat xkY dayLinkFormat 3 2 1 3 local p local function makeWikilink link display if display then return string format s s link display else return string format s link end end function p main local dateStuff p getDateStuff local dayStrings p makeDayStrings dateStuff return p export dayStrings dateStuff end function p getDateStuff Gets date data local dateStuff local lang mw language getContentLanguage Year local year lang formatDate config yearFormat year tonumber year dateStuff year year Month local month lang formatDate F dateStuff month month Month and year local monthAndYear lang formatDate config monthAndYearFormat local firstOfMonth lang formatDate 01 m Y dateStuff monthAndYear monthAndYear Previous month and year dateStuff previousMonthAndYear lang formatDate config monthAndYearFormat firstOfMonth 1 month Next month and year dateStuff nextMonthAndYear lang formatDate config monthAndYearFormat firstOfMonth 1 month Day local day lang formatDate j day tonumber day dateStuff day day Days in month local daysInMonth lang formatDate j firstOfMonth 1 month 1 day daysInMonth tonumber daysInMonth dateStuff daysInMonth daysInMonth Weekday of the first day of the month local firstWeekday lang formatDate w firstOfMonth Sunday 0 Saturday 6 firstWeekday tonumber firstWeekday firstWeekday firstWeekday 1 Make compatible with Lua tables Sunday 1 Saturday 7 dateStuff firstWeekday firstWeekday return dateStuff end function p makeDayStrings dateStuff local calStrings local currentDay dateStuff day local isLinkworthy p isLinkworthy local currentMonth dateStuff month local currentYear dateStuff year local makeDayLink p makeDayLink for day 1 dateStuff daysInMonth do if isLinkworthy day currentDay then calStrings calStrings 1 makeDayLink day currentMonth currentYear else calStrings calStrings 1 tostring day end end return calStrings end function p isLinkworthy day currentDay Returns true if the calendar day should be linked and false if not Days should be linked if they are the current day or if they are within the six preceding days as that is the number of items on the current events page if currentDay 6 lt day and day lt currentDay then return true else return false end end function p makeDayLink day month year return mw message newRawMessage config dayLinkFormat params year month day plain end function p export dayStrings dateStuff Generates the calendar HTML local monthAndYear dateStuff monthAndYear local root mw html create table root addClass infobox css width 250px text align center background color f5faff border 1px solid cedff2 Headings tag tr css background color cedff2 tag td css padding top 1px padding bottom 3px wikitext makeWikilink dateStuff previousMonthAndYear lt lt done tag td attr colspan 5 css padding 1px 4px font weight bold wikitext makeWikilink monthAndYear done tag td css padding top 1px padding bottom 3px wikitext makeWikilink dateStuff nextMonthAndYear gt gt Day of week headings local dayHeadingRow root tag tr local weekdays xa c x ph phv s s for i weekday in ipairs weekdays do dayHeadingRow tag td wikitext weekday end Days local colspan dateStuff firstWeekday 1 local cellCount 0 Tracks the number of day cells local firstDayRow root tag tr if colspan gt 1 then firstDayRow tag td attr colspan tostring colspan elseif colspan 1 then firstDayRow tag td end for i colspan 1 7 do Finish the first row cellCount cellCount 1 firstDayRow tag td wikitext dayStrings cellCount end while cellCount lt dayStrings do Second day row onwards local otherDayRow root tag tr for i 1 7 do cellCount cellCount 1 local dayString dayStrings cellCount if not dayString then break end otherDayRow tag td wikitext dayString end end Footer root tag tr tag td attr colspan 7 css padding top 3px padding bottom 5px font size 78 text align left wikitext amp nbsp amp nbsp makeWikilink monthAndYear duephimekiywkbehtukarnin monthAndYear return tostring root end return p ekhathungcak https th wikipedia org w index php title mxdul Current events calendar amp oldid 5403835, wikipedia, วิกิ หนังสือ, หนังสือ, ห้องสมุด,

บทความ

, อ่าน, ดาวน์โหลด, ฟรี, ดาวน์โหลดฟรี, mp3, วิดีโอ, mp4, 3gp, jpg, jpeg, gif, png, รูปภาพ, เพลง, เพลง, หนัง, หนังสือ, เกม, เกม