? 514256-25.patch
? sites/default/files
? sites/default/private
? sites/default/settings.php
Index: modules/block/block.admin.inc
===================================================================
RCS file: /cvs/drupal/drupal/modules/block/block.admin.inc,v
retrieving revision 1.53
diff -u -p -r1.53 block.admin.inc
--- modules/block/block.admin.inc	29 Aug 2009 05:46:02 -0000	1.53
+++ modules/block/block.admin.inc	31 Aug 2009 00:33:04 -0000
@@ -254,39 +254,37 @@ function block_admin_configure(&$form_st
     drupal_set_title(t("'%name' block", array('%name' => $info[$delta]['info'])), PASS_THROUGH);
   }
 
+  // Add JavaScript to hide the Pages field if the show always option is set.
+  drupal_add_js(drupal_get_path('module', 'block') . '/block.js');
+  drupal_add_js(array('block' => array('visibilityPageAlways' => BLOCK_VISIBILITY_PAGE_ALWAYS)), 'setting');
+
   $form['page_vis_settings'] = array(
     '#type' => 'fieldset',
     '#title' => t('Page specific visibility settings'),
     '#collapsible' => TRUE,
     '#collapsed' => TRUE,
   );
+  $form['page_vis_settings']['visibility'] = array(
+    '#type' => 'radios',
+    '#title' => t('Show this block'),
+    '#options' => array(
+      BLOCK_VISIBILITY_PAGE_ALWAYS => t('On every page.'),
+      BLOCK_VISIBILITY_PAGE_EXCLUDE => t('On every page except those specified.'),
+      BLOCK_VISIBILITY_PAGE_INCLUDE => t('On only the pages specified.'),
+    ),
+    '#default_value' => ($edit['visibility'] == BLOCK_VISIBILITY_PAGE_EXCLUDE && empty($edit['pages']) ? BLOCK_VISIBILITY_PAGE_ALWAYS : $edit['visibility']),
+    '#access' => user_access('use PHP for settings') || $edit['visibility'] != BLOCK_VISIBILITY_PAGE_PHP,
+  );
+  $form['page_vis_settings']['pages'] = array(
+    '#type' => 'textarea',
+    '#title' => t('Pages'),
+    '#default_value' => $edit['pages'],
+    '#description' => t("Enter one page per line as Drupal paths. The '*' character is a wildcard. Example paths are %blog for the blog page and %blog-wildcard for every personal blog. %front is the front page.", array('%blog' => 'blog', '%blog-wildcard' => 'blog/*', '%front' => '<front>')),
+  );
 
-  $access = user_access('use PHP for settings');
-  if ($edit['visibility'] == 2 && !$access) {
-    $form['page_vis_settings'] = array();
-    $form['page_vis_settings']['visibility'] = array('#type' => 'value', '#value' => 2);
-    $form['page_vis_settings']['pages'] = array('#type' => 'value', '#value' => $edit['pages']);
-  }
-  else {
-    $options = array(t('Every page except those specified below.'), t('Only the pages specified below.'));
-    $description = t("Enter one page per line as Drupal paths. The '*' character is a wildcard. Example paths are %blog for the blog page and %blog-wildcard for every personal blog. %front is the front page.", array('%blog' => 'blog', '%blog-wildcard' => 'blog/*', '%front' => '<front>'));
-
-    if (module_exists('php') && $access) {
-      $options[] = t('Show if the following PHP code returns <code>TRUE</code> (PHP-mode, experts only).');
-      $description .= ' ' . t('If the PHP-mode is chosen, enter PHP code between %php. Note that executing incorrect PHP-code can break your Drupal site.', array('%php' => '<?php ?>'));
-    }
-    $form['page_vis_settings']['visibility'] = array(
-      '#type' => 'radios',
-      '#title' => t('Show block on specific pages'),
-      '#options' => $options,
-      '#default_value' => $edit['visibility'],
-    );
-    $form['page_vis_settings']['pages'] = array(
-      '#type' => 'textarea',
-      '#title' => t('Pages'),
-      '#default_value' => $edit['pages'],
-      '#description' => $description,
-    );
+  if (module_exists('php') && user_access('use PHP for settings')) {
+    $form['page_vis_settings']['visibility']['#options'][BLOCK_VISIBILITY_PAGE_PHP] = t('If the following PHP code returns <code>TRUE</code> (PHP-mode, experts only).');
+    $form['page_vis_settings']['pages']['#description'] .= ' ' . t('If the PHP-mode is chosen, enter PHP code between %php. Note that executing incorrect PHP-code can break your Drupal site.', array('%php' => '<?php ?>'));
   }
 
   // Role-based visibility settings.
@@ -367,8 +365,22 @@ function block_admin_configure_validate(
   }
 }
 
