Jump to content

Module:Current RfX: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
add "Header" as an exception
let mw.title do our pattern matching for us, and add a p.titles function to get RfX title objects
Line 4: Line 4:


local rfx = require('Module:Rfx')
local rfx = require('Module:Rfx')
local p = {}
local p = {}
local exceptions = {
['Front matter'] = true,
['Header'] = true,
['bureaucratship'] = true
}
-- Get an array of title objects for current RfXs.
function p.titles()
local content = mw.title.new('Wikipedia:Requests for adminship'):getContent()
local ret = {}
for transclusion in string.gmatch(content, '{{(.-)}}') do
local title = mw.title.new(transclusion)
if title and
title.namespace == 4 and ( -- Wikipedia namespace
title.rootText == 'Requests for adminship' or
title.rootText == 'Requests for bureaucratship'
) and
title.isSubpage and
title.baseText == title.rootText and -- Is first-level subpage
not exceptions[ title.subpageText ]
then
ret[#ret + 1] = title
end
end
return ret
end

-- Get an array of page names for current RfXs.
function p.rfxNames()
function p.rfxNames()
local titles = p.titles()
local success, rfa = pcall(mw.title.new, 'Wikipedia:Requests for adminship')
local ret = {}
if not (success and rfa) then
for i, title in ipairs(titles) do
return nil
ret[#ret + 1] = title.prefixedText
end
end
local rfaText = rfa:getContent()
return ret
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 rfxNames = {}
local exceptions = {
['Front matter'] = true,
['Header'] = true,
['bureaucratship'] = true
}
local pattern = '{{[ _]*([wW]ikipedia:[rR]equests for %w+/([^{}]-))[ _]*}}'
for rfxPage, rfxSubpage in mw.ustring.gmatch(rfaText, pattern) do
if not exceptions[rfxSubpage] then
rfxNames[#rfxNames + 1] = rfxPage
end
end
return rfxNames
end
end


-- Get a table of RfA and RfB arrays containing rfx objects for current rfxes.
function p.rfx()
function p.rfx()
local rfa, rfb = {}, {}
local rfa, rfb = {}, {}

Revision as of 11:48, 25 June 2015

-- This module gets information about RfXes (requests for adminship and requests for bureaucratship)
-- that are currently open. It can return a list of page names or a list of rfx objects found using
-- [[Module:Rfx]].

local rfx = require('Module:Rfx')
local p = {}
 
local exceptions = {
	['Front matter'] = true,
	['Header'] = true,
	['bureaucratship'] = true
}
 
-- Get an array of title objects for current RfXs.
function p.titles()
	local content = mw.title.new('Wikipedia:Requests for adminship'):getContent()
	local ret = {}
	for transclusion in string.gmatch(content, '{{(.-)}}') do
		local title = mw.title.new(transclusion)
		if title and
			title.namespace == 4 and ( -- Wikipedia namespace
				title.rootText == 'Requests for adminship' or
				title.rootText == 'Requests for bureaucratship'
			) and
			title.isSubpage and
			title.baseText == title.rootText and -- Is first-level subpage
			not exceptions[ title.subpageText ]
		then
			ret[#ret + 1] = title
		end
	end
	return ret
end

-- Get an array of page names for current RfXs.
function p.rfxNames()
	local titles = p.titles()
	local ret = {}
	for i, title in ipairs(titles) do
		ret[#ret + 1] = title.prefixedText
	end
	return ret
end

-- Get a table of RfA and RfB arrays containing rfx objects for current rfxes.
function p.rfx()
	local rfa, rfb = {}, {}
	local rfxNames = p.rfxNames()
	for i, rfxName in ipairs(rfxNames) do
		local rfxObj = rfx.new(rfxName)
		if rfxObj then
			local rfxType = rfxObj.type
			if rfxType == 'rfa' then
				rfa[#rfa + 1] = rfxObj
			elseif rfxType == 'rfb' then
				rfb[#rfb + 1] = rfxObj
			end
		end
	end
	return {rfa = rfa, rfb = rfb}
end

return p