Index: feed-atom.php
===================================================================
--- feed-atom.php	(revision 10912)
+++ feed-atom.php	(working copy)
@@ -5,8 +5,26 @@
  * @package WordPress
  */
 
+function get_query_id() {
+	global $wp_query;
+	return $wp_query->get_queried_object_id();
+}
+function echo_feed_id($feed_id) {
+	echo "<id>$feed_id</id>\n";
+}
+function echo_feed_subtitle() {
+	$feed_subtitle=get_bloginfo_rss("description");
+	if(!empty($feed_subtitle)) {
+		echo '<subtitle type="text">'.$feed_subtitle.'</subtitle>'."\n";
+	}
+}
+function echo_feed_links($selfLink,$alternateLink,$repliesLink) {
+	echo '<link rel="self" type="application/atom+xml" href="'.$selfLink.'" />'."\n".'<link rel="alternate" type="text/html" href="'.$alternateLink.'" />'."\n".'<link rel="replies" type="application/atom+xml" href="'.$repliesLink.'" />'."\n";
+}
+
 header('Content-Type: ' . feed_content_type('atom') . '; charset=' . get_option('blog_charset'), true);
 $more = 1;
+$feed_type="atom";
 
 ?>
 <?php echo '<?xml version="1.0" encoding="'.get_option('blog_charset').'"?'.'>'; ?>
@@ -18,16 +36,44 @@
   <?php do_action('atom_ns'); ?>
  >
 	<title type="text"><?php bloginfo_rss('name'); wp_title_rss(); ?></title>
-	<subtitle type="text"><?php bloginfo_rss("description") ?></subtitle>
-
-	<updated><?php echo mysql2date('Y-m-d\TH:i:s\Z', get_lastpostmodified('GMT')); ?></updated>
+<?php
+if(is_category()) {
+	$cat_id=get_query_id();
+	$canonical_feed_link=get_category_feed_link($cat_id);
+	echo_feed_id($canonical_feed_link);
+	echo_feed_links($canonical_feed_link,get_category_link($cat_id),get_category_comments_feed_link($cat_id,$feed_type));
+}
+elseif(is_tag()) {
+	$tag_id=get_query_id();
+	$canonical_feed_link=get_tag_feed_link($tag_id);
+	echo_feed_id($canonical_feed_link);
+	echo_feed_links($canonical_feed_link,get_tag_link($tag_id),get_tag_comments_feed_link($tag_id,$feed_type));
+}
+elseif(is_author()) {
+	$author_id=get_query_id();
+	$canonical_feed_link=get_author_feed_link($author_id);
+	echo_feed_id($canonical_feed_link);
+	echo_feed_links($canonical_feed_link,get_author_posts_url($author_id),get_author_comments_feed_link($author_id,$feed_type));
+}
+elseif(is_date()) {
+	/* to be done */
+}
+elseif(is_search()) {
+	$search_query=get_search_query();
+	$canonical_feed_link=get_search_feed_link($search_query,$feed_type);
+	echo_feed_id($canonical_feed_link);
+	echo_feed_links($canonical_feed_link,get_search_link($search_query),get_search_comments_feed_link($search_query,$feed_type));
+}
+else {
+	$canonical_feed_link=get_bloginfo('atom_url');
+	echo_feed_subtitle();
+	echo_feed_id($canonical_feed_link);
+	echo_feed_links($canonical_feed_link,get_bloginfo_rss('url').'/',get_bloginfo_rss('comments_atom_url'));
+}
+?>
 	<?php the_generator( 'atom' ); ?>
-
-	<link rel="alternate" type="text/html" href="<?php bloginfo_rss('home') ?>" />
-	<id><?php bloginfo('atom_url'); ?></id>
-	<link rel="self" type="application/atom+xml" href="<?php self_link(); ?>" />
-
 	<?php do_action('atom_head'); ?>
+	<updated><?php echo mysql2date('Y-m-d\TH:i:s\Z', get_lastpostmodified('GMT')); ?></updated>
 	<?php while (have_posts()) : the_post(); ?>
 	<entry>
 		<author>
@@ -41,7 +87,7 @@
 		<id><?php the_guid(); ?></id>
 		<updated><?php echo get_post_modified_time('Y-m-d\TH:i:s\Z', true); ?></updated>
 		<published><?php echo get_post_time('Y-m-d\TH:i:s\Z', true); ?></published>
-		<?php the_category_rss('atom') ?>
+		<?php the_category_rss($feed_type) ?>
 		<summary type="<?php html_type_rss(); ?>"><![CDATA[<?php the_excerpt_rss(); ?>]]></summary>
 <?php if ( !get_option('rss_use_excerpt') ) : ?>
 		<content type="<?php html_type_rss(); ?>" xml:base="<?php the_permalink_rss() ?>"><![CDATA[<?php the_content('', 0, '') ?>]]></content>
@@ -49,7 +95,7 @@
 <?php atom_enclosure(); ?>
 <?php do_action('atom_entry'); ?>
 		<link rel="replies" type="text/html" href="<?php the_permalink_rss() ?>#comments" thr:count="<?php echo get_comments_number()?>"/>
-		<link rel="replies" type="application/atom+xml" href="<?php echo get_post_comments_feed_link(0,'atom') ?>" thr:count="<?php echo get_comments_number()?>"/>
+		<link rel="replies" type="application/atom+xml" href="<?php echo get_post_comments_feed_link(0,$feed_type) ?>" thr:count="<?php echo get_comments_number()?>"/>
 		<thr:total><?php echo get_comments_number()?></thr:total>
 	</entry>
 	<?php endwhile ; ?>
