function execute()
 {
     wfProfileIn(__METHOD__);
     global $wgOut, $wgRequest;
     if (wfReadOnly()) {
         $wgOut->readOnlyPage();
         wfProfileOut(__METHOD__);
         return;
     }
     $articleID = $wgRequest->getInt('articleid');
     $title = Title::newFromID($articleID);
     if (!is_null($title) && $title->exists()) {
         if (strpos($_SERVER['HTTP_USER_AGENT'], 'facebook') === false && strpos($_SERVER['HTTP_USER_AGENT'], 'bitlybot') === false) {
             $sharerID = $wgRequest->getInt('userid');
             $viewerIP = $wgRequest->getIP();
             $awardingService = new AchAwardingService();
             $awardingService->processSharing($articleID, $sharerID, $viewerIP);
         }
     } else {
         $title = Title::newMainPage();
     }
     // this works only for Wikia and only in current varnish configuration
     if (!headers_sent()) {
         header('X-Pass-Cache-Control: no-store, private, no-cache, must-revalidate');
     }
     $wgOut->redirect($title->getLocalURL());
     wfProfileOut(__METHOD__);
 }
 public function hasPersonalAnnotations()
 {
     if (!isset($this->hasPersonalAnnotations)) {
         $this->hasPersonalAnnotations = !$this->viewerUser->isAnon() && $this->viewerUser->getId() == $this->ownerUser->getId() && AchAwardingService::canEarnBadges($this->viewerUser) && !$this->viewerUser->getGlobalPreference('hidepersonalachievements');
     }
     return $this->hasPersonalAnnotations;
 }
 public static function achievements($cv_name, $city_id, $value)
 {
     wfProfileIn(__METHOD__);
     if ($cv_name == 'wgEnableAchievementsExt' && $value == true) {
         $wiki = WikiFactory::getWikiById($city_id);
         // Force WikiFactory::getWikiById() to query DB_MASTER if needed.
         if (!is_object($wiki)) {
             $wiki = WikiFactory::getWikiById($city_id, true);
         }
         $user = User::newFromId($wiki->city_founding_user);
         $user->load();
         $achService = new AchAwardingService($city_id);
         $achService->awardCustomNotInTrackBadge($user, BADGE_CREATOR);
     }
     wfProfileOut(__METHOD__);
     return true;
 }
 public function getHTML()
 {
     wfProfileIn(__METHOD__);
     global $wgTitle, $wgUser;
     //fix #10881, get correct username from user namespace subpages
     $this->mUserOwner = F::build('User', array(UserPagesHeaderController::getUserName($wgTitle, BodyController::getUserPagesNamespaces())), 'newFromName');
     if (in_array(strtolower(RequestContext::getMain()->getSkin()->getSkinName()), array('oasis')) && $this->mUserOwner && AchAwardingService::canEarnBadges($this->mUserOwner) && $this->mUserOwner->isLoggedIn() && !($wgUser->getId() == $this->mUserOwner->getId() && $wgUser->getOption('hidepersonalachievements'))) {
         $this->mUserViewer = $wgUser;
         if ($this->mUserViewer->isLoggedIn() && $this->mUserViewer->getId() != $this->mUserOwner->getId()) {
             $this->loadViewerBadges();
             $this->loadViewerCounters();
         }
         $this->loadOwnerBadges();
         $this->loadOwnerCounters();
         $this->prepareChallenges();
         $tmplData = array();
         $tmplData['ownerBadges'] = $this->mOwnerBadgesSimple;
         $tmplData['challengesBadges'] = $this->mChallengesBadges;
         $tmplData['title_no'] = wfMsg('achievements-profile-title-no', $this->mUserOwner->getName());
         $tmplData['title'] = wfMsgExt('achievements-profile-title', array('parsemag'), $this->mUserOwner->getName(), count($this->mOwnerBadgesSimple));
         $tmplData['title_challenges'] = wfMsg('achievements-profile-title-challenges', $this->mUserOwner->getName());
         $tmplData['leaderboard_url'] = Skin::makeSpecialUrl("Leaderboard");
         if (count($this->mOwnerBadgesExtended) > 0) {
             $rankingService = new AchRankingService();
             $tmplData['user_rank'] = $rankingService->getUserRankingPosition($this->mUserOwner);
         }
         if ($this->mUserViewer->isAllowed('editinterface')) {
             $tmplData['customize_url'] = Skin::makeSpecialUrl("AchievementsCustomize");
         }
         $template = new EasyTemplate(dirname(__FILE__) . '/../templates');
         $template->set_vars($tmplData);
         $out = $template->render('ProfileBox');
     } else {
         $out = '';
     }
     wfProfileOut(__METHOD__);
     return $out;
 }
    exit(0);
}
require_once "{$IP}/extensions/wikia/AchievementsII/Ach_setup.php";
echo "Loading list of users to process";
$dbw = WikiFactory::db(DB_MASTER);
$users = $dbw->select('ach_user_badges', array("DISTINCT user_id", 'wiki_id'), array('badge_type_id' => BADGE_LUCKYEDIT));
$usersCount = $users->numRows();
echo ": {$usersCount} user(s) to process\n\n";
if ($usersCount) {
    while ($currentUser = $dbw->fetchObject($users)) {
        echo "- Processing user {$currentUser->user_id} on wiki {$currentUser->wiki_id}: ";
        $badges = $dbw->selectField('ach_user_badges', array('COUNT(*) as cnt'), array('wiki_id' => $currentUser->wiki_id, 'user_id' => $currentUser->user_id, 'badge_type_id' => BADGE_LUCKYEDIT));
        if ($badges > 1) {
            $score = $dbw->selectField('ach_user_score', array('score'), array('wiki_id' => $currentUser->wiki_id, 'user_id' => $currentUser->user_id));
            echo "lucky edits {$badges}, original score {$score}";
            $wgCityId = $currentUser->wiki_id;
            $srvc = new AchAwardingService();
            $srvc->migration($currentUser->user_id);
            sleep(3);
            $score = $dbw->selectField('ach_user_score', array('score'), array('wiki_id' => $currentUser->wiki_id, 'user_id' => $currentUser->user_id));
            echo ", new score {$score}.\n";
        } else {
            echo "this user has only {$badges} lucky edits, skipping.\n";
        }
    }
    echo "\nDone\n";
} else {
    echo "Nothing to do\n";
}
$dbw->freeResult($users);
echo "\n";
예제 #6
0
<?php

