<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://eurovision.jobogamer.xyz/index.php?action=history&amp;feed=atom&amp;title=Module%3ARfx</id>
	<title>Module:Rfx - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://eurovision.jobogamer.xyz/index.php?action=history&amp;feed=atom&amp;title=Module%3ARfx"/>
	<link rel="alternate" type="text/html" href="https://eurovision.jobogamer.xyz/index.php?title=Module:Rfx&amp;action=history"/>
	<updated>2026-05-19T21:01:18Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.45.3</generator>
	<entry>
		<id>https://eurovision.jobogamer.xyz/index.php?title=Module:Rfx&amp;diff=3378&amp;oldid=prev</id>
		<title>imported&gt;Stjn: replace checks for categories with a call to mw.title’s `categories`</title>
		<link rel="alternate" type="text/html" href="https://eurovision.jobogamer.xyz/index.php?title=Module:Rfx&amp;diff=3378&amp;oldid=prev"/>
		<updated>2024-11-24T21:10:19Z</updated>

		<summary type="html">&lt;p&gt;replace checks for categories with a call to mw.title’s `categories`&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;----------------------------------------------------------------------&lt;br /&gt;
--                          Module:Rfx                              --&lt;br /&gt;
-- This is a library for retrieving information about requests      --&lt;br /&gt;
-- for adminship and requests for bureaucratship on the English     --&lt;br /&gt;
-- Wikipedia. Please see the module documentation for instructions. --&lt;br /&gt;
----------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
local libraryUtil = require(&amp;#039;libraryUtil&amp;#039;)&lt;br /&gt;
local lang = mw.getContentLanguage()&lt;br /&gt;
local textSplit = mw.text.split&lt;br /&gt;
local umatch = mw.ustring.match&lt;br /&gt;
local newTitle = mw.title.new&lt;br /&gt;
&lt;br /&gt;
local rfx = {}&lt;br /&gt;
&lt;br /&gt;
--------------------------------------&lt;br /&gt;
--         Helper functions         --&lt;br /&gt;
--------------------------------------&lt;br /&gt;
&lt;br /&gt;
local function getTitleObject(title)&lt;br /&gt;
	local success, titleObject = pcall(newTitle, title)&lt;br /&gt;
	if success and titleObject then&lt;br /&gt;
		return titleObject&lt;br /&gt;
	else&lt;br /&gt;
		return nil&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function parseVoteBoundaries(section)&lt;br /&gt;
	-- Returns an array containing the raw wikitext of RfX votes in a given section.&lt;br /&gt;
	section = section:match(&amp;#039;^.-\n#(.*)$&amp;#039;) -- Strip non-votes from the start.&lt;br /&gt;
	if not section then&lt;br /&gt;
		return {}&lt;br /&gt;
	end&lt;br /&gt;
	section = section:match(&amp;#039;^(.-)\n[^#]&amp;#039;) or section -- Discard subsequent numbered lists.&lt;br /&gt;
	local comments = textSplit(section, &amp;#039;\n#&amp;#039;)&lt;br /&gt;
	local votes = {}&lt;br /&gt;
	for i, comment in ipairs(comments) do&lt;br /&gt;
		if comment:find(&amp;#039;^[^#*;:].*%S&amp;#039;) then&lt;br /&gt;
			votes[#votes + 1] = comment&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	return votes&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function parseVote(vote)&lt;br /&gt;
	-- parses a username from an RfX vote.&lt;br /&gt;
	local userStart, userMatch = vote:match(&amp;#039;^(.*)%[%[[%s_]*:?[%s_]*[uU][sS][eE][rR][%s_]*:[%s_]*(.-)[%s_]*%]%].-$&amp;#039;)&lt;br /&gt;
	local talkStart, talkMatch = vote:match(&amp;#039;^(.*)%[%[[%s_]*:?[%s_]*[uU][sS][eE][rR][%s_]+[tT][aA][lL][kK][%s_]*:[%s_]*(.-)[%s_]*%]%].-$&amp;#039;)&lt;br /&gt;
	local contribStart, contribMatch = vote:match(&amp;#039;^(.*)%[%[[%s_]*:?[%s_]*[sS][pP][eE][cC][iI][aA][lL][%s_]*:[%s_]*[cC][oO][nN][tT][rR][iI][bB][uU][tT][iI][oO][nN][sS]/[%s_]*(.-)[%s_]*%]%].-$&amp;#039;)&lt;br /&gt;
	local username&lt;br /&gt;
	if userStart and talkStart then&lt;br /&gt;
		if #userStart &amp;gt; #talkStart then&lt;br /&gt;
			username = userMatch&lt;br /&gt;
		else&lt;br /&gt;
			username = talkMatch&lt;br /&gt;
		end&lt;br /&gt;
	elseif userStart then&lt;br /&gt;
		username = userMatch&lt;br /&gt;
	elseif talkStart then&lt;br /&gt;
		username = talkMatch&lt;br /&gt;
	elseif contribStart then&lt;br /&gt;
		username = contribMatch&lt;br /&gt;
	else&lt;br /&gt;
		return string.format( &amp;quot;&amp;#039;&amp;#039;&amp;#039;Error parsing signature&amp;#039;&amp;#039;&amp;#039;: &amp;#039;&amp;#039;%s&amp;#039;&amp;#039;&amp;quot;, vote )&lt;br /&gt;
	end&lt;br /&gt;
	username = username:match(&amp;#039;^[^|/#]*&amp;#039;)&lt;br /&gt;
	return username&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function parseVoters(votes)&lt;br /&gt;
	local voters = {}&lt;br /&gt;
	for i, vote in ipairs(votes) do&lt;br /&gt;
		voters[#voters + 1] = parseVote(vote)&lt;br /&gt;
	end&lt;br /&gt;
	return voters&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function dupesExist(...)&lt;br /&gt;
	local exists = {}&lt;br /&gt;
	local tables = {...}&lt;br /&gt;
	for i, usernames in ipairs(tables) do&lt;br /&gt;
		for j, username in ipairs(usernames) do&lt;br /&gt;
			username = lang:ucfirst(username)&lt;br /&gt;
			if exists[username] then&lt;br /&gt;
				return true&lt;br /&gt;
			else&lt;br /&gt;
				exists[username] = true&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	return false&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function hasCategory(category, catList)&lt;br /&gt;
	for _, c in ipairs(catList) do&lt;br /&gt;
		if c == category then&lt;br /&gt;
			return true&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	return false&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
------------------------------------------&lt;br /&gt;
--   Define the constructor function    --&lt;br /&gt;
------------------------------------------&lt;br /&gt;
&lt;br /&gt;
function rfx.new(title)&lt;br /&gt;
	local obj = {}&lt;br /&gt;
	local data = {}&lt;br /&gt;
	local checkSelf = libraryUtil.makeCheckSelfFunction( &amp;#039;Module:Rfx&amp;#039;, &amp;#039;rfx&amp;#039;, obj, &amp;#039;rfx object&amp;#039; )&lt;br /&gt;
	&lt;br /&gt;
	-- Get the title object and check to see whether we are a subpage of WP:RFA or WP:RFB.&lt;br /&gt;
	title = getTitleObject(title)&lt;br /&gt;
	if not title then&lt;br /&gt;
		return nil&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	function data:getTitleObject()&lt;br /&gt;
		checkSelf(self, &amp;#039;getTitleObject&amp;#039;)&lt;br /&gt;
		return title&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	if title.namespace == 4 then&lt;br /&gt;
		local rootText = title.rootText&lt;br /&gt;
		if rootText == &amp;#039;Requests for adminship&amp;#039; then&lt;br /&gt;
			data.type = &amp;#039;rfa&amp;#039;&lt;br /&gt;
		elseif rootText == &amp;#039;Requests for bureaucratship&amp;#039; then&lt;br /&gt;
			data.type = &amp;#039;rfb&amp;#039;&lt;br /&gt;
		else&lt;br /&gt;
			return nil&lt;br /&gt;
		end&lt;br /&gt;
	else&lt;br /&gt;
		return nil&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	-- Get the page content and divide it into sections.&lt;br /&gt;
	local pageText = title:getContent()&lt;br /&gt;
	if not pageText then&lt;br /&gt;
		return nil&lt;br /&gt;
	end&lt;br /&gt;
	local introText, supportText, opposeText, neutralText = umatch(&lt;br /&gt;
		pageText,&lt;br /&gt;
		&amp;#039;^(.-)\n====[^=\n][^\n]-====.-&amp;#039;&lt;br /&gt;
		.. &amp;#039;\n=====%s*[sS]upport%s*=====(.-)&amp;#039;&lt;br /&gt;
		.. &amp;#039;\n=====%s*[oO]ppose%s*=====(.-)&amp;#039;&lt;br /&gt;
		.. &amp;#039;\n=====%s*[nN]eutral%s*=====(.-)$&amp;#039;&lt;br /&gt;
	)&lt;br /&gt;
	if not introText then&lt;br /&gt;
		introText, supportText, opposeText, neutralText = umatch(&lt;br /&gt;
			pageText,&lt;br /&gt;
			&amp;quot;^(.-\n&amp;#039;&amp;#039;&amp;#039;[^\n]-%(%d+/%d+/%d+%)[^\n]-&amp;#039;&amp;#039;&amp;#039;)\n.-&amp;quot;&lt;br /&gt;
			.. &amp;quot;\n&amp;#039;&amp;#039;&amp;#039;Support&amp;#039;&amp;#039;&amp;#039;(.-)\n&amp;#039;&amp;#039;&amp;#039;Oppose&amp;#039;&amp;#039;&amp;#039;(.-)\n&amp;#039;&amp;#039;&amp;#039;Neutral&amp;#039;&amp;#039;&amp;#039;(.-)&amp;quot;&lt;br /&gt;
		)&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	-- Switch to reconfirmation request for adminship if in that category&lt;br /&gt;
	local categories = title.categories&lt;br /&gt;
	if hasCategory(&amp;#039;Reconfirmation requests for adminship&amp;#039;, categories) then&lt;br /&gt;
		data.type = &amp;#039;rrfa&amp;#039;&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	-- Get vote counts.&lt;br /&gt;
	local supportVotes, opposeVotes, neutralVotes&lt;br /&gt;
	if supportText and opposeText and neutralText then&lt;br /&gt;
		supportVotes = parseVoteBoundaries(supportText)&lt;br /&gt;
		opposeVotes = parseVoteBoundaries(opposeText)&lt;br /&gt;
		neutralVotes = parseVoteBoundaries(neutralText)&lt;br /&gt;
	end&lt;br /&gt;
	local supports, opposes, neutrals&lt;br /&gt;
	if supportVotes and opposeVotes and neutralVotes then&lt;br /&gt;
		supports = #supportVotes&lt;br /&gt;
		data.supports = supports&lt;br /&gt;
		opposes = #opposeVotes&lt;br /&gt;
		data.opposes = opposes&lt;br /&gt;
		neutrals = #neutralVotes&lt;br /&gt;
		data.neutrals = neutrals&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	-- Voter methods and dupe check.&lt;br /&gt;
&lt;br /&gt;
	function data:getSupportUsers()&lt;br /&gt;
		checkSelf(self, &amp;#039;getSupportUsers&amp;#039;)&lt;br /&gt;
		if supportVotes then&lt;br /&gt;
			return parseVoters(supportVotes)&lt;br /&gt;
		else&lt;br /&gt;
			return nil&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	function data:getOpposeUsers()&lt;br /&gt;
		checkSelf(self, &amp;#039;getOpposeUsers&amp;#039;)&lt;br /&gt;
		if opposeVotes then&lt;br /&gt;
			return parseVoters(opposeVotes)&lt;br /&gt;
		else&lt;br /&gt;
			return nil&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	function data:getNeutralUsers()&lt;br /&gt;
		checkSelf(self, &amp;#039;getNeutralUsers&amp;#039;)&lt;br /&gt;
		if neutralVotes then&lt;br /&gt;
			return parseVoters(neutralVotes)&lt;br /&gt;
		else&lt;br /&gt;
			return nil&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	function data:dupesExist()&lt;br /&gt;
		checkSelf(self, &amp;#039;dupesExist&amp;#039;)&lt;br /&gt;
		local supportUsers = self:getSupportUsers()&lt;br /&gt;
		local opposeUsers = self:getOpposeUsers()&lt;br /&gt;
		local neutralUsers = self:getNeutralUsers()&lt;br /&gt;
		if not (supportUsers and opposeUsers and neutralUsers) then&lt;br /&gt;
			return nil&lt;br /&gt;
		end&lt;br /&gt;
		return dupesExist(supportUsers, opposeUsers, neutralUsers)&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	if supports and opposes then&lt;br /&gt;
		local total = supports + opposes&lt;br /&gt;
		if total &amp;lt;= 0 then&lt;br /&gt;
			data.percent = 0&lt;br /&gt;
		else&lt;br /&gt;
			data.percent = math.floor((supports / total * 100) + 0.5)&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	if introText then&lt;br /&gt;
		data.endTime = umatch(introText, &amp;#039;(%d%d:%d%d, %d+ %w+ %d+) %(UTC%)&amp;#039;)&lt;br /&gt;
		data.user = umatch(introText, &amp;#039;===%s*%[%[[_%s]*[wW]ikipedia[_%s]*:[_%s]*[rR]equests[_ ]for[_ ]%w+/.-|[_%s]*(.-)[_%s]*%]%][_%s]*===&amp;#039;)&lt;br /&gt;
		if not data.user then&lt;br /&gt;
			data.user = umatch(introText, &amp;#039;===%s*([^\n]-)%s*===&amp;#039;)&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	-- Methods for seconds left and time left.&lt;br /&gt;
	&lt;br /&gt;
	function data:getSecondsLeft()&lt;br /&gt;
		checkSelf(self, &amp;#039;getSecondsLeft&amp;#039;)&lt;br /&gt;
		local endTime = self.endTime&lt;br /&gt;
		if not endTime then&lt;br /&gt;
			return nil&lt;br /&gt;
		end&lt;br /&gt;
		local now = tonumber(lang:formatDate(&amp;quot;U&amp;quot;))&lt;br /&gt;
		local success, endTimeU = pcall(lang.formatDate, lang, &amp;#039;U&amp;#039;, endTime)&lt;br /&gt;
		if not success then&lt;br /&gt;
			return nil&lt;br /&gt;
		end&lt;br /&gt;
		endTimeU = tonumber(endTimeU)&lt;br /&gt;
		if not endTimeU then&lt;br /&gt;
			return nil&lt;br /&gt;
		end&lt;br /&gt;
		local secondsLeft = endTimeU - now&lt;br /&gt;
		if secondsLeft &amp;lt;= 0 then&lt;br /&gt;
			return 0&lt;br /&gt;
		else&lt;br /&gt;
			return secondsLeft&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	function data:getTimeLeft()&lt;br /&gt;
		checkSelf(self, &amp;#039;getTimeLeft&amp;#039;)&lt;br /&gt;
		local secondsLeft = self:getSecondsLeft()&lt;br /&gt;
		if not secondsLeft then&lt;br /&gt;
			return nil&lt;br /&gt;
		end&lt;br /&gt;
		return mw.ustring.gsub(lang:formatDuration(secondsLeft, {&amp;#039;days&amp;#039;, &amp;#039;hours&amp;#039;}), &amp;#039; and&amp;#039;, &amp;#039;,&amp;#039;)&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	function data:getReport()&lt;br /&gt;
		-- Gets the URI object for Vote History tool&lt;br /&gt;
		checkSelf(self, &amp;#039;getReport&amp;#039;)&lt;br /&gt;
		return mw.uri.new(&amp;#039;https://apersonbot.toolforge.org/vote-history?page=&amp;#039; .. mw.uri.encode(title.prefixedText))&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	function data:getStatus()&lt;br /&gt;
		-- Gets the current status of the RfX. Returns either &amp;quot;successful&amp;quot;, &amp;quot;unsuccessful&amp;quot;,&lt;br /&gt;
		-- &amp;quot;open&amp;quot;, or &amp;quot;pending closure&amp;quot;. Returns nil if the status could not be found.&lt;br /&gt;
		checkSelf( self, &amp;#039;getStatus&amp;#039; )&lt;br /&gt;
		local rfxType = data.type&lt;br /&gt;
		if rfxType == &amp;#039;rfa&amp;#039; or rfxType == &amp;#039;rrfa&amp;#039; then&lt;br /&gt;
			if hasCategory(&amp;#039;Successful requests for adminship&amp;#039;, categories) then&lt;br /&gt;
				return &amp;#039;successful&amp;#039;&lt;br /&gt;
			elseif hasCategory(&amp;#039;Unsuccessful requests for adminship&amp;#039;, categories) then&lt;br /&gt;
				return &amp;#039;unsuccessful&amp;#039;&lt;br /&gt;
			end&lt;br /&gt;
		elseif rfxType == &amp;#039;rfb&amp;#039; then&lt;br /&gt;
			if hasCategory(&amp;#039;Successful requests for bureaucratship&amp;#039;, categories) then&lt;br /&gt;
				return &amp;#039;successful&amp;#039;&lt;br /&gt;
			elseif hasCategory(&amp;#039;Unsuccessful requests for bureaucratship&amp;#039;, categories) then&lt;br /&gt;
				return &amp;#039;unsuccessful&amp;#039;&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
		local secondsLeft = self:getSecondsLeft()&lt;br /&gt;
		if secondsLeft and secondsLeft &amp;gt; 0 then&lt;br /&gt;
			return &amp;#039;open&amp;#039;&lt;br /&gt;
		elseif secondsLeft and secondsLeft &amp;lt;= 0 then&lt;br /&gt;
			return &amp;#039;pending closure&amp;#039;&lt;br /&gt;
		else&lt;br /&gt;
			return nil&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	-- Specify which fields are read-only, and prepare the metatable.&lt;br /&gt;
	local readOnlyFields = {&lt;br /&gt;
		getTitleObject = true,&lt;br /&gt;
		[&amp;#039;type&amp;#039;] = true,&lt;br /&gt;
		getSupportUsers = true,&lt;br /&gt;
		getOpposeUsers = true,&lt;br /&gt;
		getNeutralUsers = true,&lt;br /&gt;
		supports = true,&lt;br /&gt;
		opposes = true,&lt;br /&gt;
		neutrals = true,&lt;br /&gt;
		endTime = true,&lt;br /&gt;
		percent = true,&lt;br /&gt;
		user = true,&lt;br /&gt;
		dupesExist = true,&lt;br /&gt;
		getSecondsLeft = true,&lt;br /&gt;
		getTimeLeft = true,&lt;br /&gt;
		getReport = true,&lt;br /&gt;
		getStatus = true&lt;br /&gt;
	}&lt;br /&gt;
	&lt;br /&gt;
	local function pairsfunc( t, k )&lt;br /&gt;
		local v&lt;br /&gt;
		repeat&lt;br /&gt;
			k = next( readOnlyFields, k )&lt;br /&gt;
			if k == nil then&lt;br /&gt;
				return nil&lt;br /&gt;
			end&lt;br /&gt;
			v = t[k]&lt;br /&gt;
		until v ~= nil&lt;br /&gt;
		return k, v&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	return setmetatable( obj, {&lt;br /&gt;
		__pairs = function ( t )&lt;br /&gt;
			return pairsfunc, t, nil&lt;br /&gt;
		end,&lt;br /&gt;
		__index = data,&lt;br /&gt;
		__newindex = function( t, key, value )&lt;br /&gt;
			if readOnlyFields[ key ] then&lt;br /&gt;
				error( &amp;#039;index &amp;quot;&amp;#039; .. key .. &amp;#039;&amp;quot; is read-only&amp;#039;, 2 )&lt;br /&gt;
			else&lt;br /&gt;
				rawset( t, key, value )&lt;br /&gt;
			end&lt;br /&gt;
		end,&lt;br /&gt;
		__tostring = function( t )&lt;br /&gt;
			return t:getTitleObject().prefixedText&lt;br /&gt;
		end&lt;br /&gt;
	} )&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
return rfx&lt;/div&gt;</summary>
		<author><name>imported&gt;Stjn</name></author>
	</entry>
</feed>