Put diffs into the RecentChanges RSS/Atom feed to make it more useful for offline...
authorBrion Vibber <brion@users.mediawiki.org>
Sat, 9 Oct 2004 02:55:32 +0000 (02:55 +0000)
committerBrion Vibber <brion@users.mediawiki.org>
Sat, 9 Oct 2004 02:55:32 +0000 (02:55 +0000)
Probably will want to do caching of diffs before pushing this one out the door, but it's not as bad as all that; nothing has to be parsed, just diffed.

includes/SpecialRecentchanges.php

index 4d468a7..d227aa0 100644 (file)
@@ -135,7 +135,7 @@ function wfSpecialRecentchanges( $par ) {
                        $talkpage = $title->getTalkPage();
                        $item = new FeedItem(
                                $title->getPrefixedText(),
-                               htmlspecialchars( $obj->rc_comment ),
+                               rcFormatDiff( $obj ),
                                $title->getFullURL(),
                                $obj->rc_timestamp,
                                $obj->rc_user_text,
@@ -226,4 +226,45 @@ function rcLimitLinks( $page='Recentchanges', $more='', $doall = false ) {
        return $note;
 }
 
+function rcFormatDiff( $row ) {
+       require_once( 'DifferenceEngine.php' );
+       $comment = "<p>" . htmlspecialchars( $row->rc_comment ) . "</p>\n";
+       
+       if( $row->rc_namespace >= 0 ) {
+               global $wgContLang;
+               
+               #$diff =& new DifferenceEngine( $row->rc_this_oldid, $row->rc_last_oldid, $row->rc_id );
+               #$diff->showDiffPage();
+               
+               $dbr =& wfGetDB( DB_SLAVE );
+               if( $row->rc_this_oldid ) {
+                       $newrow = $dbr->selectRow( 'old',
+                               array( 'old_flags', 'old_text' ),
+                               array( 'old_id' => $row->rc_this_oldid ) );
+                       $newtext = Article::getRevisionText( $newrow );
+               } else {
+                       $newrow = $dbr->selectRow( 'cur',
+                               array( 'cur_text' ),
+                               array( 'cur_id' => $row->rc_cur_id ) );
+                       $newtext = $newrow->cur_text;
+               }
+               if( $row->rc_last_oldid ) {
+                       $oldrow = $dbr->selectRow( 'old',
+                               array( 'old_flags', 'old_text' ),
+                               array( 'old_id' => $row->rc_last_oldid ) );
+                       $oldtext = Article::getRevisionText( $oldrow );
+                       $diffText = DifferenceEngine::getDiff( $oldtext, $newtext,
+                         wfMsg( 'revisionasof', $wgContLang->timeanddate( $row->rc_timestamp ) ),
+                         wfMsg( 'currentrev' ) );
+               } else {
+                       $diffText = '<p><b>' . wfMsg( 'newpage' ) . '</b></p>' . 
+                               '<div>' . nl2br( htmlspecialchars( $newtext ) ) . '</div>';
+               }
+               
+               return $comment . $diffText;
+       }
+       
+       return $comment;        
+}
+
 ?>