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; }
/** * axPost -- static hook/entry for ajax request post * * @static * @access public * * @return String -- json-ized array` */ public static function axPost() { global $wgRequest, $wgUser, $wgLang; $articleId = $wgRequest->getVal('article', false); $parentId = $wgRequest->getVal('parentId'); $result = array('error' => 1); $title = Title::newFromID($articleId); if (!$title) { return $result; } if (!ArticleComment::canComment($title)) { return $result; } WikiaLogger::instance()->info(__METHOD__ . ' : Comment posted', ['skin' => $wgRequest->getVal('useskin'), 'articleId' => $articleId, 'parentId' => $parentId]); $response = ArticleComment::doPost(self::getConvertedContent($wgRequest->getVal('wpArticleComment')), $wgUser, $title, $parentId); if ($response !== false) { if ($title->getNamespace() == NS_USER_TALK && $response[0] == EditPage::AS_SUCCESS_NEW_ARTICLE && $title->getText() != $wgUser->getName()) { $user = User::newFromName($title->getText()); if ($user) { $user->setNewtalk(true); } } $listing = ArticleCommentList::newFromTitle($title); $countAll = $wgLang->formatNum($listing->getCountAllNested()); $commentsHTML = $response[2]['text']; $result = array('text' => $commentsHTML, 'counter' => $countAll); if (F::app()->checkskin('wikiamobile')) { $result['counterMessage'] = wfMessage('wikiamobile-article-comments-counter')->params($countAll)->text(); } if ($parentId) { $result['parentId'] = $parentId; } return $result; } return $result; }
/** * getData -- return raw data for displaying commentList * * @access public * * @return array data for comments list */ public function getData($page = 1) { global $wgUser, $wgStylePath; //$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); $this->preloadFirstRevId($comments); $pagination = $this->doPagination($countComments, count($comments), $page); return array('avatar' => AvatarService::renderAvatar($wgUser->getName(), 50), 'userurl' => AvatarService::getUrl($wgUser->getName()), 'canEdit' => $canEdit, 'commentListRaw' => $comments, 'commentingAllowed' => ArticleComment::canComment($this->mTitle), 'commentsPerPage' => $this->mMaxPerPage, 'countComments' => $countComments, 'countCommentsNested' => $countCommentsNested, 'isAnon' => $wgUser->isAnon(), 'isBlocked' => $isBlocked, 'isReadOnly' => $isReadOnly, 'page' => $page, 'pagination' => $pagination, 'reason' => $isBlocked ? $this->blockedPage() : '', 'stylePath' => $wgStylePath, 'title' => $this->mTitle); }