WordPress.org

Make WordPress Core

Changeset 8595


Ignore:
Timestamp:
08/08/08 22:49:35 (6 years ago)
Author:
ryan
Message:

Automatic upgrade, first cut. see #5560

Location:
trunk
Files:
1 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/file.php

    r8580 r8595  
    409409            $wp_filesystem->chmod($to . $filename, 0644); 
    410410        } elseif ( 'd' == $fileinfo['type'] ) { 
    411             if ( !$wp_filesystem->mkdir($to . $filename, 0755) ) 
    412                 return new WP_Error('mkdir_failed', __('Could not create directory'), $to . $filename); 
     411            if ( !$wp_filesystem->is_dir($to . $filename) ) { 
     412                if ( !$wp_filesystem->mkdir($to . $filename, 0755) ) 
     413                    return new WP_Error('mkdir_failed', __('Could not create directory'), $to . $filename); 
     414            } 
    413415            $result = copy_dir($from . $filename, $to . $filename); 
    414416            if ( is_wp_error($result) ) 
  • trunk/wp-admin/includes/update.php

    r8589 r8595  
    1616    switch ( $cur->response ) { 
    1717    case 'development' : 
    18         return sprintf( '| '.__( 'You are using a development version (%s). Cool! Please <a href="%s">stay updated</a>.' ), $GLOBALS['wp_version'], $cur->url, $cur->current ); 
     18        return sprintf( '| '.__( 'You are using a development version (%1$s). Cool! Please <a href="%2$s">stay updated</a>.' ), $GLOBALS['wp_version'], wp_nonce_url('update.php?action=upgrade-core', 'upgrade-core')); 
    1919    break; 
    2020 
    2121    case 'upgrade' : 
    2222        if ( current_user_can('manage_options') ) { 
    23             return sprintf( '| <strong>'.__( '<a href="%2$s">Get Version %3$s</a>' ).'</strong>', $GLOBALS['wp_version'], $cur->url, $cur->current ); 
     23            return sprintf( '| <strong>'.__( '<a href="%1$s">Get Version %2$s</a>' ).'</strong>', wp_nonce_url('update.php?action=upgrade-core', 'upgrade-core'), $cur->current); 
    2424            break; 
    2525        } 
     
    2727    case 'latest' : 
    2828    default : 
    29         return sprintf( '| '.__( 'Version %s' ), $GLOBALS['wp_version'], $cur->url, $cur->current ); 
     29        return sprintf( '| '.__( 'Version %s' ), $GLOBALS['wp_version'] ); 
    3030    break; 
    3131    } 
     
    4040 
    4141    if ( current_user_can('manage_options') ) 
    42         $msg = sprintf( __('WordPress %2$s is available! <a href="%1$s">Please update now</a>.'), $cur->url, $cur->current ); 
     42        $msg = sprintf( __('WordPress %1$s is available! <a href="%2$s">Please update now</a>.'), $cur->current, wp_nonce_url('update.php?action=upgrade-core', 'upgrade-core') ); 
    4343    else 
    44         $msg = sprintf( __('WordPress %2$s is available! Please notify the site administrator.'), $cur->url, $cur->current ); 
     44        $msg = sprintf( __('WordPress %1$s is available! Please notify the site administrator.'), $cur->current ); 
    4545 
    4646    echo "<div id='update-nag'>$msg</div>"; 
     
    5454    $msg = sprintf( __('This is WordPress version %s.'), $GLOBALS['wp_version'] ); 
    5555    if ( isset( $cur->response ) && $cur->response == 'upgrade' && current_user_can('manage_options') ) 
    56         $msg .= " <a href='$cur->url' class='rbutton'>" . sprintf( __('Update to %s'), $cur->current ? $cur->current : __( 'Latest' ) ) . '</a>'; 
     56        $msg .= " <a href='" . wp_nonce_url('update.php?action=upgrade-core', 'upgrade-core') . "' class='rbutton'>" . sprintf( __('Update to %s'), $cur->current ? $cur->current : __( 'Latest' ) ) . '</a>'; 
    5757 
    5858    echo "<span id='wp-version-message'>$msg</span>"; 
     
    194194} 
    195195 
     196function wp_update_core($feedback = '') { 
     197    global $wp_filesystem; 
     198 
     199    if ( !empty($feedback) ) 
     200        add_filter('update_feedback', $feedback); 
     201 
     202    // Is an update available? 
     203    $current = get_option( 'update_core' ); 
     204    if ( !isset( $current->response ) || $current->response == 'latest' ) 
     205        return new WP_Error('up_to_date', __('WordPress is at the latest version.')); 
     206 
     207    // Is a filesystem accessor setup? 
     208    if ( ! $wp_filesystem || ! is_object($wp_filesystem) ) 
     209        WP_Filesystem(); 
     210 
     211    if ( ! is_object($wp_filesystem) ) 
     212        return new WP_Error('fs_unavailable', __('Could not access filesystem.')); 
     213 
     214    if ( $wp_filesystem->errors->get_error_code() ) 
     215        return new WP_Error('fs_error', __('Filesystem error'), $wp_filesystem->errors); 
     216 
     217    // Get the base WP folder 
     218    $wp_dir = $wp_filesystem->abspath(); 
     219    if ( empty($wp_dir) ) 
     220        return new WP_Error('fs_no_wp_dir', __('Unable to locate WordPress directory.')); 
     221 
     222    // And the same for the Content directory. 
     223    $content_dir = $wp_filesystem->wp_content_dir(); 
     224    if( empty($content_dir) ) 
     225        return new WP_Error('fs_no_content_dir', __('Unable to locate WordPress Content directory (wp-content).')); 
     226     
     227    $wp_dir = trailingslashit( $wp_dir ); 
     228    $content_dir = trailingslashit( $content_dir ); 
     229 
     230    // Get the URL to the zip file 
     231    $package = $current->package; 
     232 
     233    // Download the package 
     234    apply_filters('update_feedback', sprintf(__('Downloading update from %s'), $package)); 
     235    $download_file = download_url($package); 
     236 
     237    if ( is_wp_error($download_file) ) 
     238        return new WP_Error('download_failed', __('Download failed.'), $download_file->get_error_message()); 
     239 
     240    $working_dir = $content_dir . 'upgrade/core'; 
     241 
     242    // Clean up working directory 
     243    if ( $wp_filesystem->is_dir($working_dir) ) 
     244        $wp_filesystem->delete($working_dir, true); 
     245 
     246    apply_filters('update_feedback', __('Unpacking the update')); 
     247    // Unzip package to working directory 
     248    $result = unzip_file($download_file, $working_dir); 
     249 
     250    // Once extracted, delete the package 
     251    unlink($download_file); 
     252 
     253    if ( is_wp_error($result) ) { 
     254        $wp_filesystem->delete($working_dir, true); 
     255        return $result; 
     256    } 
     257 
     258    // Copy update-core.php from the new version into place. 
     259    if ( !$wp_filesystem->copy($working_dir . '/wordpress/wp-admin/includes/update-core.php', $wp_dir . 'wp-admin/includes/update-core.php', true) ) { 
     260        $wp_filesystem->delete($working_dir, true); 
     261        return new WP_Error('copy_failed', __('Could not copy files')); 
     262    } 
     263 
     264    require(ABSPATH . 'wp-admin/includes/update-core.php'); 
     265 
     266    return update_core($working_dir, $wp_dir); 
     267} 
     268 
    196269?> 
  • trunk/wp-admin/update.php

    r8540 r8595  
    4545} 
    4646 
     47function do_core_upgrade() { 
     48    global $wp_filesystem; 
     49 
     50    $url = wp_nonce_url("update.php?action=upgrade-core", "upgrade-core"); 
     51    if ( false === ($credentials = request_filesystem_credentials($url)) ) 
     52        return; 
     53 
     54    if ( ! WP_Filesystem($credentials) ) { 
     55        request_filesystem_credentials($url, '', true); //Failed to connect, Error and request again 
     56        return; 
     57    } 
     58 
     59    echo '<div class="wrap">'; 
     60    echo '<h2>' . __('Upgrade WordPress') . '</h2>'; 
     61    if ( $wp_filesystem->errors->get_error_code() ) { 
     62        foreach ( $wp_filesystem->errors->get_error_messages() as $message ) 
     63            show_message($message); 
     64        echo '</div>'; 
     65        return; 
     66    } 
     67 
     68    $result = wp_update_core('show_message'); 
     69 
     70    if ( is_wp_error($result) ) { 
     71        show_message($result); 
     72        if ('up_to_date' != $result->get_error_code() ) 
     73            show_message( __('Installation Failed') ); 
     74    } else { 
     75        show_message( __('WordPress upgraded successfully') );   
     76    } 
     77    echo '</div>'; 
     78} 
     79 
    4780if ( isset($_GET['action']) ) { 
    4881    $plugin = isset($_GET['plugin']) ? trim($_GET['plugin']) : ''; 
     
    85118        } 
    86119        echo "</body></html>"; 
     120    } elseif ( 'upgrade-core' == $_GET['action'] ) { 
     121        //check_admin_referer('upgrade-core'); 
     122        $title = __('Upgrade WordPress'); 
     123        $parent_file = 'index.php'; 
     124        require_once('admin-header.php'); 
     125        do_core_upgrade(); 
     126        include('admin-footer.php'); 
    87127    } 
    88128} 
  • trunk/wp-includes/update.php

    r8516 r8595  
    4141    $new_option->version_checked = $wp_version; 
    4242 
    43     $url = "http://api.wordpress.org/core/version-check/1.1/?version=$wp_version&php=$php_version&locale=$locale"; 
     43    $url = "http://api.wordpress.org/core/version-check/1.2/?version=$wp_version&php=$php_version&locale=$locale"; 
    4444    $options = array('timeout' => 3); 
    4545 
     
    5151    $response = wp_remote_request($url, $options, $headers); 
    5252 
    53     if( 200 != $response['response']['code'] ) 
     53    if ( 200 != $response['response']['code'] ) 
    5454        return false; 
    5555 
    5656    $body = $response['body']; 
    57  
    58     $body = trim( $response[1] ); 
     57    $body = trim( $body ); 
    5958    $body = str_replace(array("\r\n", "\r"), "\n", $body); 
    60  
    6159    $returns = explode("\n", $body); 
    6260 
     
    6563        $new_option->url = clean_url( $returns[1] ); 
    6664    if ( isset( $returns[2] ) ) 
    67         $new_option->current = attribute_escape( $returns[2] ); 
     65        $new_option->package = clean_url( $returns[2] ); 
     66    if ( isset( $returns[3] ) ) 
     67        $new_option->current = attribute_escape( $returns[3] ); 
     68    if ( isset( $returns[4] ) ) 
     69        $new_option->locale = attribute_escape( $returns[4] ); 
    6870 
    6971    update_option( 'update_core', $new_option ); 
  • trunk/wp-settings.php

    r8565 r8595  
    107107if ( !defined('WP_CONTENT_DIR') ) 
    108108    define( 'WP_CONTENT_DIR', ABSPATH . 'wp-content' ); // no trailing slash, full paths only - WP_CONTENT_URL is defined further down 
     109 
     110if ( file_exists(ABSPATH . '.maintenance') ) { 
     111    if ( file_exists( WP_CONTENT_DIR . '/maintenance.php' ) ) { 
     112        require_once( WP_CONTENT_DIR . '/maintenance.php' ); 
     113        die(); 
     114    } 
     115 
     116    $protocol = $_SERVER["SERVER_PROTOCOL"]; 
     117    if ( 'HTTP/1.1' != $protocol && 'HTTP/1.0' != $protocol ) 
     118        $protocol = 'HTTP/1.0'; 
     119    header( "$protocol 503 Service Unavailable", true, 503 ); 
     120    header( 'Content-Type: text/html; charset=utf-8' ); 
     121?> 
     122<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
     123<html xmlns="http://www.w3.org/1999/xhtml"> 
     124<head> 
     125<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
     126    <title>Maintenance</title> 
     127 
     128</head> 
     129<body> 
     130    <h1>Briefly unavailable for scheduled maintenance. Check back in a minute.</h1> 
     131</body> 
     132</html> 
     133<?php 
     134die(); 
     135} 
    109136 
    110137if ( !extension_loaded('mysql') && !file_exists(WP_CONTENT_DIR . '/db.php') ) 
Note: See TracChangeset for help on using the changeset viewer.