Modulo:Quorum: differenze tra le versioni

Contenuto cancellato Contenuto aggiunto
creazione modulo
 
correggo
 
(5 versioni intermedie di uno stesso utente non sono mostrate)
Riga 1:
local p = {}
local page = 'Wikipedia:Amministratori/Sistema di voto/Quorum'
 
local function set_error(msg, ...)
local messages = {
bad_list = 'Non è stato trovato un elenco di 8 elezioni in $1',
returnbad_votes = set_error('I voti nellain pagina ' .. page .. '$1 non combaciano con quelli calcolati per ciascuna elezione: $2' .. table.concat(votes, ', '))
returnduplicate_election = set_error('È stata elencata più volte la seguente elezione: $1' .. election),
missing_election = 'Non è stata trovata la pagina della seguente elezione: $1',
}
msg = mw.message.newRawMessage(messages[msg], ...):plain()
return string.format('<span class="error">%s</span>', msg)
end
 
function p.listpage()
return string.format('[[%s]]', page)
end
 
function p.main()
local page = 'Wikipedia:Amministratori/Sistema di voto/Quorum'
local source = mw.title.new(page):getContent()
local quorum = 0
local elections, candidates, votes, hash = {}, {}, {}, {}
forlocal electionpattern in string.gmatch(source,= '%[%[(W%a+:Amministratori/Elezioni/.[^|%[%]]-)[|%]][^%[}]+s[iì]') do
for election in string.gmatch(source or '', pattern) do
table.insert(elections, election)
if not source or #candidates == 8 then
local candidate = election:match('Elezioni/([^/]+)')
return set_error('bad_list', page)
table.insert(candidates, string.format('[[User:%s|%s]]', candidate, candidate))
ifelseif hashelections[election] then
end
return set_error('duplicate_election', election)
if #elections ~= 8 then
end
return set_error('È stato trovato un elenco di ' .. #elections .. ' elezioni nella pagina ' .. page)
table.insert(elections, [election)] = true
end
for i, election in ipairs(elections) do
local content = mw.title.new(election):getContent()
if not content then
return set_error('Non è stata trovata la pagina della seguente elezione: missing_election' .., election)
end
if hash[election] then
return set_error('È stata elencata più volte la seguente elezione: ' .. election)
end
hash[election] = true
content = content:gsub('\n==+ *[^\n]- *==+', '\r%0')
local candidate = election:match('Elezioni/([^/]+)')
table.insert(candidates, string.format('[[User:%s|%s]]', candidate, candidate))
votes[#candidates] = 0
for heading, section in string.gmatch(content, '\n==+ *([^\n]-) *==+(.-)\r') do
if heading == 'Pro' or heading == 'Contro' then
local _, count = section:gsub('\n#[^#:*\n][^\n]-%a', '')
quorum = quorum + count
votes[i#candidates] = (votes[i#candidates] or 0) + count
end
end
end
if #electionscandidates ~=< 8 then
if not source:match('%s' .. table.concat(votes, '%s.-%s') .. '%s') then
return set_error('bad_list', page)
return set_error('I voti nella pagina ' .. page .. ' non combaciano con quelli calcolati per ciascuna elezione: ' .. table.concat(votes, ', '))
ifelseif not source:match('%s' .. table.concat(votes, '%s.-%s') .. '%s') then
return set_error('bad_votes', page, table.concat(votes, ', '))
end
quorum = math.floor(quorum / 12)