Index: /branches/release-36/lib/MT/CMS/Template.pm
===================================================================
--- /branches/release-36/lib/MT/CMS/Template.pm (revision 2110)
+++ /branches/release-36/lib/MT/CMS/Template.pm (revision 2115)
@@ -1980,26 +1980,59 @@
       || $perms->can_rebuild;
 
-    my $blog = $app->blog;
-    my $templates =
-      MT->model('template')->lookup_multi( [ $app->param('id') ] );
+    my @ids = $app->param('id');
+    if (scalar @ids == 1) {
+        # we also support a list of comma-delimited ids like this
+        @ids = split /,/, $ids[0];
+    }
+    return $app->error($app->translate("Invalid request."))
+        unless @ids;
+
+    my $tmpl_id;
+    my %ats;
     require MT::TemplateMap;
-    # FIXME: Need multi-request support!
-    TEMPLATE: for my $tmpl (@$templates) {
-        next TEMPLATE if !defined $tmpl;
-        next TEMPLATE if $tmpl->blog_id != $blog->id;
-        my @tmpl_maps = MT::TemplateMap->load( { template_id => $tmpl->id } );
+    while (!$tmpl_id && @ids) {
+        $tmpl_id = shift @ids;
+        my @tmpl_maps = MT::TemplateMap->load( { template_id => $tmpl_id } );
         foreach my $map (@tmpl_maps) {
             next unless $map->build_type;
-            $app->rebuild(
-                Blog        => $blog,
-                ArchiveType => $map->archive_type,
-                TemplateMap => $map,
-                NoIndexes   => 1,
-                Force       => 1,
-            );
-        }
-    }
-
-    $app->call_return( published => 1 );
+            $ats{ $map->archive_type } = 1;
+        }
+        undef $tmpl_id unless keys %ats;
+    }
+
+    # we have a template and archive types to publish!
+
+    require MT::CMS::Blog;
+    my $return_args;
+    if (@ids) {
+        # we have more to do after this, so save the list
+        # of remaining archive templates...
+        $return_args = $app->uri_params(
+            mode => 'publish_archive_templates',
+            args => {
+                magic_token => $app->current_magic,
+                blog_id => scalar $app->param('blog_id'),
+                id => join(",", @ids),
+            }
+        );
+    } else {
+        # nothing left after this publish operation; just return
+        # to the listing screen.
+        $return_args = $app->uri_params(
+            mode => 'list',
+            args => {
+                _type => 'template',
+                blog_id => scalar $app->param('blog_id'),
+                published => 1
+            }
+        );
+    }
+    $return_args =~ s/^\?//;
+
+    $app->return_args( $return_args );
+    $app->param( 'template_id', $tmpl_id );
+    $app->param( 'single_template', 1 ); # forces fullscreen mode
+    $app->param( 'type', join(",", keys %ats) );
+    return MT::CMS::Blog::start_rebuild_pages($app);
 }
 
Index: /branches/release-36/lib/MT/CMS/Blog.pm
===================================================================
--- /branches/release-36/lib/MT/CMS/Blog.pm (revision 2103)
+++ /branches/release-36/lib/MT/CMS/Blog.pm (revision 2115)
@@ -588,4 +588,5 @@
     my $no_static = $q->param('no_static');
     my $template_id = $q->param('template_id');
+    my $map_id = $q->param('templatemap_id');
 
     my ($tmpl_saved);
@@ -709,5 +710,6 @@
                     FilterCallback => $cb,
                     $no_static ? ( NoStatic   => 1 )            : (),
-                    $template_id ? ( TemplateID => $template_id ) : (),
+                    $template_id ? ( TemplateID => $template_id, Force => 1 ) : (),
+                    $map_id ? ( TemplateMap => $template_id, Force => 1 ) : (),
                 ) or return $app->publish_error();
                 $offset += $count;
@@ -906,5 +908,5 @@
     }
 
-    my $type          = $q->param('type');
+    my $type          = $q->param('type') || '';
     my $next          = $q->param('next') || 0;
     my @order         = split /,/, $type;
Index: /branches/release-36/lib/MT/CMS/Common.pm
===================================================================
--- /branches/release-36/lib/MT/CMS/Common.pm (revision 2113)
+++ /branches/release-36/lib/MT/CMS/Common.pm (revision 2115)
@@ -374,9 +374,14 @@
             $app->add_return_arg( id => $obj->id );
         }
