WordPress.org

Make WordPress Core

Ticket #3601: 3601.diff

File 3601.diff, 5.1 KB (added by mdawaffe, 7 years ago)
  • wp-includes/js/autosave-js.php

     
    8585        form.submit ? form.submit.disabled = 'disabled' : null; 
    8686        form.publish ? form.publish.disabled = 'disabled' : null; 
    8787        form.deletepost ? form.deletepost.disabled = 'disabled' : null; 
     88        setTimeout('autosave_enable_buttons();', 1000); // Re-enable 1 sec later.  Just gives autosave a head start to avoid collisions. 
    8889} 
    8990 
    9091function autosave_enable_buttons() { 
  • wp-includes/script-loader.php

     
    1919                $mce_config = apply_filters('tiny_mce_config_url', '/wp-includes/js/tinymce/tiny_mce_config.php'); 
    2020                $this->add( 'wp_tiny_mce', $mce_config, array('tiny_mce'), '20061113' ); 
    2121                $this->add( 'prototype', '/wp-includes/js/prototype.js', false, '1.5.0'); 
    22                 $this->add( 'autosave', '/wp-includes/js/autosave-js.php', array('prototype', 'sack'), '4508'); 
     22                $this->add( 'autosave', '/wp-includes/js/autosave-js.php', array('prototype', 'sack'), '20070116'); 
    2323                $this->add( 'wp-ajax', '/wp-includes/js/wp-ajax-js.php', array('prototype'), '4459'); 
    2424                $this->add( 'listman', '/wp-includes/js/list-manipulation-js.php', array('wp-ajax', 'fat'), '4583'); 
    2525                $this->add( 'scriptaculous-root', '/wp-includes/js/scriptaculous/wp-scriptaculous.js', array('prototype'), '1.6.1'); 
  • wp-admin/admin-ajax.php

     
    220220        ) ); 
    221221        $x->send(); 
    222222        break; 
    223 case 'autosave' : 
     223case 'autosave' : // The name of this action is hardcoded in edit_post() 
    224224        $_POST['post_content'] = $_POST['content']; 
    225225        $_POST['post_excerpt'] = $_POST['excerpt']; 
    226226        $_POST['post_status'] = 'draft'; 
  • wp-admin/admin-functions.php

     
    2020                        return new WP_Error( 'edit_posts', __( 'You are not allowed to create posts or drafts on this blog.' ) ); 
    2121        } 
    2222 
     23 
     24        // Check for autosave collisions 
     25        if ( isset($_POST['temp_ID']) ) { 
     26                $temp_id = (int) $_POST['temp_ID']; 
     27                if ( !$draft_ids = get_option( 'autosave_draft_ids' ) ) 
     28                        $draft_ids = array(); 
     29                foreach ( $draft_ids as $temp => $real ) 
     30                        if ( time() + $temp > 86400 ) // 1 day: $temp is equal to -1 * time( then ) 
     31                                unset($draft_ids[$temp]); 
     32 
     33                if ( isset($draft_ids[$temp_id]) ) { // Edit, don't write 
     34                        $_POST['post_ID'] = $draft_ids[$temp_id]; 
     35                        unset($_POST['temp_ID']); 
     36                        relocate_children( $temp_id, $_POST['post_ID'] ); 
     37                        update_option( 'autosave_draft_ids', $draft_ids ); 
     38                        return edit_post(); 
     39                } 
     40        } 
     41 
    2342        // Rename. 
    2443        $_POST['post_content'] = $_POST['content']; 
    2544        $_POST['post_excerpt'] = $_POST['excerpt']; 
     
    88107        } 
    89108 
    90109        // Create the post. 
    91         $post_ID = wp_insert_post( $_POST); 
     110        $post_ID = wp_insert_post( $_POST ); 
     111 
    92112        add_meta( $post_ID ); 
    93113 
    94114        // Reunite any orphaned attachments with their parent 
    95         if ( $_POST['temp_ID'] ) 
     115        // Update autosave collision detection 
     116        if ( $_POST['temp_ID'] ) { 
    96117                relocate_children( $_POST['temp_ID'], $post_ID ); 
     118                $draft_ids[$temp_id] = $post_ID; 
     119                update_option( 'autosave_draft_ids', $draft_ids ); 
     120        } 
    97121 
    98122        // Now that we have an ID we can fix any attachment anchor hrefs 
    99123        fix_attachment_links( $post_ID ); 
     
    165189                        wp_die( __('You are not allowed to edit this post.' )); 
    166190        } 
    167191 
     192        // Autosave shouldn't save too soon after a real save 
     193        if ( 'autosave' == $_POST['action'] ) { 
     194                $post =& get_post( $post_ID ); 
     195                $now = time(); 
     196                $then = strtotime($post->post_date_gmt . ' +0000'); 
     197                $delta = apply_filters( 'autosave_interval', 120 ) / 2; 
     198                if ( $now - $then < $delta ) 
     199                        return $post_ID; 
     200        } 
     201 
    168202        // Rename. 
    169203        $_POST['ID'] = (int) $_POST['post_ID']; 
    170204        $_POST['post_content'] = $_POST['content']; 
  • wp-admin/edit-page-form.php

     
    55if (0 == $post_ID) { 
    66        $form_action = 'post'; 
    77        $nonce_action = 'add-page'; 
    8         $temp_ID = -1 * time(); 
     8        $temp_ID = -1 * time(); // don't change this formula without looking at wp_write_post() 
    99        $form_extra = "<input type='hidden' id='post_ID' name='temp_ID' value='$temp_ID' />"; 
    1010} else { 
    1111        $form_action = 'editpost'; 
  • wp-admin/edit-form-advanced.php

     
    1717 
    1818if (0 == $post_ID) { 
    1919        $form_action = 'post'; 
    20         $temp_ID = -1 * time(); 
     20        $temp_ID = -1 * time(); // don't change this formula without looking at wp_write_post() 
    2121        $form_extra = "<input type='hidden' id='post_ID' name='temp_ID' value='$temp_ID' />"; 
    2222        wp_nonce_field('add-post'); 
    2323} else {