Index: modules/block/block.admin.inc
===================================================================
RCS file: /cvs/drupal/drupal/modules/block/block.admin.inc,v
retrieving revision 1.38
diff -u -p -r1.38 block.admin.inc
--- modules/block/block.admin.inc	16 May 2009 15:23:15 -0000	1.38
+++ modules/block/block.admin.inc	16 May 2009 23:19:44 -0000
@@ -243,6 +243,27 @@ function block_admin_configure(&$form_st
     '#description' => t('Show this block only for the selected role(s). If you select no roles, the block will be visible to all users.'),
   );
 
+  // Content type specific configuration.
+  $node_types = node_get_types('names');
+  $default_type_options = array();
+  $result = db_query('SELECT type FROM {block_node_type} WHERE module = :module AND delta = :delta', array(':module' => $module, ':delta' => $delta));
+  foreach($result as $type) {
+    $default_type_options[] = $type->type;
+  }
+  $form['content_type_vis_settings'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('Content type specific visibility settings'),
+    '#collapsible' => TRUE,
+    '#collapsed' => TRUE,
+  );
+  $form['content_type_vis_settings']['types'] = array(
+    '#type' => 'checkboxes',
+    '#title' => t('Show block for specific content types'),
+    '#default_value' => $default_type_options,
+    '#options' => $node_types,
+    '#description' => t('Show this block only when on a page displaying a post of the given type(s). If you select no types, there will be no type specific limitation.'),
+  );
+
   // Standard block configurations.
   $form['user_vis_settings'] = array(
     '#type' => 'fieldset',
@@ -286,6 +307,11 @@ function block_admin_configure_submit($f
     foreach (array_filter($form_state['values']['roles']) as $rid) {
       db_query("INSERT INTO {block_role} (rid, module, delta) VALUES (%d, '%s', '%s')", $rid, $form_state['values']['module'], $form_state['values']['delta']);
     }
+    db_query("DELETE FROM {block_node_type} WHERE module = '%s' AND delta = '%s'", $form_state['values']['module'], $form_state['values']['delta']);
+    foreach (array_filter($form_state['values']['types']) as $type) {
+      db_query("INSERT INTO {block_node_type} (type, module, delta) VALUES ('%s', '%s', '%s')", $type, $form_state['values']['module'], $form_state['values']['delta']);
+    }
+
     module_invoke($form_state['values']['module'], 'block_save', $form_state['values']['delta'], $form_state['values']);
     drupal_set_message(t('The block configuration has been saved.'));
     cache_clear_all();
@@ -325,6 +351,9 @@ function block_add_block_form_submit($fo
   foreach (array_filter($form_state['values']['roles']) as $rid) {
     db_query("INSERT INTO {block_role} (rid, module, delta) VALUES (%d, '%s', '%s')", $rid, $form_state['values']['module'], $delta);
   }
+  foreach (array_filter($form_state['values']['types']) as $type) {
+    db_query("INSERT INTO {block_node_type} (type, module, delta) VALUES ('%s', '%s', '%s')", $type, $form_state['values']['module'], $delta);
+  }
 
   drupal_set_message(t('The block has been created.'));
   cache_clear_all();
Index: modules/block/block.install
===================================================================
RCS file: /cvs/drupal/drupal/modules/block/block.install,v
retrieving revision 1.23
diff -u -p -r1.23 block.install
--- modules/block/block.install	13 May 2009 19:42:14 -0000	1.23
+++ modules/block/block.install	16 May 2009 23:16:22 -0000
@@ -131,6 +131,34 @@ function block_schema() {
     ),
   );
 
+  $schema['block_node_type'] = array(
+    'description' => 'Sets up display criteria for blocks based on content types',
+    'fields' => array(
+      'module' => array(
+        'type' => 'varchar',
+        'length' => 64,
+        'not null' => TRUE,
+        'description' => "The block's origin module, from {block}.module.",
+      ),
+      'delta' => array(
+        'type' => 'varchar',
+        'length' => 32,
+        'not null' => TRUE,
+        'description' => "The block's unique delta within module, from {block}.delta.",
+      ),
+      'type' => array(
+        'type' => 'varchar',
+        'length' => 32,
+        'not null' => TRUE,
+        'description' => "The machine-readable name of this type from {node_types}.type.",
+      ),
+    ),
+    'primary key' => array('module', 'delta', 'type'),
+    'indexes' => array(
+      'type' => array('type'),
+    ),
+  );
+
   $schema['box'] = array(
     'description' => 'Stores contents of custom-made blocks.',
     'fields' => array(
Index: modules/block/block.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/block/block.module,v
retrieving revision 1.332
diff -u -p -r1.332 block.module
--- modules/block/block.module	16 May 2009 15:23:15 -0000	1.332
+++ modules/block/block.module	16 May 2009 23:55:59 -0000
@@ -597,6 +597,13 @@ function block_block_list_alter(&$blocks) {
     $block_roles[$record->module][$record->delta][] = $record->rid;
   }
 
+  // Build an array of node types for each block.
+  $block_node_types = array();
+  $result = db_query('SELECT module, delta, type FROM {block_node_type}');
+  foreach ($result as $record) {
+    $block_node_types[$record->module][$record->delta][] = $record->type;
+  }
+
   foreach ($blocks as $key => $block) {
     if ($block->theme != $theme_key || $block->status != 1) {
       // This block was added by a contrib module, leave it in the list.
@@ -613,6 +620,37 @@
       // No match.
       unset($blocks[$key]);
       continue;
+    }
+
+    // If a block has no node types associated, it is displayed for every type.
+    // For blocks with node types associated, if the node type does not match
+    // the settings from this block, remove it from the array.
+    if (!isset($block_node_types[$block->module][$block->delta])) {
+      // No node types associated.
+    }
+    else {
+      $node = menu_get_object();
+      if (!empty($node)) {
+        // This is a node or node edit page.
+        if (!in_array($node->type, $block_node_types[$block->module][$block->delta])) {
+          // This block should not be displayed for this node type.
+          unset($blocks[$key]);
+          continue;
+        }
+      }
+      elseif (arg(0) == 'node' && arg(1) == 'add' && in_array(arg(2), array_keys(node_get_types()))) {
+        // This is a node creation page
+        if (!in_array(arg(2), $block_node_types[$block->module][$block->delta])) {
+          // This block should not be displayed for this node type.
+          unset($blocks[$key]);
+          continue;
+        }
+      }
+      else {
+        // This is not a node page, remove the block.
+        unset($blocks[$key]);
+        continue;
+      }
     }
 
     // Use the user's block visibility setting, if necessary.
