public function getTag() { $this->wf->profileIn(__METHOD__); $imageHTML = $this->request->getVal('imageHTML'); $align = $this->request->getVal('align'); $width = $this->request->getVal('width'); $showCaption = $this->request->getVal('showCaption', false); $caption = $this->request->getVal('caption', ''); $zoomIcon = $this->request->getVal('zoomIcon', ''); $showPictureAttribution = $this->request->getVal('showPictureAttribution', false); $attributeTo = $this->request->getVal('$attributeTo', null); $html = "<figure class=\"thumb" . (!empty($align) ? " t{$align}" : '') . " thumbinner\" style=\"width:{$width}px;\">{$imageHTML}{$zoomIcon}"; if (!empty($showCaption)) { $html .= "<figcaption class=\"thumbcaption\">{$caption}"; } //picture attribution if (!empty($showPictureAttribution) && !empty($attributeTo)) { $this->wf->profileIn(__METHOD__ . '::PictureAttribution'); // render avatar and link to user page $avatar = AvatarService::renderAvatar($attributeTo, 16); $link = AvatarService::renderLink($attributeTo); $html .= Xml::openElement('div', array('class' => 'picture-attribution')) . $avatar . $this->wf->MsgExt('oasis-content-picture-added-by', array('parsemag'), $link, $attributeTo) . Xml::closeElement('div'); $this->wf->profileOut(__METHOD__ . '::PictureAttribution'); } if (!empty($showCaption)) { $html .= '</figcaption>'; } $html .= '</figure>'; $this->setVal('tag', $html); $this->wf->profileOut(__METHOD__); }
/** * Modify results from Blogs * * Add likes count and render avatar */ static function getResults(&$results) { wfProfileIn(__METHOD__); /* @var $wgLang Language */ global $wgLang; // get message for "read more" link $cutSign = wfMsg('blug-cut-sign'); foreach($results as &$result) { $result['likes'] = false; $result['avatar'] = AvatarService::renderAvatar($result['username'], 48); $result['userpage'] = AvatarService::getUrl($result['username']); $result['date'] = $wgLang->date(wfTimestamp(TS_MW, $result['timestamp'])); // "read more" handling if (strpos($result['text'], $cutSign) !== false) { $result['readmore'] = true; } } //print_pre($results); wfProfileOut(__METHOD__); return true; }
/** * Chat entry point - rendered via Ajax or pre-rendered in JS variable * @todo: backward compatibility method, remove it till Oct 2013 * @todo: Ticket to remove this function: https://wikia-inc.atlassian.net/browse/SOC-638 */ public function executeContents() { global $wgUser, $wgReadOnly, $wgEnableWallExt; wfProfileIn(__METHOD__); if (empty($wgReadOnly)) { // Main variables $this->profileType = !empty($wgEnableWallExt) ? 'message-wall' : 'talk-page'; $this->linkToSpecialChat = SpecialPage::getTitleFor("Chat")->escapeLocalUrl(); $this->isLoggedIn = $wgUser->isLoggedIn(); $this->profileAvatarUrl = $this->isLoggedIn ? AvatarService::getAvatarUrl($wgUser->getName(), ChatRailController::AVATAR_SIZE) : ''; // List of other people in chat $this->totalInRoom = 0; // Gets array of users currently in chat to populate rail module and user stats menus $this->chatters = ChatEntryPoint::getChatUsersInfo(); $this->totalInRoom = count($this->chatters); for ($i = 0; $i < $this->totalInRoom; $i++) { global $wgLang; if ($this->chatters[$i]['showSince']) { $this->chatters[$i]['since'] = $wgLang->getMonthAbbreviation($this->chatters[$i]['since_month']) . ' ' . $this->chatters[$i]['since_year']; } } ChatHelper::info(__METHOD__ . ': Method called', ['chatters' => $this->totalInRoom, 'loggedIn' => $this->isLoggedIn]); } // Cache the entire call in varnish (and browser). $this->response->setCacheValidity(self::CACHE_DURATION); wfProfileOut(__METHOD__); }
public function votersListItems() { //TODO: imaplmant load more button /** * @var $mw WallMessage */ $mw = $this->request->getVal('mw'); if (empty($mw)) { $mw = F::build('WallMessage', array($this->request->getVal('id')), 'newFromId'); } $from = (int) $this->request->getVal('from', 0); $list = $mw->getVotersList($from, 1000); if (count($list) == 26) { $this->response->setVal('hasmore', true); } else { $this->response->setVal('hasmore', false); } $out = array(); for ($i = 0; $i < min(count($list), 24); $i++) { $user = User::newFromId($list[$i]); if (!empty($user)) { $out[] = array('profilepage' => $user->getUserPage()->getFullUrl(), 'name' => $user->getName(), 'avatar' => AvatarService::getAvatarUrl($user->getName(), 50)); } } $this->response->setVal('hasmore', false); $this->response->setVal('last', $from); $this->response->setVal('list', $out); }
/** * Get details about one or more user * * @requestParam string $ids A string with a comma-separated list of user ID's, limit for query equals 100 * @requestParam integer $size [OPTIONAL] The desired width and height for the thumbnail, defaults to 100, 0 for no thumbnail * * @responseParam array $items A list of results with the user ID as the index, each item has a title, name, url, avatar, numberofedits * @responseParam string $basepath domain of a wiki to create a url for an user * * @example &ids=123&size=150 */ public function getDetails() { wfProfileIn(__METHOD__); $ids = $this->request->getVal('ids'); if (empty($ids)) { throw new InvalidParameterApiException('ids'); } $ids = explode(',', trim($ids)); $size = $this->request->getInt('size', static::AVATAR_DEFAULT_SIZE); //limit number of users $ids = array_slice($ids, 0, static::USER_LIMIT); //users are cached inside the service $users = (new UserService())->getUsers($ids); $items = array(); foreach ($users as $user) { $userName = $user->getName(); $item = array('user_id' => $user->getId(), 'title' => $user->getTitleKey(), 'name' => $userName, 'url' => AvatarService::getUrl($userName), 'numberofedits' => (int) $user->getEditCountLocal()); //add avatar url if size !== 0 if ($size > 0) { $item['avatar'] = AvatarService::getAvatarUrl($user, $size); } $items[] = $item; } if (!empty($items)) { $this->setResponseData(['basepath' => $this->wg->Server, 'items' => $items], ['imgFields' => 'avatar', 'urlFields' => ['avatar', 'url']], WikiaResponse::CACHE_STANDARD); } else { throw new NotFoundApiException(); } wfProfileOut(__METHOD__); }
/** * Chat entry point - rendered via Ajax or pre-rendered in JS variable */ public function executeContents() { global $wgUser, $wgSitename, $wgOut, $wgExtensionsPath, $wgContLang, $wgReadOnly, $wgEnableWallExt; wfProfileIn(__METHOD__); // Since there is no chat in the backup datacenter yet, if we're in read-only, disable the entry-point. // Depending on the actual failure, chat may or may not work, but the user would have to get there via URL which // is essentially saying that they accept some risk since they're going somewhere our interface doesn't direct them to. // If it's just, eg: a database problem, then they may get lucky and be able to use most of the chat features (kickbanning wouldn't work, etc.). if (empty($wgReadOnly)) { // Main variables $this->profileType = !empty($wgEnableWallExt) ? 'message-wall' : 'talk-page'; $this->linkToSpecialChat = SpecialPage::getTitleFor("Chat")->escapeLocalUrl(); $this->isLoggedIn = $wgUser->isLoggedIn(); $this->profileAvatarUrl = $this->isLoggedIn ? AvatarService::getAvatarUrl($wgUser->getName(), ChatRailController::AVATAR_SIZE) : ''; // List of other people in chat $this->totalInRoom = 0; // Gets array of users currently in chat to populate rail module and user stats menus $chattersIn = NodeApiClient::getChatters($this->totalInRoom); $this->totalInRoom = count($chattersIn); $chatters = array(); foreach ($chattersIn as $i => $val) { $chatters[$i] = array(); $cacheChatter = $this->getCachedUser($val); if (!empty($cacheChatter)) { $chatters[$i] = $cacheChatter; continue; } $chatters[$i]['username'] = $val; $chatters[$i]['avatarUrl'] = AvatarService::getAvatarUrl($chatters[$i]['username'], ChatRailController::AVATAR_SIZE); // get stats for edit count and member since $user = User::newFromName($val); if (is_object($user)) { $userStatsService = new UserStatsService($user->getId()); $stats = $userStatsService->getStats(); // edit count $chatters[$i]['editCount'] = $wgContLang->formatNum((int) $stats['edits']); // member since $chatters[$i]['showSince'] = $chatters[$i]['editCount'] != 0; $date = getdate(strtotime($stats['date'])); global $wgLang; $chatters[$i]['since'] = $wgLang->getMonthAbbreviation($date['mon']) . ' ' . $date['year']; // profile page if ($this->profileType == 'message-wall') { $chatters[$i]['profileUrl'] = Title::makeTitle(NS_USER_WALL, $chatters[$i]['username'])->getFullURL(); } else { $chatters[$i]['profileUrl'] = Title::makeTitle(NS_USER_TALK, $chatters[$i]['username'])->getFullURL(); } // contribs page $chatters[$i]['contribsUrl'] = SpecialPage::getTitleFor('Contributions', $chatters[$i]['username'])->getFullURL(); } $this->cacheUser($val, $chatters[$i]); } $this->chatters = $chatters; } // Cache the entire call in varnish (and browser). $this->response->setCacheValidity(self::CACHE_DURATION, self::CACHE_DURATION, array(WikiaResponse::CACHE_TARGET_BROWSER, WikiaResponse::CACHE_TARGET_VARNISH)); wfProfileOut(__METHOD__); }
function testDefaultAvatar() { $this->mockGlobalVariable('wgVignetteUrl', 'http://vignette.wikia-dev.com'); $user = $this->getMock('User'); $user->expects($this->any())->method('getGlobalPreference')->will($this->returnValue(null)); $masthead = $this->getMock('Masthead', [], [$user]); $masthead->expects($this->any())->method('getDefaultAvatars')->will($this->returnValue(['http://images.wikia.com/messaging/images/1/19/Avatar.jpg'])); $this->assertEquals('http://vignette.wikia-dev.com/messaging/images/1/19/Avatar.jpg/revision/latest/scale-to-width-down/150?cb=789&format=jpg', AvatarService::getVignetteUrl($masthead, 150, 789)); }
/** * Execute function for generating view of PostInfo template * Sets params' values of template * @param $params array of params described below * @param $params['post_url'] string Full link to full article * @param $params['post_title'] string Title of post * @param $params['avatar_url'] string Full url to user avatar image * @param $params['username'] string Name of post author * @param $params['user_page_url'] string Full url to author page * @param $params['date'] string Date of post publish * @param $params['short_text'] string Shortened version of text */ public function executePostInfo($params) { wfProfileIn(__METHOD__); $this->post_url = array_key_exists('post_url', $params) ? $params['post_url'] : ''; $this->post_title = array_key_exists('post_title', $params) ? $params['post_title'] : ''; $this->avatar_url = array_key_exists('avatar_url', $params) ? $params['avatar_url'] : AvatarService::renderAvatar('', EmailTemplatesHooksHelper::EMAIL_AVATAR_DEFAULT_WIDTH); $this->username = array_key_exists('username', $params) ? $params['username'] : wfMessage('oasis-anon-user')->plain(); $this->user_page_url = array_key_exists('user_page_url', $params) ? $params['user_page_url'] : ''; $this->date = array_key_exists('date', $params) ? $params['date'] : ''; wfProfileOut(__METHOD__); }
/** * Modify results from Blogs * * Add likes count and render avatar */ static function getResults(&$results) { wfProfileIn(__METHOD__); /* @var $wgLang Language */ global $wgLang; foreach ($results as &$result) { $result['likes'] = false; $result['avatar'] = AvatarService::renderAvatar($result['username'], 48); $result['userpage'] = AvatarService::getUrl($result['username']); $result['date'] = $wgLang->date(wfTimestamp(TS_MW, $result['timestamp'])); } wfProfileOut(__METHOD__); return true; }
/** * Get a list of random avatars from the wiki * * @param integer $require (number of avatars) * @param integer $wikiId * @return array $avatars */ protected function getRandomWikiAvatars($require, $wikiId = null) { $avatars = array(); $users = $this->getWikiUsers($wikiId); if (count($users) < $require) { $randomList = array_keys($users); } else { $randomList = array_rand($users, $require); } // get avatar url foreach ($randomList as $userId) { $avatars[$userId] = AvatarService::getAvatarUrl($users[$userId], 30); } return $avatars; }
function testAvatarService() { $anonName = '10.10.10.10'; $userName = '******'; // users $this->assertRegExp('/width="32"/', AvatarService::render($userName, 32)); $this->assertRegExp('/\/20px-/', AvatarService::render($userName, 16)); $this->assertRegExp('/User:WikiaBot/', AvatarService::renderLink($userName)); $this->assertRegExp('/^<img src="http:\/\/images/', AvatarService::renderAvatar($userName)); $this->assertRegExp('/^http:\/\/images/', AvatarService::getAvatarUrl($userName)); // anons $this->assertRegExp('/Special:Contributions\//', AvatarService::getUrl($anonName)); $this->assertRegExp('/^<img src="/', AvatarService::renderAvatar($anonName)); $this->assertRegExp('/\/20px-/', AvatarService::renderAvatar($anonName, 20)); $this->assertRegExp('/Special:Contributions/', AvatarService::renderLink($anonName)); }
/** * @group Slow * @slowExecutionTime 0.04016 ms * @group UsingDB */ function testAvatarService() { $anonName = '10.10.10.10'; $userName = '******'; $this->mockGlobalVariable('wgVignetteUrl', 'http://images.foo.wikia-dev.com'); $this->mockGlobalVariable('wgEnableVignette', true); // users $this->assertContains('width="32"', AvatarService::render($userName, 32)); $this->assertContains('/scale-to-width-down/20', AvatarService::render($userName, 16)); $this->assertContains('User:WikiaBot', AvatarService::renderLink($userName)); $this->assertRegExp('/^<img src="http:\\/\\/images/', AvatarService::renderAvatar($userName)); // anons $this->assertContains('Special:Contributions/', AvatarService::getUrl($anonName)); $this->assertRegExp('/^<img src="/', AvatarService::renderAvatar($anonName)); $this->assertContains('/20px-', AvatarService::renderAvatar($anonName, 20)); $this->assertContains('Special:Contributions', AvatarService::renderLink($anonName)); }
/** * Prepare a pre-rendered chat entry point for logged-in users */ public static function onMakeGlobalVariablesScript(&$vars) { global $wgUser, $wgLang; if ($wgUser->isLoggedIn()) { $vars['wgWikiaChatUsers'] = ChatEntryPoint::getChatUsersInfo(); if (empty($vars['wgWikiaChatUsers'])) { // we will need it to attract user to join chat $vars['wgWikiaChatProfileAvatarUrl'] = AvatarService::getAvatarUrl($wgUser->getName(), ChatRailController::AVATAR_SIZE); } $vars['wgWikiaChatMonts'] = $wgLang->getMonthAbbreviationsArray(); } else { $vars['wgWikiaChatUsers'] = ''; } $vars['wgWikiaChatWindowFeatures'] = ChatRailController::CHAT_WINDOW_FEATURES; return true; }
<section class="module WikiaActivityModule ForumActivityModule"> <h2><?php echo wfMessage('forum-activity-module-heading')->escaped(); ?> </h2> <ul> <?php foreach ($posts as $value) { ?> <li> <?php echo AvatarService::renderAvatar($value['user']->getName(), 20); ?> <em> <a href="<?php echo $value['wall_message']->getMessagePageUrl(true); ?> " title="<?php echo htmlspecialchars($value['metatitle']); ?> "><?php echo htmlspecialchars($value['metatitle']); ?> </a> </em> <div class="edited-by"> <?php $user = '******' . $value['user']->getUserPage()->getFullUrl() . '">' . htmlspecialchars($value['display_username']) . '</a>'; ?> <?php $time = '<span class="timeago abstimeago" title="' . $value['event_iso'] . '" alt="' . $value['event_mw'] . '"> </span>';
/** * Render header for blog post */ public function executeBlogPost() { wfProfileIn(__METHOD__); global $wgTitle, $wgLang, $wgOut; // remove User_blog:xxx from title $titleParts = explode('/', $wgTitle->getText()); array_shift($titleParts); $this->title = implode('/', $titleParts); // get user name to display in header $this->userName = self::getUserName($wgTitle, BodyController::getUserPagesNamespaces()); // render avatar (48x48) $this->avatar = AvatarService::renderAvatar($this->userName, 48); // link to user page $this->userPage = AvatarService::getUrl($this->userName); if ($this->wg->EnableBlogArticles) { // link to user blog page $this->userBlogPage = AvatarService::getUrl($this->userName, NS_BLOG_ARTICLE); // user blog page message $this->userBlogPageMessage = wfMessage('user-blog-url-link', $this->userName)->inContentLanguage()->parse(); } if (!empty($this->wg->EnableGoogleAuthorInfo) && !empty($this->wg->GoogleAuthorLinks) && array_key_exists($this->userName, $this->wg->GoogleAuthorLinks)) { $this->googleAuthorLink = $this->wg->GoogleAuthorLinks[$this->userName] . '?rel=author'; } if ($this->app->wg->Request->getVal('action') == 'history' || $this->app->wg->Request->getCheck('diff')) { $this->navLinks = Wikia::link($this->app->wg->title, wfMsg('oasis-page-header-back-to-article'), array(), array(), 'known'); } // user stats (edit points, account creation date) $this->stats = $this->getStats($this->userName); // commments / likes / date of first edit if (!empty($wgTitle) && $wgTitle->exists()) { $service = new PageStatsService($wgTitle->getArticleId()); $this->editTimestamp = $wgLang->date($service->getFirstRevisionTimestamp()); $this->comments = $service->getCommentsCount(); } $actionMenu = array(); $dropdownActions = array('move', 'protect', 'unprotect', 'delete', 'undelete', 'history'); // edit button / dropdown if (isset($this->content_actions['ve-edit'])) { // new visual editor is enabled $actionMenu['action'] = $this->content_actions['ve-edit']; // add classic editor link to the possible dropdown options array_unshift($dropdownActions, 'edit'); } else { if (isset($this->content_actions['edit'])) { $actionMenu['action'] = $this->content_actions['edit']; } } foreach ($dropdownActions as $action) { if (isset($this->content_actions[$action])) { $actionMenu['dropdown'][$action] = $this->content_actions[$action]; } } $this->actionMenu = $actionMenu; // load CSS for .WikiaUserPagesHeader (BugId:9212, 10246) $wgOut->addStyle(AssetsManager::getInstance()->getSassCommonURL("skins/oasis/css/core/UserPagesHeader.scss")); wfProfileOut(__METHOD__); }
<div class="speech-bubble-avatar"> <a href="<?php echo $user_author_url; ?> "> <?php if (!$isreply) { ?> <?php echo AvatarService::renderAvatar($username, 50); ?> <?php } else { ?> <?php echo AvatarService::renderAvatar($username, 30); ?> <?php } ?> </a> </div> <blockquote class="speech-bubble-message"> <?php if (!$isreply) { ?> <?php if ($isWatched) { ?> <a <?php
function wfCOPageHeaderIndexAfterExecute(&$controller, &$params) { if (wfCOCheck()) { if (isset($controller->content_actions['delete'])) { $action = $controller->content_actions['delete']; $action['text'] = wfMsgHtml('comments-only-delete-thread'); $controller->actionName = 'delete'; $controller->action = $action; } else { $controller->action = null; $controller->actionName = ''; } $controller->dropdown = array(); if ($controller->revisions) { global $wgTitle; $rev = $wgTitle->getFirstRevision(); if ($rev) { $user = User::newFromId($rev->getUser()); if ($user) { $controller->revisions = array('current' => array('user' => $user->getName(), 'link' => AvatarService::renderLink($user->getName()), 'avatarUrl' => AvatarService::getAvatarUrl($user->getName()), 'timestamp' => wfTimestamp(TS_ISO_8601, $rev->getTimestamp()))); } } } } return true; }
public function getData($master = false) { global $wgUser, $wgBlankImgUrl, $wgMemc, $wgArticleCommentsEnableVoting; wfProfileIn(__METHOD__); $comment = false; $canDelete = $wgUser->isAllowed('commentdelete'); if (self::isBlog()) { $canDelete = $canDelete || $wgUser->isAllowed('blog-comments-delete'); } $title = $this->getTitle(); $commentId = $title->getArticleId(); // vary cache on permission as well so it changes we can show it to a user $articleDataKey = wfMemcKey('articlecomment_data', $commentId, $title->getLatestRevID(), $wgUser->getId(), $canDelete, RequestContext::getMain()->getSkin()->getSkinName(), self::CACHE_VERSION); $data = $wgMemc->get($articleDataKey); if (!empty($data)) { $data['timestamp'] = "<a href='" . $title->getFullUrl(['permalink' => $data['id']]) . '#comm-' . $data['id'] . "' class='permalink'>" . wfTimeFormatAgo($data['rawmwtimestamp']) . "</a>"; wfProfileOut(__METHOD__); return $data; } if ($this->load($master)) { $sig = $this->mUser->isAnon() ? AvatarService::renderLink($this->mUser->getName()) : Xml::element('a', array('href' => $this->mUser->getUserPage()->getFullUrl()), $this->mUser->getName()); $isStaff = (int) in_array('staff', $this->mUser->getEffectiveGroups()); $parts = self::explode($title->getDBkey()); $buttons = []; // action links with full markup (used in Oasis) $links = []; // action links with only a URL $replyButton = ''; // this is for blogs we want to know if commenting on it is enabled // we cannot check it using $title->getBaseText, as this returns main namespace title // the subjectpage for $parts title is something like 'User blog comment:SomeUser/BlogTitle' which is fine $articleTitle = Title::makeTitle(MWNamespace::getSubject($this->mNamespace), $parts['title']); $commentingAllowed = ArticleComment::canComment($articleTitle); if (count($parts['partsStripped']) == 1 && $commentingAllowed) { $replyButton = '<button type="button" class="article-comm-reply wikia-button secondary actionButton">' . wfMsg('article-comments-reply') . '</button>'; } if (defined('NS_QUESTION_TALK') && $title->getNamespace() == NS_QUESTION_TALK) { $replyButton = ''; } if ($canDelete) { $img = '<img class="remove sprite" alt="" src="' . $wgBlankImgUrl . '" width="16" height="16" />'; $buttons[] = $img . '<a href="' . $title->getLocalUrl('redirect=no&action=delete') . '" class="article-comm-delete">' . wfMsg('article-comments-delete') . '</a>'; $links['delete'] = $title->getLocalUrl('redirect=no&action=delete'); } // due to slave lag canEdit() can return false negative - we are hiding it by CSS and force showing by JS if ($wgUser->isLoggedIn() && $commentingAllowed) { $display = $this->canEdit() ? 'test=' : ' style="display:none"'; $img = '<img class="edit-pencil sprite" alt="" src="' . $wgBlankImgUrl . '" width="16" height="16" />'; $buttons[] = "<span class='edit-link'{$display}>" . $img . '<a href="#comment' . $commentId . '" class="article-comm-edit actionButton" id="comment' . $commentId . '">' . wfMsg('article-comments-edit') . '</a></span>'; $links['edit'] = '#comment' . $commentId; } if (!$this->mTitle->isNewPage(Title::GAID_FOR_UPDATE)) { $buttons[] = RequestContext::getMain()->getSkin()->makeKnownLinkObj($title, wfMsgHtml('article-comments-history'), 'action=history', '', '', 'class="article-comm-history"'); $links['history'] = $title->getLocalUrl('action=history'); } $rawmwtimestamp = $this->mFirstRevision->getTimestamp(); $rawtimestamp = wfTimeFormatAgo($rawmwtimestamp); $timestamp = "<a rel='nofollow' href='" . $title->getFullUrl(['permalink' => $commentId]) . '#comm-' . $commentId . "' class='permalink'>" . wfTimeFormatAgo($rawmwtimestamp) . "</a>"; $comment = ['id' => $commentId, 'author' => $this->mUser, 'username' => $this->mUser->getName(), 'avatar' => AvatarService::renderAvatar($this->mUser->getName(), self::AVATAR_BIG_SIZE), 'avatarSmall' => AvatarService::renderAvatar($this->mUser->getName(), self::AVATAR_SMALL_SIZE), 'userurl' => AvatarService::getUrl($this->mUser->getName()), 'isLoggedIn' => $this->mUser->isLoggedIn(), 'buttons' => $buttons, 'links' => $links, 'replyButton' => $replyButton, 'sig' => $sig, 'text' => $this->mText, 'metadata' => $this->mMetadata, 'rawtext' => $this->mRawtext, 'timestamp' => $timestamp, 'rawtimestamp' => $rawtimestamp, 'rawmwtimestamp' => $rawmwtimestamp, 'title' => $title->getText(), 'isStaff' => $isStaff]; if (!empty($wgArticleCommentsEnableVoting)) { $comment['votes'] = $this->getVotesCount(); } $wgMemc->set($articleDataKey, $comment, self::AN_HOUR); if (!$comment['title'] instanceof Title) { $comment['title'] = Title::newFromText($comment['title'], NS_TALK); } } wfProfileOut(__METHOD__); return $comment; }
<?php } ?> </td></tr></table> </div> <?php } ?> <?php if ($showArchiveInfo) { ?> <div class="deleteorremove-infobox"> <div class="deleteorremove-bubble"> <div class="avatar"><?php echo AvatarService::renderAvatar($statusInfo['user']->getName(), 20); ?> </div> <div class="message"> <?php echo wfMsgExt('wall-message-closed-by', array('parseinline'), array($statusInfo['user']->getName(), $statusInfo['user']->getUserPage())); ?> <br> <div class="timestamp"><span><?php echo $statusInfo['fmttime']; ?> </span></div> </div> </div> </div> <?php
public static function onParserAfterTidy(Parser &$parser, &$text) { global $wgArticleAsJson; wfProfileIn(__METHOD__); if ($wgArticleAsJson && !is_null($parser->getRevisionId())) { $userName = $parser->getRevisionUser(); if (!empty($userName)) { if (User::isIP($userName)) { self::addUserObj(['userId' => 0, 'userName' => $userName, 'userThumbUrl' => AvatarService::getAvatarUrl($userName, AvatarService::AVATAR_SIZE_MEDIUM), 'userPageUrl' => Title::newFromText($userName)->getLocalURL()]); } else { $user = User::newFromName($userName); if ($user instanceof User) { self::addUserObj(['userId' => $user->getId(), 'userName' => $user->getName(), 'userThumbUrl' => AvatarService::getAvatarUrl($user, AvatarService::AVATAR_SIZE_MEDIUM), 'userPageUrl' => $user->getUserPage()->getLocalURL()]); } } } foreach (self::$media as &$media) { self::linkifyMediaCaption($parser, $media); } $text = json_encode(['content' => $text, 'media' => self::$media, 'users' => self::$users]); } wfProfileOut(__METHOD__); return true; }
public function getData($master = false, $title = null) { global $wgUser, $wgTitle, $wgBlankImgUrl, $wgMemc, $wgArticleCommentsEnableVoting; wfProfileIn(__METHOD__); $title = empty($title) ? $wgTitle : $title; $title = empty($title) ? $this->mTitle : $title; $comment = false; if ($this->load($master)) { $articleDataKey = wfMemcKey('articlecomment', 'comm_data_v2', $this->mLastRevId, $wgUser->getId()); $data = $wgMemc->get($articleDataKey); if (!empty($data)) { wfProfileOut(__METHOD__); $data['timestamp'] = "<a href='" . $this->getTitle()->getFullUrl(array('permalink' => $data['articleId'])) . '#comm-' . $data['articleId'] . "' class='permalink'>" . wfTimeFormatAgo($data['rawmwtimestamp']) . "</a>"; return $data; } $canDelete = $wgUser->isAllowed('delete'); $sig = $this->mUser->isAnon() ? AvatarService::renderLink($this->mUser->getName()) : Xml::element('a', array('href' => $this->mUser->getUserPage()->getFullUrl()), $this->mUser->getName()); $articleId = $this->mTitle->getArticleId(); $isStaff = (int) in_array('staff', $this->mUser->getEffectiveGroups()); $parts = self::explode($this->getTitle()); $buttons = array(); $replyButton = ''; $commentingAllowed = true; if (defined('NS_BLOG_ARTICLE') && $title->getNamespace() == NS_BLOG_ARTICLE) { $props = BlogArticle::getProps($title->getArticleID()); $commentingAllowed = isset($props['commenting']) ? (bool) $props['commenting'] : true; } if (count($parts['partsStripped']) == 1 && $commentingAllowed && !ArticleCommentInit::isFbConnectionNeeded()) { $replyButton = '<button type="button" class="article-comm-reply wikia-button secondary actionButton">' . wfMsg('article-comments-reply') . '</button>'; } if (defined('NS_QUESTION_TALK') && $this->mTitle->getNamespace() == NS_QUESTION_TALK) { $replyButton = ''; } if ($canDelete && !ArticleCommentInit::isFbConnectionNeeded()) { $img = '<img class="remove sprite" alt="" src="' . $wgBlankImgUrl . '" width="16" height="16" />'; $buttons[] = $img . '<a href="' . $this->mTitle->getLocalUrl('redirect=no&action=delete') . '" class="article-comm-delete">' . wfMsg('article-comments-delete') . '</a>'; } //due to slave lag canEdit() can return false negative - we are hiding it by CSS and force showing by JS if ($wgUser->isLoggedIn() && $commentingAllowed && !ArticleCommentInit::isFbConnectionNeeded()) { $display = $this->canEdit() ? 'test=' : ' style="display:none"'; $img = '<img class="edit-pencil sprite" alt="" src="' . $wgBlankImgUrl . '" width="16" height="16" />'; $buttons[] = "<span class='edit-link'{$display}>" . $img . '<a href="#comment' . $articleId . '" class="article-comm-edit actionButton" id="comment' . $articleId . '">' . wfMsg('article-comments-edit') . '</a></span>'; } if (!$this->mTitle->isNewPage(Title::GAID_FOR_UPDATE)) { $buttons[] = RequestContext::getMain()->getSkin()->makeKnownLinkObj($this->mTitle, wfMsgHtml('article-comments-history'), 'action=history', '', '', 'class="article-comm-history"'); } $commentId = $this->getTitle()->getArticleId(); $rawmwtimestamp = $this->mFirstRevision->getTimestamp(); $rawtimestamp = wfTimeFormatAgo($rawmwtimestamp); $timestamp = "<a rel='nofollow' href='" . $this->getTitle()->getFullUrl(array('permalink' => $commentId)) . '#comm-' . $commentId . "' class='permalink'>" . wfTimeFormatAgo($rawmwtimestamp) . "</a>"; $comment = array('id' => $commentId, 'articleId' => $articleId, 'author' => $this->mUser, 'username' => $this->mUser->getName(), 'avatar' => AvatarService::renderAvatar($this->mUser->getName(), self::AVATAR_BIG_SIZE), 'avatarSmall' => AvatarService::renderAvatar($this->mUser->getName(), self::AVATAR_SMALL_SIZE), 'userurl' => AvatarService::getUrl($this->mUser->getName()), 'isLoggedIn' => $this->mUser->isLoggedIn(), 'buttons' => $buttons, 'replyButton' => $replyButton, 'sig' => $sig, 'text' => $this->mText, 'metadata' => $this->mMetadata, 'rawtext' => $this->mRawtext, 'timestamp' => $timestamp, 'rawtimestamp' => $rawtimestamp, 'rawmwtimestamp' => $rawmwtimestamp, 'title' => $this->mTitle->getText(), 'isStaff' => $isStaff); if (!empty($wgArticleCommentsEnableVoting)) { $comment['votes'] = $this->getVotesCount(); } $wgMemc->set($articleDataKey, $comment, 60 * 60); if (!$comment['title'] instanceof Title) { $comment['title'] = F::build('Title', array($comment['title'], NS_TALK), 'newFromText'); } } wfProfileOut(__METHOD__); return $comment; }
echo json_encode($authService->signUp($user)); }); $app->get('/avatar', function () { if (accessIsOK()) { $request = \Slim\Slim::getInstance()->request(); $userAuth = json_decode($request->headers->get('Authorization')); $avatarService = new AvatarService(); echo json_encode($avatarService->recover($userAuth->id)); } }); $app->post('/avatar', function () { if (accessIsOK()) { $request = \Slim\Slim::getInstance()->request(); $userAuth = json_decode($request->headers->get('Authorization')); $avatar = json_decode($request->getBody()); $avatarService = new AvatarService(); echo json_encode($avatarService->save($avatar, $userAuth->id)); } }); $app->group('/user', function () use($app) { $app->get('/level', function () { if (accessIsOK()) { $request = \Slim\Slim::getInstance()->request(); $userAuth = json_decode($request->headers->get('Authorization')); $profileService = new ProfileService(); echo json_encode($profileService->getUserLevel($userAuth->id)); } }); $app->get('/score', function () { if (accessIsOK()) { $request = \Slim\Slim::getInstance()->request();
/** * Get user info ( user name, avatar url, user page url ) on given wiki * if the user has avatar * @param integer $userId * @param integer $wikiId * @param integer $avatarSize * @param callable $checkUserCallback * @return array userInfo * */ public function getUserInfo($userId, $wikiId, $avatarSize, $checkUserCallback) { $userInfo = array(); $user = User::newFromId($userId); if ($user instanceof User && $checkUserCallback($user)) { $username = $user->getName(); $userInfo['avatarUrl'] = AvatarService::getAvatarUrl($user, $avatarSize); $userInfo['edits'] = 0; $userInfo['name'] = $username; /** @var $userProfileTitle GlobalTitle */ $userProfileTitle = GlobalTitle::newFromTextCached($username, NS_USER, $wikiId); $userInfo['userPageUrl'] = $userProfileTitle instanceof Title ? $userProfileTitle->getFullURL() : '#'; $userContributionsTitle = GlobalTitle::newFromTextCached('Contributions/' . $username, NS_SPECIAL, $wikiId); $userInfo['userContributionsUrl'] = $userContributionsTitle instanceof Title ? $userContributionsTitle->getFullURL() : '#'; $userInfo['userId'] = $userId; $userStatsService = new UserStatsService($userId); $stats = $userStatsService->getGlobalStats($wikiId); if (!empty($stats['date'])) { $date = getdate(strtotime($stats['date'])); } else { $date = getdate(strtotime('2005-06-01')); } $userInfo['lastRevision'] = $stats['lastRevision']; $userInfo['since'] = F::App()->wg->Lang->getMonthAbbreviation($date['mon']) . ' ' . $date['year']; } return $userInfo; }
public function executeIndex() { wfProfileIn(__METHOD__); $maxElements = 4; global $wgLang, $wgContentNamespaces, $wgMemc, $wgUser; $this->moduleHeader = wfMsg('oasis-activity-header'); if (empty($this->userName)) { $mKey = wfMemcKey('mOasisLatestActivity'); $feedData = $wgMemc->get($mKey); } if (empty($feedData)) { // data provider $includeNamespaces = implode('|', $wgContentNamespaces); $parameters = array('type' => 'widget', 'maxElements' => $maxElements, 'flags' => array('shortlist'), 'uselang' => $wgLang->getCode(), 'includeNamespaces' => $includeNamespaces); $feedProxy = new ActivityFeedAPIProxy($includeNamespaces, $this->userName); $feedProvider = new DataFeedProvider($feedProxy, 1, $parameters); $feedData = $feedProvider->get($maxElements); if (empty($this->userName)) { $wgMemc->set($mKey, $feedData); } } // Time strings are slow to calculate, but we still want them to update frequently (60 seconds) if (empty($this->userName)) { $mKeyTimes = wfMemcKey('mOasisLatestActivity_times', $wgLang->getCode()); $this->changeList = $wgMemc->get($mKeyTimes, array()); } if (empty($this->changeList) && !empty($feedData) && is_array($feedData['results'])) { $changeList = array(); foreach ($feedData['results'] as $change) { $item = array(); $item['time_ago'] = wfTimeFormatAgoOnlyRecent($change['timestamp']); // TODO: format the timestamp on front-end to allow longer caching in memcache? $item['user_name'] = $change['username']; $item['avatar_url'] = AvatarService::getAvatarUrl($item['user_name'], 20); $item['user_href'] = AvatarService::renderLink($item['user_name']); $item['page_title'] = $change['title']; $item['changetype'] = $change['type']; $title = Title::newFromText($change['title'], $change['ns']); if (!empty($change['articleComment']) && !empty($change['url'])) { $item['page_href'] = Xml::element('a', array('href' => $change['url']), $item['page_title']); } else { if (is_object($title)) { $item['page_href'] = Xml::element('a', array('href' => $title->getLocalUrl()), $item['page_title']); } } switch ($change['type']) { case 'new': case 'edit': case 'delete': // different formatting for User Profile Pages if (!empty($this->userName)) { $item['page_href'] = wfMsg("userprofilepage-activity-{$change['type']}", $item['page_href']); $item['changemessage'] = $item['time_ago']; } else { // format message (RT #144814) $item['changemessage'] = wfMsg("oasis-latest-activity-{$change['type']}-details", $item['user_href'], $item['time_ago']); } $item['changeicon'] = $change['type']; break; default: // show just a timestamp $item['changemessage'] = $item['time_ago']; break; } $changeList[] = $item; } $this->changeList = $changeList; if (empty($this->userName)) { $wgMemc->set($mKeyTimes, $this->changeList, 60); } } // Cache the response in CDN and browser $this->response->setCacheValidity(600); wfProfileOut(__METHOD__); }
/** * @desc Returns an array with correct elements from given api results * * @param array $postData results from API call with request of posts (articles) list in a category * * @return array */ private function prepareCssUpdateData($postData) { $cssUpdatePost = []; $communityWikiId = WikiFactory::DBtoID($this->getCommunityDbName()); $blogTitle = GlobalTitle::newFromText($postData['title'], NS_MAIN, $communityWikiId); $blogTitleText = $blogTitle->getText(); $lastRevisionUser = isset($postData['revisions'][0]['user']) ? $postData['revisions'][0]['user'] : null; $timestamp = isset($postData['revisions'][0]['timestamp']) ? $postData['revisions'][0]['timestamp'] : null; $blogUser = $this->getUserFromTitleText($blogTitleText, $lastRevisionUser); $userPage = GlobalTitle::newFromText($blogUser, NS_USER, $communityWikiId); if (!is_null($lastRevisionUser) && !is_null($timestamp) && $blogTitle instanceof GlobalTitle && $userPage instanceof GlobalTitle) { // $postData['revisions'][0]['*'] is being checked in SpecialCssModel::filterRevisionsData() // which is called before this method $sectionText = $postData['revisions'][0]['*']; $cssUpdateText = $this->truncateAndParseLinks($this->getCssUpdateSection($sectionText)); $cssUpdatePost = ['title' => $this->getAfterLastSlashText($blogTitleText), 'url' => $this->appendHeadlineAnchor($blogTitle->getFullURL()), 'userAvatar' => AvatarService::renderAvatar($blogUser, 25), 'userUrl' => $userPage->getFullUrl(), 'userName' => $blogUser, 'timestamp' => $timestamp, 'text' => $cssUpdateText]; } return $cssUpdatePost; }
?> "> <?php if ($loggedIn) { echo $userName; } else { echo wfMessage('userlogin-login-heading')->text(); } ?> </header> <?php if ($loggedIn) { ?> <ul class=wkLst> <li><a class=chg href="<?php echo Sanitizer::encodeAttribute(AvatarService::getUrl($userName)); ?> "><?php echo wfMessage('wikiamobile-profile')->escaped(); ?> </a></li> <li><a class=logout href="<?php echo Sanitizer::encodeAttribute(str_replace("\$1", SpecialPage::getSafeTitleFor('UserLogout')->getPrefixedText() . '?returnto=' . $wg->Title->getPrefixedURL(), $wg->ArticlePath)); ?> "><?php echo wfMessage('logout')->escaped(); ?> </a></li> </ul> <?php }
?> <section class="WallHistoryRail module"> <h2><?php echo wfMessage('wall-history-who-involved-wall-title')->escaped(); ?> </h2> <ul> <?php foreach ($usersInvolved as $userInvolved) { ?> <li> <a href="<?php echo $userInvolved['userpage']; ?> " class="avatar"><?php echo AvatarService::renderAvatar($userInvolved['username'], 30); ?> </a> <span class="names"> <a href="<?php echo $userInvolved['userpage']; ?> "> <?php echo $userInvolved['name1']; ?> </a> <?php if (!empty($userInvolved['name2'])) { ?> <a class='realname' href="<?php
protected function getUserDataForArticles($articles, $revisions) { $ids = !is_array($articles) ? [$articles] : $articles; $result = []; foreach ($revisions as $rev) { $userIds[$rev['rev_page']] = $rev['rev_user']; } if (!empty($userIds)) { $users = (new UserService())->getUsers($userIds); foreach ($users as $user) { $userData[$user->getId()] = ['avatar' => AvatarService::getAvatarUrl($user->getName(), self::DEFAULT_AVATAR_SIZE), 'name' => $user->getName()]; } } foreach ($ids as $pageId) { if (isset($userIds[$pageId]) && isset($userData[$userIds[$pageId]])) { $result[$pageId] = $userData[$userIds[$pageId]]; } else { $result[$pageId] = ['avatar' => null, 'name' => null]; } } return $result; }
/** * getData -- return raw data for displaying commentList * * @access public * * @return array data for comments list */ public function getData($page = 1) { global $wgUser, $wgTitle, $wgStylePath; $groups = $wgUser->getEffectiveGroups(); //$isSysop = in_array('sysop', $groups) || in_array('staff', $groups); $canEdit = $wgUser->isAllowed('edit'); $isBlocked = $wgUser->isBlocked(); $isReadOnly = wfReadOnly(); //$showall = $wgRequest->getText( 'showall', false ); //default to using slave. comments are posted with ajax which hits master db //$commentList = $this->getCommentList(false); $countComments = $this->getCountAll(); $countCommentsNested = $this->getCountAllNested(); $countPages = ceil($countComments / $this->mMaxPerPage); $pageRequest = (int) $page; $page = 1; if ($pageRequest <= $countPages && $pageRequest > 0) { $page = $pageRequest; } $comments = $this->getCommentPages(false, $page); $pagination = $this->doPagination($countComments, count($comments), $page); $commentListHTML = ''; if (!empty($wgTitle)) { $commentListHTML = F::app()->getView('ArticleComments', 'CommentList', array('commentListRaw' => $comments, 'page' => $page, 'useMaster' => false))->render(); } $commentingAllowed = true; if (defined('NS_BLOG_ARTICLE') && $wgTitle && $wgTitle->getNamespace() == NS_BLOG_ARTICLE) { $props = BlogArticle::getProps($wgTitle->getArticleID()); $commentingAllowed = isset($props['commenting']) ? (bool) $props['commenting'] : true; } $retVal = array('avatar' => AvatarService::renderAvatar($wgUser->getName(), 50), 'userurl' => AvatarService::getUrl($wgUser->getName()), 'canEdit' => $canEdit, 'commentListRaw' => $comments, 'commentListHTML' => $commentListHTML, 'commentingAllowed' => $commentingAllowed, 'commentsPerPage' => $this->mMaxPerPage, 'countComments' => $countComments, 'countCommentsNested' => $countCommentsNested, 'isAnon' => $wgUser->isAnon(), 'isBlocked' => $isBlocked, 'isFBConnectionProblem' => ArticleCommentInit::isFbConnectionNeeded(), 'isReadOnly' => $isReadOnly, 'page' => $page, 'pagination' => $pagination, 'reason' => $isBlocked ? $this->blockedPage() : '', 'stylePath' => $wgStylePath, 'title' => $wgTitle); return $retVal; }
<?php if ($showModule) { ?> <section class="module WikiaActivityModule ForumActivityModule"> <h1><?php echo wfMsg('forum-related-module-heading'); ?> </h1> <ul> <?php foreach ($messages as $message) { ?> <li> <?php echo AvatarService::renderAvatar($message['message']->getUser()->getName(), 20); ?> <em> <a href="<?php echo $message['message']->getMessagePageUrl(); ?> "><?php echo $message['message']->getMetaTitle(); ?> </a> </em> <div class="edited-by"> <?php $messageLast = empty($message['reply']) ? $message['message'] : $message['reply']; ?>