protected function getLastBadge()
 {
     wfProfileIn(__METHOD__);
     if (empty($this->userId)) {
         wfProfileOut(__METHOD__);
         return null;
     }
     if (!array_key_exists($this->userId, self::$lastBadge)) {
         $key = $this->getMemcKey();
         $lastBadge = $this->app->wg->memc->get($key);
         if (!empty($lastBadge)) {
             $lastBadge = AchBadge::newFromData($lastBadge);
         } else {
             $lastBadge = null;
         }
         self::$lastBadge[$this->userId] = $lastBadge;
     }
     wfProfileOut(__METHOD__);
     return self::$lastBadge[$this->userId];
 }
 function execute($user_id)
 {
     wfProfileIn(__METHOD__);
     global $wgUser, $wgOut, $wgExtensionsPath, $wgResourceBasePath, $wgSupressPageTitle, $wgRequest, $wgJsMimeType, $wgCityId, $wgExternalSharedDB;
     global $wgEnableAchievementsStoreLocalData;
     // set basic headers
     $this->setHeaders();
     if (wfReadOnly()) {
         $wgOut->readOnlyPage();
         wfProfileOut(__METHOD__);
         return;
     }
     if (!$this->userCanExecute($wgUser)) {
         $this->displayRestrictionError();
         return;
     }
     $wgSupressPageTitle = true;
     $errorMsg = null;
     $successMsg = null;
     if ($wgRequest->wasPosted()) {
         $jsonObj = json_decode($wgRequest->getVal('json-data'));
         $dbw = null;
         foreach ($jsonObj->messages as $mKey => $mVal) {
             $tokens = explode('_', $mKey);
             if (!isset($tokens[2])) {
                 $tokens[2] = null;
             }
             list(, $badgeTypeId, $lap) = $tokens;
             $badge = new AchBadge($badgeTypeId, $lap);
             if ($badge->getName() != $mVal) {
                 $article = new Article(Title::newFromText(AchConfig::getInstance()->getBadgeNameKey($badgeTypeId, $lap), NS_MEDIAWIKI));
                 $article->doEdit($mVal, '');
             }
         }
         $cond = array();
         if (empty($wgEnableAchievementsStoreLocalData)) {
             $dbw = wfGetDB(DB_MASTER, array(), $wgExternalSharedDB);
             $cond['wiki_id'] = $wgCityId;
         } else {
             $dbw = wfGetDB(DB_MASTER);
         }
         if (count($jsonObj->statusFlags)) {
             foreach ($jsonObj->statusFlags as $mKey => $mVal) {
                 $tokens = explode('_', $mKey);
                 $where = array_merge(array('id' => $tokens[1]), $cond);
                 $dbw->update('ach_custom_badges', array('enabled' => (int) $mVal), $where);
             }
         }
         $successMsg = wfMsg('achievements-special-saved');
         if ($wgRequest->getVal('add_edit_plus_category_track') == '1') {
             $catName = $wgRequest->getVal('edit_plus_category_name');
             $category = Category::newFromName($catName);
             if (!$category || !$category->getID()) {
                 $errorMsg = wfMsg('achievements-non-existing-category');
             } else {
                 $safeCatName = $category->getTitle()->getText();
                 if (strtolower($safeCatName) == 'stub' || stripos($safeCatName, 'stub ') === 0 || stripos($safeCatName, ' stub ') !== false || strripos($safeCatName, ' stub') === strlen($safeCatName) - 5) {
                     $errorMsg = wfMsg('achievements-no-stub-category');
                 } else {
                     $existingTrack = AchConfig::getInstance()->trackForCategoryExists($safeCatName);
                     if ($existingTrack !== false) {
                         $errorMsg = wfMsg('achievements-edit-plus-category-track-exists', $existingTrack);
                     } else {
                         $dbw->insert('ach_custom_badges', array('wiki_id' => $wgCityId, 'type' => BADGE_TYPE_INTRACKEDITPLUSCATEGORY, 'cat' => $safeCatName));
                         $jsonObj->sectionId = $badge_type_id = $dbw->insertId();
                     }
                 }
             }
         }
     }
     AchConfig::getInstance()->refreshData(true);
     $template = new EasyTemplate(dirname(__FILE__) . '/templates');
     $template->set_vars(array('config' => AchConfig::getInstance(), 'scrollTo' => isset($jsonObj->sectionId) ? $jsonObj->sectionId : null, 'successMsg' => $successMsg, 'errorMsg' => $errorMsg));
     $wgOut->addHTML($template->render('SpecialCustomize'));
     $wgOut->addStyle("common/article_sidebar.css");
     $wgOut->addExtensionStyle("{$wgExtensionsPath}/wikia/AchievementsII/css/customize.css");
     // FIXME: create a module with all these JS files
     $wgOut->addScript("<script type=\"{$wgJsMimeType}\" src=\"{$wgResourceBasePath}/resources/wikia/libraries/jquery/scrollto/jquery.scrollTo-1.4.2.js\"></script>\n");
     $wgOut->addScript("<script type=\"{$wgJsMimeType}\" src=\"{$wgExtensionsPath}/wikia/AchievementsII/js/achievements.js\"></script>\n");
     $wgOut->addScript("<script type=\"{$wgJsMimeType}\" src=\"{$wgResourceBasePath}/resources/wikia/libraries/aim/jquery.aim.js\"></script>\n");
     wfProfileOut(__METHOD__);
 }