-        $q->param( 'type',            'index-' . $obj->id );
-        $q->param( 'tmpl_id',         $obj->id );
-        $q->param( 'single_template', 1 );
-        require MT::CMS::Blog;
-        return MT::CMS::Blog::start_rebuild_pages($app);
+        if ( $obj->type eq 'index' ) {
+            $q->param( 'type',            'index-' . $obj->id );
+            $q->param( 'tmpl_id',         $obj->id );
+            $q->param( 'single_template', 1 );
+            return $app->forward( 'start_rebuild' );
+        } else {
+            # archive rebuild support
+            $q->param( 'id', $obj->id );
+            return $app->forward( 'publish_archive_templates' );
+        }
     }
     elsif ( $type eq 'template' ) {
Index: /branches/release-36/tmpl/cms/edit_template.tmpl
===================================================================
--- /branches/release-36/tmpl/cms/edit_template.tmpl (revision 2054)
+++ /branches/release-36/tmpl/cms/edit_template.tmpl (revision 2115)
@@ -154,4 +154,5 @@
         type="submit"
         accesskey="v"
+        tabindex="13"
         title="Preview"
         onclick="return validate(this.form);"
@@ -160,9 +161,9 @@
     <mt:unless name="build_dynamic">
         <mt:if name="can_rebuild">
-            <mt:if name="type_index">
+            <mt:if name="template_group" like="/^(archive|index)$/">
     <button
         type="submit"
         accesskey="r"
-        tabindex="13"
+        tabindex="14"
         title="<__trans phrase="Save and Publish this template (r)">"
         onclick="return validate(this.form, 1);"
@@ -564,5 +565,5 @@
         help_section="output_file">
         <div class="textarea-wrapper">
-            <input name="outfile" id="outfile" tabindex="5" value="<mt:var name="outfile" escape="html">" class="full-width" mt:watch-change="1" />
+            <input name="outfile" id="outfile" tabindex="4" value="<mt:var name="outfile" escape="html">" class="full-width" mt:watch-change="1" />
         </div>
     </mtapp:setting>
@@ -575,5 +576,5 @@
         help_page="templates"
         help_section="template_type">
-        <select name="identifier" id="identifier" tabindex="4" class="full-width">
+        <select name="identifier" id="identifier" tabindex="5" class="full-width">
             <option value="" <mt:unless name="identifier">selected="selected"</mt:unless>><__trans phrase="Custom Index Template"></option>
         <mt:loop name="index_identifiers">
Index: /branches/release-36/tmpl/cms/rebuilding.tmpl
===================================================================
--- /branches/release-36/tmpl/cms/rebuilding.tmpl (revision 2026)
+++ /branches/release-36/tmpl/cms/rebuilding.tmpl (revision 2115)
@@ -6,5 +6,5 @@
     window.location='<mt:var name="redirect_target">';
 <mt:else>
-    window.location='<mt:var name="script_url">?__mode=rebuild&blog_id=<mt:var name="blog_id">&type=<mt:var name="build_type">&next=<mt:var name="build_next">&offset=<mt:var name="offset">&limit=<mt:var name="limit">&total=<mt:var name="total">&start_time=<mt:var name="start_time">&entry_id=<mt:var name="entry_id">&is_new=<mt:var name="is_new">&old_status=<mt:var name="old_status">&old_previous=<mt:var name="old_previous">&old_next=<mt:var name="old_next"><mt:if name="is_full_screen">&fs=1</mt:if><mt:if name="with_indexes">&with_indexes=1</mt:if><mt:if name="no_static">&no_static=1</mt:if><mt:if name="template_id">&template_id=<mt:var name="template_id"></mt:if><mt:if name="return_args">&return_args=<mt:var name="return_args" escape="url"></mt:if>';
+    window.location='<mt:var name="script_url">?__mode=rebuild&blog_id=<mt:var name="blog_id">&type=<mt:var name="build_type">&next=<mt:var name="build_next">&offset=<mt:var name="offset">&limit=<mt:var name="limit">&total=<mt:var name="total">&start_time=<mt:var name="start_time">&entry_id=<mt:var name="entry_id">&is_new=<mt:var name="is_new">&old_status=<mt:var name="old_status">&old_previous=<mt:var name="old_previous">&old_next=<mt:var name="old_next"><mt:if name="is_full_screen">&fs=1</mt:if><mt:if name="with_indexes">&with_indexes=1</mt:if><mt:if name="no_static">&no_static=1</mt:if><mt:if name="template_id">&template_id=<mt:var name="template_id"></mt:if><mt:if name="templatemap_id">&templatemap_id=<mt:var name="templatemap_id"></mt:if><mt:if name="return_args">&return_args=<mt:var name="return_args" escape="url"></mt:if>';
 </mt:if>
 }
