From 0ba152a90fd21214c8f85a91483d22ad61e9575f Mon Sep 17 00:00:00 2001 From: catch Date: Thu, 8 Nov 2012 23:03:10 +0000 Subject: [PATCH] Issue #1831364 by pdrake: Inline drupal_fast_404() function. --- core/includes/bootstrap.inc | 28 -------------------- core/lib/Drupal/Core/ExceptionController.php | 18 ++++++++----- 2 files changed, 11 insertions(+), 35 deletions(-) diff --git a/core/includes/bootstrap.inc b/core/includes/bootstrap.inc index 5577be47574..f6c69a53241 100644 --- a/core/includes/bootstrap.inc +++ b/core/includes/bootstrap.inc @@ -2587,34 +2587,6 @@ function drupal_maintenance_theme() { _drupal_maintenance_theme(); } -/** - * Returns a simple 404 Not Found page. - * - * If fast 404 pages are enabled, and this is a matching page then print a - * simple 404 page and exit. - * - * This function is called when a normal 404 page is generated, but it can also - * optionally be called directly from settings.php to prevent a Drupal - * bootstrap on these pages. See documentation in settings.php for the benefits - * and drawbacks of using this. - * - * Paths to dynamically-generated content, such as image styles, should also be - * accounted for in this function. - */ -function drupal_fast_404() { - $exclude_paths = variable_get('404_fast_paths_exclude', FALSE); - if ($exclude_paths && !preg_match($exclude_paths, request_path())) { - $fast_paths = variable_get('404_fast_paths', FALSE); - 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', '404 Not Found

Not Found

The requested URL "@path" was not found on this server.

'); - // Replace @path in the variable with the page path. - print strtr($fast_404_html, array('@path' => check_plain(request_uri()))); - exit; - } - } -} - /** * Returns TRUE if a Drupal installation is currently being attempted. */ diff --git a/core/lib/Drupal/Core/ExceptionController.php b/core/lib/Drupal/Core/ExceptionController.php index 332d4b9875a..e311c93aad6 100644 --- a/core/lib/Drupal/Core/ExceptionController.php +++ b/core/lib/Drupal/Core/ExceptionController.php @@ -130,7 +130,6 @@ class ExceptionController extends ContainerAware { $response->setStatusCode(403, 'Access denied'); } else { - $response = new Response('Access Denied', 403); // @todo Replace this block with something cleaner. $return = t('You are not authorized to access this page.'); @@ -139,7 +138,7 @@ class ExceptionController extends ContainerAware { $page = element_info('page'); $content = drupal_render_page($page); - $response->setContent($content); + $response = new Response($content, 403); } return $response; @@ -157,8 +156,15 @@ class ExceptionController extends ContainerAware { watchdog('page not found', check_plain($request->attributes->get('system_path')), array(), WATCHDOG_WARNING); // Check for and return a fast 404 page if configured. - // @todo Inline this rather than using a function. - drupal_fast_404(); + $exclude_paths = variable_get('404_fast_paths_exclude', FALSE); + if ($exclude_paths && !preg_match($exclude_paths, $request->getPathInfo())) { + $fast_paths = variable_get('404_fast_paths', FALSE); + if ($fast_paths && preg_match($fast_paths, $request->getPathInfo())) { + $fast_404_html = variable_get('404_fast_html', '404 Not Found

Not Found

The requested URL "@path" was not found on this server.

'); + $fast_404_html = strtr($fast_404_html, array('@path' => check_plain($request->getUri()))); + return new Response($fast_404_html, 404); + } + } $system_path = $request->attributes->get('system_path'); @@ -195,8 +201,6 @@ class ExceptionController extends ContainerAware { $response->setStatusCode(404, 'Not Found'); } else { - $response = new Response('Not Found', 404); - // @todo Replace this block with something cleaner. $return = t('The requested page "@path" could not be found.', array('@path' => $request->getPathInfo())); drupal_set_title(t('Page not found')); @@ -204,7 +208,7 @@ class ExceptionController extends ContainerAware { $page = element_info('page'); $content = drupal_render_page($page); - $response->setContent($content); + $response = new Response($content, 404); } return $response;