Ignore:
Timestamp:
May 15, 2007, 10:16:00 PM (14 years ago)
Author:
kake
Message:

Added experimental support for local spam detection modules.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/OpenGuides.pm

    r1034 r1037  
    12411241printing the output to STDOUT.
    12421242
     1243If you have specified the C<spam_detector_module> option in your
     1244C<wiki.conf>, this method will attempt to call the <looks_like_spam>
     1245method of that module to determine whether the edit is spam.  If this
     1246method returns true, then the C<spam_detected.tt> template will be
     1247used to display an error message.
     1248
     1249The C<looks_like_spam> method will be passed a datastructure containing
     1250content and metadata.
     1251
    12431252The geographical data that you should provide in the L<CGI> object
    12441253depends on the handler you chose in C<wiki.conf>.
     
    12951304    $new_metadata{longitude} = delete $new_metadata{longitude_unmunged}
    12961305        if $new_metadata{longitude_unmunged};
     1306
     1307    foreach my $var ( qw( summary username comment edit_type ) ) {
     1308        $new_metadata{$var} = $q->param($var) || "";
     1309    }
     1310    $new_metadata{host} = $ENV{REMOTE_ADDR};
     1311
     1312    # Wiki::Toolkit::Plugin::RSS::ModWiki wants "major_change" to be set.
     1313    $new_metadata{major_change} = ( $new_metadata{edit_type} eq "Normal edit" )
     1314                                    ? 1
     1315                                    : 0;
     1316
     1317    # If we can, check to see if this edit looks like spam.
     1318    my $spam_detector = $config->spam_detector_module;
     1319    my $is_spam;
     1320    if ( $spam_detector ) {
     1321        eval {
     1322            eval "require $spam_detector";
     1323            $is_spam = $spam_detector->looks_like_spam(
     1324                node    => $node,
     1325                content => $content,
     1326                metadata => \%new_metadata,
     1327            );
     1328        };
     1329    }
     1330
     1331    if ( $is_spam ) {
     1332        my $output = OpenGuides::Template->output(
     1333            wiki     => $self->wiki,
     1334            config   => $config,
     1335            template => "spam_detected.tt",
     1336            vars     => {
     1337                          not_editable => 1,
     1338                        },
     1339        );
     1340        return $output if $return_output;
     1341        print $output;
     1342        return;
     1343    }
    12971344
    12981345    # Check to make sure all the indexable nodes are created
     
    13061353    }
    13071354   
    1308     foreach my $var ( qw( summary username comment edit_type ) ) {
    1309         $new_metadata{$var} = $q->param($var) || "";
    1310     }
    1311     $new_metadata{host} = $ENV{REMOTE_ADDR};
    1312 
    1313     # Wiki::Toolkit::Plugin::RSS::ModWiki wants "major_change" to be set.
    1314     $new_metadata{major_change} = ( $new_metadata{edit_type} eq "Normal edit" )
    1315                                     ? 1
    1316                                     : 0;
    1317 
    13181355    my $written = $wiki->write_node( $node, $content, $checksum,
    13191356                                     \%new_metadata );
Note: See TracChangeset for help on using the changeset viewer.