Пример #1
0
 public static function instance()
 {
     if (self::$instance == null) {
         self::$instance = new EventLogger();
     }
     return self::$instance;
 }
Пример #2
0
 public function logoutEvent($runData)
 {
     $db = Database::connection();
     $db->begin();
     EventLogger::instance()->logLogout();
     if ($runData->getUser()) {
         $userId = $runData->getUser()->getUserId();
     }
     $runData->sessionStop();
     // be even wiser! delete all sessions by this user from the current IP string!
     if ($userId !== null) {
         $c = new Criteria();
         $c->add("user_id", $userId);
         $c->add("ip_address", $runData->createIpString());
         // outdate the cache first
         $ss = DB_OzoneSessionPeer::instance()->select($c);
         $mc = OZONE::$memcache;
         foreach ($ss as $s) {
             $mc->delete('session..' . $s->getSessionId());
         }
         DB_OzoneSessionPeer::instance()->delete($c);
     }
     $db->commit();
 }
 public static function disableUserActivityLog()
 {
     self::$userActivityLogEnabled = false;
 }
Пример #4
0
 public function revertEvent($runData)
 {
     $pl = $runData->getParameterList();
     $pageId = $pl->getParameterValue("pageId");
     $revisionId = $pl->getParameterValue("revisionId");
     $site = $runData->getTemp("site");
     $db = Database::connection();
     $db->begin();
     $c = new Criteria();
     $c->add("page_id", $pageId);
     $c->setForUpdate(true);
     $page = DB_PagePeer::instance()->selectOne($c);
     if ($page == null || $page->getSiteId() != $site->getSiteId()) {
         throw new ProcessException(_("Error getting page information."), "no_page");
     }
     // check for permissions again
     $category = $page->getCategory();
     $user = $runData->getUser();
     WDPermissionManager::instance()->hasPagePermission('edit', $user, $category, $page);
     // get the revision
     $toRevision = DB_PageRevisionPeer::instance()->selectByPrimaryKey($revisionId);
     $toMeta = DB_PageMetadataPeer::instance()->selectByPrimaryKey($toRevision->getMetadataId());
     $currentRevision = $page->getCurrentRevision();
     $currentMeta = $currentRevision->getMetadata();
     // compare title and source (ids and contents)
     if ($toMeta->getTitle() === $currentMeta->getTitle() && $toRevision->getSourceId() === $currentRevision->getSourceId()) {
         throw new ProcessException(_("The title and content source of the current revision and the destination revision are identical. No change has been applied."), "no_change");
     }
     // check for locks first
     DB_PageEditLockPeer::instance()->deleteOutdated($pageId);
     $c = new Criteria();
     $c->add("page_id", $page->getPageId());
     if ($pl->getParameterValue("force") === "yes") {
         DB_PageEditLockPeer::instance()->delete($c);
     }
     $locks = DB_PageEditLockPeer::instance()->select($c);
     if (count($locks) > 0) {
         $runData->ajaxResponseAdd("locks", true);
         $runData->contextAdd("locks", $locks);
         $runData->setModuleTemplate("history/RevertPageLockedWin");
         $db->rollback();
         return;
     }
     // success so far...
     $titleChanged = false;
     if ($toMeta->getTitle() !== $currentMeta->getTitle()) {
         // change the title, need to create a new metadata...
         $metadata = clone $currentMeta;
         $metadata->setMetadataId(null);
         $metadata->setNew(true);
         $metadata->setTitle($toMeta->getTitle());
         $metadata->save();
         $titleChanged = true;
     }
     $userId = $runData->getUserId();
     if ($userId == null) {
         $userString = $runData->createIpString();
     }
     if ($toRevision->getSourceId() !== $currentRevision->getSourceId()) {
         $sourceChanged = true;
         $nSource = $toRevision->getSourceText();
         $oSource = $currentRevision->getSourceText();
         if ($nSource === $oSource) {
             $sourceChanged = false;
         }
     }
     if (!$sourceChanged && !$titleChanged) {
         throw new ProcessException(_("The title and content source of the current revision and the destination revision are identical. No change has been applied."), "no_change");
     }
     $revision = clone $currentRevision;
     $revision->setNew(true);
     $revision->setRevisionId(null);
     $revision->resetFlags();
     if ($sourceChanged) {
         $revision->setFlagText(true);
     }
     if ($titleChanged) {
         $revision->setFlagTitle(true);
         $revision->setMetadataId($metadata->getMetadataId());
         $page->setTitle($toMeta->getTitle());
     }
     $revision->setComments(_("Reverted to page revision number") . " " . $toRevision->getRevisionNumber());
     if ($userId) {
         $revision->setUserId($userId);
         $page->setLastEditUserId($userId);
     } else {
         $revision->setUserId(0);
         $page->setLastEditUserId(0);
         $revision->setUserString($userString);
         $page->setLastEditUserString($userString);
     }
     if ($sourceChanged) {
         $fullSource = false;
         // first check if store new source as a diff or as a full-source.
         if (true || $currentRevision->getSinceFullSource() > 9) {
             $fullSource = true;
         } else {
             // also compare size of diff against size of new source.
             // must be less than %50 to qualify
             $differ = new ODiff();
             $diff = $differ->diffString($oSource, $nSource);
             if (strlen($diff) > 0.5 * strlen($nSource)) {
                 $fullSource = true;
             }
         }
         $pageSource = new DB_PageSource();
         if ($fullSource) {
             $pageSource->setText($nSource);
             $revision->setSinceFullSource(0);
             $revision->setDiffSource(false);
         } else {
             $pageSource->setText($diff);
             $revision->setDiffSource(true);
             $revision->setSinceFullSource($currentRevision->getSinceFullSource() + 1);
         }
         $pageSource->save();
         $revision->setSourceId($pageSource->getSourceId());
     } else {
         // copy source id i.e. do nothing
     }
     $revision->setRevisionNumber($revision->getRevisionNumber() + 1);
     $now = new ODate();
     $revision->setDateLastEdited($now);
     $revision->save();
     $page->setRevisionId($revision->getRevisionId());
     $page->setDateLastEdited($now);
     $page->setRevisionNumber($revision->getRevisionNumber());
     $page->save();
     // outdate party!
     $outdater = new Outdater();
     if ($sourceChanged) {
         $outdater->pageEvent("source_changed", $page);
     }
     if ($titleChanged) {
         $outdater->pageEvent("title_changed", $page);
     }
     // index page
     EventLogger::instance()->logSavePage($page);
     $db->commit();
     if (GlobalProperties::$UI_SLEEP) {
         sleep(1);
     }
 }
