Beispiel #1
0
 /**
  * Calculates the Athena value
  * Calls all the filters, works out the probability of each contributing to the spam level, and combines them
  *
  * @param $editPage EditPage
  * @param $text string
  * @param $summary string
  * @return double
  */
 static function calculateAthenaValue($editPage, $text, $summary)
 {
     global $wgUser, $wgAthenaTraining;
     // Get title
     $titleObj = $editPage->getTitle();
     $title = $titleObj->getTitleValue()->getText();
     // Get filter results
     $diffLang = AthenaFilters::differentLanguage($text);
     $deleted = AthenaFilters::wasDeleted($titleObj);
     $wanted = AthenaFilters::isWanted($titleObj);
     $userAge = AthenaFilters::userAge();
     $titleLength = AthenaFilters::titleLength($titleObj);
     $namespace = AthenaFilters::getNamespace($titleObj);
     $syntaxType = AthenaFilters::syntaxType($text);
     $linksPercentage = AthenaFilters::linkPercentage($text);
     // If not training, work out probabilities
     if (!$wgAthenaTraining) {
         // Array to store probability info
         $probabilityArray = array();
         $spam = null;
         $notspam = null;
         // Get the statistics table's contents
         $stats = AthenaHelper::getStatistics();
         // Calculate probability of spam
         AthenaHelper::calculateProbability_Spam($stats, $probabilityArray);
         $lnProbSpamNotSpam = log($probabilityArray['ac_p_spam'] / $probabilityArray['ac_p_not_spam']);
         /* start different language */
         AthenaHelper::calculateProbability_Language($diffLang, $stats, $probabilityArray);
         $sigma = log($probabilityArray['ac_p_langgivenspam'] / $probabilityArray['ac_p_langgivennotspam']);
         /* end different language */
         /* start deleted */
         AthenaHelper::calculateProbability_Deleted($deleted, $stats, $probabilityArray);
         $sigma += log($probabilityArray['ac_p_deletedgivenspam'] / $probabilityArray['ac_p_deletedgivennotspam']);
         /* end deleted */
         /* start wanted */
         AthenaHelper::calculateProbability_Wanted($wanted, $stats, $probabilityArray);
         $sigma += log($probabilityArray['ac_p_wantedgivenspam'] / $probabilityArray['ac_p_wantedgivennotspam']);
         /* end wanted */
         /* start user type */
         AthenaHelper::calculateProbability_User($userAge, $stats, $probabilityArray);
         $sigma += log($probabilityArray['ac_p_usergivenspam'] / $probabilityArray['ac_p_usergivennotspam']);
         /* end user type */
         /* start title length */
         AthenaHelper::calculateProbability_Length($titleLength, $stats, $probabilityArray);
         $sigma += log($probabilityArray['ac_p_titlelengthgivenspam'] / $probabilityArray['ac_p_titlelengthgivennotspam']);
         /* end title length */
         /* start namespace */
         AthenaHelper::calculateProbability_Namespace($namespace, $stats, $probabilityArray);
         $sigma += log($probabilityArray['ac_p_namespacegivenspam'] / $probabilityArray['ac_p_namespacegivennotspam']);
         /* end namespace */
         /* start syntax */
         AthenaHelper::calculateProbability_Syntax($syntaxType, $stats, $probabilityArray);
         $sigma += log($probabilityArray['ac_p_syntaxgivenspam'] / $probabilityArray['ac_p_syntaxgivennotspam']);
         /* end syntax */
         /* start links */
         AthenaHelper::calculateProbability_Links($linksPercentage, $stats, $probabilityArray);
         $sigma += log($probabilityArray['ac_p_linksgivenspam'] / $probabilityArray['ac_p_linksgivennotspam']);
         /* end links */
         $prob = $lnProbSpamNotSpam + $sigma;
         //wfErrorLog("------------------------------------------------", '/var/www/html/a/extensions/Athena/data/debug.log');
         //wfErrorLog("Probability is $prob", '/var/www/html/a/extensions/Athena/data/debug.log');
     } else {
         // al_value is double unsigned not null, so let's just set to 0 and let the code ignore it later on
         $prob = 0;
         $probabilityArray = null;
     }
     $links = AthenaFilters::numberOfLinks($text);
     $logArray = AthenaHelper::prepareLogArray($prob, $userAge, $links, $linksPercentage, $syntaxType, $diffLang, $deleted, $wanted);
     $detailsArray = AthenaHelper::preparePageDetailsArray($namespace, $title, $text, $summary, $wgUser->getId());
     AthenaHelper::logAttempt($logArray, $detailsArray, $probabilityArray);
     AthenaHelper::updateStats($logArray, $titleObj);
     return $prob;
 }