Index: modules/forum/forum.admin.inc
===================================================================
RCS file: /cvs/drupal/drupal/modules/forum/forum.admin.inc,v
retrieving revision 1.19
diff -u -p -r1.19 forum.admin.inc
--- modules/forum/forum.admin.inc	27 May 2009 18:33:57 -0000	1.19
+++ modules/forum/forum.admin.inc	13 Jun 2009 03:50:31 -0000
@@ -7,7 +7,7 @@
  */
 
 function forum_form_main($type, $edit = array()) {
-  if ((isset($_POST['op']) && $_POST['op'] == t('Delete')) || !empty($_POST['confirm'])) {
+  if ((isset($_POST['op']) && ($_POST['op'] == t('Delete') || $_POST['op'] == t('Move'))) || !empty($_POST['confirm'])) {
     return drupal_get_form('forum_confirm_delete', $edit['tid']);
   }
   switch ($type) {
@@ -162,26 +162,213 @@ function forum_form_container(&$form_sta
  */
 function forum_confirm_delete(&$form_state, $tid) {
   $term = taxonomy_term_load($tid);
+  $nids = taxonomy_select_nodes(array($tid), 'or', 'all');
+  $topics = node_load_multiple($nids);
+  foreach ($topics as $nid => $topic) {
+    // We keep the actual tid in forum table, if it's different from the
+    // current tid then it means the topic appears in two forums, one of
+    // them is a shadow copy.
+    if (isset($topic->forum_tid) && $topic->forum_tid!= $tid)
+      unset($topics[$nid]);
+  }
+
+  $question = t('Are you sure you want to delete the forum %name?', array('%name' => $term->name));
+  $description = format_plural(count($topics), 'This forum contains 1 topic. Deleting a forum or container will also delete its sub-forums and topics. This action cannot be undone.', 'This forum contains @count topics. Deleting a forum or container will also delete its sub-forums and topics. This action cannot be undone.');
+  $yes = t('Delete');
+  $cancel = l(t('Cancel'), 'admin/build/forum');
+
+  drupal_set_title($question, PASS_THROUGH);
 
   $form['tid'] = array('#type' => 'value', '#value' => $tid);
   $form['name'] = array('#type' => 'value', '#value' => $term->name);
+  $form['description'] = array('#markup' => $description);
+
+  if (count($topics) > 0) {
+    // Enable language column if translation module is enabled
+    // or if we have any node with language.
+    $multilanguage = (module_exists('translation') || db_query("SELECT COUNT(*) FROM {node} WHERE language <> ''")->fetchField());
+
+    // Build the sortable table header.
+    $header = array();
+    $header[] = theme('table_select_header_cell');
+    $header[] = array('data' => t('Title'), 'field' => 'n.title');
+    $header[] = array('data' => t('Author'), 'field' => 'u.name');
+    $header[] = array('data' => t('Status'), 'field' => 'n.status');
+    $header[] = array('data' => t('Updated'), 'field' => 'n.changed', 'sort' => 'desc');
+    if ($multilanguage) {
+      $header[] = array('data' => t('Language'), 'field' => 'n.language');
+    }
+
+    $form['header'] = array(
+     '#type' => 'value',
+     '#value' => $header,
+    );
+
+    // Build topic listing for sortable table
+    $languages = language_list();
+    $topics_checkbox = array();
+    foreach ($topics as $topic) {
+      $topics_checkbox[$topic->nid] = '';
+      $options = empty($topic->language) ? array() : array('language' => $languages[$topic->language]);
+      $form['title'][$topic->nid] = array('#markup' => l($topic->title, 'node/' . $topic->nid, $options) . ' ' . theme('mark', node_mark($topic->nid, $topic->changed)));
+      $form['username'][$topic->nid] = array('#markup' => theme('username', $topic));
+      $form['status'][$topic->nid] =  array('#markup' => ($topic->status ? t('published') : t('not published')));
+      $form['changed'][$topic->nid] = array('#markup' => format_date($topic->changed, 'small'));
+      if ($multilanguage) {
+        $form['language'][$topic->nid] = array('#markup' => empty($topic->language) ? t('Language neutral') : t($languages[$topic->language]->name));
+      }
+    }
+    $form['topics'] = array(
+      '#type' => 'checkboxes',
+      '#options' => $topics_checkbox,
+    );
+    $form['pager'] = array('#markup' => theme('pager', NULL));
+
+    // Build the 'Move selected topics' form.
+    $form['move'] = array(
+      '#type' => 'fieldset',
+      '#title' => t('Move selected topics'),
+      '#prefix' => '<div class="container-inline">',
+      '#suffix' => '</div>',
+    );
+    // Get a drop-down menu of other forum/containers to move topics.
+    $other_forums = taxonomy_form(variable_get('forum_nav_vocabulary', ''));
+    foreach ($other_forums['#options'] as $option_id => $option) {
+      if (isset($option->option[$tid])) {
+        unset($other_forums['#options'][$option_id]);
+        break;
+      }
+    }
+    // Enable the 'Move selected topics' form only if there are other forums/containers.
+    if(count($other_forums['#options']) > 1) {
+      $form['move']['tid_dst'] = $other_forums;
+      $form['move']['submit'] = array(
+        '#type' => 'submit',
+        '#value' => t('Move'),
+        '#submit' => array('forum_confirm_delete_move_submit'),
+      );
+    } else {
+      // If there are no destinations, disable 'Move selected topics' form and remove table checkboxes.
+      $form['move']['no_dst'] = array('#markup' => t('There are no other forums to move these topics.'));
+      array_shift($form['header']['#value']);
+      unset($form['topics']);
+    }
+  }
 
-  return confirm_form($form, t('Are you sure you want to delete the forum %name?', array('%name' => $term->name)), 'admin/build/forum', t('Deleting a forum or container will also delete its sub-forums, if any. To delete posts in this forum, visit <a href="@content">content administration</a> first. This action cannot be undone.', array('@content' => url('admin/content/node'))), t('Delete'), t('Cancel'));
+  $form['actions'] = array('#prefix' => '<div class="container-inline">', '#suffix' => '</div>');
+  $form['actions']['submit'] = array('#type' => 'submit', '#value' => $yes ? $yes : t('Confirm'));
+  $form['actions']['cancel'] = array('#markup' => $cancel);
+  $form['#theme'] = 'forum_confirm_delete';
+  return $form;
 }
 
 /**
- * Implement forms api _submit call. Deletes a forum after confirmation.
+ * Implement forms api _submit call. Deletes a forum after confirmation along 
+ * with all children topics.
  */
 function forum_confirm_delete_submit($form, &$form_state) {
-  taxonomy_term_delete($form_state['values']['tid']);
-  drupal_set_message(t('The forum %term and all sub-forums have been deleted.', array('%term' => $form_state['values']['name'])));
-  watchdog('content', 'forum: deleted %term and all its sub-forums.', array('%term' => $form_state['values']['name']));
+  $tid = $form_state['values']['tid'];
+  $nids = taxonomy_select_nodes(array($tid), 'or', 'all');
+  $topics = node_load_multiple($nids);
+  foreach ($topics as $nid => $topic) {
+    // We keep the actual tid in forum table, if it's different from the
+    // current tid then it means the topic appears in two forums, one of
+    // them is a shadow copy.
+    if (isset($topic->forum_tid) && $topic->forum_tid!= $tid)
+      unset($topics[$nid]);
+  }
+  $nids = array_keys($topics);
+
+  // Delete the forum/container as well as all nodes that belong to it.
+  if (count($nids) > 0) {
+    node_delete_multiple($nids);
+  }
+  taxonomy_term_delete($tid);
+
+  drupal_set_message(t('The forum %term, all sub-forums, and all children topics have been deleted.', array('%term' => $form_state['values']['name'])));
+  watchdog('content', 'forum: deleted %term, all its sub-forums, and all its children topics.', array('%term' => $form_state['values']['name']));
 
   $form_state['redirect'] = 'admin/build/forum';
   return;
 }
 
 /**
+ * Process forum delete confirmation move submissions.
+ *
+ * Execute the chosen 'Move location options' on the selected topics.
+ */
+function forum_confirm_delete_move_submit($form, &$form_state) {
+  $tid_src = $form_state['values']['tid'];
+  $tid_dst = $form_state['values']['tid_dst'];
+  // Filter out unchecked nodes
+  $topics = array_filter($form_state['values']['topics']);
+  if(!empty($topics) && $tid_dst) {
+    $topics = node_load_multiple($topics);
+    $term_dst = taxonomy_term_load($tid_dst);
+    print_r($topics);
+    print_r($term_dst);
+    foreach ($topics as $topic) {
+      $topic->tid = $tid_dst;
+      $topic->forum_tid = $tid_dst;
+      $topic->taxonomy[$tid_dst] = $term_dst;
+      module_invoke_all('node_presave', $topic, array($tid_dst));
+      module_invoke_all('node_update', $topic, array($tid_dst));
+    }
+    print_r($topics);
+  }
+  // Return to the forum_confirm_delete form with these topics now deleted.
+  $form_state['rebuild'] = TRUE;
+}
+
+/**
+ * Theme forum delete confirmation.
+ *
+ * @ingroup themeable
+ */
+function theme_forum_confirm_delete($form) {
+  $output = '';
+
+  if (isset($form['move'])) {
+    $output .= drupal_render($form['move']);
+    $header = $form['header']['#value'];
+
+    $has_topics = isset($form['title']) && is_array($form['title']);
+    if ($has_topics) {
+      $rows = array();
+      foreach (element_children($form['title']) as $key) {
+        $row = array();
+        if (isset($form['move']['tid_dst'])) {
+          $row[] = drupal_render($form['topics'][$key]);
+        }
+        $row[] = drupal_render($form['title'][$key]);
+        $row[] = drupal_render($form['username'][$key]);
+        $row[] = drupal_render($form['status'][$key]);
+        $row[] = drupal_render($form['changed'][$key]);
+        if (isset($form['language'])) {
+          $row[] = drupal_render($form['language'][$key]);
+        }
+        $rows[] = $row;
+      }
+    }
+    else {
+      $rows[] = array(
+        array('data' => t('No content available.'), 'colspan' => count($header)),
+      );
+    }
+
+    $output .= theme('table', $header, $rows);
+
+    if ($form['pager']['#markup']) {
+      $output .= drupal_render($form['pager']);
+    }
+  }
+
+  $output .= drupal_render_children($form);
+
+  return $output;
+}
+
+/**
  * Form builder for the forum settings page.
  *
  * @see system_settings_form()
Index: modules/forum/forum.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/forum/forum.module,v
retrieving revision 1.500
diff -u -p -r1.500 forum.module
--- modules/forum/forum.module	12 Jun 2009 08:39:37 -0000	1.500
+++ modules/forum/forum.module	13 Jun 2009 03:50:31 -0000
@@ -61,6 +61,10 @@ function forum_theme() {
       'template' => 'forum-submitted',
       'arguments' => array('topic' => NULL),
     ),
+    'forum_confirm_delete' => array(
+      'arguments' => array('form' => NULL),
+      'file' => 'forum.admin.inc',
+    ),
   );
 }
 
