+add the "comments" field to rss feeds
authorAntoine Musso <hashar@users.mediawiki.org>
Wed, 28 Apr 2004 04:37:31 +0000 (04:37 +0000)
committerAntoine Musso <hashar@users.mediawiki.org>
Wed, 28 Apr 2004 04:37:31 +0000 (04:37 +0000)
+Atom support !

includes/Feed.php
includes/QueryPage.php
includes/SpecialRecentchanges.php
languages/Language.php
languages/LanguageFr.php
templates/xhtml_slim.pt

index fce93e3..9a7198a 100644 (file)
@@ -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 {
                        <description><?php print $item->getDescription() ?></description>
                        <?php if( $item->getDate() ) { ?><pubDate><?php print $this->formatTime( $item->getDate() ) ?></pubDate><?php } ?>
                        <?php if( $item->getAuthor() ) { ?><author><?php print $item->getAuthor() ?></author><?php }?>
-
+                       <?php if( $item->getComments() ) { ?><comments><?php print $item->getComments() ?></comments><?php }?>
                </item>
 <?php
        }
@@ -128,4 +132,54 @@ class RSSFeed extends ChannelFeed {
        }
 }
 
+class AtomFeed extends ChannelFeed {
+       function formatTime( $ts ) {
+               // need to use RFC 822 time format at least for rss2.0
+               return gmdate( "Y-m-d\TH:i:s", wfTimestamp2Unix( $ts ) );
+       }
+
+       function outHeader() {
+               global $wgVersion, $wgOut;
+               
+               # We take over from $wgOut, excepting its cache header info
+               $wgOut->disable();
+               header( "Content-type: application/xml; charset=UTF-8" );
+               $wgOut->sendCacheControl();
+               
+               print '<' . '?xml version="1.0" encoding="utf-8"?' . ">\n";
+               ?><feed version="0.3" xml:lang="<?php print $this->getLanguage()."-".$this->getLanguage() ?>">  
+               <title><?php print $this->getTitle() ?></title>
+               <link rel="alternate" type="text/html" href="<?php print $this->getUrl() ?>"/>
+               <modified><?php print $this->formatTime( wfTimestampNow() ) ?>Z</modified>
+               <tagline><?php print $this->getDescription() ?></tagline>
+               <generator>MediaWiki <?php print $wgVersion ?></generator>
+               
+<?php
+       }
+       
+       function outItem( $item ) {
+       ?>
+       <entry>
+               <title><?php print $item->getTitle() ?></title>
+               <link rel="alternate" type="text/html" href="<?php print $item->getUrl() ?>"/>
+               <?php if( $item->getDate() ) { ?>
+               <modified><?php print $this->formatTime( $item->getDate() ) ?>Z</modified>
+               <issued><?php print $this->formatTime( $item->getDate() ) ?></issued>
+               <created><?php print $this->formatTime( $item->getDate() ) ?>Z</created><?php } ?>
+       
+               <summary type="text/plain"><?php print $item->getDescription() ?></summary>
+               <?php if( $item->getAuthor() ) { ?><author><name><?php print $item->getAuthor() ?></name><url></url><email></email></author><?php }?>
+               <comment>foobar</comment>
+       </entry>
+
+<?php /* FIXME need to add comments
+       <?php if( $item->getComments() ) { ?><dc:comment><?php print $item->getComments() ?></dc:comment><?php }?>
+      */
+       }
+       
+       function outFooter() {?>
+       </feed><?php
+       }
+}
+
 ?>
\ No newline at end of file
index b7901ad..b24826f 100644 (file)
@@ -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 "";
        }
        
index 2fa0bb9..934ffe5 100644 (file)
@@ -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();
index 3c787b1..d170f9f 100644 (file)
@@ -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]',
index 8558dcd..482b04e 100644 (file)
@@ -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]',
index 3dbfe84..d0d1c9d 100644 (file)
                 <span tal:repeat="feed feeds" 
                   tal:attributes="id string:feed-${repeat/feed/key};"><a 
                     tal:attributes="href feed/href; title feed/ttip|default"
-                    tal:content="feed/text">rss</a></span>
+                    tal:content="feed/text">rss</a>&nbsp;</span>
                 </li>
                 <li tal:condition="nav_urls/contributions/href"><a href="${nav_urls/contributions/href}"
                   i18n:attributes="accesskey string:accesskey-contributions|default; title string:tooltip-contributions|default"