Index: includes/bootstrap.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/bootstrap.inc,v
retrieving revision 1.280
diff -u -p -r1.280 bootstrap.inc
--- includes/bootstrap.inc	12 May 2009 18:08:42 -0000	1.280
+++ includes/bootstrap.inc	16 May 2009 01:06:43 -0000
@@ -1428,7 +1428,6 @@ function _drupal_bootstrap($phase) {
       break;
 
     case DRUPAL_BOOTSTRAP_PATH:
-      require_once DRUPAL_ROOT . '/includes/path.inc';
       // Initialize $_GET['q'] prior to loading modules and invoking hook_init().
       drupal_init_path();
       break;
@@ -1869,3 +1868,47 @@ function &drupal_static($name, $default_
 function drupal_static_reset($name = NULL) {
   drupal_static($name, NULL, TRUE);
 }
+
+/**
+ * @defgroup path Path handling
+ * @{
+ */
+
+/**
+ * Initialize the $_GET['q'] variable to the proper normal path.
+ */
+function drupal_init_path() {
+  if (!empty($_GET['q'])) {
+    $_GET['q'] = trim($_GET['q'], '/');
+    foreach (module_implements('lookup_path') as $module) {
+      $function = $module . '_lookup_path';
+      $function($_GET['q']);
+    }
+  }
+  else {
+    $_GET['q'] = variable_get('site_frontpage', 'node');
+  }
+}
+
+/**
+ * Check if the current page is the front page.
+ *
+ * @return
+ *   Boolean value: TRUE if the current page is the front page; FALSE if otherwise.
+ */
+function drupal_is_front_page() {
+  $is_front_page = &drupal_static(__FUNCTION__);
+
+  if (!isset($is_front_page)) {
+    // As drupal_init_path updates $_GET['q'] with the 'site_frontpage' path,
+    // we can check it against the 'site_frontpage' variable.
+    $is_front_page = ($_GET['q'] == variable_get('site_frontpage', 'node'));
+  }
+
+  return $is_front_page;
+}
+
+/**
+ * @} End of "defgroup path".
+ */
+
Index: includes/common.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/common.inc,v
retrieving revision 1.900
diff -u -p -r1.900 common.inc
--- includes/common.inc	14 May 2009 08:23:14 -0000	1.900
+++ includes/common.inc	16 May 2009 01:17:06 -0000
@@ -163,13 +163,6 @@ function drupal_get_html_head() {
 }
 
 /**
- * Reset the static variable which holds the aliases mapped for this request.
- */
-function drupal_clear_path_cache() {
-  drupal_lookup_path('wipe');
-}
-
-/**
  * Add a feed URL for the current page.
  *
  * This function can be called as long the HTML header hasn't been sent.
@@ -1718,7 +1711,7 @@ function url($path = NULL, array $option
   if ($path == '<front>') {
     $path = '';
   }
-  elseif (!empty($path) && !$options['alias']) {
+  elseif (!empty($path) && !$options['alias'] && drupal_function_exists('drupal_get_path_alias')) {
     $path = drupal_get_path_alias($path, isset($options['language']) ? $options['language']->language : '');
   }
 
@@ -1938,6 +1931,136 @@ function base_path() {
 }
 
 /**
+ * @ingroup path
+ * @{
+ */
+
+/**
+ * Return a component of the current Drupal path.
+ *
+ * When viewing a page at the path "admin/build/types", for example, arg(0)
+ * returns "admin", arg(1) returns "content", and arg(2) returns "types".
+ *
+ * Avoid use of this function where possible, as resulting code is hard to read.
+ * In menu callback functions, attempt to use named arguments. See the explanation
+ * in menu.inc for how to construct callbacks that take arguments. When attempting
+ * to use this function to load an element from the current path, e.g. loading the
+ * node on a node page, please use menu_get_object() instead.
+ *
+ * @param $index
+ *   The index of the component, where each component is separated by a '/'
+ *   (forward-slash), and where the first component has an index of 0 (zero).
+ *
+ * @return
+ *   The component specified by $index, or NULL if the specified component was
+ *   not found.
+ */
+function arg($index = NULL, $path = NULL) {
+  $arguments = &drupal_static(__FUNCTION__);
+
+  if (!isset($path)) {
+    $path = $_GET['q'];
+  }
+  if (!isset($arguments[$path])) {
+    $arguments[$path] = explode('/', $path);
+  }
+  if (!isset($index)) {
+    return $arguments[$path];
+  }
+  if (isset($arguments[$path][$index])) {
+    return $arguments[$path][$index];
+  }
+}
+
+/**
+ * Check if a path matches any pattern in a set of patterns.
+ *
+ * @param $path
+ *   The path to match.
+ * @param $patterns
+ *   String containing a set of patterns separated by \n, \r or \r\n.
+ *
+ * @return
+ *   Boolean value: TRUE if the path matches a pattern, FALSE otherwise.
+ */
+function drupal_match_path($path, $patterns) {
+  $regexps = &drupal_static(__FUNCTION__);
+
+  if (!isset($regexps[$patterns])) {
+    $regexps[$patterns] = '/^(' . preg_replace(array('/(\r\n?|\n)/', '/\\\\\*/', '/(^|\|)\\\\<front\\\\>($|\|)/'), array('|', '.*', '\1' . preg_quote(variable_get('site_frontpage', 'node'), '/') . '\2'), preg_quote($patterns, '/')) . ')$/';
+  }
+  return (bool)preg_match($regexps[$patterns], $path);
+}
+
+/**
+ * Return the current URL path of the page being viewed.
+ *
+ * Examples:
+ * - http://example.com/node/306 returns "node/306".
+ * - http://example.com/drupalfolder/node/306 returns "node/306" while
+ *   base_path() returns "/drupalfolder/".
+ * - http://example.com/path/alias (which is a path alias for node/306) returns
+ *   "node/306" as opposed to the path alias.
+ *
+ * This function is not available in hook_boot() so use $_GET['q'] instead.
+ * However, be careful when doing that because in the case of Example #3
+ * $_GET['q'] will contain "path/alias". If "node/306" is needed, calling
+ * drupal_bootstrap(DRUPAL_BOOTSTRAP_PATH) makes this function available.
+ *
+ * @return
+ *   The current Drupal URL path.
+ */
+function current_path() {
+  return $_GET['q'];
+}
+
+/**
+ * Get the title of the current page, for display on the page and in the title bar.
+ *
+ * @return
+ *   The current page's title.
+ */
+function drupal_get_title() {
+  $title = drupal_set_title();
+
+  // during a bootstrap, menu.inc is not included and thus we cannot provide a title
+  if (!isset($title) && function_exists('menu_get_active_title')) {
+    $title = check_plain(menu_get_active_title());
+  }
+
+  return $title;
+}
+
+/**
+ * Set the title of the current page, for display on the page and in the title bar.
+ *
+ * @param $title
+ *   Optional string value to assign to the page title; or if set to NULL
+ *   (default), leaves the current title unchanged.
+ * @param $output
+ *   Optional flag - normally should be left as CHECK_PLAIN. Only set to
+ *   PASS_THROUGH if you have already removed any possibly dangerous code
+ *   from $title using a function like check_plain() or filter_xss(). With this
+ *   flag the string will be passed through unchanged.
+ *
+ * @return
+ *   The updated title of the current page.
+ */
+function drupal_set_title($title = NULL, $output = CHECK_PLAIN) {
+  $stored_title = &drupal_static(__FUNCTION__);
+
+  if (isset($title)) {
+    $stored_title = ($output == PASS_THROUGH) ? $title : check_plain($title);
+  }
+
+  return $stored_title;
+}
+
+/**
+ * @} End of "ingroup path".
+ */
+
+/**
  * Add a <link> tag to the page's HEAD.
  *
  * This function can be called as long the HTML header hasn't been sent.
Index: includes/theme.maintenance.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/theme.maintenance.inc,v
retrieving revision 1.26
diff -u -p -r1.26 theme.maintenance.inc
--- includes/theme.maintenance.inc	12 May 2009 13:43:44 -0000	1.26
+++ includes/theme.maintenance.inc	16 May 2009 01:41:26 -0000
@@ -22,7 +22,6 @@ function _drupal_maintenance_theme() {
     return;
   }
 
-  require_once DRUPAL_ROOT . '/includes/path.inc';
   require_once DRUPAL_ROOT . '/includes/theme.inc';
   require_once DRUPAL_ROOT . '/includes/common.inc';
   require_once DRUPAL_ROOT . '/includes/unicode.inc';
Index: modules/block/block.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/block/block.module,v
retrieving revision 1.331
diff -u -p -r1.331 block.module
--- modules/block/block.module	14 May 2009 08:23:14 -0000	1.331
+++ modules/block/block.module	16 May 2009 01:10:35 -0000
@@ -592,7 +592,12 @@ function _block_load_blocks() {
     // Match path if necessary.
     if ($block->pages) {
       if ($block->visibility < 2) {
-        $path = drupal_get_path_alias($_GET['q']);
+        if (drupal_function_exists('drupal_get_path_alias')) {
+          $path = drupal_get_path_alias($_GET['q']);
+        }
+        else {
+          $path = $_GET['q'];
+        }
         // Compare with the internal and path alias (if any).
         $page_match = drupal_match_path($path, $block->pages);
         if ($path != $_GET['q']) {
Index: modules/path/path.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/path/path.module,v
retrieving revision 1.157
diff -u -p -r1.157 path.module
--- modules/path/path.module	10 May 2009 16:50:19 -0000	1.157
+++ modules/path/path.module	16 May 2009 01:39:49 -0000
@@ -3,10 +3,164 @@
 
 /**
  * @file
- * Enables users to rename URLs.
+ * Functions to handle paths in Drupal, including path aliasing.
+ *
+ * These functions are not loaded for cached pages, but modules that need
+ * to use them in hook_init() or hook exit() can make them available, by
+ * executing "drupal_bootstrap(DRUPAL_BOOTSTRAP_PATH);".
+ *
+ * @ingroup path
  */
 
 /**
+ * Implementation of hook_lookup_path().
+ */
+function path_lookup_path(&$alias) {
+  if ($path = drupal_get_normal_path($alias)) {
+    $alias = $path;
+  }
+}
+
+/**
+ * Given an alias, return its Drupal system URL if one exists.
+ *
+ * Given a Drupal system URL return one of its aliases if such a one exists.
+ * Otherwise, return FALSE.
+ *
+ * @param $action
+ *   One of the following values:
+ *   - wipe: delete the alias cache.
+ *   - alias: return an alias for a given Drupal system path (if one exists).
+ *   - source: return the Drupal system URL for a path alias (if one exists).
+ * @param $path
+ *   The path to investigate for corresponding aliases or system URLs.
+ * @param $path_language
+ *   Optional language code to search the path with. Defaults to the page language.
+ *   If there's no path defined for that language it will search paths without
+ *   language.
+ *
+ * @return
+ *   Either a Drupal system path, an aliased path, or FALSE if no path was
+ *   found.
+ */
+function drupal_lookup_path($action, $path = '', $path_language = '') {
+  global $language;
+  // $map is an array with language keys, holding arrays of Drupal paths to alias relations
+  $map = &drupal_static(__FUNCTION__, array());
+  $no_src = &drupal_static(__FUNCTION__ . ':no_src', array());
+  $count = &drupal_static(__FUNCTION__ . ':count');
+
+  $path_language = $path_language ? $path_language : $language->language;
+
+  // Use $count to avoid looking up paths in subsequent calls if there simply are no aliases
+  if (!isset($count)) {
+    $count = db_query('SELECT COUNT(pid) FROM {url_alias}')->fetchField();
+  }
+
+  if ($action == 'wipe') {
+    $map = array();
+    $no_src = array();
+    $count = NULL;
+  }
+  elseif ($count > 0 && $path != '') {
+    if ($action == 'alias') {
+      if (isset($map[$path_language][$path])) {
+        return $map[$path_language][$path];
+      }
+      // Get the most fitting result falling back with alias without language
+      $alias = db_query("SELECT dst FROM {url_alias} WHERE src = :src AND language IN(:language, '') ORDER BY language DESC", array(
+        ':src' => $path,
+        ':language' => $path_language)
+      )->fetchField();
+      $map[$path_language][$path] = $alias;
+      return $alias;
+    }
+    // Check $no_src for this $path in case we've already determined that there
+    // isn't a path that has this alias
+    elseif ($action == 'source' && !isset($no_src[$path_language][$path])) {
+      // Look for the value $path within the cached $map
+      $src = '';
+      if (!isset($map[$path_language]) || !($src = array_search($path, $map[$path_language]))) {
+        // Get the most fitting result falling back with alias without language
+        if ($src = db_query("SELECT src FROM {url_alias} WHERE dst = :dst AND language IN(:language, '') ORDER BY language DESC", array(
+            ':dst' => $path,
+            ':language' => $path_language)
+          )->fetchField()) {
+          $map[$path_language][$src] = $path;
+        }
+        else {
+          // We can't record anything into $map because we do not have a valid
+          // index and there is no need because we have not learned anything
+          // about any Drupal path. Thus cache to $no_src.
+          $no_src[$path_language][$path] = TRUE;
+        }
+      }
+      return $src;
+    }
+  }
+
+  return FALSE;
+}
+
+/**
+ * Given a path alias, return the internal path it represents.
+ *
+ * @param $path
+ *   A Drupal path alias.
+ * @param $path_language
+ *   An optional language code to look up the path in.
+ *
+ * @return
+ *   The internal path represented by the alias, or the original alias if no
+ *   internal path was found.
+ */
+function drupal_get_normal_path($path, $path_language = '') {
+  $result = $path;
+  if ($src = drupal_lookup_path('source', $path, $path_language)) {
+    $result = $src;
+  }
+  if (function_exists('custom_url_rewrite_inbound')) {
+    // Modules may alter the inbound request path by reference.
+    custom_url_rewrite_inbound($result, $path, $path_language);
+  }
+  return $result;
+}
+
+/**
+ * Given an internal Drupal path, return the alias set by the administrator.
+ *
+ * If no path is provided, the function will return the alias of the current
+ * page.
+ *
+ * @param $path
+ *   An internal Drupal path.
+ * @param $path_language
+ *   An optional language code to look up the path in.
+ *
+ * @return
+ *   An aliased path if one was found, or the original path if no alias was
+ *   found.
+ */
+function drupal_get_path_alias($path = NULL, $path_language = '') {
+  // If no path is specified, use the current page's path.
+  if ($path == NULL) {
+    $path = $_GET['q'];
+  }
+  $result = $path;
+  if ($alias = drupal_lookup_path('alias', $path, $path_language)) {
+    $result = $alias;
+  }
+  return $result;
+}
+
+/**
+ * Reset the static variable which holds the aliases mapped for this request.
+ */
+function drupal_clear_path_cache() {
+  drupal_lookup_path('wipe');
+}
+
+/**
  * Implementation of hook_help().
  */
 function path_help($path, $arg) {
@@ -253,6 +407,14 @@ function path_form_alter(&$form, $form_s
       );
     }
   }
+  else if ($form_id == 'system_site_information_settings') {
+    $form['site_frontpage']['#default_value'] = drupal_get_path_alias($form['site_frontpage']['#default_value']);
+    array_unshift($form['#submit'], 'path_site_information_settings_submit');
+  }
+}
+
+function path_site_information_settings_submit($form, &$form_state) {
+  $form_state['values']['site_frontpage'] = drupal_get_normal_path($form_state['values']['site_frontpage']);
 }
 
 /**
@@ -277,3 +439,4 @@ function path_perm() {
 function path_load($pid) {
   return db_query('SELECT * FROM {url_alias} WHERE pid = :pid', array(':pid' => $pid))->fetchAssoc();
 }
+
Index: modules/statistics/statistics.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/statistics/statistics.module,v
retrieving revision 1.303
diff -u -p -r1.303 statistics.module
--- modules/statistics/statistics.module	3 May 2009 10:11:35 -0000	1.303
+++ modules/statistics/statistics.module	16 May 2009 01:14:25 -0000
@@ -350,7 +350,12 @@ function statistics_block_view($delta = 
  * statistics module.
  */
 function _statistics_link($path, $width = 35) {
-  $title = drupal_get_path_alias($path);
+  if (drupal_function_exists('drupal_get_path_alias')) {
+    $title = drupal_get_path_alias($path);
+  }
+  else {
+    $title = $path;
+  }
   $title = truncate_utf8($title, $width, FALSE, TRUE);
   return l($title, $path);
 }
