r102295 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r102294‎ | r102295 | r102296 >
Date:16:12, 7 November 2011
Author:hashar
Status:ok (Comments)
Tags:
Comment:
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.
Modified paths:
  • /trunk/phase3/RELEASE-NOTES-1.19 (modified) (history)
  • /trunk/phase3/includes/FeedUtils.php (modified) (history)

Diff [purge]

Index: trunk/phase3/RELEASE-NOTES-1.19
@@ -128,6 +128,7 @@
129129 * (bug 26020) Setting $wgEmailConfirmToEdit to true no longer removes diffs
130130 from recent changes feeds
131131 * (bug 30232) add current time to message wlnote on Special:Watchlist
 132+* (bug 29110) $wgFeedDiffCutoff did not affect new pages
132133
133134 === API changes in 1.19 ===
134135 * (bug 19838) siprop=interwikimap can now use the interwiki cache.
Index: trunk/phase3/includes/FeedUtils.php
@@ -102,7 +102,7 @@
103103 $anon = new User();
104104 $accErrors = $title->getUserPermissionsErrors( 'read', $anon, true );
105105
106 - # Early exist when the page is not an article, on errors and now newid to
 106+ # Early exist when the page is not an article, on errors and no newid to
107107 # compare.
108108 if( $title->getNamespace() < 0 || $accErrors || !$newid ) {
109109 wfProfileOut( __METHOD__ );
@@ -131,14 +131,7 @@
132132
133133 if ( $wgFeedDiffCutoff <= 0 || ( strlen( $diffText ) > $wgFeedDiffCutoff ) ) {
134134 // Omit large diffs
135 - $diffLink = $title->escapeFullUrl(
136 - 'diff=' . $newid .
137 - '&oldid=' . $oldid );
138 - $diffText = '<a href="' .
139 - $diffLink .
140 - '">' .
141 - htmlspecialchars( wfMsgForContent( 'showdiff' ) ) .
142 - '</a>';
 135+ $diffText = self::getDiffText( $title, $newid, $oldid);
143136 } elseif ( $diffText === false ) {
144137 // Error in diff engine, probably a missing revision
145138 $diffText = "<p>Can't load revision $newid</p>";
@@ -150,13 +143,18 @@
151144 wfProfileOut( __METHOD__."-dodiff" );
152145 } else {
153146 $rev = Revision::newFromId( $newid );
154 - if( is_null( $rev ) ) {
 147+ if( $wgFeedDiffCutoff <= 0 || is_null( $rev ) ) {
155148 $newtext = '';
156149 } else {
157150 $newtext = $rev->getText();
158151 }
159 - $diffText = '<p><b>' . wfMsg( 'newpage' ) . '</b></p>' .
160 - '<div>' . nl2br( htmlspecialchars( $newtext ) ) . '</div>';
 152+ if ( $wgFeedDiffCutoff <= 0 || strlen( $newtext ) > $wgFeedDiffCutoff ) {
 153+ // Omit large new page diffs, bug 29110
 154+ $diffText = self::getDiffText( $title, $newid );
 155+ } else {
 156+ $diffText = '<p><b>' . wfMsg( 'newpage' ) . '</b></p>' .
 157+ '<div>' . nl2br( htmlspecialchars( $newtext ) ) . '</div>';
 158+ }
161159 }
162160 $completeText .= $diffText;
163161
@@ -165,6 +163,27 @@
166164 }
167165
168166 /**
 167+ * Generates a diff link. Used when the full diff is not wanted for example
 168+ * when $wgFeedDiffCutoff is 0.
 169+ *
 170+ * @param $title Title object: used to generate the diff URL
 171+ * @param $newid Integer newid for this diff
 172+ * @param $oldid Integer|null oldid for the diff. Null means it is a new article
 173+ */
 174+ protected static function getDiffText( Title $title, $newid, $oldid = null ) {
 175+ $queryParameters = ($oldid == null)
 176+ ? "diff={$newid}"
 177+ : "diff={$newid}&oldid={$oldid}" ;
 178+ $diffLink = $title->escapeFullUrl( $queryParameters );
 179+
 180+ $diffText = Html::RawElement( 'a', array( 'href' => $diffLink ),
 181+ htmlspecialchars( wfMsgForContent( 'showdiff' ) )
 182+ );
 183+
 184+ return $diffText;
 185+ }
 186+
 187+ /**
169188 * Hacky application of diff styles for the feeds.
170189 * Might be 'cleaner' to use DOM or XSLT or something,
171190 * but *gack* it's a pain in the ass.

Follow-up revisions

RevisionCommit summaryAuthorDate
r105654Fixes for r102295:...tstarling05:54, 9 December 2011
r105662Fix for r102295 per CR r105654: don't double-escape the URLtstarling09:32, 9 December 2011

Comments

#Comment by Hashar (talk | contribs)   16:14, 7 November 2011

That is a really minor bug. I don't think it is worth a back port in 1.18.

Status & tagging log