Example #1
0
 public function execute()
 {
     global $wgUser, $wgCodeReviewMaxDiffSize;
     // Before doing anything at all, let's check permissions
     if (!$wgUser->isAllowed('codereview-use')) {
         $this->dieUsage('You don\'t have permission to view code diffs', 'permissiondenied');
     }
     $params = $this->extractRequestParams();
     $repo = CodeRepository::newFromName($params['repo']);
     if (!$repo) {
         $this->dieUsage("Invalid repo ``{$params['repo']}''", 'invalidrepo');
     }
     $lastStoredRev = $repo->getLastStoredRev();
     if ($params['rev'] > $lastStoredRev) {
         $this->dieUsage("There is no revision with ID {$params['rev']}", 'nosuchrev');
     }
     $diff = $repo->getDiff($params['rev']);
     if (!is_string($diff)) {
         // FIXME: Are we sure we don't want to throw an error here?
         $html = 'Failed to load diff. Error message: ' . CodeRepository::getDiffErrorMessage($diff);
     } elseif (strlen($diff) > $wgCodeReviewMaxDiffSize) {
         $html = 'Diff too large.';
     } else {
         $hilite = new CodeDiffHighlighter();
         $html = $hilite->render($diff);
     }
     $data = array('repo' => $params['repo'], 'id' => $params['rev'], 'diff' => $html);
     $this->getResult()->addValue('code', 'rev', $data);
 }
Example #2
0
 /**
  * @return string
  */
 protected function formatDiff()
 {
     global $wgEnableAPI, $wgCodeReviewMaxDiffSize;
     // Asynchronous diff loads will require the API
     // And JS in the client, but tough shit eh? ;)
     $deferDiffs = $wgEnableAPI;
     if ($this->mSkipCache) {
         // We're purging the cache on purpose, probably
         // because the cached data was corrupt.
         $cache = 'skipcache';
     } elseif ($deferDiffs) {
         // If data is already cached, we'll take it now;
         // otherwise defer the load to an AJAX request.
         // This lets the page be manipulable even if the
         // SVN connection is slow or uncooperative.
         $cache = 'cached';
     } else {
         $cache = '';
     }
     $diff = $this->mRepo->getDiff($this->mRev->getId(), $cache);
     if (is_integer($diff) && $deferDiffs) {
         // We'll try loading it by AJAX...
         return $this->stubDiffLoader();
     } elseif (strlen($diff) > $wgCodeReviewMaxDiffSize) {
         return htmlspecialchars(wfMsg('code-rev-diff-too-large'));
     } else {
         $hilite = new CodeDiffHighlighter();
         return $hilite->render($diff);
     }
 }
Example #3
0
 /**
  * @dataProvider provideUnifiedDiffChunksDelimiters
  */
 function testParseChunkDelimiters($expected, $delimiter)
 {
     $this->assertEquals($expected, CodeDiffHighlighter::parseChunkDelimiter($delimiter));
 }