Example #1
0
 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);
 }