Changeset 1037

Show
Ignore:
Timestamp:
05/15/07 22:16:00 (19 months ago)
Author:
kake
Message:

Added experimental support for local spam detection modules.

Location:
trunk
Files:
2 added
6 modified

Legend:

Unmodified
Added
Removed
  • trunk/Build.PL

    r1029 r1037  
    105105   licence_name licence_url licence_info_url moderation_requires_password 
    106106   enable_node_image enable_common_categories enable_common_locales 
     107   spam_detector_module 
    107108  ) ) { 
    108109    my $q_method = $var . "__qu"; 
     
    370371                      "site_index.tt", 
    371372                      "search.tt", 
     373                      "spam_detected.tt", 
    372374                      "userstats.tt", 
    373375                      "wanted_pages.tt" 
  • trunk/Changes

    r1036 r1037  
    55 
    660.61 
     7        Added experimental support for local spam detection modules; see the 
     8          commit_node method in "perldoc OpenGuides" for details. 
    79        Added extra "edit this page" link next to the node name; if you don't 
    810          want it, add div#title_edit_link {display:none;} to your stylesheet. 
  • trunk/INSTALL

    r1015 r1037  
    278278policy, but you can leave this blank for now if you don't have one yet. 
    279279 
     280  "What module would you like to use for spam detection? (optional)" 
     281 
     282The module you choose should have a method called "looks_like_spam", which 
     283accepts a hash with content and metadata as keys, and returns true or false 
     284to the question of whether the edit should be considered to be spam.  
     285 
    280286  "Distance calculation methods available are: 
    281287      1) British National Grid 
  • trunk/MANIFEST

    r1031 r1037  
    7474templates/site_index.tt 
    7575templates/search.tt 
     76templates/spam_detected.tt 
    7677templates/userstats.tt 
    7778templates/wanted_pages.tt 
     
    137138t/74_ping_plugin.t 
    138139t/75_revert_user.t 
     140t/76_detect_spam.t 
    139141t/templates/15_test.tt 
    140142wiki.cgi 
  • 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 ); 
  • trunk/lib/OpenGuides/Config.pm

    r1015 r1037  
    2222   licence_name licence_url licence_info_url moderation_requires_password 
    2323   enable_node_image enable_common_categories enable_common_locales 
     24   spam_detector_module 
    2425); 
    2526my @questions = map { $_ . "__qu" } @variables; 
     
    106107                     licence_name => "", 
    107108                     licence_url => "", 
    108                      licence_info_url => "" 
     109                     licence_info_url => "", 
     110                     spam_detector_module => "", 
    109111                   ); 
    110112 
     
    186188        licence_name => "What licence will you use for the guide?", 
    187189        licence_url => "What is the URL to your licence?", 
    188         licence_info_url => "What is the URL to your local page about your licensing policy?" 
     190        licence_info_url => "What is the URL to your local page about your licensing policy?", 
     191        spam_detector_module => "What module would you like to use for spam detection? (optional)", 
    189192    ); 
    190193 
     
    311314=item * licence_info_url 
    312315 
     316=item * spam_detector_module 
     317 
    313318=back 
    314319