From 72bdb334e0ba313c969531055ac69dc2e83852b6 Mon Sep 17 00:00:00 2001 From: Antoine Musso Date: Wed, 28 Apr 2004 04:37:31 +0000 Subject: [PATCH] +add the "comments" field to rss feeds +Atom support ! --- includes/Feed.php | 64 ++++++++++++++++++++++++++++--- includes/QueryPage.php | 23 +++++++++-- includes/SpecialRecentchanges.php | 4 +- languages/Language.php | 1 + languages/LanguageFr.php | 1 + templates/xhtml_slim.pt | 2 +- 6 files changed, 85 insertions(+), 10 deletions(-) diff --git a/includes/Feed.php b/includes/Feed.php index fce93e3eea..9a7198adad 100644 --- a/includes/Feed.php +++ b/includes/Feed.php @@ -21,7 +21,7 @@ $wgFeedClasses = array( "rss" => "RSSFeed", - # "atom" => "AtomFeed", + "atom" => "AtomFeed", ); class FeedItem { @@ -31,12 +31,13 @@ class FeedItem { var $Date = ""; var $Author = ""; - function FeedItem( $Title, $Description, $Url, $Date = "", $Author = "" ) { + function FeedItem( $Title, $Description, $Url, $Date = "", $Author = "", $Comments = "" ) { $this->Title = $Title; $this->Description = $Description; $this->Url = $Url; $this->Date = $Date; $this->Author = $Author; + $this->Comments = $Comments; } /* Static... */ @@ -67,6 +68,9 @@ class FeedItem { function getAuthor() { return $this->xmlEncode( $this->Author ); } + function getComments() { + return $this->xmlEncode( $this->Comments ); + } } class ChannelFeed extends FeedItem { @@ -83,9 +87,9 @@ class ChannelFeed extends FeedItem { } class RSSFeed extends ChannelFeed { + function formatTime( $ts ) { - // need to use RFC 822 time format - return gmdate( "r", wfTimestamp2Unix( $ts ) ); + return gmdate( "D, d M Y H:i:s \G\M\T", wfTimestamp2Unix( $ts ) ); } function outHeader() { @@ -116,7 +120,7 @@ class RSSFeed extends ChannelFeed { getDescription() ?> getDate() ) { ?>formatTime( $item->getDate() ) ?> getAuthor() ) { ?>getAuthor() ?> - + getComments() ) { ?>getComments() ?> disable(); + header( "Content-type: application/xml; charset=UTF-8" ); + $wgOut->sendCacheControl(); + + print '<' . '?xml version="1.0" encoding="utf-8"?' . ">\n"; + ?>getLanguage() ?>"> + <?php print $this->getTitle() ?> + + formatTime( wfTimestampNow() ) ?>Z + getDescription() ?> + MediaWiki + + + + <?php print $item->getTitle() ?> + + getDate() ) { ?> + formatTime( $item->getDate() ) ?>Z + formatTime( $item->getDate() ) ?> + formatTime( $item->getDate() ) ?>Z + + getDescription() ?> + getAuthor() ) { ?>getAuthor() ?> + foobar + + +getComments() ) { ?>getComments() ?> + */ + } + + function outFooter() {?> + \ No newline at end of file diff --git a/includes/QueryPage.php b/includes/QueryPage.php index b7901adb93..b24826ff8f 100644 --- a/includes/QueryPage.php +++ b/includes/QueryPage.php @@ -98,8 +98,8 @@ class QueryPage { function doFeed( $class = "" ) { global $wgFeedClasses; global $wgOut, $wgLanguageCode, $wgLang; - if( $class == "rss" ) { - $feed = new RSSFeed( + if( isset($wgFeedClasses[$class]) ) { + $feed = new $wgFeedClasses[$class]( $this->feedTitle(), $this->feedDesc(), $this->feedUrl() ); @@ -140,12 +140,23 @@ class QueryPage { } elseif( isset( $row->rc_cur_timestamp ) ) { $date = $row->rc_cur_timestamp; } + + $comments = ""; + if( isset( $row->cur_comment ) ) { + $comments = $row->cur_comment; + } elseif( isset( $row->old_comment ) ) { + $comments = $row->old_comment; + } elseif( isset( $row->rc_cur_comment ) ) { + $comments = $row->rc_cur_comment; + } + return new FeedItem( $title->getText(), $this->feedItemDesc( $row ), $title->getFullURL(), $date, - $this->feedItemAuthor( $row ) ); + $this->feedItemAuthor( $row ), + $comments); } else { return NULL; } @@ -170,10 +181,16 @@ class QueryPage { } function feedItemAuthor( $row ) { + /* old code $fields = array( "cur_user_text", "old_user_text", "rc_user_text" ); foreach( $fields as $field ) { if( isset( $row->$field ) ) return $row->field; } + + new code follow, that's an ugly hack to fix things: */ + if( isset( $row->cur_user_text ) ) return $row->cur_user_text; + if( isset( $row->old_user_text ) ) return $row->old_user_text; + if( isset( $row->rc_user_text ) ) return $row->rc_user_text; return ""; } diff --git a/includes/SpecialRecentchanges.php b/includes/SpecialRecentchanges.php index 2fa0bb91d2..934ffe5d19 100644 --- a/includes/SpecialRecentchanges.php +++ b/includes/SpecialRecentchanges.php @@ -134,7 +134,9 @@ function wfSpecialRecentchanges( $par ) htmlspecialchars( $obj->rc_comment ), $title->getFullURL(), $obj->rc_timestamp, - $obj->rc_user_text ); + $obj->rc_user_text, + htmlspecialchars( $obj->rc_comment ) + ); $feed->outItem( $item ); } $feed->outFooter(); diff --git a/languages/Language.php b/languages/Language.php index 3c787b17fe..d170f9faed 100644 --- a/languages/Language.php +++ b/languages/Language.php @@ -1515,6 +1515,7 @@ amusement.", 'accesskey-emailuser' => '', # tooltip help for the main actions +'tooltip-atom' => 'Atom feed for this page', 'tooltip-article' => 'View the article [alt-a]', 'tooltip-talk' => 'Discussion about the article [alt-t]', 'tooltip-edit' => 'You can edit this page. Please use the preview button before saving. [alt-e]', diff --git a/languages/LanguageFr.php b/languages/LanguageFr.php index 8558dcdea8..482b04e1d4 100644 --- a/languages/LanguageFr.php +++ b/languages/LanguageFr.php @@ -1097,6 +1097,7 @@ sous le nouveau nom. S'il vous plait, fusionnez les manuellement.", 'tooltip-anontalk' => 'Discussion des éditions faites à partir de cette adresse ip [alt-n]', 'tooltip-anonuserpage' => 'La page d\'utilisateur pour l\'adresse ip depuis laquelle vous éditez [alt-.]', 'tooltip-article' => 'Voir l\'article [alt-a]', +'tooltip-atom' => 'Flux Atom pour cette page', 'tooltip-contributions' => 'Voir la liste des contributions de cet utilisateur', 'tooltip-currentevents' => 'Trouver des informations sur les évenements actuels', 'tooltip-delete' => 'Supprimer cette page [alt-d]', diff --git a/templates/xhtml_slim.pt b/templates/xhtml_slim.pt index 3dbfe84b06..d0d1c9d333 100644 --- a/templates/xhtml_slim.pt +++ b/templates/xhtml_slim.pt @@ -146,7 +146,7 @@ rss + tal:content="feed/text">rss