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() {
// Load the code that drives the authorize process.
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'])) {
drupal_set_title($_SESSION['authorize_operation']['page_title']);
}
......
......@@ -551,12 +551,8 @@ function drupal_environment_initialize() {
$_SERVER['HTTP_HOST'] = '';
}
// When clean URLs are enabled, emulate ?q=foo/bar using REQUEST_URI. It is
// not possible to append the query string using mod_rewrite without the B
// 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();
// @todo Refactor with the Symfony Request object.
_current_path(request_path());
// Enforce E_STRICT, but allow users to set levels not part of E_STRICT.
error_reporting(E_STRICT | E_ALL | error_reporting());
......@@ -597,7 +593,7 @@ function drupal_valid_http_host($host) {
* Sets the base URL, cookie domain, and session name from configuration.
*/
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
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() {
$base_url = $base_root;
// $_SERVER['SCRIPT_NAME'] can, in contrast to $_SERVER['PHP_SELF'], not
// be modified by a visitor.
// For a request URI of '/index.php/foo', $_SERVER['SCRIPT_NAME'] is
// '/index.php', whereas $_SERVER['PHP_SELF'] is '/index.php/foo'.
if ($dir = rtrim(dirname($_SERVER['SCRIPT_NAME']), '\/')) {
// Remove "core" directory if present, allowing install.php, update.php,
// cron.php and others to auto-detect a base path.
......@@ -648,6 +644,32 @@ function drupal_settings_initialize() {
$base_secure_url = str_replace('http://', 'https://', $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 the user specifies the cookie domain, also use it for session name.
$session_name = $cookie_domain;
......@@ -1488,13 +1510,15 @@ function drupal_validate_utf8($text) {
*
* Because $_SERVER['REQUEST_URI'] is only available on Apache, we generate an
* 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'])) {
$uri = $_SERVER['REQUEST_URI'];
}
else {
if (isset($_SERVER['argv'])) {
if (isset($_SERVER['argv'][0])) {
$uri = $_SERVER['SCRIPT_NAME'] . '?' . $_SERVER['argv'][0];
}
elseif (isset($_SERVER['QUERY_STRING'])) {
......@@ -1507,7 +1531,7 @@ function request_uri() {
// Prevent multiple slashes to avoid cross site requests via the Form API.
$uri = '/' . ltrim($uri, '/');
return $uri;
return $omit_query_string ? strtok($uri, '?') : $uri;
}
/**
......@@ -2181,7 +2205,7 @@ function _drupal_bootstrap_page_cache() {
if (is_object($cache)) {
header('X-Drupal-Cache: HIT');
// 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);
date_default_timezone_set(drupal_get_user_timezone());
// If the skipping of the bootstrap hooks is not enforced, call
......@@ -2418,9 +2442,9 @@ function drupal_maintenance_theme() {
*/
function drupal_fast_404() {
$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);
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');
$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.
......@@ -2655,41 +2679,44 @@ function request_path() {
return $path;
}
if (isset($_GET['q'])) {
// This is a request with a ?q=foo/bar query string. $_GET['q'] is
// overwritten in drupal_path_initialize(), but request_path() is called
// very early in the bootstrap process, so the original value is saved in
// $path and returned in later calls.
$path = $_GET['q'];
}
elseif (isset($_SERVER['REQUEST_URI'])) {
// This request is either a clean URL, or 'index.php', or nonsense.
// Extract the path from REQUEST_URI.
$request_path = strtok($_SERVER['REQUEST_URI'], '?');
$base_path_len = strlen(rtrim(dirname($_SERVER['SCRIPT_NAME']), '\/'));
// Unescape and strip $base_path prefix, leaving q without a leading slash.
$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.
// Get the part of the URI between the base path of the Drupal installation
// and the query string, and unescape it.
$request_path = request_uri(TRUE);
$base_path_len = strlen(rtrim(dirname($_SERVER['SCRIPT_NAME']), '\/'));
$path = substr(urldecode($request_path), $base_path_len + 1);
// Depending on server configuration, the URI might or might not include the
// script name. For example, the front page might be accessed as
// http://example.com or as http://example.com/index.php, and the "user"
// page might be accessed as http://example.com/user or as
// http://example.com/index.php/user. Strip the script name from $path.
$script = basename($_SERVER['SCRIPT_NAME']);
if ($path == $script) {
$path = '';
}
elseif (strpos($path, $script . '/') === 0) {
$path = substr($path, strlen($script) + 1);
}
// Under certain conditions Apache's RewriteRule directive prepends the value
// assigned to $_GET['q'] with a slash. Moreover we can always have a trailing
// slash in place, hence we need to normalize $_GET['q'].
// Extra slashes can appear in URLs or under some conditions, added by Apache,
// so normalize.
$path = trim($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.
*
......@@ -2726,7 +2753,9 @@ function arg($index = NULL, $path = NULL) {
$arguments = &$drupal_static_fast['arguments'];
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])) {
$arguments[$path] = explode('/', $path);
......
......@@ -397,14 +397,14 @@ function drupal_get_feeds($delimiter = "\n") {
* (optional) An array to be processed. Defaults to $_GET.
* @param $exclude
* (optional) A list of $query array keys to remove. Use "parent[child]" to
* exclude nested items. Defaults to array('q').
* exclude nested items.
* @param $parent
* Internal use only. Used to build the $query array key for nested items.
*
* @return
* An array containing query parameters, which can be used for url().
*/
function drupal_get_query_parameters(array $query = NULL, array $exclude = array('q'), $parent = '') {
function drupal_get_query_parameters(array $query = NULL, array $exclude = array(), $parent = '') {
// Set defaults, if none given.
if (!isset($query)) {
$query = $_GET;
......@@ -517,7 +517,7 @@ function drupal_get_destination() {
$destination = array('destination' => $_GET['destination']);
}
else {
$path = $_GET['q'];
$path = current_path();
$query = drupal_http_build_query(drupal_get_query_parameters());
if ($query != '') {
$path .= '?' . $query;
......@@ -598,13 +598,6 @@ function drupal_parse_url($url) {
$options['fragment'] = $parts['fragment'];
}
}
// The 'q' parameter contains the path of the current page if clean URLs are
// disabled. It overrides the 'path' of the URL when present, even if clean
// URLs are enabled, due to how Apache rewriting rules work.
if (isset($options['query']['q'])) {
$options['path'] = $options['query']['q'];
unset($options['query']['q']);
}
return $options;
}
......@@ -2138,14 +2131,9 @@ function _format_date_callback(array $matches = NULL, $new_langcode = NULL) {
* dependent URL requires so.
* - 'prefix': Only used internally, to modify the path when a language
* dependent URL requires so.
* - 'script': The script filename in Drupal's root directory to use when
* clean URLs are disabled, such as 'index.php'. Defaults to an empty
* string, as most modern web servers automatically find 'index.php'. If
* clean URLs are disabled, the value of $path is appended as query
* parameter 'q' to $options['script'] in the returned URL. When deploying
* Drupal on a web server that cannot be configured to automatically find
* index.php, then hook_url_outbound_alter() can be implemented to force
* this value to 'index.php'.
* - 'script': Added to the URL between the base path and the path prefix.
* Defaults to empty string when clean URLs are in effect, and to
* 'index.php/' when they are not.
* - 'entity_type': The entity type of the object that called url(). Only
* set if url() is invoked by entity_uri().
* - 'entity': The entity object (such as a node) for which the URL is being
......@@ -2161,7 +2149,8 @@ function url($path = NULL, array $options = array()) {
'query' => array(),
'absolute' => FALSE,
'alias' => FALSE,
'prefix' => ''
'prefix' => '',
'script' => $GLOBALS['script_path'],
);
if (!isset($options['external'])) {
......@@ -2243,32 +2232,9 @@ function url($path = NULL, array $options = array()) {
$base = $options['absolute'] ? $options['base_url'] . '/' : base_path();
$prefix = empty($path) ? rtrim($options['prefix'], '/') : $options['prefix'];
// With Clean URLs.
if (!empty($GLOBALS['conf']['clean_url'])) {
$path = drupal_encode_path($prefix . $path);
if ($options['query']) {
return $base . $path . '?' . drupal_http_build_query($options['query']) . $options['fragment'];
}
else {
return $base . $path . $options['fragment'];
}
}
// Without Clean URLs.
else {
$path = $prefix . $path;
$query = array();
if (!empty($path)) {
$query['q'] = $path;
}
if ($options['query']) {
// We do not use array_merge() here to prevent overriding $path via query
// parameters.
$query += $options['query'];
}
$query = $query ? ('?' . drupal_http_build_query($query)) : '';
$script = isset($options['script']) ? $options['script'] : '';
return $base . $script . $query . $options['fragment'];
}
$path = drupal_encode_path($prefix . $path);
$query = $options['query'] ? ('?' . drupal_http_build_query($options['query'])) : '';
return $base . $options['script'] . $path . $query . $options['fragment'];
}
/**
......@@ -2404,7 +2370,7 @@ function l($text, $path, array $options = array()) {
);
// Append active class.
if (($path == $_GET['q'] || ($path == '<front>' && drupal_is_front_page())) &&
if (($path == current_path() || ($path == '<front>' && drupal_is_front_page())) &&
(empty($options['language']) || $options['language']->langcode == drupal_container()->get(LANGUAGE_TYPE_URL)->langcode)) {
$options['attributes']['class'][] = 'active';
}
......@@ -2530,7 +2496,7 @@ function drupal_deliver_page($page_callback_result, $default_delivery_callback =
// If a delivery callback is specified, but doesn't exist as a function,
// something is wrong, but don't print anything, since it's not known
// what format the response needs to be in.
watchdog('delivery callback not found', 'callback %callback not found: %q.', array('%callback' => $delivery_callback, '%q' => $_GET['q']), WATCHDOG_ERROR);
watchdog('delivery callback not found', 'callback %callback not found: %path.', array('%callback' => $delivery_callback, '%path' => current_path()), WATCHDOG_ERROR);
}
}
......@@ -2571,18 +2537,18 @@ function drupal_deliver_html_page($page_callback_result) {
// Print a 404 page.
drupal_add_http_header('Status', '404 Not Found');
watchdog('page not found', check_plain($_GET['q']), NULL, WATCHDOG_WARNING);
watchdog('page not found', check_plain(current_path()), NULL, WATCHDOG_WARNING);
// Check for and return a fast 404 page if configured.
drupal_fast_404();
// Keep old path for reference, and to allow forms to redirect to it.
if (!isset($_GET['destination'])) {
$_GET['destination'] = $_GET['q'];
$_GET['destination'] = current_path();
}
$path = drupal_get_normal_path(variable_get('site_404', ''));
if ($path && $path != $_GET['q']) {
if ($path && $path != current_path()) {
// Custom 404 handler. Set the active item in case there are tabs to
// display, or other dependencies on the path.
menu_set_active_item($path);
......@@ -2603,15 +2569,15 @@ function drupal_deliver_html_page($page_callback_result) {
case MENU_ACCESS_DENIED:
// Print a 403 page.
drupal_add_http_header('Status', '403 Forbidden');
watchdog('access denied', check_plain($_GET['q']), NULL, WATCHDOG_WARNING);
watchdog('access denied', check_plain(current_path()), NULL, WATCHDOG_WARNING);
// Keep old path for reference, and to allow forms to redirect to it.
if (!isset($_GET['destination'])) {
$_GET['destination'] = $_GET['q'];
$_GET['destination'] = current_path();
}
$path = drupal_get_normal_path(variable_get('site_403', ''));
if ($path && $path != $_GET['q']) {
if ($path && $path != current_path()) {
// Custom 403 handler. Set the active item in case there are tabs to
// display or other dependencies on the path.
menu_set_active_item($path);
......@@ -3570,11 +3536,15 @@ function drupal_build_css_cache($css) {
if (!file_exists($uri) && !file_unmanaged_save_data($data, $uri, FILE_EXISTS_REPLACE)) {
return FALSE;
}
// If CSS gzip compression is enabled, clean URLs are enabled (which means
// that rewrite rules are working) and the zlib extension is available then
// create a gzipped version of this file. This file is served conditionally
// to browsers that accept gzip using .htaccess rules.
if (variable_get('css_gzip_compression', TRUE) && variable_get('clean_url', 0) && extension_loaded('zlib')) {
// If CSS gzip compression is enabled and the zlib extension is available
// then create a gzipped version of this file. This file is served
// conditionally to browsers that accept gzip using .htaccess rules.
// It's possible that the rewrite rules in .htaccess aren't working on this
// server, but there's no harm (other than the time spent generating the
// file) in generating the file anyway. Sites on servers where rewrite rules
// aren't working can set css_gzip_compression to FALSE in order to skip
// generating a file that won't be used.
if (variable_get('css_gzip_compression', TRUE) && extension_loaded('zlib')) {
if (!file_exists($uri . '.gz') && !file_unmanaged_save_data(gzencode($data, 9, FORCE_GZIP), $uri . '.gz', FILE_EXISTS_REPLACE)) {
return FALSE;
}
......@@ -4105,15 +4075,19 @@ function drupal_add_js($data = NULL, $options = NULL) {
// Add jquery.js and drupal.js, as well as the basePath setting, the
// first time a JavaScript file is added.
if (empty($javascript)) {
// url() generates the prefix using hook_url_outbound_alter(). Instead of
// running the hook_url_outbound_alter() again here, extract the prefix
// from url().
url('', array('prefix' => &$prefix));
// url() generates the script and prefix using hook_url_outbound_alter().
// Instead of running the hook_url_outbound_alter() again here, extract
// them from url().
// @todo Make this less hacky: http://drupal.org/node/1547376.
$scriptPath = $GLOBALS['script_path'];
$pathPrefix = '';
url('', array('script' => &$scriptPath, 'prefix' => &$pathPrefix));
$javascript = array(
'settings' => array(
'data' => array(
array('basePath' => base_path()),
array('pathPrefix' => empty($prefix) ? '' : $prefix),
array('scriptPath' => $scriptPath),
array('pathPrefix' => $pathPrefix),
),
'type' => 'setting',
'scope' => 'header',
......@@ -5056,11 +5030,15 @@ function drupal_build_js_cache($files) {
if (!file_exists($uri) && !file_unmanaged_save_data($contents, $uri, FILE_EXISTS_REPLACE)) {
return FALSE;
}
// If JS gzip compression is enabled, clean URLs are enabled (which means
// that rewrite rules are working) and the zlib extension is available then
// create a gzipped version of this file. This file is served conditionally
// to browsers that accept gzip using .htaccess rules.
if (variable_get('js_gzip_compression', TRUE) && variable_get('clean_url', 0) && extension_loaded('zlib')) {
// If JS gzip compression is enabled and the zlib extension is available
// then create a gzipped version of this file. This file is served
// conditionally to browsers that accept gzip using .htaccess rules.
// It's possible that the rewrite rules in .htaccess aren't working on this
// server, but there's no harm (other than the time spent generating the
// file) in generating the file anyway. Sites on servers where rewrite rules
// aren't working can set js_gzip_compression to FALSE in order to skip
// generating a file that won't be used.
if (variable_get('js_gzip_compression', TRUE) && extension_loaded('zlib')) {
if (!file_exists($uri . '.gz') && !file_unmanaged_save_data(gzencode($contents, 9, FORCE_GZIP), $uri . '.gz', FILE_EXISTS_REPLACE)) {
return FALSE;
}
......@@ -5217,7 +5195,7 @@ function _drupal_bootstrap_full() {
ini_set('error_log', 'public://error.log');
}
// Initialize $_GET['q'] prior to invoking hook_init().
// Initialize current_path() prior to invoking hook_init().
drupal_path_initialize();
// Let all modules take action before the menu system handles the request.
......@@ -5256,7 +5234,7 @@ function drupal_page_set_cache() {
$cache = (object) array(
'cid' => $base_root . request_uri(),
'data' => array(
'path' => $_GET['q'],
'path' => current_path(),
'body' => ob_get_clean(),
'title' => drupal_get_title(),
'headers' => array(),
......
......@@ -2031,7 +2031,7 @@ function file_transfer($uri, $headers) {
* @see system_menu()
*/
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();
$scheme = array_shift($args);
$target = implode('/', $args);
......
......@@ -1248,7 +1248,7 @@ function drupal_redirect_form($form_state) {
$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
'progressive' => TRUE,
'url' => $url,
'url_options' => array(),
'source_url' => $_GET['q'],
'source_url' => current_path(),
'redirect' => $redirect,
'theme' => $GLOBALS['theme_key'],
'redirect_callback' => $redirect_callback,
......
......@@ -1522,11 +1522,8 @@ function install_configure_form($form, &$form_state, &$install_state) {
// We add these strings as settings because JavaScript translation does not
// work on install time.
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
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
// index.php because: (1) setting cache table entries requires schema
......@@ -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
// try to generate one but with no loaded modules will return nothing.
//
// This logically could be done during the 'install_finished' task, but the
// clean URL check requires it now.
// @todo Move this to the 'install_finished' task?
drupal_get_schema(NULL, TRUE);
// Return the form.
......@@ -1827,12 +1823,6 @@ function _install_configure_form($form, &$form_state, &$install_state) {
'#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(
'#type' => 'fieldset',
'#title' => st('Update notifications'),
......@@ -1903,10 +1893,6 @@ function install_configure_form_submit($form, &$form_state) {
$user = user_load(1);
user_login_finalize();
if (isset($form_state['values']['clean_url'])) {
variable_set('clean_url', $form_state['values']['clean_url']);
}
// Record when this install ran.
variable_set('install_time', $_SERVER['REQUEST_TIME']);
}
......@@ -121,8 +121,7 @@ function drupal_detect_baseurl($file = 'core/install.php') {
$proto = $_SERVER['HTTPS'] ? 'https://' : 'http://';
$host = $_SERVER['SERVER_NAME'];
$port = ($_SERVER['SERVER_PORT'] == 80 ? '' : ':' . $_SERVER['SERVER_PORT']);
$uri = preg_replace("/\?.*/", '', $_SERVER['REQUEST_URI']);
$dir = str_replace("/$file", '', $uri);
$dir = str_replace("/$file", '', $_SERVER['SCRIPT_NAME']);
return "$proto$host$port$dir";
}
......
......@@ -441,7 +441,7 @@ function menu_set_item($path, $router_item) {
function menu_get_item($path = NULL, $router_item = NULL) {
$router_items = &drupal_static(__FUNCTION__);
if (!isset($path)) {
$path = $_GET['q'];
$path = current_path();
}
if (isset($router_item)) {
$router_items[$path] = $router_item;
......@@ -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
// 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.
$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);
// Only continue if the site status is not set.
......@@ -1043,11 +1043,11 @@ function menu_tree_output($tree) {
$class[] = 'active-trail';
$data['link']['localized_options']['attributes']['class'][] = 'active-trail';
}
// Normally, l() compares the href of every link with $_GET['q'] and sets
// the active class accordingly. But local tasks do not appear in menu
// Normally, l() compares the href of every link with the current path and
// 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
// 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';
}
......@@ -1846,11 +1846,11 @@ function menu_navigation_links($menu_name, $level = 0) {
$class = ' active-trail';
$l['attributes']['class'][] = 'active-trail';
}
// Normally, l() compares the href of every link with $_GET['q'] and 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
// tab root, then we have to set the class manually.
if ($item['link']['href'] == $router_item['tab_root_href'] && $item['link']['href'] != $_GET['q']) {
// Normally, l() compares the href of every link with the current path and
// 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 tab root, then we have to set the class manually.
if ($item['link']['href'] == $router_item['tab_root_href'] && $item['link']['href'] != current_path()) {
$l['attributes']['class'][] = 'active';
}
// Keyed with the unique mlid to generate classes in theme_links().
......@@ -1964,8 +1964,8 @@ function menu_local_tasks($level = 0) {
// local tasks link to their parent, but the path of default local
// tasks can still be accessed directly, in which case this link
// would not be marked as active, since l() only compares the href
// with $_GET['q'].
if ($link['href'] != $_GET['q']) {
// with current_path().
if ($link['href'] != current_path()) {
$link['localized_options']['attributes']['class'][] = 'active';
}
$tabs_current[] = array(
......@@ -2040,8 +2040,8 @@ function menu_local_tasks($level = 0) {
// 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
// links to its parent, l() will not mark it as active, as it only
// compares the link's href to $_GET['q'].
if ($link['href'] != $_GET['q']) {
// compares the link's href to current_path().
if ($link['href'] != current_path()) {
$link['localized_options']['attributes']['class'][] = 'active';
}
$tabs_current[] = array(
......@@ -2304,10 +2304,11 @@ function menu_get_active_menu_names() {
* A Drupal path - not a path alias.
*/
function menu_set_active_item($path) {
$_GET['q'] = $path;
// Since the active item has changed, the active menu trail may also be out
// of date.
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) {
$preferred_links = &drupal_static(__FUNCTION__);
if (!isset($path)) {
$path = $_GET['q'];
$path = current_path();
}
if (empty($selected_menu)) {
......@@ -3813,7 +3814,7 @@ function _menu_site_is_offline($check_only = FALSE) {
// Ensure that the maintenance mode message is displayed only once
// (allowing for page redirects) and specifically suppress its display on
// 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')) {
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) {
function pager_get_query_parameters() {
$query = &drupal_static(__FUNCTION__);
if (!isset($query)) {
$query = drupal_get_query_parameters($_GET, array('q', 'page'));
$query = drupal_get_query_parameters($_GET, array('page'));
}
return $query;
}
......@@ -638,7 +638,7 @@ function theme_pager_link($variables) {
// none of the pager links is active at any time - but it should still be
// possible to use l() here.
// @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>';
}