Exemplo n.º 1
0
 /**
  * Called when the edit is about to be saved
  *
  * @param $editPage EditPage
  * @param $text string
  * @param $section string
  * @param $error string
  * @param $summary string
  * @return bool
  */
 static function editFilter($editPage, $text, $section, &$error, $summary)
 {
     global $wgAthenaSpamThreshold, $wgAthenaTraining;
     // Check if it's a new article or not
     if ($editPage->getTitle()->getArticleID() === 0) {
         // Let's skip redirects
         $redirect = preg_match_all("/^#REDIRECT(\\s)?\\[\\[([^\\[\\]])+\\]\\]\$/", $text);
         if ($redirect !== 1) {
             $prob = AthenaHelper::calculateAthenaValue($editPage, $text, $summary);
             // This version of Bayes is based around it being greater than 0 or not
             //if ( !$wgAthenaTraining && $prob > $wgAthenaSpamThreshold ) {
             if (!$wgAthenaTraining && $prob > 0) {
                 $error = '<div class="errorbox">' . wfMessage('athena-blocked-error') . '</div>' . '<br clear="all" />';
             }
         }
     }
     return true;
 }
Exemplo n.º 2
0
 public function execute()
 {
     $dbw = wfGetDB(DB_SLAVE);
     // Get all Athena logs
     $res = $dbw->select(array('athena_page_details'), array('al_id', 'apd_language', 'apd_content'), array(), __METHOD__, array(), array());
     foreach ($res as $row) {
         echo "\n----------------------------------------------\n";
         echo "al_id is {$row->al_id} \n";
         echo "apd_language is {$row->apd_language} \n";
         $content = $row->apd_content;
         if (strlen($content) == 0) {
             $code = null;
         } else {
             file_put_contents("temp", $content);
             $code = system("franc < temp");
         }
         $code = AthenaHelper::convertISOCode($code);
         echo "Language code is {$code}\n";
         $str = $dbw->strencode(Language::fetchLanguageName($code));
         echo "Language name is {$str} \n";
         $dbw->update('athena_page_details', array('apd_language' => $str), array('al_id' => $row->al_id), __METHOD__, null);
         echo "\n----------------------------------------------\n";
     }
 }
Exemplo n.º 3
0
 /**
  * Compares the language of the site with the language of the edit
  * Returns true if different, and false if the same or null if error
  *
  * @param $text string
  * @return bool|null
  */
 public static function differentLanguage($text)
 {
     global $wgLanguageCode;
     $language = AthenaHelper::getTextLanguage($text);
     // Remove any region specialities from wiki's language code (e.g. en-gb becomes en)
     $arr = preg_split("/-/", $wgLanguageCode);
     // echo( "\n\n language code is " .  $arr[0] );
     // echo( "\n\n language is " .  $language );
     if ($language !== null) {
         if ($arr[0] === $language) {
             return false;
         }
         return true;
     }
     return null;
 }
Exemplo n.º 4
0
 /**
  * Reinforce during reinforcement page creation
  *
  * @param $id integer
  */
 static function reinforceCreateTraining($id)
 {
     // Get page details
     $res = AthenaHelper::getAthenaDetails($id);
     AthenaHelper::updateStatsCreated($res, true);
 }
Exemplo n.º 5
0
 /**
  * Deletes the page with the given Athena ID
  *
  * Well that's technically a lie - really this is only used on pages that have already been deleted but not Athena reinforced
  *
  * @param $id integer the id of the page they want to delete
  * @param $confirmed boolean whether they have clicked confirm of not
  */
 public function deleteAthenaPage($id, $confirmed)
 {
     $output = $this->getOutput();
     $this->setHeaders();
     $output->setPageTitle(wfMessage('athena-title') . ' - ' . wfMessage('athena-delete-title', $id));
     $dbw = wfGetDB(DB_SLAVE);
     $res = $dbw->selectRow(array('athena_log', 'athena_page_details'), array('athena_log.al_id', 'apd_content', 'apd_comment', 'apd_namespace', 'apd_title', 'al_success', 'al_overridden', 'apd_user'), array('athena_log.al_id' => $id, 'athena_page_details.al_id' => $id), __METHOD__, array());
     // Check the Athena id exists
     if ($res) {
         // Check it was not blocked by Athena
         if ($res->al_success == 1) {
             // Check it hasn't been overridden already
             if ($res->al_overridden == 0) {
                 $title = Title::newFromText(stripslashes($res->apd_title), $res->apd_namespace);
                 // Temporary disabling this
                 /*if ( $title->exists() ) {
                 			// Page exists - point them to delete instead
                 			$output->addWikiMsg( 'athena-delete-still-exists' );
                 			$output->addHTML( '<a href=' . $title->getFullURL( array( 'action' => 'delete' ) ) . '>' . wfMessage( 'athena-view-not-blocked-reinforce' ) . '</a>' );
                 		} else {*/
                 // At this point, we want to reinforce Athena if we've confirmed it.
                 if ($confirmed) {
                     // Reinforce the system
                     AthenaHelper::reinforceDelete($id);
                     $output->addWikiMsg('athena-create-reinforced');
                     $dbw->update('athena_log', array('al_overridden' => 1), array('al_id' => $id), __METHOD__, null);
                 } else {
                     $output->addWikiMsg('athena-delete-text', $id);
                     $output->addWikiText('[[{{NAMESPACE}}:' . wfMessage('athena-title') . '/' . wfMessage('athena-delete-url') . '/' . $res->al_id . '/' . wfMessage('athena-create-confirm-url') . '|' . wfMessage('athena-create-confirm') . ']]');
                 }
                 //}
             } else {
                 $output->addWikiMsgArray('athena-delete-error-overridden', $id);
             }
         } else {
             $output->addWikiMsgArray('athena-delete-error-not-blocked', $id);
         }
     } else {
         $output->addWikiMsgArray('athena-delete-error-not-exists', $id);
     }
 }