মডিউল:Rfa report: সংশোধিত সংস্করণের মধ্যে পার্থক্য
অবয়ব
বিষয়বস্তু বিয়োগ হয়েছে বিষয়বস্তু যোগ হয়েছে
সম্পাদনা সারাংশ নেই ট্যাগ: মোবাইল সম্পাদনা মোবাইল ওয়েব সম্পাদনা উচ্চতর মোবাইল সম্পাদনা |
সম্পাদনা সারাংশ নেই ট্যাগ: মোবাইল সম্পাদনা মোবাইল ওয়েব সম্পাদনা উচ্চতর মোবাইল সম্পাদনা |
||
১ নং লাইন: | ১ নং লাইন: | ||
-- This module is a replacement for the RfX report bot. |
|||
local convert = require('মডিউল:সংখ্যা রূপান্তরকারী').convert |
local convert = require('মডিউল:সংখ্যা রূপান্তরকারী').convert |
||
local rfx = require('Module:Rfx/খেলাঘর') |
|||
local |
local colours = mw.loadData('Module:RFX report/colour') |
||
local colours = mw.loadData( 'Module:RFX report/colour' ) |
|||
local p = {} |
local p = {} |
||
-- Helper function to get the length of a table |
|||
local function getTableLength(tbl) |
local function getTableLength(tbl) |
||
local length = 0 |
|||
for _ in pairs(tbl) do |
|||
length = length + 1 |
|||
end |
|||
return length |
|||
end |
end |
||
-- Function to fetch all active RfAs |
|||
local function getRfxes() |
local function getRfxes() |
||
-- Get the title object for [[Wikipedia:Requests for adminship]] |
-- Get the title object for [[Wikipedia:Requests for adminship]] |
||
local noError, rfa = pcall( |
local noError, rfa = pcall(mw.title.new, 'উইকিপিডিয়া:প্রশাসক হওয়ার আবেদন') |
||
if not noError or ( |
if not noError or (noError and not rfa) then |
||
return nil |
return nil |
||
end |
end |
||
২৬ নং লাইন: | ২৫ নং লাইন: | ||
return nil |
return nil |
||
end |
end |
||
-- Parse RfX pages from the transclusions |
|||
-- Return a table with a list of pages transcluded from |
|||
-- [[Wikipedia:Requests for adminship]], minus the exceptions |
|||
-- which are always transcluded there. |
|||
local t = {} |
local t = {} |
||
local exceptions = { 'শীর্ষ', 'বার্তা' } |
local exceptions = { 'শীর্ষ', 'বার্তা' } |
||
for rfxPage, rfxSubpage in mw.ustring.gmatch( |
for rfxPage, rfxSubpage in mw.ustring.gmatch(rfaText, '{{[ _]*(উইকিপিডিয়া:প্রশাসক হওয়ার আবেদন/([^{}]-))[ _]*}}') do |
||
local isException = false |
local isException = false |
||
for _, v in ipairs( |
for _, v in ipairs(exceptions) do |
||
if rfxSubpage == v then |
if rfxSubpage == v then |
||
isException = true |
isException = true |
||
৪০ নং লাইন: | ৩৭ নং লাইন: | ||
end |
end |
||
if not isException then |
if not isException then |
||
table.insert( |
table.insert(t, rfxPage) |
||
end |
end |
||
end |
end |
||
৪৬ নং লাইন: | ৪৩ নং লাইন: | ||
end |
end |
||
-- Function to generate a row for each RfX |
|||
local function makeRow( rfxObject ) |
|||
if not ( |
local function makeRow(rfxObject) |
||
if not (type(rfxObject) == 'table' and rfxObject.getTitleObject and rfxObject.getSupportUsers) then |
|||
return nil |
return nil |
||
end |
end |
||
local status = rfxObject:getStatus() |
local status = rfxObject:getStatus() |
||
local page = rfxObject:getTitleObject().prefixedText |
local page = rfxObject:getTitleObject().prefixedText |
||
৫৭ নং লাইন: | ৫৬ নং লাইন: | ||
local neutrals = convert('bn', tostring(rfxObject.neutrals)) |
local neutrals = convert('bn', tostring(rfxObject.neutrals)) |
||
local percent = convert('bn', tostring(rfxObject.percent)) |
local percent = convert('bn', tostring(rfxObject.percent)) |
||
local colour |
local colour = colours[rfxObject.type][percent] or '' |
||
if percent then |
|||
colour = colours[ rfxObject.type ][ percent ] |
|||
end |
|||
colour = colour or '' |
|||
-- Format percentage and vote data |
|||
local percentStr = mw.ustring.format( '%s', percent or 0 ) |
|||
local percentStr = mw.ustring.format('%s', percent or 0) |
|||
if percent == '০' and supports == '০' and opposes == '০' and neutrals == '০' then |
if percent == '০' and supports == '০' and opposes == '০' and neutrals == '০' then |
||
percentStr = 'N/A' |
percentStr = 'N/A' |
||
elseif percent == 100 and opposes ~= '০' |
elseif percent == 100 and opposes ~= '০' then |
||
percentStr = '>99' |
|||
then |
|||
percentStr = '>99' |
|||
end |
|||
local votes |
|||
if supports and opposes and neutrals and percent then |
|||
votes = mw.ustring.format( [==[ |
|||
| class="rfx-report-number" | [[%s#সমর্থন|%s]] |
|||
| class="rfx-report-number" | [[%s#বিরোধিতা|%s]] |
|||
| class="rfx-report-number" | [[%s#নিরপেক্ষ|%s]] |
|||
| class="rfx-report-number rfx-report-percent" style="background: #%s;" | %s%%]==], |
|||
page, supports, |
|||
page, opposes, |
|||
page, neutrals, |
|||
colour, percentStr |
|||
) |
|||
else |
|||
votes = '\n| colspan="4" class="rfx-report-error" | ভোট পার্সিংয়ে ত্রুটি' |
|||
end |
end |
||
local votes = mw.ustring.format( |
|||
'| class="rfx-report-number" | [[%s#সমর্থন|%s]]\n| class="rfx-report-number" | [[%s#বিরোধিতা|%s]]\n| class="rfx-report-number" | [[%s#নিরপেক্ষ|%s]]\n| class="rfx-report-number rfx-report-percent" style="background: #%s;" | %s%%', |
|||
page, supports, page, opposes, page, neutrals, colour, percentStr |
|||
) |
|||
if status then |
if status then |
||
status = mw.language.getContentLanguage():ucfirst( |
status = mw.language.getContentLanguage():ucfirst(status) |
||
if status == 'Pending closure' then |
if status == 'Pending closure' then |
||
status = 'Pending closure...' |
status = 'Pending closure...' |
||
৯৪ নং লাইন: | ৭৯ নং লাইন: | ||
else |
else |
||
status = '\n| class="rfx-report-error" | স্থিতি বেরকরণ ত্রুটি' |
status = '\n| class="rfx-report-error" | স্থিতি বেরকরণ ত্রুটি' |
||
end |
end |
||
-- Calculate time left |
|||
local endTime = mw.getContentLanguage():formatDate('d M Y, h:m', rfxObject.endTime, true) |
local endTime = mw.getContentLanguage():formatDate('d M Y, h:m', rfxObject.endTime, true) |
||
local secondsLeft = rfxObject:getSecondsLeft() |
|||
local timeLeft = rfxObject:getTimeLeft() |
local timeLeft = rfxObject:getTimeLeft() |
||
timeLeft = (timeLeft == "০ ঘণ্টা") and "সমাপ্ত" or timeLeft |
|||
timeLeft = "সমাপ্ত" else |
|||
local time = mw.ustring.format('\n| %s\n| %s', endTime, timeLeft) |
|||
end |
|||
-- Handle duplicate votes |
|||
local time |
|||
if endTime and timeLeft then |
|||
time = mw.ustring.format( '\n| %s\n| %s', endTime, timeLeft ) |
|||
else |
|||
time = '\n| colspan="2" class="rfx-report-error" | শেষের সময় পার্সিংয়ে ত্রুটি' |
|||
end |
|||
local dupes = rfxObject:dupesExist() |
local dupes = rfxObject:dupesExist() |
||
dupes = dupes == true and '<span class="rfx-report-dupes-yes">হ্যাঁ</span>' or (dupes == false and 'না' or '--') |
|||
if dupes then |
|||
dupes = '<span class="rfx-report-dupes-yes">হ্যাঁ</span>' |
|||
-- Handle pending closure class |
|||
local pending_class = status == 'pending closure' and 'class="rfx-report-pending"' or '' |
|||
dupes = 'না' |
|||
else |
|||
-- Return formatted row |
|||
dupes = '--' |
|||
end |
|||
local pending_class = '' |
|||
if status == 'pending closure' then |
|||
pending_class = 'class="rfx-report-pending"' |
|||
end |
|||
return mw.ustring.format( |
return mw.ustring.format( |
||
'\n|-%s\n| [[%s|%s]]%s%s%s |
'\n|-%s\n| [[%s|%s]]%s%s%s\n| class="rfx-report-dupes" | %s', |
||
pending_class, page, user, votes, status, time, dupes |
pending_class, page, user, votes, status, time, dupes |
||
) |
) |
||
end |
end |
||
-- Function to create the table heading |
|||
local function makeHeading( rfxType ) |
|||
local function makeHeading(rfxType) |
|||
local frame = mw.getCurrentFrame() |
|||
local rfxCaps |
|||
if rfxType == 'rfa' then |
if rfxType == 'rfa' then |
||
return mw.ustring.format( |
|||
'\n|-\n! scope="col" | প্রার্থী !! scope="col" | <abbr title="সমর্থন">স</abbr> !! scope="col" | <abbr title="বিরোধিতা">বি</abbr> !! scope="col" | <abbr title="নিরপেক্ষ">নি</abbr> !! scope="col" | <abbr title="সমর্থনের শতকরা হার (%%)">স %%</abbr> !! scope="col" | স্থিতি !! scope="col" | শেষ হবে (ইউটিসি) !! scope="col" | সময় বাকি !! scope="col" | <abbr title="সদৃশ ভোট আছে?">সদৃশ?</abbr>' |
|||
else |
|||
) |
|||
end |
end |
||
return |
return nil |
||
'\n|-\n! scope="col" | প্রার্থী !! scope="col" | <abbr title="সমর্থন">স</abbr> !! scope="col" | <abbr title="বিরোধিতা">বি</abbr> !! scope="col" | <abbr title="নিরপেক্ষ">নি</abbr> !! scope="col" | <abbr title="সমর্থনের শতকরা হার (%%)">স %%</abbr> !! scope="col" | স্থিতি!! scope="col" | শেষ হবে (ইউটিসি) !! scope="col" | সময় বাকি!! scope="col" | <abbr title="সদৃশ ভোট আছে?">সদৃশ?</abbr> ', |
|||
rfxCaps |
|||
) |
|||
end |
end |
||
-- Function to fetch RfAs and create rows for the report |
|||
local function getRfs() |
local function getRfs() |
||
local rfxes = getRfxes() |
|||
if not rfxes then |
if not rfxes then |
||
return nil |
return nil |
||
end |
end |
||
-- Get RfX objects and separate RfAs and RfBs. |
|||
local rfas = {} |
local rfas = {} |
||
for |
for _, rfxPage in ipairs(rfxes) do |
||
local rfxObject = rfx.new( |
local rfxObject = rfx.new(rfxPage) |
||
if rfxObject then |
if rfxObject and rfxObject.type == 'rfa' then |
||
table.insert(rfas, rfxObject) |
|||
table.insert( rfas, rfxObject ) |
|||
end |
|||
end |
end |
||
end |
end |
||
return rfas |
return rfas |
||
end |
end |
||
-- Function to generate the report rows |
|||
local function makeReportRows() |
local function makeReportRows() |
||
local rfas = getRfs() |
|||
local ret = {} |
local ret = {} |
||
if #rfas > 0 then |
if #rfas > 0 then |
||
table.insert( |
table.insert(ret, makeHeading('rfa')) |
||
for |
for _, rfaObject in ipairs(rfas) do |
||
table.insert( |
table.insert(ret, makeRow(rfaObject)) |
||
end |
end |
||
end |
end |
||
return table.concat( |
return table.concat(ret) |
||
end |
end |
||
-- Main function to generate the report |
|||
local purgeLink = mw.title.getCurrentTitle():fullUrl( |
local function makeReport(args) |
||
local purgeLink = mw.title.getCurrentTitle():fullUrl('action=purge') |
|||
local header = mw.ustring.format( |
local header = mw.ustring.format( |
||
'\n|+[[উইকিপিডিয়া:প্রশাসক হওয়ার আবেদন|প্রশাসক হওয়ার আবেদন]] <span class="rfx-report-purge plainlinks">[%s হালনাগাদ]</span>', |
'\n|+[[উইকিপিডিয়া:প্রশাসক হওয়ার আবেদন|প্রশাসক হওয়ার আবেদন]] <span class="rfx-report-purge plainlinks">[%s হালনাগাদ]</span>', |
||
১৮৪ নং লাইন: | ১৫৪ নং লাইন: | ||
rows = '\n|-\n| colspan="10" | বর্তমানে কোনো আবেদন নেই। <span class="rfx-report-recent">[[উইকিপিডিয়া:প্রশাসক হওয়ার আবেদন/সাম্প্রতিক|সাম্প্রতিক প্রশাসক হওয়ার আবেদন]]</span>' |
rows = '\n|-\n| colspan="10" | বর্তমানে কোনো আবেদন নেই। <span class="rfx-report-recent">[[উইকিপিডিয়া:প্রশাসক হওয়ার আবেদন/সাম্প্রতিক|সাম্প্রতিক প্রশাসক হওয়ার আবেদন]]</span>' |
||
end |
end |
||
local float = args.float or args.align |
local float = args.float or args.align |
||
if not float or mw.text.trim(float) == '' then |
|||
float = nil |
|||
end |
|||
local clear = args.clear |
local clear = args.clear |
||
if not clear or mw.text.trim(clear) == '' then |
|||
clear = nil |
|||
end |
|||
local style = '' |
local style = '' |
||
if float or clear then |
if float or clear then |
||
style = string.format( |
|||
'style="%s%s"', |
|||
clear and ('clear: ' .. clear .. ';') or '', |
|||
float and ('float: ' .. float .. ';') or '' |
|||
) |
|||
end |
end |
||
return mw.getCurrentFrame():extensionTag{ |
return mw.getCurrentFrame():extensionTag{ |
||
name = 'templatestyles', |
|||
args = { src = 'Module:RFX report/styles.css' } |
|||
} .. mw.ustring.format( |
|||
'\n{| class="wikitable rfx-report" %s%s%s\n|-\n|}', |
|||
style, |
|||
header, |
|||
rows |
|||
) |
) |
||
end |
end |
||
-- Count the number of active RfAs |
|||
function p.countRfas() |
function p.countRfas() |
||
local rfas = getRfs() |
|||
return getTableLength(rfas) |
|||
end |
end |
||
-- Main entry point for the module |
|||
function p.main( frame ) |
|||
function p.main(frame) |
|||
-- Process the arguments. |
|||
local args |
local args |
||
if frame == mw.getCurrentFrame() then |
if frame == mw.getCurrentFrame() then |
||
args = frame:getParent().args |
args = frame:getParent().args |
||
for k, v in pairs( |
for k, v in pairs(frame.args) do |
||
args = frame.args |
args = frame.args |
||
break |
break |
||
২২৯ নং লাইন: | ১৯৫ নং লাইন: | ||
else |
else |
||
args = frame |
args = frame |
||
end |
end |
||
return makeReport( |
return makeReport(args) |
||
end |
end |
||
১৫:৩৬, ৫ অক্টোবর ২০২৪ তারিখে সংশোধিত সংস্করণ
local convert = require('মডিউল:সংখ্যা রূপান্তরকারী').convert
local rfx = require('Module:Rfx/খেলাঘর')
local colours = mw.loadData('Module:RFX report/colour')
local p = {}
-- Helper function to get the length of a table
local function getTableLength(tbl)
local length = 0
for _ in pairs(tbl) do
length = length + 1
end
return length
end
-- Function to fetch all active RfAs
local function getRfxes()
-- Get the title object for [[Wikipedia:Requests for adminship]]
local noError, rfa = pcall(mw.title.new, 'উইকিপিডিয়া:প্রশাসক হওয়ার আবেদন')
if not noError or (noError and not rfa) then
return nil
end
local rfaText = rfa:getContent()
if not rfaText then
return nil
end
-- Parse RfX pages from the transclusions
local t = {}
local exceptions = { 'শীর্ষ', 'বার্তা' }
for rfxPage, rfxSubpage in mw.ustring.gmatch(rfaText, '{{[ _]*(উইকিপিডিয়া:প্রশাসক হওয়ার আবেদন/([^{}]-))[ _]*}}') do
local isException = false
for _, v in ipairs(exceptions) do
if rfxSubpage == v then
isException = true
end
end
if not isException then
table.insert(t, rfxPage)
end
end
return t
end
-- Function to generate a row for each RfX
local function makeRow(rfxObject)
if not (type(rfxObject) == 'table' and rfxObject.getTitleObject and rfxObject.getSupportUsers) then
return nil
end
local status = rfxObject:getStatus()
local page = rfxObject:getTitleObject().prefixedText
local user = rfxObject.user or rfxObject:getTitleObject().subpageText
local supports = convert('bn', tostring(rfxObject.supports))
local opposes = convert('bn', tostring(rfxObject.opposes))
local neutrals = convert('bn', tostring(rfxObject.neutrals))
local percent = convert('bn', tostring(rfxObject.percent))
local colour = colours[rfxObject.type][percent] or ''
-- Format percentage and vote data
local percentStr = mw.ustring.format('%s', percent or 0)
if percent == '০' and supports == '০' and opposes == '০' and neutrals == '০' then
percentStr = 'N/A'
elseif percent == 100 and opposes ~= '০' then
percentStr = '>99'
end
local votes = mw.ustring.format(
'| class="rfx-report-number" | [[%s#সমর্থন|%s]]\n| class="rfx-report-number" | [[%s#বিরোধিতা|%s]]\n| class="rfx-report-number" | [[%s#নিরপেক্ষ|%s]]\n| class="rfx-report-number rfx-report-percent" style="background: #%s;" | %s%%',
page, supports, page, opposes, page, neutrals, colour, percentStr
)
if status then
status = mw.language.getContentLanguage():ucfirst(status)
if status == 'Pending closure' then
status = 'Pending closure...'
end
status = '\n|' .. status
else
status = '\n| class="rfx-report-error" | স্থিতি বেরকরণ ত্রুটি'
end
-- Calculate time left
local endTime = mw.getContentLanguage():formatDate('d M Y, h:m', rfxObject.endTime, true)
local timeLeft = rfxObject:getTimeLeft()
timeLeft = (timeLeft == "০ ঘণ্টা") and "সমাপ্ত" or timeLeft
local time = mw.ustring.format('\n| %s\n| %s', endTime, timeLeft)
-- Handle duplicate votes
local dupes = rfxObject:dupesExist()
dupes = dupes == true and '<span class="rfx-report-dupes-yes">হ্যাঁ</span>' or (dupes == false and 'না' or '--')
-- Handle pending closure class
local pending_class = status == 'pending closure' and 'class="rfx-report-pending"' or ''
-- Return formatted row
return mw.ustring.format(
'\n|-%s\n| [[%s|%s]]%s%s%s\n| class="rfx-report-dupes" | %s',
pending_class, page, user, votes, status, time, dupes
)
end
-- Function to create the table heading
local function makeHeading(rfxType)
if rfxType == 'rfa' then
return mw.ustring.format(
'\n|-\n! scope="col" | প্রার্থী !! scope="col" | <abbr title="সমর্থন">স</abbr> !! scope="col" | <abbr title="বিরোধিতা">বি</abbr> !! scope="col" | <abbr title="নিরপেক্ষ">নি</abbr> !! scope="col" | <abbr title="সমর্থনের শতকরা হার (%%)">স %%</abbr> !! scope="col" | স্থিতি !! scope="col" | শেষ হবে (ইউটিসি) !! scope="col" | সময় বাকি !! scope="col" | <abbr title="সদৃশ ভোট আছে?">সদৃশ?</abbr>'
)
end
return nil
end
-- Function to fetch RfAs and create rows for the report
local function getRfs()
local rfxes = getRfxes()
if not rfxes then
return nil
end
local rfas = {}
for _, rfxPage in ipairs(rfxes) do
local rfxObject = rfx.new(rfxPage)
if rfxObject and rfxObject.type == 'rfa' then
table.insert(rfas, rfxObject)
end
end
return rfas
end
-- Function to generate the report rows
local function makeReportRows()
local rfas = getRfs()
local ret = {}
if #rfas > 0 then
table.insert(ret, makeHeading('rfa'))
for _, rfaObject in ipairs(rfas) do
table.insert(ret, makeRow(rfaObject))
end
end
return table.concat(ret)
end
-- Main function to generate the report
local function makeReport(args)
local purgeLink = mw.title.getCurrentTitle():fullUrl('action=purge')
local header = mw.ustring.format(
'\n|+[[উইকিপিডিয়া:প্রশাসক হওয়ার আবেদন|প্রশাসক হওয়ার আবেদন]] <span class="rfx-report-purge plainlinks">[%s হালনাগাদ]</span>',
purgeLink
)
local rows = makeReportRows() or ''
if rows == '' then
rows = '\n|-\n| colspan="10" | বর্তমানে কোনো আবেদন নেই। <span class="rfx-report-recent">[[উইকিপিডিয়া:প্রশাসক হওয়ার আবেদন/সাম্প্রতিক|সাম্প্রতিক প্রশাসক হওয়ার আবেদন]]</span>'
end
local float = args.float or args.align
local clear = args.clear
local style = ''
if float or clear then
style = string.format(
'style="%s%s"',
clear and ('clear: ' .. clear .. ';') or '',
float and ('float: ' .. float .. ';') or ''
)
end
return mw.getCurrentFrame():extensionTag{
name = 'templatestyles',
args = { src = 'Module:RFX report/styles.css' }
} .. mw.ustring.format(
'\n{| class="wikitable rfx-report" %s%s%s\n|-\n|}',
style,
header,
rows
)
end
-- Count the number of active RfAs
function p.countRfas()
local rfas = getRfs()
return getTableLength(rfas)
end
-- Main entry point for the module
function p.main(frame)
local args
if frame == mw.getCurrentFrame() then
args = frame:getParent().args
for k, v in pairs(frame.args) do
args = frame.args
break
end
else
args = frame
end
return makeReport(args)
end
return p