/**
  * API clicktracking action
  *
  * Parameters:
  * 		eventid: event name
  * 		token: unique identifier for a user session
  *
  * @see includes/api/ApiBase#execute()
  */
 public function execute()
 {
     global $wgUser, $wgClickTrackContribGranularity1, $wgClickTrackContribGranularity2, $wgClickTrackContribGranularity3;
     $params = $this->extractRequestParams();
     $eventid_to_lookup = $params['eventid'];
     $sessionId = $params['token'];
     $namespace = $params['namespacenumber'];
     $additional = null;
     if (isset($params['additional']) && strlen($params['additional']) > 0) {
         $additional = $params['additional'];
     }
     // FIXME: API should already have urldecode()d
     $eventName = urldecode($eventid_to_lookup);
     $isLoggedIn = $wgUser->isLoggedIn();
     $now = time();
     $granularity1 = $isLoggedIn ? getUserEditCountSince($now - $wgClickTrackContribGranularity1) : 0;
     $granularity2 = $isLoggedIn ? getUserEditCountSince($now - $wgClickTrackContribGranularity2) : 0;
     $granularity3 = $isLoggedIn ? getUserEditCountSince($now - $wgClickTrackContribGranularity3) : 0;
     ClickTrackingHooks::trackEvent($sessionId, $isLoggedIn, (int) $namespace, $eventName, $isLoggedIn ? $wgUser->getEditCount() : 0, $granularity1, $granularity2, $granularity3, $additional);
     // For links that go off the page, redirect the user
     // FIXME: The API should have a proper infrastructure for this
     if (!is_null($params['redirectto'])) {
         $href = $params['redirectto'];
         global $wgOut;
         $wgOut->redirect($params['redirectto']);
         $wgOut->output();
         // Prevent any further output
         $wgOut->disable();
         $this->getMain()->getPrinter()->disable();
     }
 }
Пример #2
0
 public function execute()
 {
     $params = $this->extractRequestParams();
     $result = $this->getResult();
     $userName = $params['user'];
     $daysago = $params['daysago'];
     $basetimestamp = $params['basetimestamp'];
     $user = User::newFromName($userName);
     if (!$user) {
         $this->dieUsage('Invalid username', 'bad_user');
     }
     global $wgAuth, $wgUserDailyContributionsApiCheckAuthPlugin;
     if ($wgUserDailyContributionsApiCheckAuthPlugin && !$wgAuth->userExists($userName)) {
         $this->dieUsage('Specified user does not exist', 'bad_user');
     }
     // Defaults to 'now' if not given
     $totime = wfTimestamp(TS_UNIX, $basetimestamp);
     $fromtime = $totime - $daysago * 60 * 60 * 24;
     $result->addValue($this->getModuleName(), 'id', $user->getId());
     // Returns date of registration in YYYYMMDDHHMMSS format
     $result->addValue($this->getModuleName(), 'registration', $user->getRegistration() ? $user->getRegistration() : '0');
     // Returns number of edits between daysago date and basetimestamp (or today)
     $result->addValue($this->getModuleName(), 'timeFrameEdits', getUserEditCountSince($fromtime, $user, $totime));
     // Returns total number of edits
     $result->addValue($this->getModuleName(), 'totalEdits', $user->getEditCount() == NULL ? 0 : $user->getEditCount());
 }
 /**
  * Inserts or updates properties for a specific rating
  * @param $revisionId int Revision ID
  * @param $user User object
  * @param $token string Anon token or empty string
  * @param $params array Request parameters
  */
 private function insertProperties($revisionId, $user, $token, $params)
 {
     // Expertise is given as a list of one or more tags, such as profession, hobby, etc.
     $this->insertProperty($revisionId, $user, $token, 'expertise', $params['expertise']);
     // Capture edit counts as of right now for the past 1, 3 and 6 months as well as all time
     // - These time distances match the default configuration for the ClickTracking extension
     if ($user->isLoggedIn()) {
         $this->insertProperty($revisionId, $user, $token, 'contribs-lifetime', (int) $user->getEditCount());
         // Take advantage of the UserDailyContribs extension if it's present
         if (function_exists('getUserEditCountSince')) {
             $now = time();
             $this->insertProperty($revisionId, $user, $token, 'contribs-6-months', getUserEditCountSince($now - 60 * 60 * 24 * 365 / 2));
             $this->insertProperty($revisionId, $user, $token, 'contribs-3-months', getUserEditCountSince($now - 60 * 60 * 24 * 365 / 4));
             $this->insertProperty($revisionId, $user, $token, 'contribs-1-month', getUserEditCountSince($now - 60 * 60 * 24 * 30));
         }
     }
 }
