- if ($type =~ /^author$/i) {
- my %hash = &dbGetCol("factoids", "factoid_key","created_by");
- my %author;
-
- foreach (keys %hash) {
- my $thisnuh = $hash{$_};
-
- $thisnuh =~ /^(\S+)!\S+@\S+$/;
- $author{lc $1}++;
- }
-
- if (!scalar keys %author) {
- return 'sorry, no factoids with created_by field.';
- }
-
- # work-around.
- my %count;
- foreach (keys %author) {
- $count{ $author{$_} }{$_} = 1;
- }
- undef %author;
-
- my $count;
- my @list;
- foreach $count (sort { $b <=> $a } keys %count) {
- my $author = join(", ", sort keys %{$count{$count}});
- push(@list, "$count by $author");
- }
-
- my $prefix = "factoid statistics by author: ";
- return &formListReply(0, $prefix, @list);
-
- } elsif ($type =~ /^broken$/i) {
- &status("factstats(broken): starting...");
- my $start_time = &gettimeofday();
- my %data = &dbGetCol("factoids", "factoid_key","factoid_value");
- my @list;
-
- my $delta_time = &gettimeofday() - $start_time;
- &status(sprintf("factstats(broken): %.02f sec to retreive all factoids.", $delta_time)) if ($delta_time > 0);
- $start_time = &gettimeofday();
-
- # parse the factoids.
- foreach (keys %data) {
- if (&validFactoid($_, $data{$_}) == 0) {
- s/([\,\;]+)/\037$1\037/g; # highlight chars.
- push(@list, $_); # push it.
- }
- }
-
- $delta_time = &gettimeofday() - $start_time;
- &status(sprintf("factstats(broken): %.02f sec to complete.", $delta_time)) if ($delta_time > 0);
-
- # bail out on no results.
- if (scalar @list == 0) {
- return 'no broken factoids... wooohoo.';
- }
-
- # parse the results.
- my $prefix = "broken factoid ";
- return &formListReply(1, $prefix, @list);
-
- } elsif ($type =~ /^deadredir?$/i) {
- my @list = &searchTable("factoids", "factoid_key",
- "factoid_value", "^<REPLY> see ");
- my %redir;
- my $f;
-
- for (@list) {
- my $factoid = $_;
- my $val = &getFactInfo($factoid, "factoid_value");
- if ($val =~ /^<REPLY> see( also)? (.*?)\.?$/i) {
- my $redirf = lc $2;
- my $redir = &getFactInfo($redirf, "factoid_value");
- next if (defined $redir);
-
- $redir{$redirf}{$factoid} = 1;
- }
- }
-
- my @newlist;
- foreach $f (keys %redir) {
- my @sublist = keys %{$redir{$f}};
- for (@sublist) {
- s/([\,\;]+)/\037$1\037/g;
- }
-
- push(@newlist, join(', ', @sublist)." => $f");
- }
-
- # parse the results.
- my $prefix = "Loose link (dead) redirections in factoids ";
- return &formListReply(1, $prefix, @newlist);
-
- } elsif ($type =~ /^dup(licate|e)$/i) {
- my $start_time = &gettimeofday();
- &status("factstats(dupe): starting...");
- my %hash = &dbGetCol("factoids", "factoid_key", "factoid_value", 1);
- my @list;
- my $refs = 0;
- my $v;
-
- foreach $v (keys %hash) {
- my $count = scalar(keys %{$hash{$v}});
- next if ($count == 1);
-
- my @sublist;
- foreach (keys %{$hash{$v}}) {
- if ($v =~ /^<REPLY> see /i) {
- $refs++;
- next;
- }
-
- s/([\,\;]+)/\037$1\037/g;
- if ($_ eq "") {
- &WARN("dupe: _ = NULL. should never happen!.");
- next;
- }
- push(@sublist, $_);
- }
-
- next unless (scalar @sublist);
-
- push(@list, join(", ", @sublist));
- }
-
- &status("factstats(dupe): (good) dupe refs: $refs.");
- my $delta_time = &gettimeofday() - $start_time;
- &status(sprintf("factstats(dupe): %.02f sec to complete", $delta_time)) if ($delta_time > 0);
-
- # bail out on no results.
- if (scalar @list == 0) {
- return "no duplicate factoids... woohoo.";
- }
-
- # parse the results.
- my $prefix = "dupe factoid ";
- return &formListReply(1, $prefix, @list);
-
- } elsif ($type =~ /^lame$/i) {
- # Custom select statement.
- my $query = "SELECT factoid_key,factoid_value FROM factoids WHERE length(factoid_value) <= 40";
- my $sth = $dbh->prepare($query);
- &ERROR("factstats(lame): => '$query'.") unless $sth->execute;
-
- my @list;
- while (my @row = $sth->fetchrow_array) {
- my($key,$val) = ($row[0], $row[1]);
- next if ($val =~ /^</);
- next if ($val =~ /\s{2,}/);
-
- $key =~ s/\,/\037\,\037/g;
- push(@list, $key);
- }
- $sth->finish;
-
- # parse the results.
- my $prefix = "Lame factoids ";
- return &formListReply(1, $prefix, @list);
-
- } elsif ($type =~ /^locked$/i) {
- my %hash = &dbGetCol("factoids", "factoid_key","locked_by");
- my @list = keys %hash;
-
- for (@list) {
- s/([\,\;]+)/\037$1\037/g;
- }
-
- my $prefix = "factoid statistics on $type ";
- return &formListReply(0, $prefix, @list);
-
- } elsif ($type =~ /^new$/i) {
- my %hash = &dbGetCol("factoids", "factoid_key","created_time");
- my %age;
+ if ( $type =~ /^author$/i ) {
+ my %hash = &sqlSelectColHash(
+ 'factoids', 'factoid_key,created_by',
+ undef, 'WHERE created_by IS NOT NULL'
+ );
+ my %author;
+
+ foreach my $factoid ( keys %hash ) {
+ my $thisnuh = $hash{$factoid};
+
+ $thisnuh =~ /^(\S+)!\S+@\S+$/;
+ $author{ lc $1 }++;
+ }
+
+ if ( !scalar keys %author ) {
+ return 'sorry, no factoids with created_by field.';
+ }
+
+ # work-around.
+ my %count;
+ foreach ( keys %author ) {
+ $count{ $author{$_} }{$_} = 1;
+ }
+ undef %author;
+
+ my $count;
+ my @list;
+ foreach $count ( sort { $b <=> $a } keys %count ) {
+ my $author = join( ', ', sort keys %{ $count{$count} } );
+ push( @list, "$count by $author" );
+ }
+
+ my $prefix = 'factoid statistics by author: ';
+ return &formListReply( 0, $prefix, @list );