+/**
+ * "Fix" the form_state's visibility and pages fields when adding or
+ * configuring a block.
+ */
+function _block_fix_form_state_visibility(&$form_state) {
+  // Don't actually store BLOCK_VISIBILITY_PAGE_ALWAYS in database
+  if ($form_state['values']['visibility'] == BLOCK_VISIBILITY_PAGE_ALWAYS) {
+    $form_state['values']['visibility'] = BLOCK_VISIBILITY_PAGE_EXCLUDE;
+    $form_state['values']['pages'] = '';
+  }
+}
+
 function block_admin_configure_submit($form, &$form_state) {
   if (!form_get_errors()) {
+    _block_fix_form_state_visibility(&$form_state);
+
     db_update('block')
       ->fields(array(
         'visibility' => (int) $form_state['values']['visibility'],
@@ -446,6 +458,8 @@ function block_add_block_form_validate($
  * Save the new custom block.
  */
 function block_add_block_form_submit($form, &$form_state) {
+  _block_fix_form_state_visibility(&$form_state);
+
   $delta = db_insert('block_custom')
     ->fields(array(
       'body' => $form_state['values']['body'],
@@ -461,12 +475,12 @@ function block_add_block_form_submit($fo
         'visibility' => (int) $form_state['values']['visibility'],
         'pages' => trim($form_state['values']['pages']),
         'custom' => (int) $form_state['values']['custom'],
-        'title' => $form_state['values']['title'], 
+        'title' => $form_state['values']['title'],
         'module' => $form_state['values']['module'],
-        'theme' => $theme->name, 
+        'theme' => $theme->name,
         'status' => 0,
         'weight' => 0,
-        'delta' => $delta, 
+        'delta' => $delta,
         'cache' => BLOCK_NO_CACHE,
       ));
     }
Index: modules/block/block.js
===================================================================
RCS file: /cvs/drupal/drupal/modules/block/block.js,v
retrieving revision 1.10
diff -u -p -r1.10 block.js
--- modules/block/block.js	4 Aug 2009 06:26:52 -0000	1.10
+++ modules/block/block.js	31 Aug 2009 00:33:04 -0000
@@ -107,4 +107,21 @@ Drupal.behaviors.blockDrag = {
   }
 };
 
+/**
+ * Show or hide the Pages element on the block configuration page based on
+ * whether the "On every page" setting is selected. If it's selected, hide
+ * the Pages element.
+ */
+Drupal.behaviors.blockVisibilitySettings = {
+  attach: function (context, settings) {
+    $("input[name='visibility']:not(.block-processed)", context).each(function () {
+      $(this).change(function (event) {
+        $('div.form-item-pages', context).toggle($(this).val() != Drupal.settings.block.visibilityPageAlways);
+      });
+      $(this).addClass('block-processed');
+    });
+    $('div.form-item-pages', context).toggle($("input[name='visibility'][checked]").val() != Drupal.settings.block.visibilityPageAlways);
+  }
+};
+
 })(jQuery);
Index: modules/block/block.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/block/block.module,v
retrieving revision 1.371
diff -u -p -r1.371 block.module
--- modules/block/block.module	29 Aug 2009 05:46:02 -0000	1.371
+++ modules/block/block.module	31 Aug 2009 00:33:04 -0000
@@ -60,6 +60,11 @@ define('BLOCK_CACHE_PER_PAGE', 0x0004);
  */
 define('BLOCK_CACHE_GLOBAL', 0x0008);
 
+define('BLOCK_VISIBILITY_PAGE_ALWAYS', 3);
+define('BLOCK_VISIBILITY_PAGE_PHP', 2);
+define('BLOCK_VISIBILITY_PAGE_EXCLUDE', 0);
+define('BLOCK_VISIBILITY_PAGE_INCLUDE', 1);
+
 /**
  * Implement hook_help().
  */
Index: modules/block/block.test
===================================================================
RCS file: /cvs/drupal/drupal/modules/block/block.test,v
retrieving revision 1.27
diff -u -p -r1.27 block.test
--- modules/block/block.test	28 Aug 2009 19:44:05 -0000	1.27
+++ modules/block/block.test	31 Aug 2009 00:33:04 -0000
@@ -123,6 +123,7 @@ class BlockTestCase extends DrupalWebTes
     // Set the block to be hidden on any user path, and to be shown only to
     // authenticated users.
     $edit = array();
+    $edit['visibility'] = '0'; // 'On all pages except those specified.'
     $edit['pages'] = 'user*';
     $edit['roles[2]'] = TRUE;
     $this->drupalPost('admin/structure/block/configure/' . $block['module'] . '/' . $block['delta'], $edit, t('Save block'));
