Make WordPress Core

Ticket #23665: 23665.patch

File 23665.patch, 6.3 KB (added by azaozz, 12 years ago)
  • wp-admin/edit-form-advanced.php

     
    168168                add_meta_box('authordiv', __('Author'), 'post_author_meta_box', null, 'normal', 'core');
    169169}
    170170
    171 // TODO review this count() - why do we need to add it?
    172 if ( post_type_supports($post_type, 'revisions') && 0 < $post_ID && count ( wp_get_post_revisions( $post_ID ) ) > 1  )
     171if ( post_type_supports($post_type, 'revisions') )
    173172        add_meta_box('revisionsdiv', __('Revisions'), 'post_revisions_meta_box', null, 'normal', 'core');
    174173
    175174do_action('add_meta_boxes', $post_type, $post);
  • wp-admin/includes/ajax-actions.php

     
    10381038        $do_autosave = (bool) $_POST['autosave'];
    10391039        $do_lock = true;
    10401040
     1041        if ( ! $user_id = get_current_user_id() )
     1042                wp_die('-1');
     1043
    10411044        $data = $alert = '';
    10421045        /* translators: draft saved date format, see http://php.net/date */
    10431046        $draft_saved_date_format = __('g:i:s a');
     
    10571060                $_POST['post_status'] = 'draft';
    10581061
    10591062        if ( $last = wp_check_post_lock( $post->ID ) ) {
    1060                 $do_autosave = $do_lock = false;
     1063                $do_lock = false;
    10611064
    10621065                $last_user = get_userdata( $last );
    10631066                $last_user_name = $last_user ? $last_user->display_name : __( 'Someone' );
    1064                 $data = __( 'Autosave disabled.' );
    1065 
    1066                 $supplemental['disable_autosave'] = 'disable';
    10671067                $alert .= sprintf( __( '%s is currently editing this article. If you update it, you will overwrite the changes.' ), esc_html( $last_user_name ) );
    10681068        }
    10691069
     
    10761076        }
    10771077
    10781078        if ( $do_autosave ) {
    1079                 // Drafts and auto-drafts are just overwritten by autosave
    1080                 if ( 'auto-draft' == $post->post_status || 'draft' == $post->post_status ) {
     1079                // Drafts and auto-drafts are just overwritten by autosave for the same user
     1080                if ( $user_id == $post->post_author && ( 'auto-draft' == $post->post_status || 'draft' == $post->post_status ) ) {
    10811081                        $id = edit_post();
    1082                 } else { // Non drafts are not overwritten. The autosave is stored in a special post revision.
     1082                } else { // Non drafts are not overwritten. The autosave is stored in a special post revision for each user.
    10831083                        $revision_id = wp_create_post_autosave( $post->ID );
    10841084                        if ( is_wp_error($revision_id) )
    10851085                                $id = $revision_id;
  • wp-admin/includes/post.php

     
    12361236        if ( is_wp_error( $translated ) )
    12371237                return $translated;
    12381238
    1239         // Only store one autosave. If there is already an autosave, overwrite it.
    1240         if ( $old_autosave = wp_get_post_autosave( $post_id ) ) {
     1239        $post_author = get_current_user_id();
     1240
     1241        // Store one autosave per author. If there is already an autosave, overwrite it.
     1242        if ( $old_autosave = wp_get_post_autosave( $post_id, $post_author ) ) {
    12411243                $new_autosave = _wp_post_revision_fields( $_POST, true );
    12421244                $new_autosave['ID'] = $old_autosave->ID;
    1243                 $new_autosave['post_author'] = get_current_user_id();
     1245                $new_autosave['post_author'] = $post_author;
    12441246                return wp_update_post( $new_autosave );
    12451247        }
    12461248
  • wp-admin/post.php

     
    169169                add_action('admin_notices', '_admin_notice_post_locked' );
    170170        } else {
    171171                $active_post_lock = wp_set_post_lock( $post->ID );
    172 
    173                 if ( 'attachment' !== $post_type )
    174                         wp_enqueue_script('autosave');
    175172        }
    176173
     174        if ( 'attachment' !== $post_type )
     175                wp_enqueue_script('autosave');
     176
    177177        $title = $post_type_object->labels->edit_item;
    178178        $post = get_post($post_id, OBJECT, 'edit');
    179179
  • wp-includes/revision.php

     
    135135 * Retrieve the autosaved data of the specified post.
    136136 *
    137137 * Returns a post object containing the information that was autosaved for the
    138  * specified post.
     138 * specified post. If the optional $user_id is passed, returns the autosave for that user
     139 * otherwise returns the latest autosave.
    139140 *
    140141 * @package WordPress
    141142 * @subpackage Post_Revisions
    142143 * @since 2.6.0
    143144 *
    144145 * @param int $post_id The post ID.
     146 * @param int $user_id optional The post author ID.
    145147 * @return object|bool The autosaved data or false on failure or when no autosave exists.
    146148 */
    147 function wp_get_post_autosave( $post_id ) {
     149function wp_get_post_autosave( $post_id, $user_id = 0 ) {
     150        $revisions = wp_get_post_revisions($post_id);
    148151
    149         if ( !$post = get_post( $post_id ) )
    150                 return false;
     152        foreach ( $revisions as $revision ) {
     153                if ( false !== strpos( $revision->post_name, "{$post_id}-autosave" ) ) {
     154                        if ( $user_id && $user_id != $revision->post_author )
     155                                continue;
    151156
    152         $q = array(
    153                 'name' => "{$post->ID}-autosave",
    154                 'post_parent' => $post->ID,
    155                 'post_type' => 'revision',
    156                 'post_status' => 'inherit'
    157         );
     157                        return $revision;
     158                        break;
     159                }
     160        }
    158161
    159         // Use WP_Query so that the result gets cached
    160         $autosave_query = new WP_Query;
    161 
    162         add_action( 'parse_query', '_wp_get_post_autosave_hack' );
    163         $autosave = $autosave_query->query( $q );
    164         remove_action( 'parse_query', '_wp_get_post_autosave_hack' );
    165 
    166         if ( $autosave && is_array($autosave) && is_object($autosave[0]) )
    167                 return $autosave[0];
    168 
    169162        return false;
    170163}
    171164
    172165/**
    173  * Internally used to hack WP_Query into submission.
    174  *
    175  * @package WordPress
    176  * @subpackage Post_Revisions
    177  * @since 2.6.0
    178  *
    179  * @param object $query WP_Query object
    180  */
    181 function _wp_get_post_autosave_hack( $query ) {
    182         $query->is_single = false;
    183 }
    184 
    185 /**
    186166 * Determines if the specified post is a revision.
    187167 *
    188168 * @package WordPress
     
    211191function wp_is_post_autosave( $post ) {
    212192        if ( !$post = wp_get_post_revision( $post ) )
    213193                return false;
    214         if ( "{$post->post_parent}-autosave" !== $post->post_name )
    215                 return false;
    216         return (int) $post->post_parent;
     194
     195        if ( false !== strpos( $post->post_name, "{$post->post_parent}-autosave" ) )
     196                return (int) $post->post_parent;
     197
     198        return false;
    217199}
    218200
    219201/**