Exemplo n.º 1
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;
}
 private function saveBadges()
 {
     wfProfileIn(__METHOD__);
     if (count($this->mNewBadges) > 0) {
         $dbw = wfGetDB(DB_MASTER);
         // Doing replace instead of insert prevents dupes in case of slave lag or other errors
         foreach ($this->mNewBadges as $key => $val) {
             $this->mNewBadges[$key]['user_id'] = $this->mUser->getId();
             $dbw->replace('ach_user_badges', null, $this->mNewBadges[$key], __METHOD__);
         }
         $dbw->commit();
         //notify the user only if he wants to be notified
         if (!$this->mUser->getGlobalPreference('hidepersonalachievements')) {
             $_SESSION['achievementsNewBadges'] = true;
             $achNotificationService = new AchNotificationService($this->mUser);
             $achNotificationService->addBadges($this->mNewBadges);
             // Hook to give backend stuff something to latch onto at award-time rather than notifcation-time.
             // NOTE: This has the limitation that it is only called for a max of one badge per page.
             // If the user earned multiple badges on the same page, the hook will only be run on the badge which getBadgeToNotify() determines is more important.
             global $wgWikiaForceAIAFdebug;
             Wikia::log(__METHOD__, "", "Saving a new badge. About to run hook if badge can be re-loaded.", $wgWikiaForceAIAFdebug);
             $badge = $achNotificationService->getBadge(false);
             if ($badge !== null) {
                 wfRunHooks('AchievementEarned', array($this->mUser, $badge));
             }
         }
         //touch user when badges are given
         $this->mUser->invalidateCache();
         //purge the user page to update counters/ranking/badges/score, FB#2872
         $this->mUser->getUserPage()->purgeSquid();
         //run a hook to let other extensions know when Achievements-related cache should be purged
         wfRunHooks('AchievementsInvalidateCache', array($this->mUser));
     }
     wfProfileOut(__METHOD__);
 }