public static function achievements($cv_name, $city_id, $value) { wfProfileIn(__METHOD__); if ($cv_name == 'wgEnableAchievementsExt' && $value == true) { $wiki = WikiFactory::getWikiById($city_id); // Force WikiFactory::getWikiById() to query DB_MASTER if needed. if (!is_object($wiki)) { $wiki = WikiFactory::getWikiById($city_id, true); } $user = User::newFromId($wiki->city_founding_user); $user->load(); $achService = new AchAwardingService($city_id); $achService->awardCustomNotInTrackBadge($user, BADGE_CREATOR); } wfProfileOut(__METHOD__); return true; }
<?php /* * written to retroactively award founders with BADGE_CREATOR * * @author tor */ include '/usr/wikia/source/trunk/maintenance/commandLine.inc'; if (class_exists(AchAwardingService)) { $wiki = WikiFactory::getWikiByDB($wgDBname); if (empty($wiki)) { exit; } $founderId = $wiki->city_founding_user; if (empty($founderId)) { exit; } $founder = User::newFromId($founderId); $founder->load(); // get achievement to chek if it's there already $achService = new AchAwardingService(); $achService->awardCustomNotInTrackBadge($founder, BADGE_CREATOR); }
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; }
public static function editPlatinumBadge() { global $wgCityId, $wgRequest, $wgSitename, $wgServer, $wgScriptPath, $wgExternalSharedDB; $badge_type_id = $wgRequest->getVal('type_id'); $ret = array('errors' => null, 'typeId' => $badge_type_id); $isSponsored = $wgRequest->getBool('is_sponsored'); $usernamesToAward = $wgRequest->getArray('award_user'); $usersToAward = array(); if (is_array($usernamesToAward)) { //Webklit browsers don't send an empty array of inputs in a POST request foreach ($usernamesToAward as $usernameToAward) { if ($usernameToAward != '') { $user = User::newFromName($usernameToAward); if ($user && $user->isLoggedIn()) { $usersToAward[] = $user; } else { // FIXME: needs i18n. $ret['errors'][] = "User '{$usernameToAward}' does not exist"; } } } } // upload an image if ($ret['errors'] == null && $wgRequest->getFileName('wpUploadFile')) { ob_start(); $badgeImage = AchImageUploadService::uploadBadge(AchConfig::getInstance()->getBadgePictureName($badge_type_id), AchConfig::getInstance()->getLevelMsgKeyPart(BADGE_LEVEL_PLATINUM)); ob_end_clean(); if (!$badgeImage) { $ret['errors'][] = wfMsg('achievements-upload-error'); } } //upload Sponsored achievement hover content if ($isSponsored && $wgRequest->getFileName('hover_content')) { $hoverImage = AchImageUploadService::uploadHover(AchConfig::getInstance()->getHoverPictureName($badge_type_id)); if (!$hoverImage) { $ret['errors'][] = wfMsg('achievements-upload-error'); } } // update a badge if ($ret['errors'] == null) { global $wgEnableAchievementsStoreLocalData; $where = array('id' => $badge_type_id); if (empty($wgEnableAchievementsStoreLocalData)) { $dbw = wfGetDB(DB_MASTER, array(), $wgExternalSharedDB); $where['wiki_id'] = $wgCityId; } else { $dbw = wfGetDB(DB_MASTER); } $dbw->update('ach_custom_badges', array('enabled' => $wgRequest->getBool('status'), 'sponsored' => $isSponsored, 'badge_tracking_url' => $wgRequest->getText('badge_impression_pixel_url'), 'hover_tracking_url' => $wgRequest->getText('hover_impression_pixel_url'), 'click_tracking_url' => $wgRequest->getText('badge_redirect_url')), $where); // edit/create MW articles $badgeNameKey = AchConfig::getInstance()->getBadgeNameKey($badge_type_id); $messagesToEdit = array(); $messagesToEdit[$badgeNameKey] = 'badge_name'; $messagesToEdit[AchConfig::getInstance()->getBadgeToGetKey($badge_type_id)] = 'how_to'; $messagesToEdit[AchConfig::getInstance()->getBadgeDescKey($badge_type_id)] = 'awarded_for'; foreach ($messagesToEdit as $messageKey => $valueKey) { $value = $wgRequest->getVal($valueKey); if ($value && wfMsgForContent($messageKey) != $value) { $article = new Article(Title::newFromText($messageKey, NS_MEDIAWIKI)); $article->doEdit($value, ''); } } // award users if (count($usersToAward) > 0) { foreach ($usersToAward as $userToAward) { $awardingService = new AchAwardingService(); $awardingService->awardCustomNotInTrackBadge($userToAward, $badge_type_id); if ($userToAward->getEmail() != null && !$userToAward->getOption('hidepersonalachievements')) { $bodyParams = array(htmlspecialchars($userToAward->getName()), wfMsgHtml($badgeNameKey), "{$wgServer}{$wgScriptPath}", htmlspecialchars($wgSitename), $userToAward->getUserPage()->getFullURL()); $userToAward->sendMail(wfMsg('achievements-community-platinum-awarded-email-subject'), wfMsg('achievements-community-platinum-awarded-email-body-text', $bodyParams), null, null, 'CommunityPlatinumBadgesAwardNotification', wfMsg('achievements-community-platinum-awarded-email-body-html', $bodyParams)); } } } $dbw->commit(); if (empty($badgeImage)) { $badgeImage = wfFindFile(AchConfig::getInstance()->getBadgePictureName($badge_type_id)); } if (empty($hoverImage)) { $hoverImage = wfFindFile(AchConfig::getInstance()->getHoverPictureName($badge_type_id)); } // render form $badge = array(); $badge['type_id'] = $badge_type_id; $badge['enabled'] = $wgRequest->getBool('status'); $badge['thumb_url'] = $badgeImage->createThumb(90) . "?cb=" . rand(); $badge['awarded_users'] = AchPlatinumService::getAwardedUserNames($badge_type_id, true); $badge['is_sponsored'] = $isSponsored; $badge['badge_tracking_url'] = $wgRequest->getText('badge_impression_pixel_url'); $badge['hover_tracking_url'] = $wgRequest->getText('hover_impression_pixel_url'); $badge['click_tracking_url'] = $wgRequest->getText('badge_redirect_url'); $badge['hover_content_url'] = is_object($hoverImage) ? wfReplaceImageServer($hoverImage->getFullUrl()) . "?cb=" . rand() : null; $ret['output'] = AchPlatinumService::getPlatinumForm($badge); } return '<script type="text/javascript">window.document.responseContent = ' . json_encode($ret) . ';</script>'; }