Un article de Wikipédia, l'encyclopédie libre.
#!/usr/bin/perl
my $page_name;
my $wikisyntax = 0;
do {
my $command = shift;
if ($command =~ /^\-(\w)/)
{
$wikisyntax = 1 if ($1 eq "w");
}
else
{
$page_name = $command;
}
} while (not $page_name);
my $tmp_file = $page_name . ".html";
my $url = 'http://fr.wikipedia.org/w/index.php?title=' . $page_name .
'\&action=history\&limit=10000\&offset=0';
print "\n$url\n";
system("wget -O $tmp_file $url");
my %authors = ();
open (FILE, "$tmp_file") or die "Error with file $tmp_file: $!\n";
my @text = <FILE>;
chomp @text;
my $content = join "", @text;
while ($content =~
/class\=\'user\'\>\<a\s+href\=\"\/wiki\/Utilisateur\:([^"]+)\"|
class\=\'user\'\>\<a\s+href=\"\/w\/index\.php\?title\=Special\:Contributions\&\;target\=([0-9.]+)\"/g)
{
my $user = $1 . $2; #anyway, one of them is empty.
$authors{$user}++;
}
close (FILE);
foreach my $user (sort {$authors{$b} <=> $authors{$a}} keys %authors)
{
if ($wikisyntax)
{ print "\* $authors{$user} contribs\t\[\[Utilisateur\:$user\]\]\n";}
else
{ print "$user : $authors{$user}\n";}
}
exit;