You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

172 regels
7.0 KiB

  1. <?php
  2. /**
  3. * Database Repair and Optimization Script.
  4. *
  5. * @package WordPress
  6. * @subpackage Database
  7. */
  8. define('WP_REPAIRING', true);
  9. require_once( dirname( dirname( dirname( __FILE__ ) ) ) . '/wp-load.php' );
  10. header( 'Content-Type: text/html; charset=utf-8' );
  11. ?>
  12. <!DOCTYPE html>
  13. <html xmlns="http://www.w3.org/1999/xhtml" <?php language_attributes(); ?>>
  14. <head>
  15. <meta name="viewport" content="width=device-width" />
  16. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  17. <meta name="robots" content="noindex,nofollow" />
  18. <title><?php _e( 'WordPress &rsaquo; Database Repair' ); ?></title>
  19. <?php
  20. wp_admin_css( 'install', true );
  21. ?>
  22. </head>
  23. <body class="wp-core-ui">
  24. <p id="logo"><a href="<?php echo esc_url( __( 'https://wordpress.org/' ) ); ?>" tabindex="-1"><?php _e( 'WordPress' ); ?></a></p>
  25. <?php
  26. if ( ! defined( 'WP_ALLOW_REPAIR' ) ) {
  27. echo '<h1 class="screen-reader-text">' . __( 'Allow automatic database repair' ) . '</h1>';
  28. echo '<p>';
  29. printf(
  30. /* translators: %s: wp-config.php */
  31. __( '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.' ),
  32. '<code>wp-config.php</code>'
  33. );
  34. echo "</p><p><code>define('WP_ALLOW_REPAIR', true);</code></p>";
  35. $default_key = 'put your unique phrase here';
  36. $missing_key = false;
  37. $duplicated_keys = array();
  38. foreach ( array( 'AUTH_KEY', 'SECURE_AUTH_KEY', 'LOGGED_IN_KEY', 'NONCE_KEY', 'AUTH_SALT', 'SECURE_AUTH_SALT', 'LOGGED_IN_SALT', 'NONCE_SALT' ) as $key ) {
  39. if ( defined( $key ) ) {
  40. // Check for unique values of each key.
  41. $duplicated_keys[ constant( $key ) ] = isset( $duplicated_keys[ constant( $key ) ] );
  42. } else {
  43. // If a constant is not defined, it's missing.
  44. $missing_key = true;
  45. }
  46. }
  47. // If at least one key uses the default value, consider it duplicated.
  48. if ( isset( $duplicated_keys[ $default_key ] ) ) {
  49. $duplicated_keys[ $default_key ] = true;
  50. }
  51. // Weed out all unique, non-default values.
  52. $duplicated_keys = array_filter( $duplicated_keys );
  53. if ( $duplicated_keys || $missing_key ) {
  54. echo '<h2 class="screen-reader-text">' . __( 'Check secret keys' ) . '</h2>';
  55. // Translators: 1: wp-config.php; 2: Secret key service URL.
  56. 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>';
  57. }
  58. } elseif ( isset( $_GET['repair'] ) ) {
  59. echo '<h1 class="screen-reader-text">' . __( 'Database repair results' ) . '</h1>';
  60. $optimize = 2 == $_GET['repair'];
  61. $okay = true;
  62. $problems = array();
  63. $tables = $wpdb->tables();
  64. // Sitecategories may not exist if global terms are disabled.
  65. $query = $wpdb->prepare( "SHOW TABLES LIKE %s", $wpdb->esc_like( $wpdb->sitecategories ) );
  66. if ( is_multisite() && ! $wpdb->get_var( $query ) ) {
  67. unset( $tables['sitecategories'] );
  68. }
  69. /**
  70. * Filters additional database tables to repair.
  71. *
  72. * @since 3.0.0
  73. *
  74. * @param array $tables Array of prefixed table names to be repaired.
  75. */
  76. $tables = array_merge( $tables, (array) apply_filters( 'tables_to_repair', array() ) );
  77. // Loop over the tables, checking and repairing as needed.
  78. foreach ( $tables as $table ) {
  79. $check = $wpdb->get_row( "CHECK TABLE $table" );
  80. echo '<p>';
  81. if ( 'OK' == $check->Msg_text ) {
  82. /* translators: %s: table name */
  83. printf( __( 'The %s table is okay.' ), "<code>$table</code>" );
  84. } else {
  85. /* translators: 1: table name, 2: error message, */
  86. 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>" );
  87. $repair = $wpdb->get_row( "REPAIR TABLE $table" );
  88. echo '<br />&nbsp;&nbsp;&nbsp;&nbsp;';
  89. if ( 'OK' == $check->Msg_text ) {
  90. /* translators: %s: table name */
  91. printf( __( 'Successfully repaired the %s table.' ), "<code>$table</code>" );
  92. } else {
  93. /* translators: 1: table name, 2: error message, */
  94. echo sprintf( __( 'Failed to repair the %1$s table. Error: %2$s' ), "<code>$table</code>", "<code>$check->Msg_text</code>" ) . '<br />';
  95. $problems[$table] = $check->Msg_text;
  96. $okay = false;
  97. }
  98. }
  99. if ( $okay && $optimize ) {
  100. $check = $wpdb->get_row( "ANALYZE TABLE $table" );
  101. echo '<br />&nbsp;&nbsp;&nbsp;&nbsp;';
  102. if ( 'Table is already up to date' == $check->Msg_text ) {
  103. /* translators: %s: table name */
  104. printf( __( 'The %s table is already optimized.' ), "<code>$table</code>" );
  105. } else {
  106. $check = $wpdb->get_row( "OPTIMIZE TABLE $table" );
  107. echo '<br />&nbsp;&nbsp;&nbsp;&nbsp;';
  108. if ( 'OK' == $check->Msg_text || 'Table is already up to date' == $check->Msg_text ) {
  109. /* translators: %s: table name */
  110. printf( __( 'Successfully optimized the %s table.' ), "<code>$table</code>" );
  111. } else {
  112. /* translators: 1: table name, 2: error message, */
  113. printf( __( 'Failed to optimize the %1$s table. Error: %2$s' ), "<code>$table</code>", "<code>$check->Msg_text</code>" );
  114. }
  115. }
  116. }
  117. echo '</p>';
  118. }
  119. if ( $problems ) {
  120. printf( '<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>', __( 'https://wordpress.org/support/forum/how-to-and-troubleshooting' ) );
  121. $problem_output = '';
  122. foreach ( $problems as $table => $problem )
  123. $problem_output .= "$table: $problem\n";
  124. echo '<p><textarea name="errors" id="errors" rows="20" cols="60">' . esc_textarea( $problem_output ) . '</textarea></p>';
  125. } else {
  126. 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>";
  127. }
  128. } else {
  129. echo '<h1 class="screen-reader-text">' . __( 'WordPress database repair' ) . '</h1>';
  130. if ( isset( $_GET['referrer'] ) && 'is_blog_installed' == $_GET['referrer'] )
  131. 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>';
  132. else
  133. echo '<p>' . __( 'WordPress can automatically look for some common database problems and repair them. Repairing can take a while, so please be patient.' ) . '</p>';
  134. ?>
  135. <p class="step"><a class="button button-large" href="repair.php?repair=1"><?php _e( 'Repair Database' ); ?></a></p>
  136. <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>
  137. <p class="step"><a class="button button-large" href="repair.php?repair=2"><?php _e( 'Repair and Optimize Database' ); ?></a></p>
  138. <?php
  139. }
  140. ?>
  141. </body>
  142. </html>