public static function getBadge($badgeTypeId) { wfProfileIn(__METHOD__); $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; }
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>'; }