Index: includes/common.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/common.inc,v
retrieving revision 1.627
diff -u -r1.627 common.inc
--- includes/common.inc	6 Apr 2007 13:27:20 -0000	1.627
+++ includes/common.inc	8 Apr 2007 23:11:23 -0000
@@ -24,6 +24,10 @@
  */
 define('SAVED_DELETED', 3);
 
+define('PAGE_MATCH_ALL_BUT_LISTED', 0);
+define('PAGE_MATCH_ONLY_LISTED', 1);
+define('PAGE_MATCH_PHP', 2);
+
 /**
  * Set content for a specified region.
  *
@@ -2180,6 +2184,41 @@
 
 
 /**
+ * Determine if an item should display on the current page.
+ *
+ * @param $visibility
+ *   Method to be used to determine visibility; one of the three constant:
+ *   - PAGE_MATCH_ALL_BUT_LISTED: Show on all pages except those listed.
+ *   - PAGE_MATCH_ONLY_LISTED: Show only on listed pages.
+ *   - PAGE_MATCH_PHP: show if a PHP expression evaluates to TRUE.
+ * @param $pages
+ *   The pages on which the item should or should not display, or a PHP
+ *   code block.
+ *
+ * @return
+ *   Boolean indicating if the item should display.
+ */
+function drupal_page_match($visibility, $pages) {
+  if ($visibility < PAGE_MATCH_PHP) {
+    $path = drupal_get_path_alias($_GET['q']);
+    $regexp = '/^('. preg_replace(array('/(\r\n?|\n)/', '/\\\\\*/', '/(^|\|)\\\\<front\\\\>($|\|)/'), array('|', '.*', '\1'. preg_quote(variable_get('site_frontpage', 'node'), '/') .'\2'), preg_quote($pages, '/')) .')$/';
+    // Compare with the internal and path alias (if any).
+    $page_match = preg_match($regexp, $path);
+    if ($path != $_GET['q']) {
+      $page_match = $page_match || preg_match($regexp, $_GET['q']);
+    }
+    // When $visibility has a value of 0, the item is displayed on
+    // all pages except those listed in $pages. When set to 1, it
+    // is displayed only on those pages listed in $pages.
+    $page_match = !($visibility xor $page_match);
+  }
+  else {
+    $page_match = drupal_eval($pages);
+  }
+  return $page_match;
+}
+
+/**
  * Renders HTML given a structured array tree. Recursively iterates over each
  * of the array elements, generating HTML code. This function is usually
  * called from within a another function, like drupal_get_form() or node_view().
Index: modules/block/block.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/block/block.module,v
retrieving revision 1.256
diff -u -r1.256 block.module
--- modules/block/block.module	9 Apr 2007 13:58:02 -0000	1.256
+++ modules/block/block.module	9 Apr 2007 15:18:54 -0000
@@ -63,7 +63,7 @@
  * Implementation of hook_perm().
  */
 function block_perm() {
-  return array('administer blocks', 'use PHP for block visibility');
+  return array('administer blocks');
 }
 
 /**
@@ -455,39 +455,7 @@
     '#description' =>  t('Show this block only for the selected role(s). If you select no roles, the block will be visible to all users.'),
   );
 
-  $form['page_vis_settings'] = array(
-    '#type' => 'fieldset',
-    '#title' => t('Page specific visibility settings'),
-    '#collapsible' => TRUE,
-  );
-  $access = user_access('use PHP for block visibility');
-
-  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('Show on every page except the listed pages.'), t('Show on only the listed 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>'));
-
-    if ($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,
-    );
-  }
+  $form += system_page_match_form($edit['visibility'], $edit['pages']);
 
   $form['submit'] = array(
     '#type' => 'submit',
@@ -699,27 +667,7 @@
       }
 
       // Match path if necessary
-      if ($block->pages) {
-        if ($block->visibility < 2) {
-          $path = drupal_get_path_alias($_GET['q']);
-          $regexp = '/^('. preg_replace(array('/(\r\n?|\n)/', '/\\\\\*/', '/(^|\|)\\\\<front\\\\>($|\|)/'), array('|', '.*', '\1'. preg_quote(variable_get('site_frontpage', 'node'), '/') .'\2'), preg_quote($block->pages, '/')) .')$/';
-          // Compare with the internal and path alias (if any).
-          $page_match = preg_match($regexp, $path);
-          if ($path != $_GET['q']) {
-            $page_match = $page_match || preg_match($regexp, $_GET['q']);
-          }
-          // When $block->visibility has a value of 0, the block is displayed on
-          // all pages except those listed in $block->pages. When set to 1, it
-          // is displayed only on those pages listed in $block->pages.
-          $page_match = !($block->visibility xor $page_match);
-        }
-        else {
-          $page_match = drupal_eval($block->pages);
-        }
-      }
-      else {
-        $page_match = TRUE;
-      }
+      $page_match = $block->pages ? drupal_page_match($block->visibility, $block->pages) : TRUE;
 
       if ($enabled && $page_match) {
         // Check the current throttle status and see if block should be displayed
Index: modules/system/system.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/system/system.module,v
retrieving revision 1.463
diff -u -r1.463 system.module
--- modules/system/system.module	6 Apr 2007 14:31:51 -0000	1.463
+++ modules/system/system.module	9 Apr 2007 15:23:32 -0000
@@ -83,7 +83,7 @@
  * Implementation of hook_perm().
  */
 function system_perm() {
-  return array('administer site configuration', 'access administration pages', 'select different theme');
+  return array('administer site configuration', 'access administration pages', 'select different theme', 'use PHP for settings');
 }
 
 /**
@@ -2217,6 +2217,62 @@
 }
 
 /**
+ * Output a page match form.
+ *
+ * This function returns a form fragment for matching pages.
+ *
+ * @param $visibility
+ *   Method to be used to determine visibility; one of the three constant:
+ *   - PAGE_MATCH_ALL_BUT_LISTED: Show on all pages except those listed.
+ *   - PAGE_MATCH_ONLY_LISTED: Show only on listed pages.
+ *   - PAGE_MATCH_PHP: show if a PHP expression evaluates to TRUE.
+ * @param $pages
+ *   The pages on which the item should or should not display, or a PHP
+ *   code block.
+ *
+ * @return
+ *   The form.
+ */
+function system_page_match_form($visibility, $pages) {
+  $access = user_access('use PHP for settings');
+  $form = array();
+
+  $form['page_vis_settings'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('Page specific visibility settings'),
+    '#collapsible' => TRUE,
+  );
+
+  if ($visibility == PAGE_MATCH_PHP && !$access) {
+    $form['page_vis_settings'] = array();
+    $form['page_vis_settings']['visibility'] = array('#type' => 'value', '#value' => PAGE_MATCH_PHP);
+    $form['page_vis_settings']['pages'] = array('#type' => 'value', '#value' => $pages);
+  }
+  else {
+    $options = array(t('Show on every page except the listed pages.'), t('Show on only the listed 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>'));
+
+    if ($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' => $visibility,
+    );
+    $form['page_vis_settings']['pages'] = array(
+      '#type' => 'textarea',
+      '#title' => t('Pages'),
+      '#default_value' => $pages,
+      '#description' => $description,
+    );
+  }
+  return $form;
+}
+
+/**
  * Determine if a user is in compact mode.
  */
 function system_admin_compact_mode() {
