[pLog-svn] r6125 - plog/branches/lifetype-1.2/class/security

jondaley at devel.lifetype.net jondaley at devel.lifetype.net
Mon Dec 24 14:19:21 EST 2007


Author: jondaley
Date: 2007-12-24 14:19:21 -0500 (Mon, 24 Dec 2007)
New Revision: 6125

Modified:
   plog/branches/lifetype-1.2/class/security/bayesianfilter.class.php
   plog/branches/lifetype-1.2/class/security/commentfilter.class.php
   plog/branches/lifetype-1.2/class/security/nullpipelinefilter.class.php
   plog/branches/lifetype-1.2/class/security/pipeline.class.php
   plog/branches/lifetype-1.2/class/security/pipelinefilter.class.php
Log:
reverted revision 6093 to start doing it as discussed on the svn list

Modified: plog/branches/lifetype-1.2/class/security/bayesianfilter.class.php
===================================================================
--- plog/branches/lifetype-1.2/class/security/bayesianfilter.class.php	2007-12-24 18:35:29 UTC (rev 6124)
+++ plog/branches/lifetype-1.2/class/security/bayesianfilter.class.php	2007-12-24 19:19:21 UTC (rev 6125)
@@ -41,7 +41,7 @@
         * @return A positive PipelineResult object is the comment is not spam or a negative
         * one if it is.
         */
-        function filter($secondRun = false)
+        function filter()
         {
             $config =& Config::getConfig();
 
@@ -134,65 +134,41 @@
             if( $parentId == "" )
                 $parentId = 0;
 
-            $spamicity = $this->getSpamProbability($blogInfo->getId(),
-                                                   $commentTopic, $commentText,
-                                                   $userName, $userEmail, $userUrl);
-            if($spamicity >=
-               $config->getValue("bayesian_filter_spam_probability_treshold"))
+            $spamicity = $this->getSpamProbability($blogInfo->getId(), $commentTopic, $commentText, $userName, $userEmail, $userUrl);
+
+            if ($spamicity >= $config->getValue("bayesian_filter_spam_probability_treshold"))
             {
-                    // need this to get the locale
+                // need this to get the locale
                 $plr = $this->getPipelineRequest();
                 $bi = $plr->getBlogInfo();
                 $locale = $bi->getLocale();
-                
-                    // now we need to check what we have to do with this comment... either throw it away
-                    // or keep it in the database
-                
-                    // this piece of code shouldn't really go here, but it's easier than letting
-                    // the AddComment action that there was actually a comment and that it should
-                    // still be added but marked as spam and so on... sometimes breaking a few
-                    // rules makes things easier :)
+
+                // now we need to check what we have to do with this comment... either throw it away
+                // or keep it in the database
+
+                // this piece of code shouldn't really go here, but it's easier than letting
+                // the AddComment action that there was actually a comment and that it should
+                // still be added but marked as spam and so on... sometimes breaking a few
+                // rules makes things easier :)
                 if( $config->getValue( "bayesian_filter_spam_comments_action" ) == BAYESIAN_FILTER_KEEP_COMMENT_ACTION ) {
                     $result = new PipelineResult(false, HIGH_SPAM_PROBABILITY, $locale->tr("error_comment_spam_keep" ));
                     $comments = new ArticleComments();
                     $clientIp = Client::getIp();
                     $comment = new UserComment( $articleId, $blogInfo->getId(), $parentId, $commentTopic, $commentText,
-                                                null, $userName, $userEmail, $userUrl, $clientIp,
-                                                0, COMMENT_STATUS_SPAM );
-                        // mark it as a trackback instead of a user comment...
-                    
+                                                   null, $userName, $userEmail, $userUrl, $clientIp,
+                                                   0, COMMENT_STATUS_SPAM );
+                    // mark it as a trackback instead of a user comment...
+
                     if( $isTrackback ) {
                         $comment->setType( COMMENT_TYPE_TRACKBACK );
                     }
-                    if(!$secondRun){
-                            // add the comment to the db
-                        $comments->addComment( $comment );
-                    }
-                    else{
-                            // This is the second time through this filter, so
-                            // the comment has already been saved to the
-                            // database. However, if we previously trained this
-                            // as non-spam, and another filter said it was
-                            // spam, we should train it as spam now.
-                            //
-                            // Assuming previouslyRejected gets set correctly
-                            // for the second pass, I think the below code will
-                            // take care of this for us.
-                            //
-                            // Mark pointed out a situation where if the
-                            // bayesian filter catches a comments as spam, and
-                            // the auth-image (or other plugin) also catches it
-                            // as spam, we probably don't want the comment in
-                            // the database at all.  I am not sure who should
-                            // remove it, either here, since we added it
-                            // incorrectly, or the other plugin, since it is
-                            // overriding the bayesian filter.
-                    }
+
+                    // add the comment to the db
+                    $comments->addComment( $comment );
                 }
                 else {
-                        // nothing to do here, simply throw the comment away
-                    $result = new PipelineResult(false, HIGH_SPAM_PROBABILITY,
-                                                 $locale->tr("error_comment_spam_throw_away" ));
+                    // nothing to do here, simply throw the comment away
+                    $result = new PipelineResult(false, HIGH_SPAM_PROBABILITY, $locale->tr("error_comment_spam_throw_away" ));
                 }
                 $spam = true;
             }
