/** * 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(); } }
/** * runs when the API is called with "clicktracking", takes in "eventid" and an edit token given to the user, "token" * @see includes/api/ApiBase#execute() */ public function execute() { global $wgUser, $wgTitle, $wgClickTrackContribGranularity1, $wgClickTrackContribGranularity2, $wgClickTrackContribGranularity3; $params = $this->extractRequestParams(); $this->validateParams($params); $eventid_to_lookup = $params['eventid']; $session_id = $params['token']; // Event ID lookup table // FIXME: API should already have urldecode()d $event_id = ClickTrackingHooks::getEventIDFromName(urldecode($eventid_to_lookup)); $is_logged_in = $wgUser->isLoggedIn(); $now = time(); $granularity1 = $is_logged_in ? ClickTrackingHooks::getEditCountSince($now - $wgClickTrackContribGranularity1) : 0; $granularity2 = $is_logged_in ? ClickTrackingHooks::getEditCountSince($now - $wgClickTrackContribGranularity2) : 0; $granularity3 = $is_logged_in ? ClickTrackingHooks::getEditCountSince($now - $wgClickTrackContribGranularity3) : 0; ClickTrackingHooks::trackEvent($session_id, $is_logged_in, $wgTitle->getNamespace(), $event_id, $is_logged_in ? $wgUser->getEditCount() : 0, $granularity1, $granularity2, $granularity3); // 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'])) { global $wgOut; $wgOut->enable(); $wgOut->redirect($params['redirectto']); $wgOut->output(); } }