/** * @static * @return AchConfig instance */ public static function getInstance() { if (!isset(self::$mInstance)) { self::$mInstance = new self(); } return self::$mInstance; }
public static function getBadge($badgeTypeId) { wfProfileIn(__METHOD__); global $wgExternalSharedDB; global $wgEnableAchievementsStoreLocalData; $badges = array(); if (empty($wgEnableAchievementsStoreLocalData)) { $dbr = wfGetDB(DB_SLAVE, array(), $wgExternalSharedDB); } else { $dbr = wfGetDB(DB_SLAVE); } $res = $dbr->select('ach_custom_badges', array('id', 'enabled', 'sponsored', 'badge_tracking_url', 'hover_tracking_url', 'click_tracking_url'), array('id' => $badgeTypeId), __METHOD__); if ($row = $dbr->fetchObject($res)) { $badge = array(); $image = wfFindFile(AchConfig::getInstance()->getBadgePictureName($row->id)); if ($image) { $hoverImage = wfFindFile(AchConfig::getInstance()->getHoverPictureName($row->id)); $badge['type_id'] = $row->id; $badge['enabled'] = $row->enabled; $badge['thumb_url'] = $image->createThumb(90); $badge['awarded_users'] = AchPlatinumService::getAwardedUserNames($row->id); $badge['is_sponsored'] = $row->sponsored; $badge['badge_tracking_url'] = $row->badge_tracking_url; $badge['hover_tracking_url'] = $row->hover_tracking_url; $badge['click_tracking_url'] = $row->click_tracking_url; $badge['hover_content_url'] = is_object($hoverImage) ? wfReplaceImageServer($hoverImage->getFullUrl()) : null; wfProfileOut(__METHOD__); return $badge; } } wfProfileOut(__METHOD__); return false; }
private static function cmp($a, $b) { if ($a->getLevel() == BADGE_LEVEL_PLATINUM && $b->getLevel() == BADGE_LEVEL_PLATINUM || AchConfig::getInstance()->getBadgeType($a->getTypeId()) == BADGE_TYPE_INTRACKEDITPLUSCATEGORY && AchConfig::getInstance()->getBadgeType($b->getTypeId()) == BADGE_TYPE_INTRACKEDITPLUSCATEGORY) { $aO = $a->getTypeId(); $bO = $b->getTypeId(); } else { $aO = array_search($a->getTypeId(), self::$order); if ($aO === false) { $aO = 9; } $bO = array_search($b->getTypeId(), self::$order); if ($bO === false) { $bO = 9; } if ($aO == $bO) { return 0; } } return $aO < $bO ? -1 : 1; }
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__); }
<?php global $wgScriptPath; $badgeName = wfMsgForContent(AchConfig::getInstance()->getBadgeNameKey($type_id)); $badgeAwardedFor = wfMsgForContent(AchConfig::getInstance()->getBadgeDescKey($type_id)); $badgeHowToEarn = wfMsgForContent(AchConfig::getInstance()->getBadgeToGetKey($type_id)); ?> <form class="clearfix" action="<?php echo $wgScriptPath; ?> /index.php?action=ajax&rs=AchAjax&method=editPlatinumBadge" method="POST" onsubmit="return SpecialCustomizePlatinum.editSubmit(this);" enctype="multipart/form-data"> <fieldset class="customize-platinum-badge readonly"> <input type="hidden" name="type_id" value="<?php echo $type_id; ?> "/> <legend> <!-- toggle group --> <input name="badge_name" type="text" class="dark_text_2" value="<?php echo $badgeName; ?> " /> <span class="dark_text_2"><?php echo $badgeName; ?> </span> <!-- toggle group --> <input name="status" id="enabled-status" type="checkbox" <?php echo $enabled ? 'checked="checked" ' : ''; ?>
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__); }
</h1> <p><?php echo wfMsg('achievements-notification-subtitle', $badge->getName(), $badge->getPersonalGivenFor()); ?> </p> <p><?php echo wfMsgExt('achievements-notification-link', array('parse'), $user->getName()); ?> </p> </div> <div class="points <?php echo AchConfig::getInstance()->getLevelMsgKeyPart($badge->getLevel()); ?> "> <span><?php echo wfMsg('achievements-points-with-break', AchConfig::getInstance()->getLevelScore($badge->getLevel())); ?> </span> </div> </div> <script> // FIXME: move this somewhere else? wgAfterContentAndJS.push(function() { $(function() { $('.AchievementsNotification').slideDown('slow'); setTimeout(function() {$('.AchievementsNotification').slideUp('slow');}, 10000); }); }); </script>
/** * Handle notifications about new badges * * @param $user User * @param $badge AchBadge */ public static function addBadgeNotification($user, $badge, &$html) { wfProfileIn(__METHOD__); if ( F::app()->checkSkin( 'oasis' ) ) { // clear old-style notification $html = ''; // add notification $data = array( 'name' => $badge->getName(), 'picture' => $badge->getPictureUrl(90), 'points' => wfMsg('achievements-points', AchConfig::getInstance()->getLevelScore($badge->getLevel())), 'reason' => $badge->getPersonalGivenFor(), 'userName' => $user->getName(), 'userPage' => $user->getUserPage()->getLocalUrl(), ); #var_dump($data); $message = wfMsg('oasis-badge-notification', $data['userName'], $data['name'], $data['reason']); self::addNotification($message, $data, self::NOTIFICATION_NEW_ACHIEVEMENTS_BADGE); } wfProfileOut(__METHOD__); return true; }
public function isInTrack() { return AchConfig::getInstance()->isInTrack($this->mBadgeTypeId); }
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); }
private function loadUserBadges() { wfProfileIn(__METHOD__); $where = array('user_id' => $this->mUser->getId()); $dbr = wfGetDB(DB_SLAVE); $res = $dbr->select('ach_user_badges', 'badge_type_id, badge_lap', $where, __METHOD__, array('ORDER BY' => 'badge_type_id, badge_lap')); while ($row = $dbr->fetchObject($res)) { if (AchConfig::getInstance()->isInTrack($row->badge_type_id)) { if (!isset($this->mBadges[$row->badge_type_id])) { $this->mBadges[$row->badge_type_id] = array(); } $this->mBadges[$row->badge_type_id][] = $row->badge_lap; } else { if (!isset($this->mBadges[$row->badge_type_id])) { $this->mBadges[$row->badge_type_id] = 0; } $this->mBadges[$row->badge_type_id]++; } } wfProfileOut(__METHOD__); }
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; }
public function isSponsored() { return AchConfig::getInstance()->isSponsored($this->mBadgeTypeId); }
private function loadUserBadges() { wfProfileIn(__METHOD__); global $wgExternalSharedDB; global $wgEnableAchievementsStoreLocalData; $where = array('user_id' => $this->mUser->getId()); if (empty($wgEnableAchievementsStoreLocalData)) { $dbr = wfGetDB(DB_SLAVE, array(), $wgExternalSharedDB); $where['wiki_id'] = $this->mCityId; } else { $dbr = wfGetDB(DB_SLAVE); } $res = $dbr->select('ach_user_badges', 'badge_type_id, badge_lap', $where, __METHOD__, array('ORDER BY' => 'badge_type_id, badge_lap')); while ($row = $dbr->fetchObject($res)) { if (AchConfig::getInstance()->isInTrack($row->badge_type_id)) { if (!isset($this->mBadges[$row->badge_type_id])) { $this->mBadges[$row->badge_type_id] = array(); } $this->mBadges[$row->badge_type_id][] = $row->badge_lap; } else { if (!isset($this->mBadges[$row->badge_type_id])) { $this->mBadges[$row->badge_type_id] = 0; } $this->mBadges[$row->badge_type_id]++; } } wfProfileOut(__METHOD__); }