Index: trunk/extensions/CodeReview/CodeReview.i18n.php |
— | — | @@ -75,6 +75,7 @@ |
76 | 76 | 'code-rev-inline-preview' => 'Preview:', |
77 | 77 | 'code-rev-diff' => 'Diff', |
78 | 78 | 'code-rev-diff-link' => 'diff', |
| 79 | + 'code-rev-diff-too-large' => 'The diff is too large to display.', |
79 | 80 | 'code-rev-purge-link' => 'purge', |
80 | 81 | 'code-status-new' => 'new', |
81 | 82 | 'code-status-fixme' => 'fixme', |
Index: trunk/extensions/CodeReview/CodeReview.php |
— | — | @@ -140,6 +140,11 @@ |
141 | 141 | // Should match test runner's $wgParserTestRemote['secret']. |
142 | 142 | $wgCodeReviewSharedSecret = false; |
143 | 143 | |
| 144 | +/** |
| 145 | + * Maximum size of diff text before it is omitted from the revision view |
| 146 | + */ |
| 147 | +$wgCodeReviewMaxDiffSize = 500000; |
| 148 | + |
144 | 149 | # Schema changes |
145 | 150 | $wgHooks['LoadExtensionSchemaUpdates'][] = 'efCodeReviewSchemaUpdates'; |
146 | 151 | |
Index: trunk/extensions/CodeReview/api/ApiCodeDiff.php |
— | — | @@ -3,7 +3,7 @@ |
4 | 4 | class ApiCodeDiff extends ApiBase { |
5 | 5 | |
6 | 6 | public function execute() { |
7 | | - global $wgUser; |
| 7 | + global $wgUser, $wgCodeReviewMaxDiffSize; |
8 | 8 | // Before doing anything at all, let's check permissions |
9 | 9 | if( !$wgUser->isAllowed('codereview-use') ) { |
10 | 10 | $this->dieUsage('You don\'t have permission to view code diffs','permissiondenied'); |
— | — | @@ -31,12 +31,14 @@ |
32 | 32 | |
33 | 33 | $diff = $repo->getDiff( $params['rev'] ); |
34 | 34 | |
35 | | - if ( $diff ) { |
| 35 | + if ( strval( $diff ) === '' ) { |
| 36 | + // FIXME: Are we sure we don't want to throw an error here? |
| 37 | + $html = 'Failed to load diff.'; |
| 38 | + } elseif ( strlen( $diff ) > $wgCodeReviewMaxDiffSize ) { |
| 39 | + $html = 'Diff too large.'; |
| 40 | + } else { |
36 | 41 | $hilite = new CodeDiffHighlighter(); |
37 | 42 | $html = $hilite->render( $diff ); |
38 | | - } else { |
39 | | - // FIXME: Are we sure we don't want to throw an error here? |
40 | | - $html = 'Failed to load diff.'; |
41 | 43 | } |
42 | 44 | |
43 | 45 | $data = array( |
Index: trunk/extensions/CodeReview/ui/CodeRevisionView.php |
— | — | @@ -357,7 +357,7 @@ |
358 | 358 | } |
359 | 359 | |
360 | 360 | protected function formatDiff() { |
361 | | - global $wgEnableAPI; |
| 361 | + global $wgEnableAPI, $wgCodeReviewMaxDiffSize; |
362 | 362 | |
363 | 363 | // Asynchronous diff loads will require the API |
364 | 364 | // And JS in the client, but tough shit eh? ;) |
— | — | @@ -380,6 +380,8 @@ |
381 | 381 | if ( !$diff && $deferDiffs ) { |
382 | 382 | // We'll try loading it by AJAX... |
383 | 383 | return $this->stubDiffLoader(); |
| 384 | + } elseif ( strlen( $diff ) > $wgCodeReviewMaxDiffSize ) { |
| 385 | + return htmlspecialchars( wfMsg( 'code-rev-diff-too-large' ) ); |
384 | 386 | } else { |
385 | 387 | $hilite = new CodeDiffHighlighter(); |
386 | 388 | return $hilite->render( $diff ); |