/*
 * written to retroactively award founders with BADGE_CREATOR
 *
 * @author tor
 */
include '/usr/wikia/source/trunk/maintenance/commandLine.inc';
if (class_exists(AchAwardingService)) {
    $wiki = WikiFactory::getWikiByDB($wgDBname);
    if (empty($wiki)) {
        exit;
    }
    $founderId = $wiki->city_founding_user;
    if (empty($founderId)) {
        exit;
    }
    $founder = User::newFromId($founderId);
    $founder->load();
    // get achievement to chek if it's there already
    $achService = new AchAwardingService();
    $achService->awardCustomNotInTrackBadge($founder, BADGE_CREATOR);
}
예제 #7
0
function Ach_GetHTMLAfterBody($skin, &$html)
{
    wfProfileIn(__METHOD__);
    global $wgOut, $wgTitle, $wgUser;
    if ($wgUser->isLoggedIn() && !$wgUser->getOption('hidepersonalachievements')) {
        if ($wgTitle->getNamespace() == NS_SPECIAL && array_shift(SpecialPageFactory::resolveAlias($wgTitle->getDBkey())) == 'MyHome') {
            $awardingService = new AchAwardingService();
            $awardingService->awardCustomNotInTrackBadge($wgUser, BADGE_WELCOME);
        }
        if ((!empty($_SESSION['achievementsNewBadges']) || 5 == rand(1, 20)) && get_class(RequestContext::getMain()->getSkin()) != 'SkinMonobook') {
            // this works only for Wikia and only in current varnish configuration
            if (!headers_sent()) {
                header('X-Pass-Cache-Control: no-store, private, no-cache, must-revalidate');
            }
            $notificationService = new AchNotificationService();
            $wgOut->addHTML($notificationService->getNotifcationHTML($wgUser));
            if (isset($_SESSION['achievementsNewBadges'])) {
                unset($_SESSION['achievementsNewBadges']);
            }
        }
    }
    wfProfileOut(__METHOD__);
    return true;
}
if ($usersCount) {
    echo "Removing the badges\n\n";
    $dbw->delete('ach_user_badges', $queryBadgeFilters);
    echo "Recalculating user score and counters:\n\n";
    while ($currentUser = $dbw->fetchObject($usersList)) {
        echo "\t* Processing user {$currentUser->user_id}\n";
        $userCounters = $dbw->select('ach_user_counters', array('data'), array('user_id' => $currentUser->user_id));
        if ($row = $dbw->fetchObject($userCounters)) {
            $counters = unserialize($row->data);
            foreach ($counters as $wikiId => $data) {
                $data[BADGE_BLOGPOST] = 1;
                $wgCityId = $wikiId;
                echo "\t\t- Recalculating user counters for Wiki ID {$wikiId}\n";
                $userCountersService = new AchUserCountersService($currentUser->user_id);
                $userCountersService->setCounters($data);
                $userCountersService->save();
                echo "\t\t- Recalculating user score for Wiki ID {$wikiId}\n\n";
                $awardingService = new AchAwardingService();
                $awardingService->migration($currentUser->user_id);
            }
        } else {
            echo '\\t\\tError, this user has no counters!';
        }
    }
    $dbw->commit();
    echo "\nDone\n";
} else {
    echo "Nothing to do\n";
}
$dbw->freeResult($usersList);
echo "\n";
예제 #9
0
 /**
  * Returns the list of recently awarded badges for the current wiki and specified level
  *
  * @param $badgeLevel - the level of the badges to list
  * @param $limit - limit the list to the specified amount of items Integer
  * @param $daySpan - a span of days to subtract to the current date Integer
  * @param $blackList - a list of the badge type IDs to exclude from the result Array
  * @return Array
  */
 public function getRecentAwardedBadges($badgeLevel = null, $limit = null, $daySpan = null, $blackList = null)
 {
     wfProfileIn(__METHOD__);
     $badges = array();
     $conds = array();
     $dbr = wfGetDB(DB_SLAVE);
     $rules = array('ORDER BY' => 'date DESC, badge_lap DESC');
     if ($badgeLevel != null) {
         $conds['badge_level'] = $badgeLevel;
     }
     if ($daySpan != null) {
         $conds[] = "date >= (CURDATE() - INTERVAL {$daySpan} DAY)";
     }
     if (is_array($blackList)) {
         $conds[] = 'badge_type_id NOT IN (' . implode($blackList) . ')';
     }
     if ($limit != null) {
         $rules['LIMIT'] = $limit * 2;
     }
     //bots and blocked users are filtered after the query hs been run, let's admit that ratio is 2:1
     $res = $dbr->select('ach_user_badges', 'user_id, badge_type_id, badge_lap, badge_level, date', $conds, __METHOD__, $rules);
     while (($row = $dbr->fetchObject($res)) && count($badges) <= $limit) {
         $user = User::newFromId($row->user_id);
         if ($user && AchAwardingService::canEarnBadges($user)) {
             $badges[] = array('user' => $user, 'badge' => new AchBadge($row->badge_type_id, $row->badge_lap, $row->badge_level), 'date' => $row->date);
         }
     }
     $dbr->freeResult($res);
     wfProfileOut(__METHOD__);
     return $badges;
 }
