diff --git a/wp-admin/includes/file.php b/wp-admin/includes/file.php index 2cae7da034..85ff48ab0e 100644 --- a/wp-admin/includes/file.php +++ b/wp-admin/includes/file.php @@ -408,8 +408,10 @@ function copy_dir($from, $to) { return new WP_Error('copy_failed', __('Could not copy file'), $to . $filename); $wp_filesystem->chmod($to . $filename, 0644); } elseif ( 'd' == $fileinfo['type'] ) { - if ( !$wp_filesystem->mkdir($to . $filename, 0755) ) - return new WP_Error('mkdir_failed', __('Could not create directory'), $to . $filename); + if ( !$wp_filesystem->is_dir($to . $filename) ) { + if ( !$wp_filesystem->mkdir($to . $filename, 0755) ) + return new WP_Error('mkdir_failed', __('Could not create directory'), $to . $filename); + } $result = copy_dir($from . $filename, $to . $filename); if ( is_wp_error($result) ) return $result; diff --git a/wp-admin/includes/update-core.php b/wp-admin/includes/update-core.php new file mode 100644 index 0000000000..60b0b8862e --- /dev/null +++ b/wp-admin/includes/update-core.php @@ -0,0 +1,50 @@ +delete($from, true); + return new WP_Error('insane_distro', __('The update could not be unpacked') ); + } + + apply_filters('update_feedback', __('Installing the latest version')); + + // Create maintenance file to signal that we are upgrading + $maintenance_string = ''; + $maintenance_file = $to . '.maintenance'; + $wp_filesystem->delete($maintenance_file); + $wp_filesystem->put_contents($maintenance_file, $maintenance_string, 0644); + + // Copy new versions of WP files into place. + $result = copy_dir($from . '/wordpress', $to); + if ( is_wp_error($result) ) { + $wp_filesystem->delete($maintenance_file); + //$wp_filesystem->delete($working_dir, true); //TODO: Uncomment? This DOES mean that the new files are available in the upgrade folder if it fails. + return $result; + } + + // Might have to do upgrade in a separate step. + apply_filters('update_feedback', __('Upgrading database')); + // Get new db version + global $wp_db_version; + require (ABSPATH . WPINC . '/version.php'); + // Upgrade db + define('WP_INSTALLING', true); + require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); + wp_upgrade(); + + // Remove working directory + $wp_filesystem->delete($from, true); + + // Remove maintenance file, we're done. + $wp_filesystem->delete($maintenance_file); + + // Force refresh of update information + delete_option('update_core'); +} + +?> \ No newline at end of file diff --git a/wp-admin/includes/update.php b/wp-admin/includes/update.php index fbc64a31ec..3edfa702b8 100644 --- a/wp-admin/includes/update.php +++ b/wp-admin/includes/update.php @@ -15,18 +15,18 @@ function core_update_footer( $msg = '' ) { switch ( $cur->response ) { case 'development' : - return sprintf( '| '.__( 'You are using a development version (%s). Cool! Please stay updated.' ), $GLOBALS['wp_version'], $cur->url, $cur->current ); + return sprintf( '| '.__( 'You are using a development version (%1$s). Cool! Please stay updated.' ), $GLOBALS['wp_version'], wp_nonce_url('update.php?action=upgrade-core', 'upgrade-core')); break; case 'upgrade' : if ( current_user_can('manage_options') ) { - return sprintf( '| '.__( 'Get Version %3$s' ).'', $GLOBALS['wp_version'], $cur->url, $cur->current ); + return sprintf( '| '.__( 'Get Version %2$s' ).'', wp_nonce_url('update.php?action=upgrade-core', 'upgrade-core'), $cur->current); break; } case 'latest' : default : - return sprintf( '| '.__( 'Version %s' ), $GLOBALS['wp_version'], $cur->url, $cur->current ); + return sprintf( '| '.__( 'Version %s' ), $GLOBALS['wp_version'] ); break; } } @@ -39,9 +39,9 @@ function update_nag() { return false; if ( current_user_can('manage_options') ) - $msg = sprintf( __('WordPress %2$s is available! Please update now.'), $cur->url, $cur->current ); + $msg = sprintf( __('WordPress %1$s is available! Please update now.'), $cur->current, wp_nonce_url('update.php?action=upgrade-core', 'upgrade-core') ); else - $msg = sprintf( __('WordPress %2$s is available! Please notify the site administrator.'), $cur->url, $cur->current ); + $msg = sprintf( __('WordPress %1$s is available! Please notify the site administrator.'), $cur->current ); echo "
$msg
"; } @@ -53,7 +53,7 @@ function update_right_now_message() { $msg = sprintf( __('This is WordPress version %s.'), $GLOBALS['wp_version'] ); if ( isset( $cur->response ) && $cur->response == 'upgrade' && current_user_can('manage_options') ) - $msg .= " " . sprintf( __('Update to %s'), $cur->current ? $cur->current : __( 'Latest' ) ) . ''; + $msg .= " " . sprintf( __('Update to %s'), $cur->current ? $cur->current : __( 'Latest' ) ) . ''; echo "$msg"; } @@ -193,4 +193,77 @@ function wp_update_plugin($plugin, $feedback = '') { return $folder . '/' . $pluginfiles[0]; } +function wp_update_core($feedback = '') { + global $wp_filesystem; + + if ( !empty($feedback) ) + add_filter('update_feedback', $feedback); + + // Is an update available? + $current = get_option( 'update_core' ); + if ( !isset( $current->response ) || $current->response == 'latest' ) + return new WP_Error('up_to_date', __('WordPress is at the latest version.')); + + // Is a filesystem accessor setup? + if ( ! $wp_filesystem || ! is_object($wp_filesystem) ) + WP_Filesystem(); + + if ( ! is_object($wp_filesystem) ) + return new WP_Error('fs_unavailable', __('Could not access filesystem.')); + + if ( $wp_filesystem->errors->get_error_code() ) + return new WP_Error('fs_error', __('Filesystem error'), $wp_filesystem->errors); + + // Get the base WP folder + $wp_dir = $wp_filesystem->abspath(); + if ( empty($wp_dir) ) + return new WP_Error('fs_no_wp_dir', __('Unable to locate WordPress directory.')); + + // And the same for the Content directory. + $content_dir = $wp_filesystem->wp_content_dir(); + if( empty($content_dir) ) + return new WP_Error('fs_no_content_dir', __('Unable to locate WordPress Content directory (wp-content).')); + + $wp_dir = trailingslashit( $wp_dir ); + $content_dir = trailingslashit( $content_dir ); + + // Get the URL to the zip file + $package = $current->package; + + // Download the package + apply_filters('update_feedback', sprintf(__('Downloading update from %s'), $package)); + $download_file = download_url($package); + + if ( is_wp_error($download_file) ) + return new WP_Error('download_failed', __('Download failed.'), $download_file->get_error_message()); + + $working_dir = $content_dir . 'upgrade/core'; + + // Clean up working directory + if ( $wp_filesystem->is_dir($working_dir) ) + $wp_filesystem->delete($working_dir, true); + + apply_filters('update_feedback', __('Unpacking the update')); + // Unzip package to working directory + $result = unzip_file($download_file, $working_dir); + + // Once extracted, delete the package + unlink($download_file); + + if ( is_wp_error($result) ) { + $wp_filesystem->delete($working_dir, true); + return $result; + } + + // Copy update-core.php from the new version into place. + if ( !$wp_filesystem->copy($working_dir . '/wordpress/wp-admin/includes/update-core.php', $wp_dir . 'wp-admin/includes/update-core.php', true) ) { + $wp_filesystem->delete($working_dir, true); + return new WP_Error('copy_failed', __('Could not copy files')); + } + + require(ABSPATH . 'wp-admin/includes/update-core.php'); + + return update_core($working_dir, $wp_dir); +} + ?> diff --git a/wp-admin/update.php b/wp-admin/update.php index b01e1d44e0..d25b4c5392 100644 --- a/wp-admin/update.php +++ b/wp-admin/update.php @@ -44,6 +44,39 @@ function do_plugin_upgrade($plugin) { echo ''; } +function do_core_upgrade() { + global $wp_filesystem; + + $url = wp_nonce_url("update.php?action=upgrade-core", "upgrade-core"); + if ( false === ($credentials = request_filesystem_credentials($url)) ) + return; + + if ( ! WP_Filesystem($credentials) ) { + request_filesystem_credentials($url, '', true); //Failed to connect, Error and request again + return; + } + + echo '
'; + echo '

