Make WordPress Core

Ticket #18201: 18201.2.diff

File 18201.2.diff, 4.2 KB (added by pento, 11 years ago)
  • wp-admin/includes/update.php

     
    5959        return $result;
    6060}
    6161
     62function get_core_checksums( $version ) {
     63        if ( $checksums = get_site_transient( "core_checksums_$version" ) )
     64                return $checksums;
     65
     66        $url = 'http://api.wordpress.org/core/checksum/1.0/?' . http_build_query( array( 'version' => $version ), null, '&' );
     67
     68        if ( wp_http_supports( array( 'ssl' ) ) )
     69                $url = set_url_scheme( $url, 'https' );
     70
     71        $options = array(
     72                'timeout' => ( ( defined('DOING_CRON') && DOING_CRON ) ? 30 : 3 ),
     73                'user-agent' => 'WordPress/' . $version . '; ' . home_url( '/' )
     74        );
     75
     76        $response = wp_remote_get( $url, $options );
     77
     78        if ( is_wp_error( $response ) || 200 != wp_remote_retrieve_response_code( $response ) )
     79                return false;
     80
     81        $body = trim( wp_remote_retrieve_body( $response ) );
     82        $body = json_decode( $body, true );
     83
     84        if ( ! is_array( $body ) || ! isset( $body['checksums'] ) || ! is_array( $body['checksums'] ) )
     85                return false;
     86
     87        set_site_transient( "core_checksums_$version", $body['checksums'], HOUR_IN_SECONDS );
     88
     89        return $body['checksums'];
     90}
     91
    6292function dismiss_core_update( $update ) {
    6393        $dismissed = get_site_option( 'dismissed_update_core' );
    6494        $dismissed[ $update->current . '|' . $update->locale ] = true;
  • wp-admin/includes/class-wp-upgrader.php

     
    10901090
    10911091                $wp_dir = trailingslashit($wp_filesystem->abspath());
    10921092
     1093                $no_partial = false;
     1094                if ( ! $this->check_files() )
     1095                        $no_partial = true;
     1096
    10931097                // If partial update is returned from the API, use that, unless we're doing a reinstall.
    10941098                // If we cross the new_bundled version number, then use the new_bundled zip.
    10951099                // Don't though if the constant is set to skip bundled items.
    10961100                // If the API returns a no_content zip, go with it. Finally, default to the full zip.
    1097                 if ( $current->packages->partial && 'reinstall' != $current->response && $wp_version == $current->partial_version )
     1101                if ( $current->packages->partial && 'reinstall' != $current->response && $wp_version == $current->partial_version && ! $no_partial )
    10981102                        $to_download = 'partial';
    10991103                elseif ( $current->packages->new_bundled && version_compare( $wp_version, $current->new_bundled, '<' )
    11001104                        && ( ! defined( 'CORE_UPGRADE_SKIP_NEW_BUNDLED' ) || ! CORE_UPGRADE_SKIP_NEW_BUNDLED ) )
     
    11291133                return $result;
    11301134        }
    11311135
     1136        function check_files() {
     1137                global $wp_version;
     1138
     1139                if ( ! function_exists( 'md5_file' ) )
     1140                        return false;
     1141
     1142                $checksums = get_core_checksums( $wp_version );
     1143
     1144                if ( empty( $checksums ) )
     1145                        return false;
     1146
     1147                $home = get_home_path();
     1148
     1149                foreach ( $checksums as $file => $checksum ) {
     1150                        if ( md5_file( $home . $file ) !== $checksum )
     1151                                return false;
     1152                }
     1153
     1154                return true;
     1155        }
    11321156}
    11331157
    11341158/**
  • wp-admin/includes/update-core.php

     
    690690
    691691        apply_filters('update_feedback', __('Installing the latest version&#8230;'));
    692692
     693        // Check to see which files don't really need updating
     694        $skip = array( 'wp-content' );
     695        if ( function_exists( 'md5_file' ) ) {
     696                $checksums = get_core_checksums( $wp_version );
     697                if ( ! empty( $checksums ) ) {
     698                        foreach( $checksums as $file => $checksum ) {
     699                                if ( md5_file( $to . $file ) === $checksum )
     700                                        $skip[] = $file;
     701                        }
     702                }
     703        }
     704
    693705        // Create maintenance file to signal that we are upgrading
    694706        $maintenance_string = '<?php $upgrading = ' . time() . '; ?>';
    695707        $maintenance_file = $to . '.maintenance';
     
    697709        $wp_filesystem->put_contents($maintenance_file, $maintenance_string, FS_CHMOD_FILE);
    698710
    699711        // Copy new versions of WP files into place.
    700         $result = _copy_dir($from . $distro, $to, array('wp-content') );
     712        $result = _copy_dir($from . $distro, $to, $skip );
    701713
    702714        // Custom Content Directory needs updating now.
    703715        // Copy Languages