@@ -202,8 +178,6 @@
                 $spam = false;
             }
 
-                // if(!$secondRun){   // if this is commented, the bayesian filter can
-                // train on the text of comments that other filters marked as spam.
             if ( !$previouslyRejected )
             {
                 // train the filter with the message, be it spam or not...
@@ -220,15 +194,14 @@
             	{
             		// Un-train this non-spam
 					BayesianFilterCore::untrain( $blogInfo->getId(), $commentTopic, $commentText, $userName, $userEmail,
-											   $userUrl, false );
+											   $userUrl, $spam );
 
 					// train this as spam
 					BayesianFilterCore::train( $blogInfo->getId(), $commentTopic, $commentText, $userName, $userEmail,
 											   $userUrl, true );
             	}
             }
-                // }   // end of don't let bayesian filter train on other filters
-            
+
             //print "<h1>" . number_format($spamicity * 100, 0) . "% of spamicity</h1>";
             return $result;
         }

Modified: plog/branches/lifetype-1.2/class/security/commentfilter.class.php
===================================================================
--- plog/branches/lifetype-1.2/class/security/commentfilter.class.php	2007-12-24 18:35:29 UTC (rev 6124)
+++ plog/branches/lifetype-1.2/class/security/commentfilter.class.php	2007-12-24 19:19:21 UTC (rev 6125)
@@ -33,7 +33,7 @@
          *
          * @return A PipelineResult object
          */
-        function filter($secondRun = false)
+        function filter()
         {
         	// check if we're posting a comment
             $request = $this->_pipelineRequest->getHttpRequest();

Modified: plog/branches/lifetype-1.2/class/security/nullpipelinefilter.class.php
===================================================================
--- plog/branches/lifetype-1.2/class/security/nullpipelinefilter.class.php	2007-12-24 18:35:29 UTC (rev 6124)
+++ plog/branches/lifetype-1.2/class/security/nullpipelinefilter.class.php	2007-12-24 19:19:21 UTC (rev 6125)
@@ -21,7 +21,7 @@
         /**
          * Always returns a positive result
          */
-        function filter($secondRun = false)
+        function filter()
         {
             lt_include( PLOG_CLASS_PATH . 'class/security/pipelineresult.class.php' );
 

Modified: plog/branches/lifetype-1.2/class/security/pipeline.class.php
===================================================================
--- plog/branches/lifetype-1.2/class/security/pipeline.class.php	2007-12-24 18:35:29 UTC (rev 6124)
+++ plog/branches/lifetype-1.2/class/security/pipeline.class.php	2007-12-24 19:19:21 UTC (rev 6125)
@@ -135,7 +135,7 @@
                 $pipelineRequest = new PipelineRequest( $this->_httpRequest, $this->_blogInfo );
                 $filter = new $filterClass( $pipelineRequest );
                 // and execute it...            
-                $result = $filter->filter(false);
+                $result = $filter->filter();
                 // if there was an error, we better say so now
                 // and quite, making sure that we're keeping the
                 // error code
@@ -163,7 +163,7 @@
                                                             true );
                     $filter = new $filterClass( $pipelineRequest );
                     // and execute it...            
-                    $result = $filter->filter(true);
+                    $result = $filter->filter();
                     // if there was an error, we want to keep going
                 }
             }

Modified: plog/branches/lifetype-1.2/class/security/pipelinefilter.class.php
===================================================================
--- plog/branches/lifetype-1.2/class/security/pipelinefilter.class.php	2007-12-24 18:35:29 UTC (rev 6124)
+++ plog/branches/lifetype-1.2/class/security/pipelinefilter.class.php	2007-12-24 19:19:21 UTC (rev 6125)
@@ -53,7 +53,7 @@
          * @return a PipelineResult object
          * @see Pipelineresult
          */
-        function filter($secondRun=false)
+        function filter()
         {
             throw( new Exception( "This method must be implemented by child classes!" ));
         }



More information about the pLog-svn mailing list