예제 #3
0
			</form>
		</div>
		<h2><?php 
    echo wfMsg($config->getTrackNameKey($badgeTypeId), isset($trackData['category']) ? $trackData['category'] : null);
    ?>
</h2>

		<ul class="custom-badges">
			<?php 
    $inTrackBadgesCount = count($trackData['laps']);
    ?>
			<?php 
    foreach ($trackData['laps'] as $lap => $badgeData) {
        ?>
				<?php 
        $badge = new AchBadge($badgeTypeId, $lap, $badgeData['level']);
        ?>
				<li class="<?php 
        echo $lap == $inTrackBadgesCount - 1 ? ' last' : null;
        ?>
">

					<div class="content-form">
						<p class="input">
							<input class="c-message" type="text" name="msg_<?php 
        echo $badgeTypeId;
        ?>
_<?php 
        echo $lap;
        ?>
" value="<?php 
예제 #4
0
            ?>
					<table class="wallfeed"><?php 
            print FeedRenderer::getDetails($row);
            ?>
</table>
				<?php 
        }
        ?>
				<?php 
        // copied from feed.tmpl.php, BugId:97673
        global $wgEnableAchievementsInActivityFeed, $wgEnableAchievementsExt;
        if (!empty($wgEnableAchievementsInActivityFeed) && !empty($wgEnableAchievementsExt)) {
            if (isset($row['Badge'])) {
                $badge = unserialize($row['Badge']);
                $ownerBadge = array('badge' => $badge);
                AchBadge::renderForActivityFeed($ownerBadge, true);
            }
        }
        ?>
			</li>
		<?php 
    }
    ?>
		</ul>
		<?php 
    if ($showMore) {
        ?>
			<div class="activity-feed-more"><a href="#" data-since="<?php 
        echo $query_continue;
        ?>
"><?php 
 private function loadOwnerBadges()
 {
     global $wgCityId, $wgExternalSharedDB;
     global $wgEnableAchievementsStoreLocalData;
     wfProfileIn(__METHOD__);
     $where = array('user_id' => $this->mUserOwner->getId());
     if (empty($wgEnableAchievementsStoreLocalData)) {
         $dbr = wfGetDB(DB_SLAVE, array(), $wgExternalSharedDB);
         $where['wiki_id'] = $wgCityId;
     } else {
         $dbr = wfGetDB(DB_SLAVE);
     }
     $res = $dbr->select('ach_user_badges', 'badge_type_id, badge_lap', $where, __METHOD__, array('ORDER BY' => 'date DESC, badge_lap DESC'));
     while ($row = $dbr->fetchObject($res)) {
         if (AchConfig::getInstance()->isInTrack($row->badge_type_id)) {
             // in track
             if (!isset($this->mOwnerBadgesExtended[$row->badge_type_id])) {
                 $this->mOwnerBadgesExtended[$row->badge_type_id] = array();
             }
             $this->mOwnerBadgesExtended[$row->badge_type_id][] = $row->badge_lap;
         } else {
             // not in track
             if (!isset($this->mOwnerBadgesExtended[$row->badge_type_id])) {
                 $this->mOwnerBadgesExtended[$row->badge_type_id] = 0;
             }
             $this->mOwnerBadgesExtended[$row->badge_type_id]++;
         }
         $badge = new AchBadge($row->badge_type_id, $row->badge_lap);
         $to_get = '';
         if (is_array($this->mViewerCounters)) {
             if (AchConfig::getInstance()->isInTrack($row->badge_type_id)) {
                 // in track
                 if (!isset($this->mViewerBadgesExtended[$row->badge_type_id]) || !in_array($row->badge_lap, $this->mViewerBadgesExtended[$row->badge_type_id])) {
                     if (!isset($this->mViewerBadgesExtended[$row->badge_type_id])) {
                         $eventsCounter = 0;
                     } else {
                         if ($row->badge_type_id == BADGE_LOVE) {
                             $eventsCounter = $this->mViewerCounters[$row->badge_type_id][COUNTERS_COUNTER];
                         } else {
                             if ($row->badge_type_id == BADGE_BLOGCOMMENT) {
                                 $eventsCounter = count($this->mViewerCounters[$row->badge_type_id]);
                             } else {
                                 $eventsCounter = $this->mViewerCounters[$row->badge_type_id];
                             }
                         }
                     }
                     $to_get = $badge->getToGet(AchConfig::getInstance()->getRequiredEvents($row->badge_type_id, $row->badge_lap) - $eventsCounter);
                 }
             } else {
                 // not in track
                 if (!isset($this->mViewerBadgesExtended[$row->badge_type_id])) {
                     $to_get = $badge->getToGet();
                 }
             }
         }
         $this->mOwnerBadgesSimple[] = array('badge' => $badge, 'to_get' => $to_get);
     }
     wfProfileOut(__METHOD__);
 }
예제 #6
0
 public static function resetBadge()
 {
     global $wgRequest, $wgUser;
     if (!$wgUser->isAllowed('editinterface')) {
         return false;
     }
     $badge_type_id = $wgRequest->getVal('type_id');
     $lap = $wgRequest->getVal('lap') != '' ? $wgRequest->getVal('lap') : null;
     $image = wfFindFile(AchConfig::getInstance()->getBadgePictureName($badge_type_id, $lap));
     if ($image) {
         $image->delete('');
     }
     $badge = new AchBadge($badge_type_id, $lap);
     $ret = array('output' => $badge->getPictureUrl(90, true), 'message' => wfMsg('achievements-reverted'));
     return json_encode($ret);
 }
예제 #7
0
 /**
  * When the notification to the user is called (at the bottom of the page), attach the
  * achievement-earning to our best guess at what the associated RecentChange is.
  *
  * To account for race-conditions between RecentChanges and Achievements: currently, this
  * is done by recording when an RC is saved. If it happens on this page before this
  * function is called, then this function will load that RC by id.  If this function gets
  * called before any RCs have been recorded, then a serialized copy of the badge is stored
  * and can be inserted later (when the RC actually does get saved).
  *
  * @param User $user
  * @param AchBadge $badge
  */
 public static function attachAchievementToRc($user, $badge)
 {
     global $wgWikiaForceAIAFdebug;
     wfProfileIn(__METHOD__);
     // If user has 'hidepersonalachievements' set, then they probably don't want to play.
     // Also, other users may see that someone won, then click the username and look around for a way to see what achievements a user has...
     // then when they can't find it (since users with this option won't have theirs displayed), they might assume that there is no way to see
     // achievements.  It would be better to do this check at display-time rather than save-time, but we don't have access to the badge's user
     // at that point.
     Wikia::log(__METHOD__, "", "Noticed an achievement", $wgWikiaForceAIAFdebug);
     if ($badge->getTypeId() != BADGE_WELCOME && !$user->getGlobalPreference('hidepersonalachievements')) {
         Wikia::log(__METHOD__, "", "Attaching badge to recent change...", $wgWikiaForceAIAFdebug);
         // Make sure this Achievement gets added to its corresponding RecentChange (whether that has
         // been saved already during this pageload or is still pending).
         global $wgARecentChangeHasBeenSaved, $wgAchievementToAddToRc;
         Wikia::log(__METHOD__, "", "About to see if there is an existing RC. RC: " . print_r($wgARecentChangeHasBeenSaved, true), $wgWikiaForceAIAFdebug);
         if (!empty($wgARecentChangeHasBeenSaved)) {
             // Due to slave-lag, instead of storing the rc_id and looking it up (which didn't always work, even with a retry-loop), store entire RC.
             Wikia::log(__METHOD__, "", "Attaching badge to existing RecentChange from earlier in pageload.", $wgWikiaForceAIAFdebug);
             $rc = $wgARecentChangeHasBeenSaved;
             if ($rc) {
                 Wikia::log(__METHOD__, "", "Found recent change to attach to.", $wgWikiaForceAIAFdebug);
                 // Add the (serialized) badge into the rc_params field.
                 $rc_data = array();
                 $rc_data['Badge'] = serialize($badge);
                 MyHome::storeAdditionalRcData($rc_data, $rc);
             }
         } else {
             // Spool this achievement for when its corresponding RecentChange shows up (later in this pageload).
             $wgAchievementToAddToRc = serialize($badge);
             Wikia::log(__METHOD__, "", "RecentChange hasn't been saved yet, storing the badge for later.", $wgWikiaForceAIAFdebug);
         }
     }
     wfProfileOut(__METHOD__);
     return true;
 }
 public function getChallengesAnnotated()
 {
     wfProfileIn(__METHOD__);
     $achConfig = AchConfig::getInstance();
     $notInTrackCommunityPlatinum = $achConfig->getNotInTrackCommunityPlatinum();
     $inTrackStatic = $achConfig->getInTrackStatic();
     $inTrackEditPlusCategory = $achConfig->getInTrackEditPlusCategory();
     $ownerByType = $this->owner->getBadgesByType();
     $ownerCounters = $this->owner->getCounters();
     $challenges = array();
     // PLATINUM BADGES
     foreach ($notInTrackCommunityPlatinum as $badge_type_id => $badge_config) {
         if ($badge_config['enabled']) {
             if (!isset($ownerByType[$badge_type_id])) {
                 $challenges[$badge_type_id] = null;
             }
         }
     }
     // IN TRACK BADGES (only those for which user already has at least lap 0)
     foreach ($ownerByType as $badge_type_id => $typeData) {
         $badgeType = $achConfig->getBadgeType($badge_type_id);
         if ($badgeType == BADGE_TYPE_INTRACKEDITPLUSCATEGORY) {
             if ($achConfig->isEnabled($badge_type_id)) {
                 $challenges[$badge_type_id] = $typeData['count'];
             }
         } else {
             if ($badgeType == BADGE_TYPE_INTRACKSTATIC) {
                 if ($inTrackStatic[$badge_type_id]['infinite']) {
                     $challenges[$badge_type_id] = $typeData['count'];
                 } else {
                     if ($typeData['count'] < count($inTrackStatic[$badge_type_id]['laps'])) {
                         $challenges[$badge_type_id] = $typeData['count'];
                     }
                 }
             }
         }
     }
     $challengesOrder = array(BADGE_WELCOME, BADGE_INTRODUCTION, BADGE_EDIT, 0, BADGE_PICTURE, BADGE_SAYHI, BADGE_BLOGCOMMENT, BADGE_CATEGORY, BADGE_BLOGPOST, BADGE_LOVE);
     foreach ($challengesOrder as $badge_type_id) {
         if ($badge_type_id == 0) {
             foreach ($inTrackEditPlusCategory as $badge_type_id_2 => $badge_config) {
                 if ($badge_config['enabled']) {
                     if (!isset($ownerByType[$badge_type_id_2]) && !isset($challenges[$badge_type_id_2])) {
                         $challenges[$badge_type_id_2] = 0;
                     }
                 }
             }
         } else {
             if (!isset($ownerByType[$badge_type_id]) && !isset($challenges[$badge_type_id])) {
                 $challenges[$badge_type_id] = $achConfig->isInTrack($badge_type_id) ? 0 : null;
             }
         }
     }
     global $wgEnableAchievementsForSharing;
     $challengesAnnotated = array();
     foreach ($challenges as $badge_type_id => $badge_lap) {
         $badge = new AchBadge($badge_type_id, $badge_lap);
         if ($badge_lap === null) {
             $toGet = $badge->getToGet();
         } else {
             if (!isset($ownerCounters[$badge_type_id])) {
                 $eventsCounter = 0;
             } else {
                 if ($badge_type_id == BADGE_LOVE) {
                     $eventsCounter = $ownerCounters[$badge_type_id][COUNTERS_COUNTER];
                 } else {
                     if ($badge_type_id == BADGE_BLOGCOMMENT) {
                         $eventsCounter = count($ownerCounters[$badge_type_id]);
                     } else {
                         $eventsCounter = $ownerCounters[$badge_type_id];
                     }
                 }
             }
             $requiredEvents = $achConfig->getRequiredEvents($badge_type_id, $badge_lap);
             $toGet = $badge->getToGet($requiredEvents);
             if ($badge_type_id != BADGE_SHARING) {
                 $toGet .= " ({$eventsCounter}/{$requiredEvents})";
             } else {
                 if (empty($wgEnableAchievementsForSharing)) {
                     continue;
                 }
             }
         }
         $challengesAnnotated[] = array('badge' => $badge, 'to_get' => $toGet);
     }
     wfProfileOut(__METHOD__);
     return $challengesAnnotated;
 }