[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

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( __DIR__, 2 ) . '/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, initial-scale=1.0" />
  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">' .
  31          /* translators: Hidden accessibility text. */
  32          __( 'Allow automatic database repair' ) .
  33      '</h1>';
  34  
  35      echo '<p>';
  36      printf(
  37          /* translators: %s: wp-config.php */
  38          __( '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.' ),
  39          '<code>wp-config.php</code>'
  40      );
  41      echo "</p><p><code>define('WP_ALLOW_REPAIR', true);</code></p>";
  42  
  43      $default_keys    = array_unique(
  44          array(
  45              'put your unique phrase here',
  46              /*
  47               * translators: This string should only be translated if wp-config-sample.php is localized.
  48               * You can check the localized release package or
  49               * https://i18n.svn.wordpress.org/<locale code>/branches/<wp version>/dist/wp-config-sample.php
  50               */
  51              __( 'put your unique phrase here' ),
  52          )
  53      );
  54      $missing_key     = false;
  55      $duplicated_keys = array();
  56  
  57      foreach ( array( 'AUTH_KEY', 'SECURE_AUTH_KEY', 'LOGGED_IN_KEY', 'NONCE_KEY', 'AUTH_SALT', 'SECURE_AUTH_SALT', 'LOGGED_IN_SALT', 'NONCE_SALT' ) as $key ) {
  58          if ( defined( $key ) ) {
  59              // Check for unique values of each key.
  60              $duplicated_keys[ constant( $key ) ] = isset( $duplicated_keys[ constant( $key ) ] );
  61          } else {
  62              // If a constant is not defined, it's missing.
  63              $missing_key = true;
  64          }
  65      }
  66  
  67      // If at least one key uses a default value, consider it duplicated.
  68      foreach ( $default_keys as $default_key ) {
  69          if ( isset( $duplicated_keys[ $default_key ] ) ) {
  70              $duplicated_keys[ $default_key ] = true;
  71          }
  72      }
  73  
  74      // Weed out all unique, non-default values.
  75      $duplicated_keys = array_filter( $duplicated_keys );
  76  
  77      if ( $duplicated_keys || $missing_key ) {
  78  
  79          echo '<h2 class="screen-reader-text">' .
  80              /* translators: Hidden accessibility text. */
  81              __( 'Check secret keys' ) .
  82          '</h2>';
  83  
  84          /* translators: 1: wp-config.php, 2: Secret key service URL. */
  85          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>';
  86      }
  87  } elseif ( isset( $_GET['repair'] ) ) {
  88  
  89      echo '<h1 class="screen-reader-text">' .
  90          /* translators: Hidden accessibility text. */
  91          __( 'Database repair results' ) .
  92      '</h1>';
  93  
  94      $optimize = '2' === $_GET['repair'];
  95      $okay     = true;
  96      $problems = array();
  97  
  98      $tables = $wpdb->tables();
  99  
 100      /**
 101       * Filters additional database tables to repair.
 102       *
 103       * @since 3.0.0
 104       *
 105       * @param string[] $tables Array of prefixed table names to be repaired.
 106       */
 107      $tables = array_merge( $tables, (array) apply_filters( 'tables_to_repair', array() ) );
 108  
 109      // Loop over the tables, checking and repairing as needed.
 110      foreach ( $tables as $table ) {
 111          $check = $wpdb->get_row( "CHECK TABLE $table" );
 112  
 113          echo '<p>';
 114          if ( 'OK' === $check->Msg_text ) {
 115              /* translators: %s: Table name. */
 116              printf( __( 'The %s table is okay.' ), "<code>$table</code>" );
 117          } else {
 118              /* translators: 1: Table name, 2: Error message. */
 119              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>" );
 120  
 121              $repair = $wpdb->get_row( "REPAIR TABLE $table" );
 122  
 123              echo '<br />&nbsp;&nbsp;&nbsp;&nbsp;';
 124              if ( 'OK' === $repair->Msg_text ) {
 125                  /* translators: %s: Table name. */
 126                  printf( __( 'Successfully repaired the %s table.' ), "<code>$table</code>" );
 127              } else {
 128                  /* translators: 1: Table name, 2: Error message. */
 129                  printf( __( 'Failed to repair the %1$s table. Error: %2$s' ), "<code>$table</code>", "<code>$repair->Msg_text</code>" ) . '<br />';
 130                  $problems[ $table ] = $repair->Msg_text;
 131                  $okay               = false;
 132              }
 133          }
 134  
 135          if ( $okay && $optimize ) {
 136              $analyze = $wpdb->get_row( "ANALYZE TABLE $table" );
 137  
 138              echo '<br />&nbsp;&nbsp;&nbsp;&nbsp;';
 139              if ( 'Table is already up to date' === $analyze->Msg_text ) {
 140                  /* translators: %s: Table name. */
 141                  printf( __( 'The %s table is already optimized.' ), "<code>$table</code>" );
 142              } else {
 143                  $optimize = $wpdb->get_row( "OPTIMIZE TABLE $table" );
 144  
 145                  echo '<br />&nbsp;&nbsp;&nbsp;&nbsp;';
 146                  if ( 'OK' === $optimize->Msg_text || 'Table is already up to date' === $optimize->Msg_text ) {
 147                      /* translators: %s: Table name. */
 148                      printf( __( 'Successfully optimized the %s table.' ), "<code>$table</code>" );
 149                  } else {
 150                      /* translators: 1: Table name. 2: Error message. */
 151                      printf( __( 'Failed to optimize the %1$s table. Error: %2$s' ), "<code>$table</code>", "<code>$optimize->Msg_text</code>" );
 152                  }
 153              }
 154          }
 155          echo '</p>';
 156      }
 157  
 158      if ( $problems ) {
 159          printf(
 160              /* translators: %s: URL to "Fixing WordPress" forum. */
 161              '<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>',
 162              __( 'https://wordpress.org/support/forum/how-to-and-troubleshooting' )
 163          );
 164          $problem_output = '';
 165          foreach ( $problems as $table => $problem ) {
 166              $problem_output .= "$table: $problem\n";
 167          }
 168          echo '<p><textarea name="errors" id="errors" rows="20" cols="60">' . esc_textarea( $problem_output ) . '</textarea></p>';
 169      } else {
 170          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>";
 171      }
 172  } else {
 173  
 174      echo '<h1 class="screen-reader-text">' .
 175          /* translators: Hidden accessibility text. */
 176          __( 'WordPress database repair' ) .
 177      '</h1>';
 178  
 179      if ( isset( $_GET['referrer'] ) && 'is_blog_installed' === $_GET['referrer'] ) {
 180          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>';
 181      } else {
 182          echo '<p>' . __( 'WordPress can automatically look for some common database problems and repair them. Repairing can take a while, so please be patient.' ) . '</p>';
 183      }
 184      ?>
 185      <p class="step"><a class="button button-large" href="repair.php?repair=1"><?php _e( 'Repair Database' ); ?></a></p>
 186      <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>
 187      <p class="step"><a class="button button-large" href="repair.php?repair=2"><?php _e( 'Repair and Optimize Database' ); ?></a></p>
 188      <?php
 189  }
 190  ?>
 191  </body>
 192  </html>


Generated : Thu Nov 21 08:20:01 2024 Cross-referenced by PHPXref