$dbw = wfGetDB(DB_MASTER, array(), $wgExternalSharedDB);
$dbw->insert('ach_user_badges', $badgesToInsert);
sleep(1);
/*
 * CONUTERS
 */
$dbr = wfGetDB(DB_MASTER);
$res = $dbr->query("select * from achievements_counters");
while ($row = $dbr->fetchObject($res)) {
    $counter = array();
    $counter['user_id'] = $row->user_id;
    $counter['data'] = array();
    $data = unserialize($row->data);
    foreach ($data as $counter_key => $counter_value) {
        if ($counter_key == 6) {
            $counter_value_new = array(1 => $counter_value['counter'], 2 => $counter_value['date']);
        } else {
            if ($counter_key == 13) {
                $counter_value_new = array(1 => $counter_value['counter'], 2 => $counter_value['date']);
            } else {
                $counter_value_new = $counter_value;
            }
        }
        $counter['data'][-1 * $counter_key] = $counter_value_new;
    }
    $userCountersService = new AchUserCountersService($counter['user_id']);
    $userCountersService->setCounters($counter['data']);
    $userCountersService->save();
    $awardingService = new AchAwardingService();
    $awardingService->migration($counter['user_id']);
}
$rows = $dbw->select('ach_user_badges', array("user_id", 'wiki_id', 'badge_type_id', 'badge_lap', 'badge_level', 'min(date) as first', 'count(badge_type_id) as dupes'), array(), __METHOD__, array("GROUP BY" => "wiki_id, user_id,badge_type_id, badge_lap, badge_level having dupes > 1"));
$rowCount = $rows->numRows();
print_pre($dbw);
echo ": {$rowCount} duplicate badges to process\n\n";
if ($rowCount) {
    while ($dupe = $dbw->fetchObject($rows)) {
        echo "- Processing dupe for user {$dupe->user_id} on wiki {$dupe->wiki_id}\n";
        // Delete all but the first duplicate badge
        $criteria = array();
        $criteria['user_id'] = $dupe->user_id;
        $criteria['wiki_id'] = $dupe->wiki_id;
        $criteria['badge_type_id'] = $dupe->badge_type_id;
        $criteria['badge_lap'] = $dupe->badge_lap;
        $criteria['badge_level'] = $dupe->badge_level;
        $criteria[] = "date > '{$dupe->first}'";
        $dbw->delete('ach_user_badges', $criteria);
        $dbw->commit();
        // wait for slave lag
        sleep(1);
        // set the global wgCityId so AchAwardingService does the right thing
        $wgCityId = $dupe->wiki_id;
        $srvc = new AchAwardingService();
        // recalculate score
        $srvc->migration($dupe->user_id);
    }
    echo "\nDone\n";
} else {
    echo "Nothing to do\n";
}
$dbw->freeResult($rows);
echo ": {$rowCount} duplicate badges deleted.\n\n";
예제 #12
0
 public static function editPlatinumBadge()
 {
     global $wgCityId, $wgRequest, $wgSitename, $wgServer, $wgScriptPath, $wgExternalSharedDB;
     $badge_type_id = $wgRequest->getVal('type_id');
     $ret = array('errors' => null, 'typeId' => $badge_type_id);
     $isSponsored = $wgRequest->getBool('is_sponsored');
     $usernamesToAward = $wgRequest->getArray('award_user');
     $usersToAward = array();
     if (is_array($usernamesToAward)) {
         //Webklit browsers don't send an empty array of inputs in a POST request
         foreach ($usernamesToAward as $usernameToAward) {
             if ($usernameToAward != '') {
                 $user = User::newFromName($usernameToAward);
                 if ($user && $user->isLoggedIn()) {
                     $usersToAward[] = $user;
                 } else {
                     // FIXME: needs i18n.
                     $ret['errors'][] = "User '{$usernameToAward}' does not exist";
                 }
             }
         }
     }
     // upload an image
     if ($ret['errors'] == null && $wgRequest->getFileName('wpUploadFile')) {
         ob_start();
         $badgeImage = AchImageUploadService::uploadBadge(AchConfig::getInstance()->getBadgePictureName($badge_type_id), AchConfig::getInstance()->getLevelMsgKeyPart(BADGE_LEVEL_PLATINUM));
         ob_end_clean();
         if (!$badgeImage) {
             $ret['errors'][] = wfMsg('achievements-upload-error');
         }
     }
     //upload Sponsored achievement hover content
     if ($isSponsored && $wgRequest->getFileName('hover_content')) {
         $hoverImage = AchImageUploadService::uploadHover(AchConfig::getInstance()->getHoverPictureName($badge_type_id));
         if (!$hoverImage) {
             $ret['errors'][] = wfMsg('achievements-upload-error');
         }
     }
     // update a badge
     if ($ret['errors'] == null) {
         global $wgEnableAchievementsStoreLocalData;
         $where = array('id' => $badge_type_id);
         if (empty($wgEnableAchievementsStoreLocalData)) {
             $dbw = wfGetDB(DB_MASTER, array(), $wgExternalSharedDB);
             $where['wiki_id'] = $wgCityId;
         } else {
             $dbw = wfGetDB(DB_MASTER);
         }
         $dbw->update('ach_custom_badges', array('enabled' => $wgRequest->getBool('status'), 'sponsored' => $isSponsored, 'badge_tracking_url' => $wgRequest->getText('badge_impression_pixel_url'), 'hover_tracking_url' => $wgRequest->getText('hover_impression_pixel_url'), 'click_tracking_url' => $wgRequest->getText('badge_redirect_url')), $where);
         // edit/create MW articles
         $badgeNameKey = AchConfig::getInstance()->getBadgeNameKey($badge_type_id);
         $messagesToEdit = array();
         $messagesToEdit[$badgeNameKey] = 'badge_name';
         $messagesToEdit[AchConfig::getInstance()->getBadgeToGetKey($badge_type_id)] = 'how_to';
         $messagesToEdit[AchConfig::getInstance()->getBadgeDescKey($badge_type_id)] = 'awarded_for';
         foreach ($messagesToEdit as $messageKey => $valueKey) {
             $value = $wgRequest->getVal($valueKey);
             if ($value && wfMsgForContent($messageKey) != $value) {
                 $article = new Article(Title::newFromText($messageKey, NS_MEDIAWIKI));
                 $article->doEdit($value, '');
             }
         }
         // award users
         if (count($usersToAward) > 0) {
             foreach ($usersToAward as $userToAward) {
                 $awardingService = new AchAwardingService();
                 $awardingService->awardCustomNotInTrackBadge($userToAward, $badge_type_id);
                 if ($userToAward->getEmail() != null && !$userToAward->getOption('hidepersonalachievements')) {
                     $bodyParams = array(htmlspecialchars($userToAward->getName()), wfMsgHtml($badgeNameKey), "{$wgServer}{$wgScriptPath}", htmlspecialchars($wgSitename), $userToAward->getUserPage()->getFullURL());
                     $userToAward->sendMail(wfMsg('achievements-community-platinum-awarded-email-subject'), wfMsg('achievements-community-platinum-awarded-email-body-text', $bodyParams), null, null, 'CommunityPlatinumBadgesAwardNotification', wfMsg('achievements-community-platinum-awarded-email-body-html', $bodyParams));
                 }
             }
         }
         $dbw->commit();
         if (empty($badgeImage)) {
             $badgeImage = wfFindFile(AchConfig::getInstance()->getBadgePictureName($badge_type_id));
         }
         if (empty($hoverImage)) {
             $hoverImage = wfFindFile(AchConfig::getInstance()->getHoverPictureName($badge_type_id));
         }
         // render form
         $badge = array();
         $badge['type_id'] = $badge_type_id;
         $badge['enabled'] = $wgRequest->getBool('status');
         $badge['thumb_url'] = $badgeImage->createThumb(90) . "?cb=" . rand();
         $badge['awarded_users'] = AchPlatinumService::getAwardedUserNames($badge_type_id, true);
         $badge['is_sponsored'] = $isSponsored;
         $badge['badge_tracking_url'] = $wgRequest->getText('badge_impression_pixel_url');
         $badge['hover_tracking_url'] = $wgRequest->getText('hover_impression_pixel_url');
         $badge['click_tracking_url'] = $wgRequest->getText('badge_redirect_url');
         $badge['hover_content_url'] = is_object($hoverImage) ? wfReplaceImageServer($hoverImage->getFullUrl()) . "?cb=" . rand() : null;
         $ret['output'] = AchPlatinumService::getPlatinumForm($badge);
     }
     return '<script type="text/javascript">window.document.responseContent = ' . json_encode($ret) . ';</script>';
 }
예제 #13
0
 public function processSaveComplete($article, $user, $revision, $status)
 {
     wfProfileIn(__METHOD__);
     $this->mUser = $user;
     if (self::canEarnBadges($this->mUser)) {
         $this->mArticle = $article;
         $this->mRevision = $revision;
         if ($this->mArticle) {
             // logic should be processed only one time during one request
             if (!self::$mDone) {
                 $this->mStatus = $status;
                 $this->mTitle = $this->mArticle->getTitle();
                 $this->mUserCountersService = new AchUserCountersService($this->mUser->getID());
                 $this->mCounters = $this->mUserCountersService->getCounters();
                 $this->loadUserBadges();
                 $this->processAllNotInTrack();
                 $this->processAllInTrack();
                 $this->mUserCountersService->setCounters($this->mCounters);
                 $this->mUserCountersService->save();
                 $this->processCountersForInTrack();
                 $this->saveBadges();
                 if (count($this->mNewBadges) > 0) {
                     $this->calculateAndSaveScore();
                 }
                 self::$mDone = true;
             }
         }
     }
     wfProfileOut(__METHOD__);
 }