/**
 * MakeGlobalVariablesScript hook handler
 * This function sets all the psuedo-global Javascript variables that are used by CentralNotice
 * @param $vars array
 * @return bool
 */
function efCentralNoticeDefaults(&$vars)
{
    // Using global $wgUser for compatibility with 1.18
    global $wgNoticeProject, $wgUser, $wgMemc;
    // Initialize global Javascript variables. We initialize Geo with empty values so if the geo
    // IP lookup fails we don't have any surprises.
    $geo = array('city' => '', 'country' => '');
    $vars['Geo'] = $geo;
    // change this to wgGeo if Ops updates the variable name on their end
    $vars['wgNoticeProject'] = $wgNoticeProject;
    // Output the user's registration date, total edit count, and past year's edit count.
    // This is useful for banners that need to be targeted to specific types of users.
    // Only do this for logged-in users, keeping anonymous user output equal (for Squid-cache).
    if ($wgUser->isLoggedIn()) {
        $cacheKey = wfMemcKey('CentralNotice', 'UserData', $wgUser->getId());
        $userData = $wgMemc->get($cacheKey);
        // Cached?
        if (!$userData) {
            // Exclude bots
            if ($wgUser->isAllowed('bot')) {
                $userData = false;
            } else {
                $userData = array();
                // Add the user's registration date (MediaWiki timestamp)
                $registrationDate = $wgUser->getRegistration() ? $wgUser->getRegistration() : 0;
                $userData['registration'] = $registrationDate;
                // Make sure UserDailyContribs extension is installed.
                if (function_exists('getUserEditCountSince')) {
                    // Add the user's total edit count
                    if ($wgUser->getEditCount() == null) {
                        $userData['editcount'] = 0;
                    } else {
                        $userData['editcount'] = intval($wgUser->getEditCount());
                    }
                    // Add the user's edit count for the past year
                    $userData['pastyearseditcount'] = getUserEditCountSince(time() - 365 * 24 * 3600, $wgUser, time());
                }
            }
            // Cache the data for 7 days
            $wgMemc->set($cacheKey, $userData, strtotime('+7 days'));
        }
        // Set the variable that will be output to the page
        $vars['wgNoticeUserData'] = $userData;
    }
    return true;
}
 /**
  * Inserts or updates properties for a specific rating
  * @param $revisionId int    Revision ID
  */
 private function saveUserProperties($feedbackId)
 {
     global $wgUser;
     $dbw = wfGetDB(DB_MASTER);
     $dbr = wfGetDB(DB_SLAVE);
     $rows = array();
     // Only save data for logged-in users.
     if (!$wgUser->isLoggedIn()) {
         return null;
     }
     // Total edits by this user
     $rows[] = array('afp_feedback_id' => $feedbackId, 'afp_key' => 'contribs-lifetime', 'afp_value_int' => (int) $wgUser->getEditCount());
     // Use the UserDailyContribs extension if it's present. Get
     // edit counts for last 6 months, last 3 months, and last month.
     if (function_exists('getUserEditCountSince')) {
         $now = time();
         $rows[] = array('afp_feedback_id' => $feedbackId, 'afp_key' => 'contribs-6-months', 'afp_value_int' => getUserEditCountSince($now - 60 * 60 * 24 * 365 / 2));
         $rows[] = array('afp_feedback_id' => $feedbackId, 'afp_key' => 'contribs-3-months', 'afp_value_int' => getUserEditCountSince($now - 60 * 60 * 24 * 365 / 4));
         $rows[] = array('afp_feedback_id' => $feedbackId, 'afp_key' => 'contribs-1-months', 'afp_value_int' => getUserEditCountSince($now - 60 * 60 * 24 * 30));
     }
     $dbw->insert('aft_article_feedback_properties', $rows, __METHOD__);
 }