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);
......
This diff is collapsed.
......@@ -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>';
}
......
......@@ -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() {
// Ensure $_GET['q'] is set before calling drupal_normal_path(), to support
// path caching with hook_url_inbound_alter().
if (empty($_GET['q'])) {
$_GET['q'] = variable_get('site_frontpage', 'user');
// At this point, the current path is either the request path (due to
// drupal_environment_initialize()) or some modified version of it due to
// other bootstrap code (e.g., language negotiation), but it has not yet been
// 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() {
function drupal_get_path_alias($path = NULL, $langcode = NULL) {
// If no path is specified, use the current page's path.
if ($path == NULL) {
$path = $_GET['q'];
$path = current_path();
}
$result = $path;
if ($alias = drupal_lookup_path('alias', $path, $langcode)) {
......@@ -289,9 +298,7 @@ function drupal_is_front_page() {
$is_front_page = &$drupal_static_fast['is_front_page'];
if (!isset($is_front_page)) {
// As drupal_path_initialize 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', 'user'));
$is_front_page = (current_path() == variable_get('site_frontpage', 'user'));
}
return $is_front_page;
......@@ -340,9 +347,9 @@ function drupal_match_path($path, $patterns) {
* - 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.
* 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
* $_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.
*
* @return
......@@ -351,7 +358,7 @@ function drupal_match_path($path, $patterns) {
* @see request_path()
*/
function current_path() {
return $_GET['q'];
return _current_path();
}
/**
......
......@@ -150,7 +150,7 @@ function tablesort_header($cell, $header, $ts) {
$ts['sort'] = 'asc';
$image = '';
}
$cell['data'] = l($cell['data'] . $image, $_GET['q'], array('attributes' => array('title' => $title), 'query' => array_merge($ts['query'], array('sort' => $ts['sort'], 'order' => $cell['data'])), 'html' => TRUE));
$cell['data'] = l($cell['data'] . $image, current_path(), array('attributes' => array('title' => $title), 'query' => array_merge($ts['query'], array('sort' => $ts['sort'], 'order' => $cell['data'])), 'html' => TRUE));
unset($cell['field'], $cell['sort']);
}
......@@ -193,7 +193,7 @@ function tablesort_cell($cell, $header, $ts, $i) {
* page request except for those pertaining to table sorting.
*/
function tablesort_get_query_parameters() {
return drupal_get_query_parameters($_GET, array('q', 'sort', 'order'));
return drupal_get_query_parameters($_GET, array('sort', 'order'));
}
/**
......
......@@ -1743,7 +1743,7 @@ function theme_links($variables) {
// Handle links.
if (isset($link['href'])) {
$is_current_path = ($link['href'] == $_GET['q'] || ($link['href'] == '<front>' && drupal_is_front_page()));
$is_current_path = ($link['href'] == current_path() || ($link['href'] == '<front>' && drupal_is_front_page()));
$is_current_language = (empty($link['language']) || $link['language']->langcode == $language_url->langcode);
if ($is_current_path && $is_current_language) {
$class[] = 'active';
......
......@@ -115,16 +115,12 @@ Drupal.ajax = function (base, element, element_settings) {
// Replacing 'nojs' with 'ajax' in the URL allows for an easy method to let
// the server detect when it needs to degrade gracefully.
// There are five scenarios to check for:
// There are four scenarios to check for:
// 1. /nojs/
// 2. /nojs$ - The end of a URL string.
// 3. /nojs? - Followed by a query (with clean URLs enabled).
// E.g.: path/nojs?destination=foobar
// 4. /nojs& - Followed by a query (without clean URLs enabled).
// E.g.: ?q=path/nojs&destination=foobar
// 5. /nojs# - Followed by a fragment.
// E.g.: path/nojs#myfragment
this.url = element_settings.url.replace(/\/nojs(\/|$|\?|&|#)/g, '/ajax$1');
// 3. /nojs? - Followed by a query (e.g. path/nojs?destination=foobar).
// 4. /nojs# - Followed by a fragment (e.g.: path/nojs#myfragment).
this.url = element_settings.url.replace(/\/nojs(\/|$|\?|#)/g, '/ajax$1');
this.wrapper = '#' + element_settings.wrapper;
// If there isn't a form, jQuery.ajax() will be used instead, allowing us to
......
......@@ -201,6 +201,13 @@ Drupal.t = function (str, args, options) {
return str;
};
/**
* Returns the URL to a Drupal page.
*/
Drupal.url = function (path) {
return Drupal.settings.basePath + Drupal.settings.scriptPath + path;
}
/**
* Format a string containing a count of items.
*
......
......@@ -50,8 +50,8 @@ Drupal.behaviors.setTimezone = {
var element = this;
$.ajax({
async: false,
url: settings.basePath,
data: { q: path, date: dateString },
url: Drupal.url(path),
data: { date: dateString },
dataType: 'json',
success: function (data) {
if (data) {
......
......@@ -836,13 +836,10 @@ function block_block_list_alter(&$blocks) {
// with different case. Ex: /Page, /page, /PAGE.
$pages = drupal_strtolower($block->pages);
if ($block->visibility < BLOCK_VISIBILITY_PHP) {
// Convert the Drupal path to lowercase
$path = drupal_strtolower(drupal_get_path_alias($_GET['q']));
// Compare the lowercase internal and lowercase path alias (if any).
$page_match = drupal_match_path($path, $pages);
if ($path != $_GET['q']) {
$page_match = $page_match || drupal_match_path($_GET['q'], $pages);
}
// Compare the lowercase path alias (if any) and internal path.
$path = current_path();
$path_alias = drupal_strtolower(drupal_get_path_alias($path));
$page_match = drupal_match_path($path_alias, $pages) || (($path != $path_alias) && drupal_match_path($path, $pages));
// When $block->visibility has a value of 0 (BLOCK_VISIBILITY_NOTLISTED),
// the block is displayed on all pages except those listed in $block->pages.
// When set to 1 (BLOCK_VISIBILITY_LISTED), it is displayed only on those
......
......@@ -500,12 +500,10 @@ function comment_permalink($cid) {
// Find the current display page for this comment.
$page = comment_get_display_page($comment->cid, $node->type);
// Set $_GET['q'] and $_GET['page'] ourselves so that the node callback
// behaves as it would when visiting the page directly.
$_GET['q'] = 'node/' . $node->nid;
$_GET['page'] = $page;
// Return the node view, this will show the correct comment in context.
// @todo Refactor to use Symfony's Request object.
_current_path('node/' . $node->nid);
$_GET['page'] = $page;
return menu_execute_active_handler('node/' . $node->nid, FALSE);
}
drupal_not_found();
......
......@@ -173,7 +173,7 @@ function contact_mail($key, &$message, $params) {
'!site-name' => variable_get('site_name', 'Drupal'),
'!subject' => $params['subject'],
'!category' => isset($params['category']['category']) ? $params['category']['category'] : '',
'!form-url' => url($_GET['q'], array('absolute' => TRUE, 'language' => $language)),
'!form-url' => url(current_path(), array('absolute' => TRUE, 'language' => $language)),
'!sender-name' => user_format_name($params['sender']),
'!sender-url' => $params['sender']->uid ? url('user/' . $params['sender']->uid, array('absolute' => TRUE, 'language' => $language)) : $params['sender']->mail,
);
......
......@@ -869,10 +869,10 @@ function image_style_url($style_name, $path) {
$uri = image_style_path($style_name, $path);
// If not using clean URLs, the image derivative callback is only available
// with the query string. If the file does not exist, use url() to ensure
// with the script path. If the file does not exist, use url() to ensure
// that it is included. Once the file exists it's fine to fall back to the
// actual file path, this avoids bootstrapping PHP once the files are built.
if (!variable_get('clean_url') && file_uri_scheme($uri) == 'public' && !file_exists($uri)) {
if ($GLOBALS['script_path'] && file_uri_scheme($uri) == 'public' && !file_exists($uri)) {
$directory_path = file_stream_wrapper_get_instance_by_uri($uri)->getDirectoryPath();
return url($directory_path . '/' . file_uri_target($uri), array('absolute' => TRUE));
}
......
......@@ -184,10 +184,12 @@ class ImageStylesPathAndUrlUnitTest extends DrupalWebTestCase {
* Test image_style_url().
*/
function _testImageStyleUrlAndPath($scheme, $clean_url = TRUE) {
$script_path_original = $GLOBALS['script_path'];
$GLOBALS['script_path'] = $clean_url ? '' : 'index.php/';
// Make the default scheme neither "public" nor "private" to verify the
// functions work for other than the default scheme.
variable_set('file_default_scheme', 'temporary');
variable_set('clean_url', $clean_url);
// Create the directories for the styles.
$directory = $scheme . '://styles/' . $this->style_name;
......@@ -209,8 +211,8 @@ class ImageStylesPathAndUrlUnitTest extends DrupalWebTestCase {
$this->assertFalse(file_exists($generated_uri), t('Generated file does not exist.'));
$generate_url = image_style_url($this->style_name, $original_uri);
if (!$clean_url) {
$this->assertTrue(strpos($generate_url, '?q=') !== FALSE, 'When using non-clean URLS, the system path contains the query string.');
if ($GLOBALS['script_path']) {
$this->assertTrue(strpos($generate_url, $GLOBALS['script_path']) !== FALSE, 'When using non-clean URLS, the system path contains the script name.');
}
// Fetch the URL that generates the file.
......@@ -224,6 +226,8 @@ class ImageStylesPathAndUrlUnitTest extends DrupalWebTestCase {
if ($scheme == 'private') {
$this->assertEqual($this->drupalGetHeader('X-Image-Owned-By'), 'image_module_test', t('Expected custom header has been added.'));
}
$GLOBALS['script_path'] = $script_path_original;
}
}
......
......@@ -679,7 +679,7 @@ function language_negotiation_configure_url_form($form, &$form_state) {
'#title' => t('%language (%langcode) path prefix', array('%language' => $language->name, '%langcode' => $language->langcode)),
'#maxlength' => 64,
'#default_value' => isset($prefixes[$langcode]) ? $prefixes[$langcode] : '',
'#field_prefix' => $base_url . '/' . (variable_get('clean_url', 0) ? '' : '?q='),
'#field_prefix' => $base_url . '/',
);
$form['domain'][$langcode] = array(
'#type' => 'textfield',
......
......@@ -463,7 +463,7 @@ function language_block_info() {
*/
function language_block_view($type) {
if (language_multilingual()) {
$path = drupal_is_front_page() ? '<front>' : $_GET['q'];
$path = drupal_is_front_page() ? '<front>' : current_path();
$links = language_negotiation_get_switch_links($type, $path);
if (isset($links->links)) {
......
......@@ -209,9 +209,11 @@ function language_from_url($languages) {
switch (variable_get('language_negotiation_url_part', LANGUAGE_NEGOTIATION_URL_PREFIX)) {
case LANGUAGE_NEGOTIATION_URL_PREFIX:
// $_GET['q'] might not be available at this time, because path
// initialization runs after the language bootstrap phase.
list($language, $_GET['q']) = language_url_split_prefix(isset($_GET['q']) ? $_GET['q'] : NULL, $languages);
// Language negotiation happens before the public function current_path()
// is available.
// @todo Refactor with Symfony's Request object.
list($language, $path) = language_url_split_prefix(_current_path(), $languages);
_current_path($path);
if ($language !== FALSE) {
$language_url = $language->langcode;
}
......@@ -319,7 +321,6 @@ function language_switcher_session($type, $path) {
$links = array();
$query = $_GET;
unset($query['q']);
foreach ($languages as $language) {