/** * axSave -- static hook/entry for ajax request save comment * * @static * @access public * * @return String -- json-ized array */ public static function axSave() { global $wgRequest, $wgUser; $articleId = $wgRequest->getVal('article', false); $commentId = $wgRequest->getVal('id', false); $parentId = $wgRequest->getVal('parentId', 0); $result = array('error' => 1); $title = Title::newFromID($articleId); if (!$title) { return $result; } if (!ArticleComment::canComment()) { return $result; } $comment = ArticleComment::newFromId($commentId); if ($comment) { $comment->load(true); if ($comment->canEdit()) { $text = self::getConvertedContent($wgRequest->getVal('wpArticleComment')); $commentId = $wgRequest->getText('id', false); $response = $comment->doSaveComment($text, $wgUser, $title, $commentId); if ($response !== false) { $status = $response[0]; $article = $response[1]; return ArticleComment::doAfterPost($status, $article, $parentId); } } } return $result; }
/** * axSave -- static hook/entry for ajax request save comment * * @static * @access public * * @return String -- json-ized array */ public static function axSave() { global $wgRequest, $wgUser; $articleId = $wgRequest->getVal('article', false); $commentId = $wgRequest->getVal('id', false); $parentId = $wgRequest->getVal('parentId', 0); $result = array('error' => 1); $title = Title::newFromID($articleId); if (!$title) { return $result; } $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 (!$commentingAllowed) { return $result; } $comment = ArticleComment::newFromId($commentId); if ($comment) { $comment->load(true); if ($comment->canEdit()) { $text = self::getConvertedContent($wgRequest->getVal('wpArticleComment')); $commentId = $wgRequest->getText('id', false); $response = $comment->doSaveComment($text, $wgUser, $title, $commentId); if ($response !== false) { $status = $response[0]; $article = $response[1]; return ArticleComment::doAfterPost($status, $article, $parentId); } } } return $result; }
/** * doPost -- static hook/entry for normal request post * * @static * @access public * * @param WebRequest $request -- instance of WebRequest * @param User $user -- instance of User who is leaving the comment * @param Title $title -- instance of Title * * @return Article -- newly created article */ public static function doPost($text, $user, $title, $parentId = false, $metadata = array()) { global $wgTitle; wfProfileIn(__METHOD__); if (!$text || !strlen($text)) { wfProfileOut(__METHOD__); return false; } if (wfReadOnly()) { wfProfileOut(__METHOD__); return false; } /** * title for comment is combination of article title and some 'random' data */ if ($parentId == false) { //1st level comment $commentTitle = sprintf('%s/%s%s-%s', $title->getText(), ARTICLECOMMENT_PREFIX, $user->getName(), wfTimestampNow()); } else { $parentArticle = Article::newFromID($parentId); if (empty($parentArticle)) { $parentTitle = Title::newFromID($parentId, Title::GAID_FOR_UPDATE); // it's possible for Title to be empty at this point // if article was removed in the meantime // (for eg. when replying on Wall from old browser session // to non-existing thread) // it's fine NOT to create Article in that case if (!empty($parentTitle)) { $parentArticle = new Article($parentTitle); } // if $parentTitle is empty the logging below will be executed } //FB#2875 (log data for further debugging) if (is_null($parentArticle)) { $debugTitle = !empty($title) ? $title->getText() : '--EMPTY--'; // BugId:2646 Wikia::log(__FUNCTION__, __LINE__, "Failed to create Article object, ID={$parentId}, title={$debugTitle}, user={$user->getName()}", true); wfProfileOut(__METHOD__); return false; } $parentTitle = $parentArticle->getTitle(); //nested comment $commentTitle = sprintf('%s/%s%s-%s', $parentTitle->getText(), ARTICLECOMMENT_PREFIX, $user->getName(), wfTimestampNow()); } $commentTitle = Title::newFromText($commentTitle, MWNamespace::getTalk($title->getNamespace())); /** * because we save different tile via Ajax request TODO: fix it !! */ $wgTitle = $commentTitle; if (!$commentTitle instanceof Title) { return false; } /** * add article using EditPage class (for hooks) */ $article = new Article($commentTitle, 0); $retval = self::doSaveAsArticle($text, $article, $user, $metadata); // add comment to database if ($retval->value == EditPage::AS_SUCCESS_NEW_ARTICLE) { $revId = $article->getRevIdFetched(); $data = array('namespace' => $title->getNamespace(), 'parentPageId' => $title->getArticleID(), 'commentId' => $article->getID(), 'parentCommentId' => intval($parentId), 'firstRevId' => $revId, 'lastRevId' => $revId); /** * @var $commentsIndex CommentsIndex */ $commentsIndex = F::build('CommentsIndex', array($data)); $commentsIndex->addToDatabase(); // set last child comment id $commentsIndex->updateParentLastCommentId($data['commentId']); wfRunHooks('EditCommentsIndex', array($article->getTitle(), $commentsIndex)); } $res = ArticleComment::doAfterPost($retval, $article, $parentId); ArticleComment::doPurge($title, $commentTitle); wfProfileOut(__METHOD__); return array($retval, $article, $res); }