Reedy has uploaded a new change for review. https://gerrit.wikimedia.org/r/78534
Change subject: Rework server side diff code ...................................................................... Rework server side diff code Prevents AJAX loading attempts if they are just going to fail anyway, or arne't ever going to have a diff (too many paths || nothing to compare) Add a couple of braces Change-Id: I2dd18b22ad9252cd143d04432e6ccb404afe92a3 --- M backend/CodeRepository.php M ui/CodeRevisionView.php 2 files changed, 31 insertions(+), 18 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/CodeReview refs/changes/34/78534/1 diff --git a/backend/CodeRepository.php b/backend/CodeRepository.php index 43607dc..cf03b04 100644 --- a/backend/CodeRepository.php +++ b/backend/CodeRepository.php @@ -564,8 +564,9 @@ * @return string|bool */ public function wikiUserAuthor( $name ) { - if ( isset( self::$authorLinks[$name] ) ) + if ( isset( self::$authorLinks[$name] ) ) { return self::$authorLinks[$name]; + } $dbr = wfGetDB( DB_SLAVE ); $res = $dbr->selectField( diff --git a/ui/CodeRevisionView.php b/ui/CodeRevisionView.php index 51da19b..01f4e41 100644 --- a/ui/CodeRevisionView.php +++ b/ui/CodeRevisionView.php @@ -172,16 +172,18 @@ # Output diff if ( $this->mRev->isDiffable() ) { $diffHtml = $this->formatDiff(); - // @todo FIXME: Hard coded brackets. - $html .= - "<h2>" . wfMessage( 'code-rev-diff' )->escaped() . - ' <small>[' . Linker::link( - $special, - wfMessage( 'code-rev-purge-link' )->escaped(), - array(), - array( 'action' => 'purge' ) - ) . ']</small></h2>' . - "<div class='mw-codereview-diff' id='mw-codereview-diff'>" . $diffHtml . "</div>\n"; + if ( $diffHtml !== '' ) { + // @todo FIXME: Hard coded brackets. + $html .= + "<h2>" . wfMessage( 'code-rev-diff' )->escaped() . + ' <small>[' . Linker::link( + $special, + wfMessage( 'code-rev-purge-link' )->escaped(), + array(), + array( 'action' => 'purge' ) + ) . ']</small></h2>' . + "<div class='mw-codereview-diff' id='mw-codereview-diff'>" . $diffHtml . "</div>\n"; + } $html .= $this->formatImgDiff(); } @@ -475,15 +477,25 @@ $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 ) { + + // If there isn't anything to diff, or if it's too large, don't AJAX load + if ( is_string( $diff ) && strlen( $diff ) > $wgCodeReviewMaxDiffSize ) { return wfMessage( 'code-rev-diff-too-large' )->escaped(); - } else { - $hilite = new CodeDiffHighlighter(); - return $hilite->render( $diff ); + } elseif ( is_integer( $diff ) + && in_array( $diff, + array( CodeRepository::DIFFRESULT_NothingToCompare, CodeRepository::DIFFRESULT_TooManyPaths ) + ) + ) { + // Some other error condition, no diff required + return ''; + } elseif ( $diff === CodeRepository::DIFFRESULT_NotInCache || $deferDiffs ) { + // Api Enabled || Not cached => Load via JS via API + return $this->stubDiffLoader(); } + + // CodeRepository::DIFFRESULT_NoDataReturned still ends up here, and we can't differentiate + $hilite = new CodeDiffHighlighter(); + return $hilite->render( $diff ); } /** -- To view, visit https://gerrit.wikimedia.org/r/78534 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I2dd18b22ad9252cd143d04432e6ccb404afe92a3 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/CodeReview Gerrit-Branch: master Gerrit-Owner: Reedy <re...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits