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 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;
 }
예제 #3
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;
 }