Make WordPress Core

Changeset 2075


Ignore:
Timestamp:
01/10/2005 08:21:06 PM (22 years ago)
Author:
saxmatt
Message:

Spam tastes great, we should eat more of it. Add 'spam' approval value, and basic blacklist.

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/edit-comments.php

    r1977 r2075  
    6767                $offset = 0;
    6868
    69         $comments = $wpdb->get_results("SELECT * FROM $wpdb->comments ORDER BY comment_date DESC LIMIT $offset,20");
     69        $comments = $wpdb->get_results("SELECT * FROM $wpdb->comments WHERE comment_approved = '0' OR comment_approved = '1' ORDER BY comment_date DESC LIMIT $offset,20");
    7070}
    7171if ('view' == $mode) {
  • trunk/wp-admin/options-discussion.php

    r1818 r2075  
    2323        <form name="form1" method="post" action="options.php">
    2424                <input type="hidden" name="action" value="update" />
    25                 <input type="hidden" name="page_options" value="'default_pingback_flag','default_ping_status','default_comment_status','comments_notify','moderation_notify','comment_moderation','require_name_email','comment_whitelist','comment_max_links','moderation_keys'" />
     25                <input type="hidden" name="page_options" value="'default_pingback_flag','default_ping_status','default_comment_status','comments_notify','moderation_notify','comment_moderation','require_name_email','comment_whitelist','comment_max_links','moderation_keys','blacklist_keys'" />
    2626<fieldset class="options">
    2727        <legend><?php _e('Usual settings for an article: <em>(These settings may be overridden for individual articles.)</em>') ?></legend>
    … …  
    8080                </p>
    8181                <p>
    82                         <a id="retrospambutton" href="options-discussion.php?action=retrospam" title="Click this link to check old comments for spam that your current filters would catch.">Check past comments against current word list</a>
     82                        <a id="retrospambutton" href="options-discussion.php?action=retrospam"><?php _e('Check past comments against moderation list'); ?></a>
    8383                </p>
     84</fieldset>
     85<fieldset class="options">
     86    <legend><?php _e('Comment Blacklist') ?></legend>
     87    <p><?php _e('This is a list of words that you want completely blacklisted from your blog. Be very careful what you add here, because if a comment matches something here it will be completely nuked and there will be no notification. Remember that partial words can match, so if there is any chance something here might match it would be better to put it in the moderation box above.') ?></p>
     88                <p>
     89                        <textarea name="blacklist_keys" cols="60" rows="4" id="blacklist_keys" style="width: 98%; font-size: 12px;" class="code"><?php form_option('blacklist_keys'); ?></textarea>
     90                </p>
    8491</fieldset>
    8592                <p class="submit">
  • trunk/wp-admin/upgrade-schema.php

    r2009 r2075  
    2323  comment_content text NOT NULL,
    2424  comment_karma int(11) NOT NULL default '0',
    25   comment_approved enum('0','1') NOT NULL default '1',
     25  comment_approved enum('0','1','spam') NOT NULL default '1',
    2626  comment_agent varchar(255) NOT NULL default '',
    2727  comment_type varchar(20) NOT NULL default '',
    … …  
    213213        add_option('comment_whitelist', 1);
    214214        add_option('page_uris');
     215        add_option('blacklist_keys');
    215216
    216217        // Delete unused options
    … …  
    221222
    222223        // Set up a few options not to load by default
    223         $fatoptions = array( 'moderation_keys', 'recently_edited' );
     224        $fatoptions = array( 'moderation_keys', 'recently_edited', 'blacklist_keys' );
    224225        foreach ($fatoptions as $fatoption) :
    225226                $wpdb->query("UPDATE $wpdb->options SET `autoload` = 'no' WHERE option_name = '$fatoption'");
    226227        endforeach;
    227228}
     229
    228230?>
  • trunk/wp-includes/comment-functions.php

    r2068 r2075  
    725725        if ( 1 == get_settings('comment_whitelist')) {
    726726                if( $author != '' && $email != '' ) {
    727                     $ok_to_comment = $wpdb->get_var("SELECT comment_approved FROM $wpdb->comments WHERE comment_author_email = '$email' and comment_approved = '1' ");
     727                    $ok_to_comment = $wpdb->get_var("SELECT comment_approved FROM $wpdb->comments WHERE comment_author = '$author' AND comment_author_email = '$email' and comment_approved = '1' ");
    728728                    if ( 1 == $ok_to_comment && false === strpos( $email, get_settings('moderation_keys')) )
    729729                        return true;
    730730                } else {
    731731                        return false;
    732                 }
    733         }
    734 
    735         // Useless numeric encoding is a pretty good spam indicator:
    736         // Extract entities:
    737         if (preg_match_all('/&#(\d+);/',$comment,$chars)) {
    738                 foreach ($chars[1] as $char) {
    739                         // If it's an encoded char in the normal ASCII set, reject
    740                         if ($char < 128)
    741                                 return false;
    742732                }
    743733        }
  • trunk/wp-includes/functions-post.php

    r2064 r2075  
    382382}
    383383
    384 
    385 function wp_new_comment( $commentdata ) {
     384function wp_blacklist_check($author, $email, $url, $comment, $user_ip, $user_agent) {
     385        global $wpdb;
     386
     387        if ( preg_match_all('/&#(\d+);/', $comment, $chars) ) {
     388                foreach ($chars[1] as $char) {
     389                        // If it's an encoded char in the normal ASCII set, reject
     390                        if ($char < 128)
     391                                return true;
     392                }
     393        }
     394
     395        $mod_keys = trim( get_settings('blacklist_keys') );
     396        if ('' == $mod_keys )
     397                return false; // If moderation keys are empty
     398        $words = explode("\n", $mod_keys );
     399
     400        foreach ($words as $word) {
     401                $word = trim($word);
     402
     403                // Skip empty lines
     404                if ( empty($word) ) { continue; }
     405
     406                // Do some escaping magic so that '#' chars in the
     407                // spam words don't break things:
     408                $word = preg_quote($word, '#');
     409               
     410                $pattern = "#$word#i";
     411                if ( preg_match($pattern, $author    ) ) return true;
     412                if ( preg_match($pattern, $email     ) ) return true;
     413                if ( preg_match($pattern, $url       ) ) return true;
     414                if ( preg_match($pattern, $comment   ) ) return true;
     415                if ( preg_match($pattern, $user_ip   ) ) return true;
     416                if ( preg_match($pattern, $user_agent) ) return true;
     417        }
     418
     419        return false;
     420}
     421
     422function wp_new_comment( $commentdata, $spam = false ) {
    386423        global $wpdb;
    387424
    … …  
    413450        }
    414451
    415         if( check_comment($author, $email, $url, $comment, $user_ip, $user_agent) )
     452        if ( check_comment($author, $email, $url, $comment, $user_ip, $user_agent) )
    416453                $approved = 1;
    417454        else
    418455                $approved = 0;
     456        if ( wp_blacklist_check($author, $email, $url, $comment, $user_ip, $user_agent) )
     457                $approved = 'spam';
    419458
    420459        $result = $wpdb->query("INSERT INTO $wpdb->comments
    … …  
    427466        do_action('comment_post', $comment_id);
    428467
    429         if ( !$approved )
    430                 wp_notify_moderator($comment_id);
    431 
    432         if ( get_settings('comments_notify') && $approved )
    433                 wp_notify_postauthor($comment_id, 'comment');
     468        if ( 'spam' != $approved ) { // If it's spam save it silently for later crunching
     469                if ( !$approved )
     470                        wp_notify_moderator($comment_id);
     471       
     472                if ( get_settings('comments_notify') && $approved )
     473                        wp_notify_postauthor($comment_id, 'comment');
     474        }
    434475
    435476        return $result;
Note: See TracChangeset for help on using the changeset viewer.