private function getBadgesData() {
		global $wgContLang;

		// get achievement lists
		$rankingService = new AchRankingService();
		$userProfileService = new AchUserProfileService();
		$userProfileService->getHTML();   // have to call this because it creates our data as a side effect

		$this->ownerName = $userProfileService->mUserOwner->getName();
		$this->ownerBadges = $userProfileService->mOwnerBadgesSimple;
		$this->ownerCounters = $userProfileService->mOwnerCounters;

		$this->ownerRank = $rankingService->getUserRankingPosition($userProfileService->mUserOwner);
		$this->ownerScore = $wgContLang->formatNum($rankingService->getUserScore($userProfileService->mUserOwner->getId()));

		if($userProfileService->mUserViewer && $userProfileService->mUserViewer->isLoggedIn() && $userProfileService->mUserViewer->getId() == $userProfileService->mUserOwner->getId()) {
			$this->viewer_is_owner = true;
			$challengesBadges = $userProfileService->mChallengesBadges;

			// Let's prune the challengesBadges list to the correct length before passing it to the template
			if ($this->max_challenges != "all") {
				while (count($challengesBadges) > $this->max_challenges) array_pop($challengesBadges);
			}
			$this->challengesBadges = $challengesBadges;
		}

		// UI elements
		$this->leaderboard_url = Skin::makeSpecialUrl("Leaderboard");


		if($userProfileService->mUserViewer && $userProfileService->mUserViewer->isAllowed('editinterface')) {
			$this->customize_url = Skin::makeSpecialUrl("AchievementsCustomize");
		}
	}
 public function getHTML()
 {
     wfProfileIn(__METHOD__);
     if ($this->isVisible()) {
         $ownerName = $this->ownerUser->getName();
         $tmplData = array();
         $tmplData['ownerBadges'] = $this->getBadgesAnnotated();
         $tmplData['challengesBadges'] = $this->getChallengesAnnotated();
         $tmplData['title_no'] = wfMsg('achievements-profile-title-no', $ownerName);
         $tmplData['title'] = wfMsgExt('achievements-profile-title', array('parsemag'), $ownerName, $this->owner->getBadgesCount());
         $tmplData['title_challenges'] = wfMsg('achievements-profile-title-challenges', $ownerName);
         $tmplData['leaderboard_url'] = Skin::makeSpecialUrl("Leaderboard");
         if ($this->owner->getBadgesCount() > 0) {
             $rankingService = new AchRankingService();
             $tmplData['user_rank'] = $rankingService->getUserRankingPosition($this->ownerUser);
         }
         if ($this->viewerUser->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;
 }
 public function executeIndex()
 {
     $maxBadgesToDisplay = 6;
     // Could make this a global if we want
     wfProfileIn(__METHOD__);
     // include oasis.css override
     $this->wg->Out->addStyle(AssetsManager::getInstance()->getSassCommonURL('extensions/wikia/AchievementsII/css/oasis.scss'));
     // This code was taken from SpecialLeaderboard so it can be used by both the module and the old Monaco .tmpl
     $rankingService = new AchRankingService();
     // ignore welcome badges
     $blackList = array(BADGE_WELCOME);
     $awardedBadges = $rankingService->getRecentAwardedBadges(null, $maxBadgesToDisplay, 3, $blackList);
     $recents = array();
     $count = 1;
     // getRecentAwardedBadges can sometimes return more than $max items
     foreach ($awardedBadges as $badgeData) {
         //$level = $badgeData['badge']->getLevel();
         $recents[] = $badgeData;
         if ($count++ >= $maxBadgesToDisplay) {
             break;
         }
     }
     $this->recents = $recents;
     wfProfileOut(__METHOD__);
 }
Ejemplo n.º 4
0
function OnAchievementsInvalidateCache(User $user)
{
    wfProfileIn(__METHOD__);
    global $wgMemc;
    //used in ParterFeed:FeedAchivementsLeaderboard()
    $rankingCacheKey = AchRankingService::getRankingCacheKey(20);
    $wgMemc->delete($rankingCacheKey);
    wfProfileOut(__METHOD__);
    return true;
}
 function execute($user_id)
 {
     wfProfileIn(__METHOD__);
     global $wgOut, $wgExtensionsPath, $wgStylePath, $wgSupressPageSubtitle, $wgUser, $wgResourceBasePath, $wgJsMimeType;
     $wgSupressPageSubtitle = true;
     $rankingService = new AchRankingService();
     $this->setHeaders();
     $wgOut->setPageTitle(wfMsg('achievements-title'));
     $skinName = get_class($this->getSkin());
     if ($skinName == 'SkinOasis') {
         $assetsManager = F::build('AssetsManager', array(), 'getInstance');
         $scssPackage = 'special_leaderboard_oasis_css';
         $jsPackage = 'special_leaderboard_oasis_js';
         foreach ($assetsManager->getURL($scssPackage) as $url) {
             $wgOut->addStyle($url);
         }
         foreach ($assetsManager->getURL($jsPackage) as $url) {
             $wgOut->addScript("<script src=\"{$url}\"></script>");
         }
     } else {
         // FIXME: use AM group here
         $wgOut->addStyle("common/article_sidebar.css");
         $wgOut->addExtensionStyle("{$wgExtensionsPath}/wikia/AchievementsII/css/achievements_sidebar.css");
         $wgOut->addScript("<script type=\"{$wgJsMimeType}\" src=\"{$wgExtensionsPath}/wikia/AchievementsII/js/achievements.js\"></script>\n");
         if ($skinName == 'SkinMonoBook') {
             $wgOut->addExtensionStyle("{$wgExtensionsPath}/wikia/AchievementsII/css/leaderboard_monobook.css");
         }
     }
     // ranking
     $ranking = $rankingService->getUsersRanking(20, true);
     //make array of latest badges, per user
     $topUserIDs = array();
     foreach ($ranking as $rankedUser) {
         $topUserIDs[] = $rankedUser->getID();
     }
     $userService = new AchUserProfileService();
     $topUserBadges = $userService->getMostRecentUserBadge($topUserIDs);
     $template = new EasyTemplate(dirname(__FILE__) . '/templates');
     $template->set_vars(array('ranking' => $ranking, 'topUserBadges' => $topUserBadges, 'userpage' => $wgUser->getUserPage()->getPrefixedURL()));
     $wgOut->addHTML($template->render('SpecialLeaderboard'));
     wfProfileOut(__METHOD__);
 }
 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;
 }
 public function executeIndex()
 {
     global $wgContLang;
     wfProfileIn(__METHOD__);
     $userProfileService = new AchUserProfileService();
     if (!$userProfileService->isVisible()) {
         $this->skipRendering();
         wfProfileOut(__METHOD__);
         return;
     }
     // add CSS and JS for this module
     $this->response->addAsset('achievements_css');
     $this->response->addAsset('achievements_js');
     $rankingService = new AchRankingService();
     // get achievement lists
     $this->ownerName = $userProfileService->getOwnerUser()->getName();
     $this->ownerBadgesCount = $userProfileService->getBadgesCount();
     $this->ownerBadges = $userProfileService->getBadgesAnnotated(0);
     $this->ownerCounters = $userProfileService->getCounters();
     $this->ownerRank = $rankingService->getUserRankingPosition($userProfileService->getOwnerUser());
     $this->ownerScore = $wgContLang->formatNum($rankingService->getUserScore($userProfileService->getOwnerUser()->getId()));
     // if user is viewing their own page
     if ($userProfileService->getViewerUser() && !$userProfileService->getViewerUser()->isAnon() && $userProfileService->getViewerUser()->getId() == $userProfileService->getOwnerUser()->getId()) {
         $this->viewer_is_owner = true;
         $challengesBadges = $userProfileService->getChallengesAnnotated();
         // Let's prune the challengesBadges list to the correct length before passing it to the template
         if ($this->max_challenges != "all") {
             $challengesBadges = array_slice($challengesBadges, 0, $this->max_challenges);
         }
         $this->challengesBadges = $challengesBadges;
     }
     // UI elements
     $this->leaderboard_url = Skin::makeSpecialUrl("Leaderboard");
     if ($userProfileService->getViewerUser() && $userProfileService->getViewerUser()->isAllowed('editinterface')) {
         $this->customize_url = Skin::makeSpecialUrl("AchievementsCustomize");
     }
     wfProfileOut(__METHOD__);
 }
 public function executeIndex()
 {
     $maxBadgesToDisplay = 6;
     // Could make this a global if we want
     wfProfileIn(__METHOD__);
     $this->response->addAsset('achievements_js');
     // This code was taken from SpecialLeaderboard so it can be used by both the module and the old Monaco .tmpl
     $rankingService = new AchRankingService();
     // ignore welcome badges
     $blackList = array(BADGE_WELCOME);
     $awardedBadges = $rankingService->getRecentAwardedBadges(null, $maxBadgesToDisplay, 3, $blackList);
     $recents = array();
     $count = 1;
     // getRecentAwardedBadges can sometimes return more than $max items
     foreach ($awardedBadges as $badgeData) {
         //$level = $badgeData['badge']->getLevel();
         $recents[] = $badgeData;
         if ($count++ >= $maxBadgesToDisplay) {
             break;
         }
     }
     $this->recents = $recents;
     wfProfileOut(__METHOD__);
 }
Ejemplo n.º 9
0
 function execute($user_id)
 {
     wfProfileIn(__METHOD__);
     global $wgOut, $wgExtensionsPath, $wgStylePath, $wgSupressPageSubtitle, $wgUser, $wgResourceBasePath, $wgJsMimeType;
     $wgSupressPageSubtitle = true;
     $rankingService = new AchRankingService();
     $this->setHeaders();
     $wgOut->setPageTitle(wfMsg('achievements-title'));
     $skinName = get_class($this->getSkin());
     if ($skinName == 'SkinOasis') {
         $assetsManager = AssetsManager::getInstance();
         $scssPackage = 'special_leaderboard_oasis_css';
         $jsPackage = 'special_leaderboard_oasis_js';
         foreach ($assetsManager->getURL($scssPackage) as $url) {
             $wgOut->addStyle($url);
         }
         foreach ($assetsManager->getURL($jsPackage) as $url) {
             $wgOut->addScript("<script src=\"{$url}\"></script>");
         }
     }
     // include oasis.css override
     $wgOut->addStyle(AssetsManager::getInstance()->getSassCommonURL('extensions/wikia/AchievementsII/css/oasis.scss'));
     // ranking
     $ranking = $rankingService->getUsersRanking(20, true);
     //make array of latest badges, per user
     $topUserIDs = array();
     foreach ($ranking as $rankedUser) {
         $topUserIDs[] = $rankedUser->getID();
     }
     $usersService = new AchUsersService();
     $topUserBadges = $usersService->getMostRecentUserBadge($topUserIDs);
     $template = new EasyTemplate(dirname(__FILE__) . '/templates');
     $template->set_vars(array('ranking' => $ranking, 'topUserBadges' => $topUserBadges, 'userpage' => $wgUser->getUserPage()->getPrefixedURL()));
     $wgOut->addHTML($template->render('SpecialLeaderboard'));
     wfProfileOut(__METHOD__);
 }
Ejemplo n.º 10
0
function Ach_InvalidateCache(User $user)
{
    wfProfileIn(__METHOD__);
    global $wgMemc;
    $rankingCacheKeys = array(AchRankingService::getRankingCacheKey(1000, false), AchRankingService::getRankingCacheKey(20, true));
    foreach ($rankingCacheKeys as $key) {
        $wgMemc->delete($key);
    }
    wfProfileOut(__METHOD__);
    return true;
}
Ejemplo n.º 11
0
 /**
  * @author Jakub Kurcek
  * @param format string 'rss' or 'atom'
  */
 private function FeedAchivementsLeaderboard($format)
 {
     global $wgEnableAchievementsExt, $wgLang;
     if (empty($wgEnableAchievementsExt)) {
         $this->showMenu();
     } else {
         // local settings
         $maxEntries = 20;
         $howOld = 3;
         $userAvatarSize = 48;
         $rankingService = new AchRankingService();
         $ranking = $rankingService->getUsersRanking(20);
         $levels = array(BADGE_LEVEL_PLATINUM, BADGE_LEVEL_GOLD, BADGE_LEVEL_SILVER, BADGE_LEVEL_BRONZE);
         $recents = array();
         $specialPage = SpecialPageFactory::getPage('Leaderboard');
         $specialPageTitle = $specialPage->getTitle();
         $pageUrl = $specialPageTitle->getFullUrl();
         foreach ($levels as $level) {
             $limit = 3;
             $blackList = null;
             if ($level == BADGE_LEVEL_BRONZE) {
                 if ($maxEntries <= 0) {
                     break;
                 }
                 $limit = $maxEntries;
                 $blackList = array(BADGE_WELCOME);
             }
             $awardedBadges = $rankingService->getRecentAwardedBadges($level, $limit, $howOld, $blackList);
             if ($total = count($awardedBadges)) {
                 $recents[$level] = $awardedBadges;
                 $maxEntries -= $total;
             }
         }
         $feedArray = array();
         foreach ($ranking as $rank => $rankedUser) {
             ++$rank;
             $name = htmlspecialchars($rankedUser->getName());
             $feedArray[] = array('title' => $name, 'description' => $wgLang->formatNum($rankedUser->getScore()), 'url' => $pageUrl, 'date' => time(), 'author' => '', '', 'otherTags' => array('media:thumbnail' => AvatarService::getAvatarUrl($rankedUser->getName(), $userAvatarSize)));
         }
         $this->showFeed($format, wfMsg('feed-title-leaderboard'), $feedArray);
     }
 }