پودمان:بایگانی گمخ/تمرین
Appearance
اینجا صفحهٔ تمرین پودمان برای پودمان:بایگانی گمخ (تفاوت) است. |
require('strict')
local p = {}
local numConv = require('Module:Numeral converter').convert
local data = mw.loadJsonData('ویکیپدیا:گزیدن مقالههای خوب/بایگانی/فهرست.json')
local months = {
"دسامبر",
"نوامبر",
"اکتبر",
"سپتامبر",
"اوت",
"ژوئیه",
"ژوئن",
"مه",
"آوریل",
"مارس",
"فوریه",
"ژانویه"
}
function p.main (frame)
local date = os.date('*t')
local year, minyear = date.year, 2007
local tableYear = year -- Stored in another variable to get manipulated later (see end of p.main)
local text = ''
while tableYear >= minyear do
local y = tableYear
local tbl = mw.html.create('table')
if data[y] then
text = text .. '== ' .. numConv('fa', y) .. ' ==\n'
tbl
:attr('class', 'wikitable')
:css('width', '100%')
:tag('tr')
:tag('th'):wikitext('ماه')
:tag('th'):wikitext('موفق')
:tag('th'):wikitext('تعداد')
:tag('th'):wikitext('ناموفق')
:tag('th'):wikitext('تعداد')
:tag('th'):wikitext('ردشده در بازبینی')
:tag('th'):wikitext('تعداد')
:tag('th'):wikitext('مجموع')
:done()
for i, month in ipairs(months) do
local m = month
if data[y][m] then
local iSuccess = 1
local seccessCellData = ''
while data[y][m]['success'][iSuccess] do
seccessCellData = seccessCellData .. frame:expandTemplate{ title = 'ویکیپدیا:گزیدن مقالههای خوب/بایگانی/مقاله', args = {
data[y][m]['success'][iSuccess]['article'],
data[y][m]['success'][iSuccess]['GANPage'] or data[y][m]['success'][iSuccess]['article'],
data[y][m]['success'][iSuccess]['nomNum'] and data[y][m]['success'][iSuccess]['nomNum'] or ''
}
}
iSuccess = iSuccess + 1
if data[y][m]['success'][iSuccess] then
seccessCellData = seccessCellData .. ' • '
end
end
local iFail = 1
local failCellData = ''
while data[y][m]['fail'][iFail] do
failCellData = failCellData .. frame:expandTemplate{ title = 'ویکیپدیا:گزیدن مقالههای خوب/بایگانی/مقاله', args = {
data[y][m]['fail'][iFail]['article'],
data[y][m]['fail'][iFail]['GANPage'] or data[y][m]['fail'][iFail]['article'],
data[y][m]['fail'][iFail]['nomNum'] and data[y][m]['fail'][iFail]['nomNum'] or ''
}
}
iFail = iFail + 1
if data[y][m]['fail'][iFail] then
failCellData = failCellData .. ' • '
end
end
local iReject = 1
local rejectCellData = ''
while data[y][m]['reject'][iReject] do
rejectCellData = rejectCellData .. frame:expandTemplate{ title = 'ویکیپدیا:گزیدن مقالههای خوب/بایگانی/مقاله', args = {
data[y][m]['reject'][iReject]['article'],
data[y][m]['reject'][iReject]['GANPage'] or data[y][m]['reject'][iReject]['article'],
data[y][m]['reject'][iReject]['nomNum'] and data[y][m]['reject'][iReject]['nomNum'] or ''
}
}
iReject = iReject + 1
if data[y][m]['reject'][iReject] then
rejectCellData = rejectCellData .. ' • '
end
end
if (iSuccess + iFail + iReject) > 3 then -- Avoid empty table rows for months without any closures
tbl
:tag('tr')
:tag('th')
:attr('scope', 'row')
:wikitext(m)
:tag('td')
:wikitext(tostring(seccessCellData))
:tag('td')
:wikitext(numConv('fa', iSuccess - 1))
:tag('td')
:wikitext(tostring(failCellData))
:tag('td')
:wikitext(numConv('fa', iFail - 1))
:tag('td')
:wikitext(tostring(rejectCellData))
:tag('td')
:wikitext(numConv('fa', iReject - 1))
:tag('td')
:wikitext(numConv('fa', ((iSuccess - 1) + (iFail - 1) + (iReject - 1))))
:done()
end
end
end
end
tbl:done()
text = text .. tostring(tbl) .. '\n'
tableYear = tableYear - 1
end
return text
end
return p