Esempio n. 1
0
function WidgetFounderBadge($id, $params)
{
    $output = "";
    wfProfileIn(__METHOD__);
    global $wgMemc;
    $key = wfMemcKey("WidgetFounderBadge", "user");
    $user = $wgMemc->get($key);
    if (is_null($user)) {
        global $wgCityId;
        $user = WikiFactory::getWikiById($wgCityId)->city_founding_user;
        $wgMemc->set($key, $user, 3600);
    }
    if (0 == $user) {
        return wfMsgForContent("widget-founderbadge-notavailable");
    }
    $key = wfMemcKey("WidgetFounderBadge", "edits");
    $edits = $wgMemc->get($key);
    if (empty($edits)) {
        $edits = AttributionCache::getInstance()->getUserEditPoints($user);
        $wgMemc->set($key, $edits, 300);
    }
    $author = array("user_id" => $user, "user_name" => User::newFromId($user)->getName(), "edits" => $edits);
    $output = Answer::getUserBadge($author);
    wfProfileOut(__METHOD__);
    return $output;
}
Esempio n. 2
0
/**
 * @author Maciej Błaszkowski <marooned at wikia-inc.com>
 */
function wfAnswersGetEditPointsAjax()
{
    global $wgRequest, $wgSquidMaxage;
    $userId = intval($wgRequest->getVal('userId'));
    $points = AttributionCache::getInstance()->getUserEditPoints($userId);
    $timestamp = AttributionCache::getInstance()->getUserLastModifiedFromCache($userId);
    $timestamp = !empty($timestamp) ? $timestamp : wfTimestampNow();
    $data = array('points' => $points, 'timestamp' => wfTimestampNow());
    $json = json_encode($data);
    $response = new AjaxResponse($json);
    $response->setContentType('application/json; charset=utf-8');
    $response->checkLastModified(strtotime($timestamp));
    $response->setCacheDuration($wgSquidMaxage);
    return $response;
}
Esempio n. 3
0
 public static function getUserEditPoints($user_id)
 {
     return AttributionCache::getInstance()->getUserEditPoints($user_id);
 }
Esempio n. 4
0
 public static function getUserStatsData($userName, $useMasterDb = false)
 {
     global $wgLang, $wgCityId, $wgExternalDatawareDB;
     $result = array('editCount' => 0, 'firstDate' => 0);
     $destionationUser = User::newFromName($userName);
     $destionationUserId = $destionationUser ? $destionationUser->getId() : 0;
     if ($destionationUserId != 0) {
         global $wgMemc, $wgEnableAnswers;
         if (!empty($wgEnableAnswers) && class_exists('AttributionCache')) {
             // use AttributionCache to get edit points and first edit date
             $attrCache = AttributionCache::getInstance();
             $editCount = $attrCache->getUserEditPoints($destionationUserId);
             $firstDate = $wgLang->date(wfTimestamp(TS_MW, $attrCache->getUserFirstEditDateFromCache($destionationUserId)));
         } else {
             $mastheadDataEditDateKey = wfMemcKey('mmastheadData-editDate-' . $destionationUserId);
             $mastheadDataEditCountKey = wfMemcKey('mmastheadData-editCount-' . $destionationUserId);
             $mastheadDataEditDate = $wgMemc->get($mastheadDataEditDateKey);
             $mastheadDataEditCount = $wgMemc->get($mastheadDataEditCountKey);
             if (empty($mastheadDataEditCount) || empty($mastheadDataEditDate)) {
                 $dbr = wfGetDB($useMasterDb ? DB_MASTER : DB_SLAVE);
                 $dbResult = $dbr->select('revision', array('min(rev_timestamp) AS date, count(*) AS edits'), array('rev_user_text' => $destionationUser->getName()), __METHOD__);
                 if ($row = $dbr->FetchObject($dbResult)) {
                     $firstDate = $wgLang->date(wfTimestamp(TS_MW, $row->date));
                     $editCount = $row->edits;
                 }
                 if ($dbResult !== false) {
                     $dbr->FreeResult($dbResult);
                 }
                 $wgMemc->set($mastheadDataEditDateKey, $firstDate, 60 * 60);
                 $wgMemc->set($mastheadDataEditCountKey, $editCount, 60 * 60);
             } else {
                 $firstDate = $mastheadDataEditDate;
                 $editCount = $mastheadDataEditCount;
             }
         }
         $result['editCount'] = $editCount;
         $result['firstDate'] = $firstDate;
     }
     return $result;
 }
 /**
  * hook: TitleMoveComplete
  */
 public static function purgeArticleContribsAfterMove($oldTitle, $newTitle, $user)
 {
     AttributionCache::getInstance()->purge($oldTitle, $user);
     //AttributionCache::getInstance()->purge($newTitle, $user);
     return true;
 }