Пример #5
0
 public function flagAnonymousEvent($runData)
 {
     $pl = $runData->getParameterList();
     $toFlag = $pl->getParameterValue("flag");
     $userString = $pl->getParameterValue("userString");
     if ($userString == null || $userString == '') {
         throw new ProcessException(_("Error processing the request."), "no_user_string");
     }
     // check if userString match the IP pattern
     if (preg_match('/^[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+(\\|[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+)?$/', $userString) !== 1) {
         throw new ProcessException(_("Error processing the request."), "bad_user_string");
     }
     $site = $runData->getTemp("site");
     $user = $runData->getUser();
     $db = Database::connection();
     $db->begin();
     $ips = explode('|', $userString);
     if ($toFlag) {
         $i = 0;
         foreach ($ips as $ip) {
             $i++;
             if (false && preg_match("/^(10\\..*)|(172\\.16\\..*)|(192\\.168\\..*)|(127\\..*)|(169\\.254\\..*)/", $ip) != 0) {
                 continue;
             }
             // flag the IP
             // check if not flagged already
             $c = new Criteria();
             $c->add("user_id", $user->getUserId());
             $c->add("address", $ip);
             $flag = DB_AnonymousAbuseFlagPeer::instance()->selectOne($c);
             if ($flag == null) {
                 $siteId = $site->getSiteId();
                 $flag = new DB_AnonymousAbuseFlag();
                 $flag->setUserId($user->getUserId());
                 $flag->setSiteId($siteId);
                 $flag->setAddress($ip);
                 if ($i == 2) {
                     $flag->setProxy(true);
                 }
                 $flag->save();
             }
         }
         EventLogger::instance()->logFlagAnonymous($userString);
     } else {
         foreach ($ips as $ip) {
             // 	unflag
             $c = new Criteria();
             $c->add("user_id", $user->getUserId());
             $c->add("address", $ip);
             DB_AnonymousAbuseFlagPeer::instance()->delete($c);
         }
         EventLogger::instance()->logUnflagAnonymous($userString);
     }
     $db->commit();
 }
