Modulo:WikipedianoVotazioni

Da Wikipedia, l'enciclopedia libera.
Vai alla navigazione Vai alla ricerca

Questo modulo serve a ordinare i vari eventi in WP:Wikipediano/Votazioni. Prende in input un solo parametro, il contenuto della pagina, e ordina le varie sezioni in ordine cronologico decrescente, usando come chiave di ogni sezione l'evento più recente all'interno di tale sezione. Il modulo viene richiamato da Wikipedia:Wikipediano/Votazioni/Lista.


local p = {}

function p.main(frame)
    items = split( frame.args[1] );
    table.sort( items, function ( first, second ) return getMaxKey( first ) > getMaxKey( second ); end );
    return table.concat( items, '\n' );
end

function getMaxKey( section )
	lines = mw.text.split( section, '\n' );
	reg = '\* *<span style *= *"display:none">(%d+)</span>';
	max = 0;
	for _,line in pairs( lines ) do
		match = string.match( line, reg );
		if match ~= nil and tonumber( match ) > max then
			max = tonumber( match );
		end
	end
	return max;	
end

function split( text )
	res = mw.text.split( text, '\n;', true );
	ret = {};
	for _,v in pairs( res ) do
		if v ~= '' and v ~= nil and v ~= '\n' then
			table.insert( ret, ';' .. v );
		end
	end
    return ret;
end


return p