public function execute() { global $wgUser; // Before doing anything at all, let's check permissions if (!$wgUser->isAllowed('codereview-use')) { $this->dieUsage('You don\'t have permission to update code', 'permissiondenied'); } $params = $this->extractRequestParams(); if ($params['comment'] && !$wgUser->isAllowed('codereview-post-comment')) { $this->dieUsage('You do not have permission to post comment', 'permissiondenied'); } global $wgCodeReviewInlineComments; if (!$wgCodeReviewInlineComments && isset($params['patchline'])) { $this->dieUsageMsg("Can not attach a comment to a diff when inline commenting is disabled (\$wgCodeReviewInlineComments is false)."); } $repo = CodeRepository::newFromName($params['repo']); if (!$repo) { $this->dieUsage("Invalid repo ``{$params['repo']}''", 'invalidrepo'); } $rev = $repo->getRevision($params['rev']); if (!$rev) { $this->dieUsage("There is no revision with ID {$params['rev']}", 'nosuchrev'); } $revisionCommitter = new CodeRevisionCommitterApi($repo, $rev); $commentID = $revisionCommitter->revisionUpdate($params['status'], $params['addtags'], $params['removetags'], $params['addflags'], $params['removeflags'], $params['addreferences'], $params['removereferences'], $params['comment'], $params['addreferenced'], $params['removereferenced']); // Forge a response object $r = array('result' => 'Success'); if ($commentID !== 0) { // id inserted $r['commentid'] = intval($commentID); // HTML Formatted comment $view = new CodeRevisionView($repo, $rev); $comment = CodeComment::newFromID($commentID, $rev); $r['HTML'] = $view->formatComment($comment); } $this->getResult()->addValue(null, $this->getModuleName(), $r); }
/** * @param CodeComment $comment * @return string */ protected function commentStyle($comment) { $align = wfUILang()->AlignStart(); $depth = $comment->threadDepth(); $margin = ($depth - 1) * 48; return "margin-{$align}: {$margin}px"; }
/** * @return array */ public function getComments() { $dbr = wfGetDB(DB_SLAVE); $result = $dbr->select('code_comment', array('cc_id', 'cc_text', 'cc_user', 'cc_user_text', 'cc_timestamp', 'cc_sortkey'), array('cc_repo_id' => $this->repoId, 'cc_rev_id' => $this->id), __METHOD__, array('ORDER BY' => 'cc_sortkey')); $comments = array(); foreach ($result as $row) { $comments[] = CodeComment::newFromRow($this, $row); } return $comments; }