Issue #1831364 by pdrake: Inline drupal_fast_404() function.

8.0.x
catch 2012-11-08 23:03:10 +00:00
parent 8870347cb2
commit 0ba152a90f
2 changed files with 11 additions and 35 deletions

View File

@ -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', '<!DOCTYPE html><html><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.
print strtr($fast_404_html, array('@path' => check_plain(request_uri())));
exit;
}
}
}
/**
* Returns TRUE if a Drupal installation is currently being attempted.
*/

View File

@ -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', '<!DOCTYPE html><html><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 = 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;