From 92d98413ceb0d7afee5fad0bd72650880546f638 Mon Sep 17 00:00:00 2001 From: Antoine Musso Date: Mon, 7 Nov 2011 16:12:37 +0000 Subject: [PATCH] bug 29110 - $wgFeedDiffCutoff doesn't affect new pages Patch by John Du Hart. Rewritten to avoid code duplication, duplicate code is now in a helper function. --- RELEASE-NOTES-1.19 | 1 + includes/FeedUtils.php | 43 ++++++++++++++++++++++++++++++------------ 2 files changed, 32 insertions(+), 12 deletions(-) diff --git a/RELEASE-NOTES-1.19 b/RELEASE-NOTES-1.19 index a434b7f480..9b8696fed2 100644 --- a/RELEASE-NOTES-1.19 +++ b/RELEASE-NOTES-1.19 @@ -128,6 +128,7 @@ production. * (bug 26020) Setting $wgEmailConfirmToEdit to true no longer removes diffs from recent changes feeds * (bug 30232) add current time to message wlnote on Special:Watchlist +* (bug 29110) $wgFeedDiffCutoff did not affect new pages === API changes in 1.19 === * (bug 19838) siprop=interwikimap can now use the interwiki cache. diff --git a/includes/FeedUtils.php b/includes/FeedUtils.php index 140881862c..a8a86ba1bd 100644 --- a/includes/FeedUtils.php +++ b/includes/FeedUtils.php @@ -102,7 +102,7 @@ class FeedUtils { $anon = new User(); $accErrors = $title->getUserPermissionsErrors( 'read', $anon, true ); - # Early exist when the page is not an article, on errors and now newid to + # Early exist when the page is not an article, on errors and no newid to # compare. if( $title->getNamespace() < 0 || $accErrors || !$newid ) { wfProfileOut( __METHOD__ ); @@ -131,14 +131,7 @@ class FeedUtils { if ( $wgFeedDiffCutoff <= 0 || ( strlen( $diffText ) > $wgFeedDiffCutoff ) ) { // Omit large diffs - $diffLink = $title->escapeFullUrl( - 'diff=' . $newid . - '&oldid=' . $oldid ); - $diffText = '' . - htmlspecialchars( wfMsgForContent( 'showdiff' ) ) . - ''; + $diffText = self::getDiffText( $title, $newid, $oldid); } elseif ( $diffText === false ) { // Error in diff engine, probably a missing revision $diffText = "

Can't load revision $newid

"; @@ -150,13 +143,18 @@ class FeedUtils { wfProfileOut( __METHOD__."-dodiff" ); } else { $rev = Revision::newFromId( $newid ); - if( is_null( $rev ) ) { + if( $wgFeedDiffCutoff <= 0 || is_null( $rev ) ) { $newtext = ''; } else { $newtext = $rev->getText(); } - $diffText = '

' . wfMsg( 'newpage' ) . '

' . - '
' . nl2br( htmlspecialchars( $newtext ) ) . '
'; + if ( $wgFeedDiffCutoff <= 0 || strlen( $newtext ) > $wgFeedDiffCutoff ) { + // Omit large new page diffs, bug 29110 + $diffText = self::getDiffText( $title, $newid ); + } else { + $diffText = '

' . wfMsg( 'newpage' ) . '

' . + '
' . nl2br( htmlspecialchars( $newtext ) ) . '
'; + } } $completeText .= $diffText; @@ -164,6 +162,27 @@ class FeedUtils { return $completeText; } + /** + * Generates a diff link. Used when the full diff is not wanted for example + * when $wgFeedDiffCutoff is 0. + * + * @param $title Title object: used to generate the diff URL + * @param $newid Integer newid for this diff + * @param $oldid Integer|null oldid for the diff. Null means it is a new article + */ + protected static function getDiffText( Title $title, $newid, $oldid = null ) { + $queryParameters = ($oldid == null) + ? "diff={$newid}" + : "diff={$newid}&oldid={$oldid}" ; + $diffLink = $title->escapeFullUrl( $queryParameters ); + + $diffText = Html::RawElement( 'a', array( 'href' => $diffLink ), + htmlspecialchars( wfMsgForContent( 'showdiff' ) ) + ); + + return $diffText; + } + /** * Hacky application of diff styles for the feeds. * Might be 'cleaner' to use DOM or XSLT or something, -- 2.20.1