/** * axEdit -- static hook/entry for ajax request post -- edit comment * * @static * @access public * * @return String -- html -> textarea */ public static function axEdit() { global $wgRequest; $articleId = $wgRequest->getVal('article', false); $commentId = $wgRequest->getVal('id', false); $result = array('error' => 1, 'id' => $commentId, 'show' => false, 'text' => ''); /** * check owner of article */ $title = Title::newFromID($articleId); if (!$title) { return $result; } /** * edit comment */ $comment = ArticleComment::newFromId($commentId); if ($comment) { $comment->load(true); if ($comment->canEdit()) { $result['error'] = 0; $result['show'] = true; $result['text'] = $comment->editPage(); if (ArticleComment::isMiniEditorEnabled()) { $result['edgeCases'] = MiniEditorHelper::getEdgeCases(); } $result['emptyMsg'] = wfMsg('article-comments-empty-comment', $comment->getTitle()->getLocalUrl('redirect=no&action=delete')); } } return $result; }
/** * Hook * * @param RecentChange $oRC -- instance of RecentChange class * * @static * @access public * * @return Bool true -- because it's a hook */ public static function watchlistNotify(RecentChange &$oRC) { global $wgEnableGroupedArticleCommentsRC; wfProfileIn(__METHOD__); wfRunHooks('AC_RecentChange_Save', array(&$oRC)); if (!empty($wgEnableGroupedArticleCommentsRC) && $oRC instanceof RecentChange) { $title = $oRC->getAttribute('rc_title'); $namespace = $oRC->getAttribute('rc_namespace'); $article_id = $oRC->getAttribute('rc_cur_id'); $title = Title::newFromText($title, $namespace); //TODO: review if (MWNamespace::isTalk($namespace) && ArticleComment::isTitleComment($title) && !empty($article_id)) { $comment = ArticleComment::newFromId($article_id); if ($comment instanceof ArticleComment) { $oArticlePage = $comment->getArticleTitle(); $mAttribs = $oRC->mAttribs; $mAttribs['rc_title'] = $oArticlePage->getDBkey(); $mAttribs['rc_namespace'] = $oArticlePage->getNamespace(); $mAttribs['rc_log_action'] = 'article_comment'; $oRC->setAttribs($mAttribs); } } } wfProfileOut(__METHOD__); return true; }
/** * @static * @param $body * @param $page * @param $user * @param string $metaTitle * @param bool|WallMessage $parent * @param array $relatedTopics * @param bool $notify * @param bool $notifyEveryone * @return WallMessage|Bool */ public static function buildNewMessageAndPost($body, $page, $user, $metaTitle = '', $parent = false, $relatedTopics = array(), $notify = true, $notifyEveryone = false) { wfProfileIn(__METHOD__); if ($page instanceof Title) { $userPageTitle = $page; } else { $userPageTitle = F::build('Title', array($page, NS_USER_WALL), 'newFromText'); } // create wall page by bot if not exist if (!$userPageTitle->exists()) { $userPageTitle = self::addMessageWall($userPageTitle); } if (empty($userPageTitle)) { wfProfileOut(__METHOD__); return false; } if ($parent === false) { $metaData = array('title' => $metaTitle); if ($notifyEveryone) { $metaData['notify_everyone'] = time(); } if (!empty($relatedTopics)) { $metaData['related_topics'] = implode('|', $relatedTopics); } $acStatus = F::build('ArticleComment', array($body, $user, $userPageTitle, false, $metaData), 'doPost'); } else { if (!$parent->canReply()) { wfProfileOut(__METHOD__); return false; } $acStatus = F::build('ArticleComment', array($body, $user, $userPageTitle, $parent->getTitle()->getArticleId(), null), 'doPost'); } if ($acStatus === false) { wfProfileOut(__METHOD__); return false; } $ac = ArticleComment::newFromId($acStatus[1]->getId()); if (empty($ac)) { wfProfileOut(__METHOD__); return false; } // after successful posting invalidate Wall cache /** * @var $class WallMessage */ $class = F::build('WallMessage', array($ac->getTitle(), $ac)); if ($parent === false) { //$db = DB_SLAVE $class->storeRelatedTopicsInDB($relatedTopics); $class->setOrderId(1); $class->getWall()->invalidateCache(); } else { $count = $parent->getOrderId(true); //this is not work perfect with transations if (is_numeric($count)) { $count++; $parent->setOrderId($count); $class->setOrderId($count); } // after successful posting invalidate Thread cache $class->getThread()->invalidateCache(); } //Build data for sweet url ? id#number_of_comment //notify if ($notify) { $class->sendNotificationAboutLastRev(); } if ($parent === false && $notifyEveryone) { $class->notifyEveryone(); } $class->addWatch($user); wfRunHooks('AfterBuildNewMessageAndPost', array(&$class)); wfProfileOut(__METHOD__); return $class; }
public function getQueryWhere($dbr) { wfProfileIn(__METHOD__); $like = "page_title" . $dbr->buildLike(sprintf("%s/%s", $this->mText, ARTICLECOMMENT_PREFIX), $dbr->anyString()); $namspace = MWNamespace::getTalk($this->getTitle()->getNamespace()); if (empty($this->mCommentId)) { wfProfileOut(__METHOD__); return array($like, 'page_namespace' => $namspace); } $ac = ArticleComment::newFromId($this->mCommentId); $parent = $ac->getTopParent(); $title = $ac->getTitle(); if (empty($parent) && !empty($title)) { $parent = $title->getDBkey(); } $like = "page_title" . $dbr->buildLike($parent, $dbr->anyString()); wfProfileOut(__METHOD__); return array($like, 'page_namespace' => $namspace); }
/** * Generate comment item object from comment article id * * @param integer $articleId * @return null|mixed */ private function getComment($articleId) { $articleComment = ArticleComment::newFromId($articleId); if (!$articleComment instanceof ArticleComment) { return null; } $commentData = $articleComment->getData(); // According to `extensions/wikia/ArticleComments/classes/ArticleComment.class.php:179` // no revision data means that the comment should be ignored if ($commentData === false) { return null; } return ['id' => $commentData['id'], 'text' => $commentData['text'], 'created' => (int) wfTimestamp(TS_UNIX, $commentData['rawmwtimestamp']), 'userName' => $this->addUser($commentData)]; }