diff --git a/core/includes/theme.inc b/core/includes/theme.inc index 5402dae..520a9ac 100644 --- a/core/includes/theme.inc +++ b/core/includes/theme.inc @@ -2622,6 +2622,10 @@ function drupal_common_theme() { 'variables' => array('content' => NULL, 'show_messages' => TRUE), 'template' => 'install-page', ), + 'maintenance_access_denied' => array( + 'variables' => array('script_name' => 'update.php', 'settings_name' => 'update_free_access', 'login' => TRUE, 'postfix' => ''), + 'template' => 'maintenance-access-denied', + ), 'task_list' => array( 'variables' => array('items' => NULL, 'active' => NULL, 'variant' => NULL), ), diff --git a/core/includes/theme.maintenance.inc b/core/includes/theme.maintenance.inc index d206e79..4ab8e3f 100644 --- a/core/includes/theme.maintenance.inc +++ b/core/includes/theme.maintenance.inc @@ -194,37 +194,21 @@ function theme_authorize_message($variables) { } /** - * Renders a 403 access denied page for update.php or similar scripts. + * Prepares variables for maintenance access denied templates. * - * @return - * Rendered HTML warning with 403 status. + * Default template: maintenance-access-denied.html.twig. + * + * @param array $variables + * An associative array containing: + * - script_name: The script name for which access was denied. + * - login: Whether the user can login to allow access. + * - settings_name: The name of the setting in settings.php that can be + * updated to allow access. + * - postfix: Additional text to be rendered at the end. */ -function maintenance_access_denied_page($script_name = 'update.php', $settings_name = 'update_free_access', $login = TRUE, $postfix = '') { +function template_preprocess_maintenance_access_denied(&$variables) { drupal_add_http_header('Status', '403 Forbidden'); header(\Drupal::request()->server->get('SERVER_PROTOCOL') . ' 403 Forbidden'); - watchdog('access denied', $script_name, NULL, WATCHDOG_WARNING); + watchdog('access denied', $variables['script_name'], NULL, WATCHDOG_WARNING); drupal_set_title('Access denied'); - $output = '

Access denied. You are not authorized to access this page.'; - if ($login) { - $output .= 'Log in using either an account with the administer software updates permission or the site maintenance account (the account you created during installation). If you cannot log in, you will have to'; - } - else { - $output .= 'You need to '; - } - $output .= 'edit settings.php to bypass this access check. To do this:

-
    -
  1. With a text editor find the settings.php file on your system. From the main Drupal directory that you installed all the files into, go to sites/your_site_name if such directory exists, or else to sites/default which applies otherwise.
  2. -
  3. There is a line inside your settings.php file that says $settings[\'' . $settings_name . '\'] = FALSE;. Change it to $settings[\'' . $settings_name . '\'] = TRUE;.
  4. -
  5. As soon as the ' . $script_name . ' script is done, you must change the settings.php file back to its original form with $settings[\'' . $settings_name .'\'] = FALSE;.
  6. -
  7. - '; - if ($login) { - $output .= 'To avoid having this problem in the future, remember to log in to your website using either an account with the administer software updates permission or the site maintenance account (the account you created during installation) before you backup your database at the beginning of the update process.'; - } - if ($postfix) { - $output .= $postfix; - } - $output .= '
'; - return $output; } - diff --git a/core/modules/system/templates/maintenance-access-denied.html.twig b/core/modules/system/templates/maintenance-access-denied.html.twig new file mode 100644 index 0000000..29cfadd --- /dev/null +++ b/core/modules/system/templates/maintenance-access-denied.html.twig @@ -0,0 +1,36 @@ +{# +/** + * @file + * Default theme implementation for a maintenance access denied message. + * + * Variables: + * - script_name: The script name for which access was denied. + * - login: Whether the user can login to allow access. + * - settings_name: The name of the setting in settings.php that can be updated + * to allow access. + * - postfix: Additional text to be rendered at the end. + * + * @see template_preprocess_maintenance_access_denied() + * + * @ingroup themeable + */ +#} +

Access denied. You are not authorized to access this page. +{% if login %} + Log in using either an account with the administer software updates permission or the site maintenance account (the account you created during installation). If you cannot log in, you will have to +{% else %} + You need to +{% endif %} +edit settings.php to bypass this access check. To do this:

+ +
    +
  1. With a text editor find the settings.php file on your system. From the main Drupal directory that you installed all the files into, go to sites/your_site_name if such directory exists, or else to sites/default which applies otherwise.
  2. +
  3. There is a line inside your settings.php file that says $settings['{{ settings_name }}'] = FALSE;. Change it to $settings['{{ settings_name }}'] = TRUE;.
  4. +
  5. As soon as the {{ script_name }} script is done, you must change the settings.php file back to its original form with $settings['{{ settings_name }}'] = FALSE;.
  6. + {% if login %} +
  7. To avoid having this problem in the future, remember to log in to your website using either an account with the administer software updates permission or the site maintenance account (the account you created during installation) before you backup your database at the beginning of the update process.
  8. + {% endif %} + {% if postfix %} +
  9. {{ postfix }}
  10. + {% endif %} +
diff --git a/core/rebuild.php b/core/rebuild.php index 937cf3b..5a1d0aa 100644 --- a/core/rebuild.php +++ b/core/rebuild.php @@ -37,11 +37,17 @@ require_once DRUPAL_ROOT . '/core/includes/update.inc'; $install_state = array('interactive' => FALSE) + install_state_defaults(); install_begin_request($install_state, FALSE); - $output = maintenance_access_denied_page('rebuild.php', 'rebuild_access', FALSE, 'Read more information, see the handbook.'); drupal_add_http_header('Content-Type', 'text/html; charset=utf-8'); + $content = array( + '#theme' => 'maintenance_access_denied', + '#script_name' => 'rebuild.php', + '#settings_name' => 'rebuild_access', + '#login' => FALSE, + '#postfix' => 'Read more information, see the handbook.', + ); $maintenance_page = array( '#theme' => 'maintenance_page', - '#content' => $output, + '#content' => drupal_render($content), '#show_messages' => FALSE, ); print drupal_render($maintenance_page); diff --git a/core/update.php b/core/update.php index e4f252b..393bbb7 100644 --- a/core/update.php +++ b/core/update.php @@ -438,7 +438,8 @@ function update_check_requirements($skip_warnings = FALSE) { } } else { - $output = maintenance_access_denied_page(); + $content = array('#theme' => 'maintenance_access_denied'); + $output = drupal_render($content); } if (isset($output) && $output) { // Explicitly start a session so that the update.php token will be accepted.