Commit 02750689 authored by Dries's avatar Dries

- Patch #1183208 by effulgentsia, Niklas Fiekas, katbailey, no_commit_credit,...

- Patch #1183208 by effulgentsia, Niklas Fiekas, katbailey, no_commit_credit, catch: remove variable_get()('clean_url()') and switch to index.php/path pattern for dirty URL support.
parent 34ef955a
...@@ -103,17 +103,6 @@ function authorize_access_allowed() { ...@@ -103,17 +103,6 @@ function authorize_access_allowed() {
// Load the code that drives the authorize process. // Load the code that drives the authorize process.
require_once DRUPAL_ROOT . '/core/includes/authorize.inc'; require_once DRUPAL_ROOT . '/core/includes/authorize.inc';
// For the sake of Batch API and a few other low-level functions, we need to
// initialize the URL path into $_GET['q']. However, we do not want to raise
// our bootstrap level, nor do we want to call drupal_initialize_path(),
// since that is assuming that modules are loaded and invoking hooks.
// However, all we really care is if we're in the middle of a batch, in which
// case $_GET['q'] will already be set, we just initialize it to an empty
// string if it's not already defined.
if (!isset($_GET['q'])) {
$_GET['q'] = '';
}
if (isset($_SESSION['authorize_operation']['page_title'])) { if (isset($_SESSION['authorize_operation']['page_title'])) {
drupal_set_title($_SESSION['authorize_operation']['page_title']); drupal_set_title($_SESSION['authorize_operation']['page_title']);
} }
......
...@@ -551,12 +551,8 @@ function drupal_environment_initialize() { ...@@ -551,12 +551,8 @@ function drupal_environment_initialize() {
$_SERVER['HTTP_HOST'] = ''; $_SERVER['HTTP_HOST'] = '';
} }
// When clean URLs are enabled, emulate ?q=foo/bar using REQUEST_URI. It is // @todo Refactor with the Symfony Request object.
// not possible to append the query string using mod_rewrite without the B _current_path(request_path());
// flag (this was added in Apache 2.2.8), because mod_rewrite unescapes the
// path before passing it on to PHP. This is a problem when the path contains
// e.g. "&" or "%" that have special meanings in URLs and must be encoded.
$_GET['q'] = request_path();
// Enforce E_STRICT, but allow users to set levels not part of E_STRICT. // Enforce E_STRICT, but allow users to set levels not part of E_STRICT.
error_reporting(E_STRICT | E_ALL | error_reporting()); error_reporting(E_STRICT | E_ALL | error_reporting());
...@@ -597,7 +593,7 @@ function drupal_valid_http_host($host) { ...@@ -597,7 +593,7 @@ function drupal_valid_http_host($host) {
* Sets the base URL, cookie domain, and session name from configuration. * Sets the base URL, cookie domain, and session name from configuration.
*/ */
function drupal_settings_initialize() { function drupal_settings_initialize() {
global $base_url, $base_path, $base_root; global $base_url, $base_path, $base_root, $script_path;
// Export the following settings.php variables to the global namespace // Export the following settings.php variables to the global namespace
global $databases, $cookie_domain, $conf, $installed_profile, $update_free_access, $db_url, $db_prefix, $drupal_hash_salt, $is_https, $base_secure_url, $base_insecure_url, $config_directory_name, $config_signature_key; global $databases, $cookie_domain, $conf, $installed_profile, $update_free_access, $db_url, $db_prefix, $drupal_hash_salt, $is_https, $base_secure_url, $base_insecure_url, $config_directory_name, $config_signature_key;
...@@ -626,8 +622,8 @@ function drupal_settings_initialize() { ...@@ -626,8 +622,8 @@ function drupal_settings_initialize() {
$base_url = $base_root; $base_url = $base_root;
// $_SERVER['SCRIPT_NAME'] can, in contrast to $_SERVER['PHP_SELF'], not // For a request URI of '/index.php/foo', $_SERVER['SCRIPT_NAME'] is
// be modified by a visitor. // '/index.php', whereas $_SERVER['PHP_SELF'] is '/index.php/foo'.
if ($dir = rtrim(dirname($_SERVER['SCRIPT_NAME']), '\/')) { if ($dir = rtrim(dirname($_SERVER['SCRIPT_NAME']), '\/')) {
// Remove "core" directory if present, allowing install.php, update.php, // Remove "core" directory if present, allowing install.php, update.php,
// cron.php and others to auto-detect a base path. // cron.php and others to auto-detect a base path.
...@@ -648,6 +644,32 @@ function drupal_settings_initialize() { ...@@ -648,6 +644,32 @@ function drupal_settings_initialize() {
$base_secure_url = str_replace('http://', 'https://', $base_url); $base_secure_url = str_replace('http://', 'https://', $base_url);
$base_insecure_url = str_replace('https://', 'http://', $base_url); $base_insecure_url = str_replace('https://', 'http://', $base_url);
// Determine the path of the script relative to the base path, and add a
// trailing slash. This is needed for creating URLs to Drupal pages.
if (!isset($script_path)) {
$script_path = '';
// We don't expect scripts outside of the base path, but sanity check
// anyway.
if (strpos($_SERVER['SCRIPT_NAME'], $base_path) === 0) {
$script_path = substr($_SERVER['SCRIPT_NAME'], strlen($base_path)) . '/';
// If the request URI does not contain the script name, then clean URLs
// are in effect and the script path can be similarly dropped from URL
// generation. For servers that don't provide $_SERVER['REQUEST_URI'], we
// do not know the actual URI requested by the client, and request_uri()
// returns a URI with the script name, resulting in non-clean URLs unless
// there's other code that intervenes.
if (strpos(request_uri(TRUE) . '/', $base_path . $script_path) !== 0) {
$script_path = '';
}
// @todo Temporary BC for install.php, update.php, and other scripts.
// - http://drupal.org/node/1547184
// - http://drupal.org/node/1546082
if ($script_path !== 'index.php/') {
$script_path = '';
}
}
}
if ($cookie_domain) { if ($cookie_domain) {
// If the user specifies the cookie domain, also use it for session name. // If the user specifies the cookie domain, also use it for session name.
$session_name = $cookie_domain; $session_name = $cookie_domain;
...@@ -1488,13 +1510,15 @@ function drupal_validate_utf8($text) { ...@@ -1488,13 +1510,15 @@ function drupal_validate_utf8($text) {
* *
* Because $_SERVER['REQUEST_URI'] is only available on Apache, we generate an * Because $_SERVER['REQUEST_URI'] is only available on Apache, we generate an
* equivalent using other environment variables. * equivalent using other environment variables.
*
* @todo The above comment is incorrect: http://drupal.org/node/1547294.
*/ */
function request_uri() { function request_uri($omit_query_string = FALSE) {
if (isset($_SERVER['REQUEST_URI'])) { if (isset($_SERVER['REQUEST_URI'])) {
$uri = $_SERVER['REQUEST_URI']; $uri = $_SERVER['REQUEST_URI'];
} }
else { else {
if (isset($_SERVER['argv'])) { if (isset($_SERVER['argv'][0])) {
$uri = $_SERVER['SCRIPT_NAME'] . '?' . $_SERVER['argv'][0]; $uri = $_SERVER['SCRIPT_NAME'] . '?' . $_SERVER['argv'][0];
} }
elseif (isset($_SERVER['QUERY_STRING'])) { elseif (isset($_SERVER['QUERY_STRING'])) {
...@@ -1507,7 +1531,7 @@ function request_uri() { ...@@ -1507,7 +1531,7 @@ function request_uri() {
// Prevent multiple slashes to avoid cross site requests via the Form API. // Prevent multiple slashes to avoid cross site requests via the Form API.
$uri = '/' . ltrim($uri, '/'); $uri = '/' . ltrim($uri, '/');
return $uri; return $omit_query_string ? strtok($uri, '?') : $uri;
} }
/** /**
...@@ -2181,7 +2205,7 @@ function _drupal_bootstrap_page_cache() { ...@@ -2181,7 +2205,7 @@ function _drupal_bootstrap_page_cache() {
if (is_object($cache)) { if (is_object($cache)) {
header('X-Drupal-Cache: HIT'); header('X-Drupal-Cache: HIT');
// Restore the metadata cached with the page. // Restore the metadata cached with the page.
$_GET['q'] = $cache->data['path']; _current_path($cache->data['path']);
drupal_set_title($cache->data['title'], PASS_THROUGH); drupal_set_title($cache->data['title'], PASS_THROUGH);
date_default_timezone_set(drupal_get_user_timezone()); date_default_timezone_set(drupal_get_user_timezone());
// If the skipping of the bootstrap hooks is not enforced, call // If the skipping of the bootstrap hooks is not enforced, call
...@@ -2418,9 +2442,9 @@ function drupal_maintenance_theme() { ...@@ -2418,9 +2442,9 @@ function drupal_maintenance_theme() {
*/ */
function drupal_fast_404() { function drupal_fast_404() {
$exclude_paths = variable_get('404_fast_paths_exclude', FALSE); $exclude_paths = variable_get('404_fast_paths_exclude', FALSE);
if ($exclude_paths && !preg_match($exclude_paths, $_GET['q'])) { if ($exclude_paths && !preg_match($exclude_paths, request_path())) {
$fast_paths = variable_get('404_fast_paths', FALSE); $fast_paths = variable_get('404_fast_paths', FALSE);
if ($fast_paths && preg_match($fast_paths, $_GET['q'])) { if ($fast_paths && preg_match($fast_paths, request_path())) {
drupal_add_http_header('Status', '404 Not Found'); drupal_add_http_header('Status', '404 Not Found');
$fast_404_html = variable_get('404_fast_html', '<html xmlns="http://www.w3.org/1999/xhtml"><head><title>404 Not Found</title></head><body><h1>Not Found</h1><p>The requested URL "@path" was not found on this server.</p></body></html>'); $fast_404_html = variable_get('404_fast_html', '<html xmlns="http://www.w3.org/1999/xhtml"><head><title>404 Not Found</title></head><body><h1>Not Found</h1><p>The requested URL "@path" was not found on this server.</p></body></html>');
// Replace @path in the variable with the page path. // Replace @path in the variable with the page path.
...@@ -2655,41 +2679,44 @@ function request_path() { ...@@ -2655,41 +2679,44 @@ function request_path() {
return $path; return $path;
} }
if (isset($_GET['q'])) { // Get the part of the URI between the base path of the Drupal installation
// This is a request with a ?q=foo/bar query string. $_GET['q'] is // and the query string, and unescape it.
// overwritten in drupal_path_initialize(), but request_path() is called $request_path = request_uri(TRUE);
// very early in the bootstrap process, so the original value is saved in $base_path_len = strlen(rtrim(dirname($_SERVER['SCRIPT_NAME']), '\/'));
// $path and returned in later calls. $path = substr(urldecode($request_path), $base_path_len + 1);
$path = $_GET['q'];
} // Depending on server configuration, the URI might or might not include the
elseif (isset($_SERVER['REQUEST_URI'])) { // script name. For example, the front page might be accessed as
// This request is either a clean URL, or 'index.php', or nonsense. // http://example.com or as http://example.com/index.php, and the "user"
// Extract the path from REQUEST_URI. // page might be accessed as http://example.com/user or as
$request_path = strtok($_SERVER['REQUEST_URI'], '?'); // http://example.com/index.php/user. Strip the script name from $path.
$base_path_len = strlen(rtrim(dirname($_SERVER['SCRIPT_NAME']), '\/')); $script = basename($_SERVER['SCRIPT_NAME']);
// Unescape and strip $base_path prefix, leaving q without a leading slash. if ($path == $script) {
$path = substr(urldecode($request_path), $base_path_len + 1);
// If the path equals the script filename, either because 'index.php' was
// explicitly provided in the URL, or because the server added it to
// $_SERVER['REQUEST_URI'] even when it wasn't provided in the URL (some
// versions of Microsoft IIS do this), the front page should be served.
if ($path == basename($_SERVER['PHP_SELF'])) {
$path = '';
}
}
else {
// This is the front page.
$path = ''; $path = '';
} }
elseif (strpos($path, $script . '/') === 0) {
$path = substr($path, strlen($script) + 1);
}
// Under certain conditions Apache's RewriteRule directive prepends the value // Extra slashes can appear in URLs or under some conditions, added by Apache,
// assigned to $_GET['q'] with a slash. Moreover we can always have a trailing // so normalize.
// slash in place, hence we need to normalize $_GET['q'].
$path = trim($path, '/'); $path = trim($path, '/');
return $path; return $path;
} }
/**
* @todo This is a temporary function pending refactoring Drupal to use
* Symfony's Request object exclusively.
*/
function _current_path($path = NULL) {
static $current_path = '';
if (isset($path)) {
$current_path = $path;
}
return $current_path;
}
/** /**
* Returns a component of the current Drupal path. * Returns a component of the current Drupal path.
* *
...@@ -2726,7 +2753,9 @@ function arg($index = NULL, $path = NULL) { ...@@ -2726,7 +2753,9 @@ function arg($index = NULL, $path = NULL) {
$arguments = &$drupal_static_fast['arguments']; $arguments = &$drupal_static_fast['arguments'];
if (!isset($path)) { if (!isset($path)) {
$path = $_GET['q']; // @todo The public function current_path() is not available during early
// bootstrap.
$path = _current_path();
} }
if (!isset($arguments[$path])) { if (!isset($arguments[$path])) {
$arguments[$path] = explode('/', $path); $arguments[$path] = explode('/', $path);
......
This diff is collapsed.
...@@ -2031,7 +2031,7 @@ function file_transfer($uri, $headers) { ...@@ -2031,7 +2031,7 @@ function file_transfer($uri, $headers) {
* @see system_menu() * @see system_menu()
*/ */
function file_download() { function file_download() {
// Merge remainder of arguments from GET['q'], into relative file path. // Merge remaining path arguments into relative file path.
$args = func_get_args(); $args = func_get_args();
$scheme = array_shift($args); $scheme = array_shift($args);
$target = implode('/', $args); $target = implode('/', $args);
......
...@@ -1248,7 +1248,7 @@ function drupal_redirect_form($form_state) { ...@@ -1248,7 +1248,7 @@ function drupal_redirect_form($form_state) {
$function($form_state['redirect']); $function($form_state['redirect']);
} }
} }
drupal_goto($_GET['q']); drupal_goto(current_path());
} }
} }
...@@ -4682,7 +4682,7 @@ function batch_process($redirect = NULL, $url = 'batch', $redirect_callback = 'd ...@@ -4682,7 +4682,7 @@ function batch_process($redirect = NULL, $url = 'batch', $redirect_callback = 'd
'progressive' => TRUE, 'progressive' => TRUE,
'url' => $url, 'url' => $url,
'url_options' => array(), 'url_options' => array(),
'source_url' => $_GET['q'], 'source_url' => current_path(),
'redirect' => $redirect, 'redirect' => $redirect,
'theme' => $GLOBALS['theme_key'], 'theme' => $GLOBALS['theme_key'],
'redirect_callback' => $redirect_callback, 'redirect_callback' => $redirect_callback,
......
...@@ -1522,11 +1522,8 @@ function install_configure_form($form, &$form_state, &$install_state) { ...@@ -1522,11 +1522,8 @@ function install_configure_form($form, &$form_state, &$install_state) {
// We add these strings as settings because JavaScript translation does not // We add these strings as settings because JavaScript translation does not
// work on install time. // work on install time.
drupal_add_js(array('copyFieldValue' => array('edit-site-mail' => array('edit-account-mail'))), 'setting'); drupal_add_js(array('copyFieldValue' => array('edit-site-mail' => array('edit-account-mail'))), 'setting');
drupal_add_js('jQuery(function () { Drupal.cleanURLsInstallCheck(); });', 'inline');
// Add JS to show / hide the 'Email administrator about site updates' elements // Add JS to show / hide the 'Email administrator about site updates' elements
drupal_add_js('jQuery(function () { Drupal.hideEmailAdministratorCheckbox() });', 'inline'); drupal_add_js('jQuery(function () { Drupal.hideEmailAdministratorCheckbox() });', 'inline');
// Build menu to allow clean URL check.
menu_rebuild();
// Cache a fully-built schema. This is necessary for any invocation of // Cache a fully-built schema. This is necessary for any invocation of
// index.php because: (1) setting cache table entries requires schema // index.php because: (1) setting cache table entries requires schema
...@@ -1534,8 +1531,7 @@ function install_configure_form($form, &$form_state, &$install_state) { ...@@ -1534,8 +1531,7 @@ function install_configure_form($form, &$form_state, &$install_state) {
// loaded, so (3) if there is no cached schema, drupal_get_schema() will // loaded, so (3) if there is no cached schema, drupal_get_schema() will
// try to generate one but with no loaded modules will return nothing. // try to generate one but with no loaded modules will return nothing.
// //
// This logically could be done during the 'install_finished' task, but the // @todo Move this to the 'install_finished' task?
// clean URL check requires it now.
drupal_get_schema(NULL, TRUE); drupal_get_schema(NULL, TRUE);
// Return the form. // Return the form.
...@@ -1827,12 +1823,6 @@ function _install_configure_form($form, &$form_state, &$install_state) { ...@@ -1827,12 +1823,6 @@ function _install_configure_form($form, &$form_state, &$install_state) {
'#attributes' => array('class' => array('timezone-detect')), '#attributes' => array('class' => array('timezone-detect')),
); );
$form['server_settings']['clean_url'] = array(
'#type' => 'hidden',
'#default_value' => 0,
'#attributes' => array('id' => 'edit-clean-url', 'class' => array('install')),
);
$form['update_notifications'] = array( $form['update_notifications'] = array(
'#type' => 'fieldset', '#type' => 'fieldset',
'#title' => st('Update notifications'), '#title' => st('Update notifications'),
...@@ -1903,10 +1893,6 @@ function install_configure_form_submit($form, &$form_state) { ...@@ -1903,10 +1893,6 @@ function install_configure_form_submit($form, &$form_state) {
$user = user_load(1); $user = user_load(1);
user_login_finalize(); user_login_finalize();
if (isset($form_state['values']['clean_url'])) {
variable_set('clean_url', $form_state['values']['clean_url']);
}
// Record when this install ran. // Record when this install ran.
variable_set('install_time', $_SERVER['REQUEST_TIME']); variable_set('install_time', $_SERVER['REQUEST_TIME']);
} }
...@@ -121,8 +121,7 @@ function drupal_detect_baseurl($file = 'core/install.php') { ...@@ -121,8 +121,7 @@ function drupal_detect_baseurl($file = 'core/install.php') {
$proto = $_SERVER['HTTPS'] ? 'https://' : 'http://'; $proto = $_SERVER['HTTPS'] ? 'https://' : 'http://';
$host = $_SERVER['SERVER_NAME']; $host = $_SERVER['SERVER_NAME'];
$port = ($_SERVER['SERVER_PORT'] == 80 ? '' : ':' . $_SERVER['SERVER_PORT']); $port = ($_SERVER['SERVER_PORT'] == 80 ? '' : ':' . $_SERVER['SERVER_PORT']);
$uri = preg_replace("/\?.*/", '', $_SERVER['REQUEST_URI']); $dir = str_replace("/$file", '', $_SERVER['SCRIPT_NAME']);
$dir = str_replace("/$file", '', $uri);
return "$proto$host$port$dir"; return "$proto$host$port$dir";
} }
......
...@@ -441,7 +441,7 @@ function menu_set_item($path, $router_item) { ...@@ -441,7 +441,7 @@ function menu_set_item($path, $router_item) {
function menu_get_item($path = NULL, $router_item = NULL) { function menu_get_item($path = NULL, $router_item = NULL) {
$router_items = &drupal_static(__FUNCTION__); $router_items = &drupal_static(__FUNCTION__);
if (!isset($path)) { if (!isset($path)) {
$path = $_GET['q']; $path = current_path();
} }
if (isset($router_item)) { if (isset($router_item)) {
$router_items[$path] = $router_item; $router_items[$path] = $router_item;
...@@ -498,7 +498,7 @@ function menu_execute_active_handler($path = NULL, $deliver = TRUE) { ...@@ -498,7 +498,7 @@ function menu_execute_active_handler($path = NULL, $deliver = TRUE) {
// Allow other modules to change the site status but not the path because that // Allow other modules to change the site status but not the path because that
// would not change the global variable. hook_url_inbound_alter() can be used // would not change the global variable. hook_url_inbound_alter() can be used
// to change the path. Code later will not use the $read_only_path variable. // to change the path. Code later will not use the $read_only_path variable.
$read_only_path = !empty($path) ? $path : $_GET['q']; $read_only_path = !empty($path) ? $path : current_path();
drupal_alter('menu_site_status', $page_callback_result, $read_only_path); drupal_alter('menu_site_status', $page_callback_result, $read_only_path);
// Only continue if the site status is not set. // Only continue if the site status is not set.
...@@ -1043,11 +1043,11 @@ function menu_tree_output($tree) { ...@@ -1043,11 +1043,11 @@ function menu_tree_output($tree) {
$class[] = 'active-trail'; $class[] = 'active-trail';
$data['link']['localized_options']['attributes']['class'][] = 'active-trail'; $data['link']['localized_options']['attributes']['class'][] = 'active-trail';
} }
// Normally, l() compares the href of every link with $_GET['q'] and sets // Normally, l() compares the href of every link with the current path and
// the active class accordingly. But local tasks do not appear in menu // sets the active class accordingly. But local tasks do not appear in menu
// trees, so if the current path is a local task, and this link is its // trees, so if the current path is a local task, and this link is its
// tab root, then we have to set the class manually. // tab root, then we have to set the class manually.
if ($data['link']['href'] == $router_item['tab_root_href'] && $data['link']['href'] != $_GET['q']) { if ($data['link']['href'] == $router_item['tab_root_href'] && $data['link']['href'] != current_path()) {
$data['link']['localized_options']['attributes']['class'][] = 'active'; $data['link']['localized_options']['attributes']['class'][] = 'active';
} }
...@@ -1846,11 +1846,11 @@ function menu_navigation_links($menu_name, $level = 0) { ...@@ -1846,11 +1846,11 @@ function menu_navigation_links($menu_name, $level = 0) {
$class = ' active-trail'; $class = ' active-trail';
$l['attributes']['class'][] = 'active-trail'; $l['attributes']['class'][] = 'active-trail';
} }
// Normally, l() compares the href of every link with $_GET['q'] and sets // Normally, l() compares the href of every link with the current path and
// the active class accordingly. But local tasks do not appear in menu // sets the active class accordingly. But local tasks do not appear in
// trees, so if the current path is a local task, and this link is its // menu trees, so if the current path is a local task, and this link is
// tab root, then we have to set the class manually. // its tab root, then we have to set the class manually.
if ($item['link']['href'] == $router_item['tab_root_href'] && $item['link']['href'] != $_GET['q']) { if ($item['link']['href'] == $router_item['tab_root_href'] && $item['link']['href'] != current_path()) {
$l['attributes']['class'][] = 'active'; $l['attributes']['class'][] = 'active';
} }
// Keyed with the unique mlid to generate classes in theme_links(). // Keyed with the unique mlid to generate classes in theme_links().
...@@ -1964,8 +1964,8 @@ function menu_local_tasks($level = 0) { ...@@ -1964,8 +1964,8 @@ function menu_local_tasks($level = 0) {
// local tasks link to their parent, but the path of default local // local tasks link to their parent, but the path of default local
// tasks can still be accessed directly, in which case this link // tasks can still be accessed directly, in which case this link
// would not be marked as active, since l() only compares the href // would not be marked as active, since l() only compares the href
// with $_GET['q']. // with current_path().
if ($link['href'] != $_GET['q']) { if ($link['href'] != current_path()) {
$link['localized_options']['attributes']['class'][] = 'active'; $link['localized_options']['attributes']['class'][] = 'active';
} }
$tabs_current[] = array( $tabs_current[] = array(
...@@ -2040,8 +2040,8 @@ function menu_local_tasks($level = 0) { ...@@ -2040,8 +2040,8 @@ function menu_local_tasks($level = 0) {
// Mark the link as active, if the current path is a (second-level) // Mark the link as active, if the current path is a (second-level)
// local task of a default local task. Since this default local task // local task of a default local task. Since this default local task
// links to its parent, l() will not mark it as active, as it only // links to its parent, l() will not mark it as active, as it only
// compares the link's href to $_GET['q']. // compares the link's href to current_path().
if ($link['href'] != $_GET['q']) { if ($link['href'] != current_path()) {
$link['localized_options']['attributes']['class'][] = 'active'; $link['localized_options']['attributes']['class'][] = 'active';
} }
$tabs_current[] = array( $tabs_current[] = array(
...@@ -2304,10 +2304,11 @@ function menu_get_active_menu_names() { ...@@ -2304,10 +2304,11 @@ function menu_get_active_menu_names() {
* A Drupal path - not a path alias. * A Drupal path - not a path alias.
*/ */
function menu_set_active_item($path) { function menu_set_active_item($path) {
$_GET['q'] = $path;
// Since the active item has changed, the active menu trail may also be out // Since the active item has changed, the active menu trail may also be out
// of date. // of date.
drupal_static_reset('menu_set_active_trail'); drupal_static_reset('menu_set_active_trail');
// @todo Refactor to use the Symfony Request object.
_current_path($path);
} }
/** /**
...@@ -2421,7 +2422,7 @@ function menu_link_get_preferred($path = NULL, $selected_menu = NULL) { ...@@ -2421,7 +2422,7 @@ function menu_link_get_preferred($path = NULL, $selected_menu = NULL) {
$preferred_links = &drupal_static(__FUNCTION__); $preferred_links = &drupal_static(__FUNCTION__);
if (!isset($path)) { if (!isset($path)) {
$path = $_GET['q']; $path = current_path();
} }
if (empty($selected_menu)) { if (empty($selected_menu)) {
...@@ -3813,7 +3814,7 @@ function _menu_site_is_offline($check_only = FALSE) { ...@@ -3813,7 +3814,7 @@ function _menu_site_is_offline($check_only = FALSE) {
// Ensure that the maintenance mode message is displayed only once // Ensure that the maintenance mode message is displayed only once
// (allowing for page redirects) and specifically suppress its display on // (allowing for page redirects) and specifically suppress its display on
// the maintenance mode settings page. // the maintenance mode settings page.
if (!$check_only && $_GET['q'] != 'admin/config/development/maintenance') { if (!$check_only && current_path() != 'admin/config/development/maintenance') {
if (user_access('administer site configuration')) { if (user_access('administer site configuration')) {
drupal_set_message(t('Operating in maintenance mode. <a href="@url">Go online.</a>', array('@url' => url('admin/config/development/maintenance'))), 'status', FALSE); drupal_set_message(t('Operating in maintenance mode. <a href="@url">Go online.</a>', array('@url' => url('admin/config/development/maintenance'))), 'status', FALSE);
} }
......
...@@ -297,7 +297,7 @@ function pager_default_initialize($total, $limit, $element = 0) { ...@@ -297,7 +297,7 @@ function pager_default_initialize($total, $limit, $element = 0) {
function pager_get_query_parameters() { function pager_get_query_parameters() {
$query = &drupal_static(__FUNCTION__); $query = &drupal_static(__FUNCTION__);
if (!isset($query)) { if (!isset($query)) {
$query = drupal_get_query_parameters($_GET, array('q', 'page')); $query = drupal_get_query_parameters($_GET, array('page'));
} }
return $query; return $query;
} }
...@@ -638,7 +638,7 @@ function theme_pager_link($variables) { ...@@ -638,7 +638,7 @@ function theme_pager_link($variables) {
// none of the pager links is active at any time - but it should still be // none of the pager links is active at any time - but it should still be
// possible to use l() here. // possible to use l() here.
// @see http://drupal.org/node/1410574 // @see http://drupal.org/node/1410574
$attributes['href'] = url($_GET['q'], array('query' => $query)); $attributes['href'] = url(current_path(), array('query' => $query));
return '<a' . drupal_attributes($attributes) . '>' . check_plain($text) . '</a>'; return '<a' . drupal_attributes($attributes) . '>' . check_plain($text) . '</a>';
} }
......
...@@ -10,15 +10,24 @@ ...@@ -10,15 +10,24 @@
*/ */
/** /**
* Initialize the $_GET['q'] variable to the proper normal path. * Initializes the current path to the proper normal path.
*/ */
function drupal_path_initialize() { function drupal_path_initialize() {
// Ensure $_GET['q'] is set before calling drupal_normal_path(), to support // At this point, the current path is either the request path (due to
// path caching with hook_url_inbound_alter(). // drupal_environment_initialize()) or some modified version of it due to
if (empty($_GET['q'])) { // other bootstrap code (e.g., language negotiation), but it has not yet been
$_GET['q'] = variable_get('site_frontpage', 'user'); // normalized by drupal_get_normal_path().
$path = _current_path();
// If on the front page, resolve to the front page path, including for calls
// to current_path() while drupal_get_normal_path() is in progress.
if (empty($path)) {
$path = variable_get('site_frontpage', 'user');
_current_path($path);
} }
$_GET['q'] = drupal_get_normal_path($_GET['q']);
// Normalize the path.
_current_path(drupal_get_normal_path($path));
} }
/** /**
...@@ -234,7 +243,7 @@ function drupal_cache_system_paths() { ...@@ -234,7 +243,7 @@ function drupal_cache_system_paths() {
function drupal_get_path_alias($path = NULL, $langcode = NULL) { function drupal_get_path_alias($path = NULL, $langcode = NULL) {
// If no path is specified, use the current page's path. // If no path is specified, use the current page's path.
if ($path == NULL) { if ($path == NULL) {
$path = $_GET['q']; $path = current_path();
} }
$result = $path; $result = $path;
if ($alias = drupal_lookup_path('alias', $path, $langcode)) { if ($alias = drupal_lookup_path('alias', $path, $langcode)) {
...@@ -289,9 +298,7 @@ function drupal_is_front_page() { ...@@ -289,9 +298,7 @@ function drupal_is_front_page() {
$is_front_page = &$drupal_static_fast['is_front_page']; $is_front_page = &$drupal_static_fast['is_front_page'];
if (!isset($is_front_page)) { if (!isset($is_front_page)) {
// As drupal_path_initialize updates $_GET['q'] with the 'site_frontpage' path, $is_front_page = (current_path() == variable_get('site_frontpage', 'user'));
// we can check it against the 'site_frontpage' variable.
$is_front_page = ($_GET['q'] == variable_get('site_frontpage', 'user'));
} }
return $is_front_page; return $is_front_page;
...@@ -340,9 +347,9 @@ function drupal_match_path($path, $patterns) { ...@@ -340,9 +347,9 @@ function drupal_match_path($path, $patterns) {
* - http://example.com/path/alias (which is a path alias for node/306) returns * - http://example.com/path/alias (which is a path alias for node/306) returns
* "node/306" as opposed to the path alias. * "node/306" as opposed to the path alias.
* *
* This function is not available in hook_boot() so use $_GET['q'] instead. * This function is not available in hook_boot() so use request_path() instead.
* However, be careful when doing that because in the case of Example #3 * 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 * request_path() will contain "path/alias". If "node/306" is needed, calling
* drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL) makes this function available. * drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL) makes this function available.
* *
* @return * @return
...@@ -351,7 +358,7 @@ function drupal_match_path($path, $patterns) { ...@@ -351,7 +358,7 @@ function drupal_match_path($path, $patterns) {
* @see request_path() * @see request_path()
*/ */
function current_path() { function current_path() {