Content deleted Content added
don't match higher-level headings |
use Module:Rfx, clean up my spaghetti code, add a new header, and add a message to display when there are no current RfXes |
||
Line 1:
-- This module is a replacement for the RfX report bot.
local rfx = require( 'Module:Rfx' )
local colours = mw.loadData( 'Module:RFX report/colour' )
local p = {}
local function
-- Get the title object for [[Wikipedia:Requests for adminship]].
local noError, rfa =
return
end
local rfaText = rfa:getContent()
if not rfaText then
return nil
end
-- 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 exceptions = { 'Front matter', 'bureaucratship' }
for rfxPage, rfxSubpage in mw.ustring.gmatch( rfaText, '{{[ _]*([wW]ikipedia:[rR]equests for %w+/([^{}]-))[ _]*}}' ) do
local isException = false
end
end
if not isException then
table.insert(
end
end
return t
end
local function
if not ( type( rfxObject ) == 'table' and rfxObject.getTitleObject and rfxObject.getSupportUsers ) then
return nil
end
local
local styleInline = ''
local status = rfxObject:getStatus()
if status == 'pending closure' then
style = ' style="background: #f8cdc6;" |'
styleInline = ' background: #f8cdc6;'
end
local
local user = rfxObject.user or rfxObject:getTitleObject().subpageText
local supports = rfxObject.supports
local opposes = rfxObject.opposes
local neutrals = rfxObject.neutrals
local percent = rfxObject.percent
local colour
colour = colours[ rfxObject.type ][ percent ]
end
colour = colour or ''
local votes
if supports and opposes and neutrals and percent then
votes = mw.ustring.format( [==[
| style="text-align: right;%s" | [[%s#Support|%d]]
| style="text-align: right;%s" | [[%s#Oppose|%d]]
| style="text-align: right;%s" | [[%s#Neutral|%d]]
| style="text-align: right; background: #%s;" | %d]==],
styleInline, page,
styleInline, page,
)
else
votes = '\n| colspan="4" style="background: #f8cdc6;" | Error parsing votes'
end
if status then
status = mw.language.getContentLanguage():ucfirst( status )
if status == 'Pending closure' then
status = 'Pending closure...'
end
status = mw.ustring.format( '\n| %s', status )
else
status = '\n| style="background: #f8cdc6;" | Error getting status'
end
local endTime = rfxObject.endTime
local secondsLeft = rfxObject:getSecondsLeft()
local timeLeft = rfxObject:getTimeLeft()
local time
if endTime and timeLeft then
time = mw.ustring.format( '\n| %s\n| %s', endTime, timeLeft )
else
time = '\n| colspan="2" style="background: #f8cdc6;" | Error parsing end time'
end
local dupes = rfxObject:dupesExist()
if dupes then
dupes = "'''yes'''"
elseif dupes == false then
dupes = 'no'
else
dupes = '--'
end
local report = rfxObject:getReport()
if report then
report = mw.ustring.format( '\n|%s [%s report]', style, tostring( report ) )
else
report = '\n| style="background: #f8cdc6;" | Report not found'
end
return mw.ustring.format(
'\n|-\n|%s [[%s|%s]]%s%s%s\n| style="text-align: center;%s" | %s%s',
style, page, user, votes, status, time, styleInline, dupes, report
)
end
local function
local rfxCaps
if rfxType == 'rfa' then
rfxCaps = 'RfA'
elseif rfxType == 'rfb' then
rfxCaps = 'RfB'
else
return nil
end
return
'\n|-\n! %s candidate !! S !! O !! N !! S%% !! Status !! Ending (UTC) !! Time left !! Dupes? !! Report',
rfxCaps
)
end
local function
if not rfxes then
end
-- Get RfX objects and separate RfAs and RfBs.
local rfas = {}
local rfbs = {}
for i, rfxPage in ipairs( rfxes ) do
local rfxObject = rfx.new( rfxPage )
if
elseif rfxObject.type == 'rfb' then
end
end
end
local if #rfas > 0
table.insert( ret, makeHeading( 'rfa' ) )
for i, rfaObject in
end
end
if #rfbs > 0 then
table.insert( ret, makeHeading( 'rfb' ) )
for i, rfbObject in ipairs( rfbs ) do
table.insert( ret, makeRow( rfbObject ) )
end
end
return table.concat( ret )
end
local function makeReport( args )
local purgeLink = mw.title.getCurrentTitle():fullUrl( 'action=purge' )
local header = mw.ustring.format(
'\n|-\n! colspan="10" style="text-align: center;" | Requests for [[Wikipedia:Requests for adminship|adminship]] and [[Wikipedia:Requests for bureaucratship|bureaucratship]]<span class="plainlinks" style="float: right;"><small>[%s update]</small></span>',
purgeLink
)
local
if rows == '' then
rows = '\n|-\n| colspan="10" | No current discussions. <small>Recent RfAs: ([[Wikipedia:Successful requests for adminship|successful]], [[Wikipedia:Unsuccessful adminship candidacies (Chronological)|unsuccessful]]) Recent RfBs: ([[Wikipedia:Successful bureaucratship candidacies|successful]], [[Wikipedia:Unsuccessful bureaucratship candidacies|unsuccessful]])</small>'
end
if not style then
local clear = args.clear or 'left'
style = mw.ustring.format(
'style="white-space:wrap; clear: %s; margin-top: 0em; margin-bottom: .5em; float: %s; padding: .5em 0em 0em 1.4em; background: #ffffff; border-collapse: collapse; border-spacing: 0;"',
)
end
return mw.ustring.format( '\n{| class="wikitable" %s%s%s\n|-\n|}', style, header, rows )
end
function p.main( frame )
-- Process the arguments.
local args
if frame == mw.getCurrentFrame() then
args = frame:getParent().args
for k, v in pairs( frame.args ) do
args = frame.args
break
Line 255 ⟶ 195:
args = frame
end
return makeReport( args )
end
|