تضامنًا مع حق الشعب الفلسطيني |
وحدة:Islamic months table maker
اذهب إلى التنقل
اذهب إلى البحث
![](https://upload.wikimedia.org/wikipedia/commons/thumb/4/43/Test_Template_Info-Icon_-_Version_%282%29.svg/50px-Test_Template_Info-Icon_-_Version_%282%29.svg.png)
-- Islamic months table maker
-- Used in templates such as {{شوال}}
-- Written by Alireza Eskandarpour Shoferi in Lua
--
-- Distributed under the terms of the CC BY-SA 4.0
--[[ INSTRUCTIONS
1. Place '{{#invoke:Islamic months table maker|main|{{PAGENAME}}}}' into Islamic month templates; Or place '{{#invoke:Islamic months table maker|main|month_name}}' anywhere with replacing 'month_name' with Islamic month name.
]]--
-- Load necessary modules.
local convertToAr = require("Module:Numeral converter").convert
local p = {}
local monthNames = {"محرم","صفر","ربيع الأول","ربيع الآخر","جمادى الأولى","جمادى الآخرة","رجب","شعبان","رمضان","شوال","ذو القعدة","ذو الحجة"}
local monthDays = {30,30,30,30,30,30,30,30,30,30,30,30}
function p.main(frame)
local selectedMonth = frame.args[1]
-- convert argument: if true convert returned number to Arabic.
local function getMonthNumber(givenMonth, convert)
convert = convert or false
for k,v in pairs(monthNames) do
if v == givenMonth then
if convert then
return convertToFa("ar",k)
end
return k
end
end
end
local function getPreviousMonthName(givenMonth)
local previousMonthName
for _,v in pairs(monthNames) do
if(v == givenMonth) then
if type(previousMonthName) == "nil" then
return monthNames[#monthNames]
end
return previousMonthName
end
previousMonthName = v
end
end
local function getNextMonthName(givenMonth)
local _,v = next(monthNames,getMonthNumber(givenMonth))
if type(v) == "nil" then
return monthNames[1]
end
return v
end
if type(selectedMonth) == "string" and type(monthNames[getMonthNumber(selectedMonth)]) ~= "nil" then
local wrapper = mw.html.create("table")
:addClass("toccolours")
:css("float","left")
:css("margin-right","1em")
:css("text-align","center")
local header = mw.html.create("tr")
:css("background-color","#ccccff")
:css("text-align","center")
-- Modify disambiguation pages to the right month article pages.
local link = nil
local preLink = nil
local nexLink = nil
for _,m in pairs({"محرم", "صفر", "رمضان"}) do
if m == selectedMonth then
link = m .. " (شهر)"
elseif m == getPreviousMonthName(selectedMonth) then
preLink = m .. " (شهر)"
elseif m == getNextMonthName(selectedMonth) then
nexLink = m .. " (شهر)"
end
end
link = link or selectedMonth
preLink = preLink or getPreviousMonthName(selectedMonth)
nexLink = nexLink or getNextMonthName(selectedMonth)
header:node(mw.html.create("td"):attr("colspan","2"):wikitext("[[" .. preLink .. "|" .. getPreviousMonthName(selectedMonth) .. "]]"):done())
header:node(mw.html.create("td"):attr("colspan","3"):wikitext("'''[[" .. link .. "|" .. selectedMonth .. "]]'''"):done())
header:node(mw.html.create("td"):attr("colspan","2"):wikitext("[[" .. nexLink .. "|" .. getNextMonthName(selectedMonth) .. "]]"):done())
local underHeader = mw.html.create("tr")
:css("background-color","#ccccff")
:css("text-align","center")
for _ = 1, 7 do
local underHeaderContent = mw.html.create("td")
:css("width","14%")
underHeader:node(underHeaderContent:done())
end
local container = mw.html.create(nil)
local n = 1
for _ = 1, 5 do
if n < monthDays[getMonthNumber(selectedMonth)] then
local numberRow = mw.html.create("tr")
for _=1, 7 do
if n > monthDays[getMonthNumber(selectedMonth)] then
break
end
numberRow:node(mw.html.create("td"):wikitext("[[" .. convertToAr("ar",n) .. " " .. selectedMonth .. "|" .. convertToAr("ar",n) .. "]]"):done())
n = n +1
end
container:node(numberRow:allDone())
end
end
local footer = mw.html.create("tr")
:css("background-color","lightblue")
footer:node(mw.html.create("td"):attr("colspan","7"):attr("align","center"):attr("bgcolor","#ccccff"):wikitext("[[تقويم هجري|* * * * تـقــويـم هـجــري * * * *]]"):done())
wrapper:node(header)
wrapper:node(underHeader)
wrapper:node(container)
wrapper:node(footer)
return tostring(wrapper)
else
error("الحجج في بداية الأمر أن يکون من قسم الحقل و إسم الشهر")
end
end
return p