' . __('Upgrade WordPress') . '

'; + if ( $wp_filesystem->errors->get_error_code() ) { + foreach ( $wp_filesystem->errors->get_error_messages() as $message ) + show_message($message); + echo '
'; + return; + } + + $result = wp_update_core('show_message'); + + if ( is_wp_error($result) ) { + show_message($result); + if ('up_to_date' != $result->get_error_code() ) + show_message( __('Installation Failed') ); + } else { + show_message( __('WordPress upgraded successfully') ); + } + echo ''; +} + if ( isset($_GET['action']) ) { $plugin = isset($_GET['plugin']) ? trim($_GET['plugin']) : ''; @@ -84,6 +117,13 @@ wp_admin_css( 'colors', true ); include(WP_PLUGIN_DIR . '/' . $plugin); } echo ""; + } elseif ( 'upgrade-core' == $_GET['action'] ) { + //check_admin_referer('upgrade-core'); + $title = __('Upgrade WordPress'); + $parent_file = 'index.php'; + require_once('admin-header.php'); + do_core_upgrade(); + include('admin-footer.php'); } } diff --git a/wp-includes/update.php b/wp-includes/update.php index a1b6a16bf3..3b072411d9 100644 --- a/wp-includes/update.php +++ b/wp-includes/update.php @@ -40,7 +40,7 @@ function wp_version_check() { $new_option->last_checked = time(); // this gets set whether we get a response or not, so if something is down or misconfigured it won't delay the page load for more than 3 seconds, twice a day $new_option->version_checked = $wp_version; - $url = "http://api.wordpress.org/core/version-check/1.1/?version=$wp_version&php=$php_version&locale=$locale"; + $url = "http://api.wordpress.org/core/version-check/1.2/?version=$wp_version&php=$php_version&locale=$locale"; $options = array('timeout' => 3); $headers = array( @@ -50,21 +50,23 @@ function wp_version_check() { $response = wp_remote_request($url, $options, $headers); - if( 200 != $response['response']['code'] ) + if ( 200 != $response['response']['code'] ) return false; $body = $response['body']; - - $body = trim( $response[1] ); + $body = trim( $body ); $body = str_replace(array("\r\n", "\r"), "\n", $body); - $returns = explode("\n", $body); $new_option->response = attribute_escape( $returns[0] ); if ( isset( $returns[1] ) ) $new_option->url = clean_url( $returns[1] ); if ( isset( $returns[2] ) ) - $new_option->current = attribute_escape( $returns[2] ); + $new_option->package = clean_url( $returns[2] ); + if ( isset( $returns[3] ) ) + $new_option->current = attribute_escape( $returns[3] ); + if ( isset( $returns[4] ) ) + $new_option->locale = attribute_escape( $returns[4] ); update_option( 'update_core', $new_option ); } diff --git a/wp-settings.php b/wp-settings.php index 12a89bec12..b16384b7bf 100644 --- a/wp-settings.php +++ b/wp-settings.php @@ -107,6 +107,33 @@ if ( version_compare( '4.3', phpversion(), '>' ) ) { if ( !defined('WP_CONTENT_DIR') ) define( 'WP_CONTENT_DIR', ABSPATH . 'wp-content' ); // no trailing slash, full paths only - WP_CONTENT_URL is defined further down +if ( file_exists(ABSPATH . '.maintenance') ) { + if ( file_exists( WP_CONTENT_DIR . '/maintenance.php' ) ) { + require_once( WP_CONTENT_DIR . '/maintenance.php' ); + die(); + } + + $protocol = $_SERVER["SERVER_PROTOCOL"]; + if ( 'HTTP/1.1' != $protocol && 'HTTP/1.0' != $protocol ) + $protocol = 'HTTP/1.0'; + header( "$protocol 503 Service Unavailable", true, 503 ); + header( 'Content-Type: text/html; charset=utf-8' ); +?> + + + + + Maintenance + + + +

Briefly unavailable for scheduled maintenance. Check back in a minute.

+ + +