/** * doSaveComment -- save comment * * @access public * * @param string $text * @param User $user * @param Title $title * @param int $commentId * @param bool $force * @param string $summary * @param bool $preserveMetadata : hack to fix bug 102384 (prevent metadata override when trying to modify one of metadata keys) * * @return Array|false TODO: Document what the array contains. */ public function doSaveComment($text, $user, $title = null, $commentId = 0, $force = false, $summary = '', $preserveMetadata = false) { global $wgTitle; wfProfileIn(__METHOD__); $metadata = $this->mMetadata; $this->load(true); if ($force || $this->canEdit()) { if (wfReadOnly()) { wfProfileOut(__METHOD__); return false; } if (!$text || !strlen($text)) { wfProfileOut(__METHOD__); return false; } if (empty($this->mTitle) && !$commentId) { wfProfileOut(__METHOD__); return false; } $commentTitle = $this->mTitle ? $this->mTitle : Title::newFromId($commentId); /** * because we save different title via Ajax request */ $origTitle = $wgTitle; $wgTitle = $commentTitle; /** * add article using EditPage class (for hooks) */ $article = new Article($commentTitle, intval($this->mLastRevId)); if ($preserveMetadata) { $this->mMetadata = $metadata; } $retval = self::doSaveAsArticle($text, $article, $user, $this->mMetadata, $summary); if (!empty($title)) { $purgeTarget = $title; } else { $purgeTarget = $origTitle; } ArticleCommentList::purgeCache($purgeTarget); $res = [$retval, $article]; } else { $res = false; } $this->mLastRevId = $this->mTitle->getLatestRevID(Title::GAID_FOR_UPDATE); $this->mLastRevision = Revision::newFromId($this->mLastRevId); wfProfileOut(__METHOD__); return $res; }