Пример #6
0
function __autoload($className)
{
    include $className . ".php";
    EventLogger::logDebug("Loaded class " . $className);
}
Пример #7
0
 private function logEvent()
 {
     wfProfileIn(__METHOD__);
     global $wgRequest;
     $event = explode(",", trim(urldecode($wgRequest->getVal('log'))));
     if (sizeof($event)) {
         $key = 'mqg';
         $type = $event[0];
         $val = str_replace("-", "\t", $event[1]);
         EventLogger::logEvent($key, $type, $val);
     }
     wfProfileOut(__METHOD__);
 }
Пример #8
0
 public function setRating($articleId, $rating)
 {
     EventLogger::logEvent('mrt', $articleId, $rating);
 }
Пример #9
0
 public function deletePostEvent($runData)
 {
     $pl = $runData->getParameterList();
     $site = $runData->getTemp("site");
     $postId = $pl->getParameterValue("postId");
     if ($postId == null || !is_numeric($postId)) {
         throw new ProcessException(_("No such post."), "no_post");
     }
     $db = Database::connection();
     $db->begin();
     $post = DB_ForumPostPeer::instance()->selectByPrimaryKey($postId);
     if ($post == null || $post->getSiteId() != $site->getSiteId()) {
         throw new ProcessException(_("No such post."), "no_post");
     }
     $thread = $post->getForumThread();
     $category = $thread->getForumCategory();
     try {
         WDPermissionManager::instance()->hasForumPermission('moderate_forum', $runData->getUser(), $category);
     } catch (Exception $e) {
         throw new WDPermissionException(_("Sorry, you are not allowed to delete posts. Only site administrators and moderators are the ones who can."));
     }
     $c = new Criteria();
     $c->add("parent_id", $postId);
     $toDelete = array();
     $chposts = DB_ForumPostPeer::instance()->select($c);
     while ($chposts && count($chposts) > 0) {
         $toDelete = array_merge($toDelete, $chposts);
         $c = new Criteria();
         foreach ($chposts as $f) {
             $c->addOr("parent_id", $f->getPostId());
         }
         $chposts = DB_ForumPostPeer::instance()->select($c);
     }
     DB_ForumPostPeer::instance()->deleteByPrimaryKey($post->getPostId());
     foreach ($toDelete as $f) {
         DB_ForumPostPeer::instance()->deleteByPrimaryKey($f->getPostId());
     }
     // now recalculate a few things...
     $thread->calculateNumberPosts();
     $thread->findLastPost();
     $thread->save();
     $category->calculateNumberPosts();
     $category->findLastPost();
     $category->save();
     // outdate
     $o = new Outdater();
     $o->forumEvent("thread_save", $thread);
     // index thread
     Indexer::instance()->indexThread($thread);
     EventLogger::instance()->logPostDelete($thread, $post->getTitle());
     $db->commit();
     if (GlobalProperties::$UI_SLEEP) {
         sleep(1);
     }
 }