[ Index ]

PHP Cross Reference of WordPress

title

Body

[close]

/wp-admin/maint/ -> repair.php (source)

   1  <?php
   2  /**
   3   * Database Repair and Optimization Script.
   4   *
   5   * @package WordPress
   6   * @subpackage Database
   7   */
   8  define( 'WP_REPAIRING', true );
   9  
  10  require_once dirname( dirname( __DIR__ ) ) . '/wp-load.php';
  11  
  12  header( 'Content-Type: text/html; charset=utf-8' );
  13  ?>
  14  <!DOCTYPE html>
  15  <html <?php language_attributes(); ?>>
  16  <head>
  17      <meta name="viewport" content="width=device-width" />
  18      <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  19      <meta name="robots" content="noindex,nofollow" />
  20      <title><?php _e( 'WordPress &rsaquo; Database Repair' ); ?></title>
  21      <?php wp_admin_css( 'install', true ); ?>
  22  </head>
  23  <body class="wp-core-ui">
  24  <p id="logo"><a href="<?php echo esc_url( __( 'https://wordpress.org/' ) ); ?>"><?php _e( 'WordPress' ); ?></a></p>
  25  
  26  <?php
  27  
  28  if ( ! defined( 'WP_ALLOW_REPAIR' ) || ! WP_ALLOW_REPAIR ) {
  29  
  30      echo '<h1 class="screen-reader-text">' . __( 'Allow automatic database repair' ) . '</h1>';
  31  
  32      echo '<p>';
  33      printf(
  34          /* translators: %s: wp-config.php */
  35          __( 'To allow use of this page to automatically repair database problems, please add the following line to your %s file. Once this line is added to your config, reload this page.' ),
  36          '<code>wp-config.php</code>'
  37      );
  38      echo "</p><p><code>define('WP_ALLOW_REPAIR', true);</code></p>";
  39  
  40      $default_key     = 'put your unique phrase here';
  41      $missing_key     = false;
  42      $duplicated_keys = array();
  43  
  44      foreach ( array( 'AUTH_KEY', 'SECURE_AUTH_KEY', 'LOGGED_IN_KEY', 'NONCE_KEY', 'AUTH_SALT', 'SECURE_AUTH_SALT', 'LOGGED_IN_SALT', 'NONCE_SALT' ) as $key ) {
  45          if ( defined( $key ) ) {
  46              // Check for unique values of each key.
  47              $duplicated_keys[ constant( $key ) ] = isset( $duplicated_keys[ constant( $key ) ] );
  48          } else {
  49              // If a constant is not defined, it's missing.
  50              $missing_key = true;
  51          }
  52      }
  53  
  54      // If at least one key uses the default value, consider it duplicated.
  55      if ( isset( $duplicated_keys[ $default_key ] ) ) {
  56          $duplicated_keys[ $default_key ] = true;
  57      }
  58  
  59      // Weed out all unique, non-default values.
  60      $duplicated_keys = array_filter( $duplicated_keys );
  61  
  62      if ( $duplicated_keys || $missing_key ) {
  63  
  64          echo '<h2 class="screen-reader-text">' . __( 'Check secret keys' ) . '</h2>';
  65  
  66          /* translators: 1: wp-config.php, 2: Secret key service URL. */
  67          echo '<p>' . sprintf( __( 'While you are editing your %1$s file, take a moment to make sure you have all 8 keys and that they are unique. You can generate these using the <a href="%2$s">WordPress.org secret key service</a>.' ), '<code>wp-config.php</code>', 'https://api.wordpress.org/secret-key/1.1/salt/' ) . '</p>';
  68      }
  69  } elseif ( isset( $_GET['repair'] ) ) {
  70  
  71      echo '<h1 class="screen-reader-text">' . __( 'Database repair results' ) . '</h1>';
  72  
  73      $optimize = 2 == $_GET['repair'];
  74      $okay     = true;
  75      $problems = array();
  76  
  77      $tables = $wpdb->tables();
  78  
  79      // Sitecategories may not exist if global terms are disabled.
  80      $query = $wpdb->prepare( 'SHOW TABLES LIKE %s', $wpdb->esc_like( $wpdb->sitecategories ) );
  81      if ( is_multisite() && ! $wpdb->get_var( $query ) ) {
  82          unset( $tables['sitecategories'] );
  83      }
  84  
  85      /**
  86       * Filters additional database tables to repair.
  87       *
  88       * @since 3.0.0
  89       *
  90       * @param string[] $tables Array of prefixed table names to be repaired.
  91       */
  92      $tables = array_merge( $tables, (array) apply_filters( 'tables_to_repair', array() ) );
  93  
  94      // Loop over the tables, checking and repairing as needed.
  95      foreach ( $tables as $table ) {
  96          $check = $wpdb->get_row( "CHECK TABLE $table" );
  97  
  98          echo '<p>';
  99          if ( 'OK' === $check->Msg_text ) {
 100              /* translators: %s: Table name. */
 101              printf( __( 'The %s table is okay.' ), "<code>$table</code>" );
 102          } else {
 103              /* translators: 1: Table name, 2: Error message. */
 104              printf( __( 'The %1$s table is not okay. It is reporting the following error: %2$s. WordPress will attempt to repair this table&hellip;' ), "<code>$table</code>", "<code>$check->Msg_text</code>" );
 105  
 106              $repair = $wpdb->get_row( "REPAIR TABLE $table" );
 107  
 108              echo '<br />&nbsp;&nbsp;&nbsp;&nbsp;';
 109              if ( 'OK' === $repair->Msg_text ) {
 110                  /* translators: %s: Table name. */
 111                  printf( __( 'Successfully repaired the %s table.' ), "<code>$table</code>" );
 112              } else {
 113                  /* translators: 1: Table name, 2: Error message. */
 114                  printf( __( 'Failed to repair the %1$s table. Error: %2$s' ), "<code>$table</code>", "<code>$repair->Msg_text</code>" ) . '<br />';
 115                  $problems[ $table ] = $repair->Msg_text;
 116                  $okay               = false;
 117              }
 118          }
 119  
 120          if ( $okay && $optimize ) {
 121              $analyze = $wpdb->get_row( "ANALYZE TABLE $table" );
 122  
 123              echo '<br />&nbsp;&nbsp;&nbsp;&nbsp;';
 124              if ( 'Table is already up to date' === $analyze->Msg_text ) {
 125                  /* translators: %s: Table name. */
 126                  printf( __( 'The %s table is already optimized.' ), "<code>$table</code>" );
 127              } else {
 128                  $optimize = $wpdb->get_row( "OPTIMIZE TABLE $table" );
 129  
 130                  echo '<br />&nbsp;&nbsp;&nbsp;&nbsp;';
 131                  if ( 'OK' === $optimize->Msg_text || 'Table is already up to date' === $optimize->Msg_text ) {
 132                      /* translators: %s: Table name. */
 133                      printf( __( 'Successfully optimized the %s table.' ), "<code>$table</code>" );
 134                  } else {
 135                      /* translators: 1: Table name. 2: Error message. */
 136                      printf( __( 'Failed to optimize the %1$s table. Error: %2$s' ), "<code>$table</code>", "<code>$optimize->Msg_text</code>" );
 137                  }
 138              }
 139          }
 140          echo '</p>';
 141      }
 142  
 143      if ( $problems ) {
 144          printf(
 145              /* translators: %s: URL to "Fixing WordPress" forum. */
 146              '<p>' . __( 'Some database problems could not be repaired. Please copy-and-paste the following list of errors to the <a href="%s">WordPress support forums</a> to get additional assistance.' ) . '</p>',
 147              __( 'https://wordpress.org/support/forum/how-to-and-troubleshooting' )
 148          );
 149          $problem_output = '';
 150          foreach ( $problems as $table => $problem ) {
 151              $problem_output .= "$table: $problem\n";
 152          }
 153          echo '<p><textarea name="errors" id="errors" rows="20" cols="60">' . esc_textarea( $problem_output ) . '</textarea></p>';
 154      } else {
 155          echo '<p>' . __( 'Repairs complete. Please remove the following line from wp-config.php to prevent this page from being used by unauthorized users.' ) . "</p><p><code>define('WP_ALLOW_REPAIR', true);</code></p>";
 156      }
 157  } else {
 158  
 159      echo '<h1 class="screen-reader-text">' . __( 'WordPress database repair' ) . '</h1>';
 160  
 161      if ( isset( $_GET['referrer'] ) && 'is_blog_installed' === $_GET['referrer'] ) {
 162          echo '<p>' . __( 'One or more database tables are unavailable. To allow WordPress to attempt to repair these tables, press the &#8220;Repair Database&#8221; button. Repairing can take a while, so please be patient.' ) . '</p>';
 163      } else {
 164          echo '<p>' . __( 'WordPress can automatically look for some common database problems and repair them. Repairing can take a while, so please be patient.' ) . '</p>';
 165      }
 166      ?>
 167      <p class="step"><a class="button button-large" href="repair.php?repair=1"><?php _e( 'Repair Database' ); ?></a></p>
 168      <p><?php _e( 'WordPress can also attempt to optimize the database. This improves performance in some situations. Repairing and optimizing the database can take a long time and the database will be locked while optimizing.' ); ?></p>
 169      <p class="step"><a class="button button-large" href="repair.php?repair=2"><?php _e( 'Repair and Optimize Database' ); ?></a></p>
 170      <?php
 171  }
 172  ?>
 173  </body>
 174  </html>


Generated: Sat Apr 27 01:00:02 2024 Cross-referenced by PHPXref 0.7.1