WordPress.org

Make WordPress Core

Ticket #20074: 20074.diff

File 20074.diff, 5.1 KB (added by sivel, 2 years ago)
  • wp-admin/includes/file.php

     
    492492 * 
    493493 * @param string $url the URL of the file to download 
    494494 * @param int $timeout The timeout for the request to download the file default 300 seconds 
    495  * @return mixed WP_Error on failure, string Filename on success. 
     495 * @param bool $full_response Whether to return the full response instead of just the filename 
     496 * @return mixed WP_Error on failure, string Filename or HTTP API response array on success. 
    496497 */ 
    497 function download_url( $url, $timeout = 300 ) { 
     498function download_url( $url, $timeout = 300, $full_response = false ) { 
    498499        //WARNING: The file is not automatically deleted, The script must unlink() the file. 
    499500        if ( ! $url ) 
    500501                return new WP_Error('http_no_url', __('Invalid URL Provided.')); 
     
    515516                return new WP_Error( 'http_404', trim( wp_remote_retrieve_response_message( $response ) ) ); 
    516517        } 
    517518 
    518         return $tmpfname; 
     519        if ( $full_response ) 
     520                return $response; 
     521        else 
     522                return $tmpfname; 
    519523} 
    520524 
    521525/** 
  • wp-admin/includes/class-wp-upgrader.php

     
    4949                $this->strings['fs_no_folder'] = __('Unable to locate needed folder (%s).'); 
    5050 
    5151                $this->strings['download_failed'] = __('Download failed.'); 
     52                $this->strings['download_verification_failed'] = __('Unable to verify download.'); 
    5253                $this->strings['installing_package'] = __('Installing the latest version…'); 
    5354                $this->strings['folder_exists'] = __('Destination folder already exists.'); 
    5455                $this->strings['mkdir_failed'] = __('Could not create directory.'); 
     
    115116 
    116117                $this->skin->feedback('downloading_package', $package); 
    117118 
    118                 $download_file = download_url($package); 
     119                $response = download_url($package, 300, true); 
    119120 
    120                 if ( is_wp_error($download_file) ) 
    121                         return new WP_Error('download_failed', $this->strings['download_failed'], $download_file->get_error_message()); 
     121                if ( is_wp_error($response) ) 
     122                        return new WP_Error('download_failed', $this->strings['download_failed'], $response->get_error_message()); 
    122123 
     124                $download_file = $response['filename']; 
     125 
     126                $content_md5 = wp_remote_retrieve_header( $response, 'content-md5' ); 
     127 
     128                if ( ! empty( $content_md5 ) ) { 
     129                        $this->skin->feedback('verifying_package'); 
     130                        $md5_file = md5_file( $download_file ); 
     131                        if ( $md5_file != $content_md5 ) 
     132                                return new WP_Error('download_verification_failed', $this->strings['download_verification_failed'], sprintf( __( 'The checksum of the download (%1$s) does not match the provided checksum value (%2$s).' ), $md5_file, $content_md5 ) ); 
     133                } 
     134 
    123135                return $download_file; 
    124136        } 
    125137 
     
    373385                $this->strings['up_to_date'] = __('The plugin is at the latest version.'); 
    374386                $this->strings['no_package'] = __('Update package not available.'); 
    375387                $this->strings['downloading_package'] = __('Downloading update from <span class="code">%s</span>&#8230;'); 
     388                $this->strings['verifying_package'] = __('Verifying the update&#8230;'); 
    376389                $this->strings['unpack_package'] = __('Unpacking the update&#8230;'); 
    377390                $this->strings['deactivate_plugin'] = __('Deactivating the plugin&#8230;'); 
    378391                $this->strings['remove_old'] = __('Removing the old version of the plugin&#8230;'); 
     
    384397        function install_strings() { 
    385398                $this->strings['no_package'] = __('Install package not available.'); 
    386399                $this->strings['downloading_package'] = __('Downloading install package from <span class="code">%s</span>&#8230;'); 
     400                $this->strings['verifying_package'] = __('Verifying the install package&#8230;'); 
    387401                $this->strings['unpack_package'] = __('Unpacking the package&#8230;'); 
    388402                $this->strings['installing_package'] = __('Installing the plugin&#8230;'); 
    389403                $this->strings['process_failed'] = __('Plugin install failed.'); 
     
    648662                $this->strings['up_to_date'] = __('The theme is at the latest version.'); 
    649663                $this->strings['no_package'] = __('Update package not available.'); 
    650664                $this->strings['downloading_package'] = __('Downloading update from <span class="code">%s</span>&#8230;'); 
     665                $this->strings['verifying_package'] = __('Verifying the update&#8230;'); 
    651666                $this->strings['unpack_package'] = __('Unpacking the update&#8230;'); 
    652667                $this->strings['remove_old'] = __('Removing the old version of the theme&#8230;'); 
    653668                $this->strings['remove_old_failed'] = __('Could not remove the old theme.'); 
     
    658673        function install_strings() { 
    659674                $this->strings['no_package'] = __('Install package not available.'); 
    660675                $this->strings['downloading_package'] = __('Downloading install package from <span class="code">%s</span>&#8230;'); 
     676                $this->strings['verifying_package'] = __('Verifying the install package&#8230;'); 
    661677                $this->strings['unpack_package'] = __('Unpacking the package&#8230;'); 
    662678                $this->strings['installing_package'] = __('Installing the theme&#8230;'); 
    663679                $this->strings['process_failed'] = __('Theme install failed.');