Exemplo n.º 1
0
 /**
  * Updates the total amount of points the user has.
  *
  * @return Array
  */
 public function updateTotalPoints()
 {
     global $wgEnableFacebook, $wgUserLevels;
     if ($this->user_id == 0) {
         return array();
     }
     $stats_data = array();
     if (is_array($wgUserLevels)) {
         // Load points before update
         $stats = new UserStats($this->user_id, $this->user_name);
         $stats_data = $stats->getUserStats();
         $points_before = $stats_data['points'];
         // Load Honorific Level before update
         $user_level = new UserLevel($points_before);
         $level_number_before = $user_level->getLevelNumber();
     }
     $dbw = wfGetDB(DB_MASTER);
     $res = $dbw->select('user_stats', '*', array("stats_user_id = {$this->user_id}"), __METHOD__);
     $row = $dbw->fetchObject($res);
     if ($row) {
         // recaculate point total
         $new_total_points = 1000;
         if ($this->point_values) {
             foreach ($this->point_values as $point_field => $point_value) {
                 if ($this->stats_fields[$point_field]) {
                     $field = $this->stats_fields[$point_field];
                     $new_total_points += $point_value * $row->{$field};
                 }
             }
         }
         if ($wgEnableFacebook) {
             $s = $dbw->selectRow('fb_link_view_opinions', array('fb_user_id', 'fb_user_session_key'), array('fb_user_id_wikia' => $this->user_id), __METHOD__);
             if ($s !== false) {
                 $new_total_points += $this->point_values['facebook'];
             }
         }
         $dbw->update('user_stats', array('stats_total_points' => $new_total_points), array('stats_user_id' => $this->user_id), __METHOD__);
         // If user levels is in settings, check to see if user advanced with update
         if (is_array($wgUserLevels)) {
             // Get New Honorific Level
             $user_level = new UserLevel($new_total_points);
             $level_number_after = $user_level->getLevelNumber();
             // Check if the user advanced to a new level on this update
             if ($level_number_after > $level_number_before) {
                 $m = new UserSystemMessage();
                 $m->addMessage($this->user_name, 2, wfMessage('level-advanced-to', $user_level->getLevelName())->inContentLanguage()->parse());
                 $m->sendAdvancementNotificationEmail($this->user_id, $user_level->getLevelName());
             }
         }
         $this->clearCache();
     }
     return $stats_data;
 }
/**
 * Track new user registrations to the user_register_track database table if
 * $wgRegisterTrack is set to true.
 *
 * @param $user Object: the User object representing the newly-created user
 * @return Boolean: true
 */
function fnRegisterTrack($user)
{
    global $wgRequest, $wgRegisterTrack, $wgMemc;
    if ($wgRegisterTrack) {
        $wgMemc->delete(wfMemcKey('users', 'new', '1'));
        // How the user registered (via email from friend, just on the site etc.)?
        $from = $wgRequest->getInt('from');
        if (!$from) {
            $from = 0;
        }
        // Track if the user clicked on email from friend
        $user_id_referral = 0;
        $user_name_referral = '';
        $referral_user = $wgRequest->getVal('referral');
        if ($referral_user) {
            $user_registering_title = Title::makeTitle(NS_USER, $user->getName());
            $user_title = Title::newFromDBkey($referral_user);
            $user_id_referral = User::idFromName($user_title->getText());
            if ($user_id_referral) {
                $user_name_referral = $user_title->getText();
            }
            $stats = new UserStatsTrack($user_id_referral, $user_title->getText());
            $stats->incStatField('referral_complete');
            if (class_exists('UserSystemMessage')) {
                $m = new UserSystemMessage();
                // Nees to be forContent because addMessage adds this into a
                // database table - we don't want to display Japanese text
                // to English users
                $message = wfMsgForContent('login-reg-recruited', $user_registering_title->getFullURL(), $user->getName());
                $m->addMessage($user_title->getText(), 1, $message);
            }
        }
        // Track registration
        $dbw = wfGetDB(DB_MASTER);
        $dbw->insert('user_register_track', array('ur_user_id' => $user->getID(), 'ur_user_name' => $user->getName(), 'ur_user_id_referral' => $user_id_referral, 'ur_user_name_referral' => $user_name_referral, 'ur_from' => $from, 'ur_date' => date('Y-m-d H:i:s')), __METHOD__);
        $dbw->commit();
        // Just in case...
    }
    return true;
}