Make WordPress Core

Ticket #23314: 23314.2.diff

File 23314.2.diff, 16.8 KB (added by kovshenin, 12 years ago)
  • wp-includes/post.php

     
    3030                'rewrite' => false,
    3131                'query_var' => false,
    3232                'delete_with_user' => true,
    33                 'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'trackbacks', 'custom-fields', 'comments', 'revisions', 'post-formats' ),
     33                'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'trackbacks', 'custom-fields', 'comments', 'revisions', 'advanced-revisions', 'post-formats' ),
    3434        ) );
    3535
    3636        register_post_type( 'page', array(
     
    4747                'rewrite' => false,
    4848                'query_var' => false,
    4949                'delete_with_user' => true,
    50                 'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'page-attributes', 'custom-fields', 'comments', 'revisions' ),
     50                'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'page-attributes', 'custom-fields', 'comments', 'revisions', 'advanced-revisions' ),
    5151        ) );
    5252
    5353        register_post_type( 'attachment', array(
     
    7979                'labels' => array(
    8080                        'name' => __( 'Revisions' ),
    8181                        'singular_name' => __( 'Revision' ),
     82                        'edit_item' => __( 'Edit Revision' ),
    8283                ),
    8384                'public' => false,
    8485                '_builtin' => true, /* internal use only. don't use this when registering your own post type. */
     
    52415242                return $post;
    52425243
    52435244        $preview = wp_get_post_autosave($post->ID);
     5245        $autosave_id = ( $preview ) ? $preview->ID : 0;
    52445246
     5247        $preview_id = (int) $_GET['preview_id'];
     5248        if ( $autosave_id != $preview_id && current_user_can( 'read_post', $preview_id ) ) {
     5249                $revision = get_post( $preview_id );
     5250                if ( 'revision' == $revision->post_type && $revision->post_parent == $post->ID ) {
     5251                        $preview = $revision;
     5252                }
     5253        }
     5254
    52455255        if ( ! is_object($preview) )
    52465256                return $post;
    52475257
  • wp-admin/includes/post.php

     
    160160        $post_data['post_type'] = $post->post_type;
    161161        $post_data['post_mime_type'] = $post->post_mime_type;
    162162
     163        $parent = null;
     164        $is_advanced_revision = false;
     165        if ( 'revision' == $post->post_type ) {
     166                $parent = get_post( $post->post_parent );
     167                if ( post_type_supports( $parent->post_type, 'advanced-revisions' ) )
     168                        $is_advanced_revision = true;
     169        }
     170
    163171        $ptype = get_post_type_object($post_data['post_type']);
    164172        if ( !current_user_can( $ptype->cap->edit_post, $post_ID ) ) {
    165173                if ( 'page' == $post_data['post_type'] )
     
    243251
    244252        update_post_meta( $post_ID, '_edit_last', $GLOBALS['current_user']->ID );
    245253
    246         wp_update_post( $post_data );
     254        if ( ! empty( $_POST['save-version'] ) && post_type_supports( $post->post_type, 'advanced-revisions' ) ) {
     255                unset( $post_data['post_ID'], $post_data['ID'] );
     256                $post_data['post_type'] = 'revision';
     257                $post_data['post_parent'] = $post_ID;
     258                $post_data['post_status'] = 'draft';
     259        }
    247260
     261        if ( ! empty( $_POST['publish'] ) && $is_advanced_revision ) {
     262                if ( ! current_user_can( 'edit_post', $parent->ID ) )
     263                        wp_die( __( 'You are not allowed to edit this post.' ) );
     264
     265                unset( $post_data['post_parent'] );
     266                $post_data['post_type'] = $parent->post_type;
     267                $post_data['post_status'] = $parent->post_status;
     268                $post_data['ID'] = $parent->ID;
     269                $post_data['post_ID'] = $parent->ID;
     270
     271                // Discard the revision
     272                wp_delete_post( $post->ID, true );
     273        }
     274
     275        $post_ID = ( ! empty( $post_data['ID'] ) ) ? wp_update_post( $post_data ) : wp_insert_post( $post_data );
     276
    248277        // Now that we have an ID we can fix any attachment anchor hrefs
    249278        _fix_attachment_links( $post_ID );
    250279
     
    12791308        $_POST['ID'] = $post_ID;
    12801309        $post = get_post($post_ID);
    12811310
     1311        $parent = null;
     1312        $is_advanced_revision = null;
     1313        if ( 'revision' == $post->post_type ) {
     1314                $parent = get_post( $post->post_parent );
     1315                if ( post_type_supports( $parent->post_type, 'advanced-revisions' ) )
     1316                        $is_advanced_revision = true;
     1317        }
     1318
    12821319        if ( 'page' == $post->post_type ) {
    12831320                if ( !current_user_can('edit_page', $post_ID) )
    12841321                        wp_die(__('You are not allowed to edit this page.'));
     
    12871324                        wp_die(__('You are not allowed to edit this post.'));
    12881325        }
    12891326
     1327        if ( $is_advanced_revision ) {
     1328                $nonce = wp_create_nonce( 'post_preview_' . $post->ID );
     1329                $url = add_query_arg( array( 'preview' => 'true', 'preview_id' => $post->ID, 'preview_nonce' => $nonce ), get_permalink( $parent->ID ) );
     1330                return $url;
     1331        }
     1332
    12901333        if ( 'draft' == $post->post_status ) {
    12911334                $id = edit_post();
    12921335        } else { // Non drafts are not overwritten. The autosave is stored in a special post revision.
  • wp-admin/includes/meta-boxes.php

     
    1515        $post_type = $post->post_type;
    1616        $post_type_object = get_post_type_object($post_type);
    1717        $can_publish = current_user_can($post_type_object->cap->publish_posts);
     18
     19        $parent = null;
     20        $is_advanced_revision = false;
     21        if ( 'revision' == $post->post_type && $post->post_parent ) {
     22                $parent = get_post( $post->post_parent );
     23                $is_advanced_revision = post_type_supports( $parent->post_type, 'advanced-revisions' );
     24        }
    1825?>
    1926<div class="submitbox" id="submitpost">
    2027
     
    2734
    2835<div id="minor-publishing-actions">
    2936<div id="save-action">
    30 <?php if ( 'publish' != $post->post_status && 'future' != $post->post_status && 'pending' != $post->post_status ) { ?>
     37<?php if ( $is_advanced_revision ) { ?>
     38<input type="submit" name="save" id="save-post" value="<?php esc_attr_e( 'Save Changes' ); ?>" class="button" />
     39<?php } elseif ( 'publish' != $post->post_status && 'future' != $post->post_status && 'pending' != $post->post_status ) { ?>
    3140<input <?php if ( 'private' == $post->post_status ) { ?>style="display:none"<?php } ?> type="submit" name="save" id="save-post" value="<?php esc_attr_e('Save Draft'); ?>" class="button" />
    3241<?php } elseif ( 'pending' == $post->post_status && $can_publish ) { ?>
    3342<input type="submit" name="save" id="save-post" value="<?php esc_attr_e('Save as Pending'); ?>" class="button" />
     43<?php } elseif ( 'publish' == $post->post_status && post_type_supports( $post->post_type, 'advanced-revisions' ) ) { ?>
     44<input type="submit" name="save-version" id="save-post" value="<?php esc_attr_e( 'Save a Version' ); ?>" class="button" />
    3445<?php } ?>
    3546<span class="spinner"></span>
    3647</div>
    37 <?php if ( $post_type_object->public ) : ?>
     48<?php if ( $post_type_object->public || $is_advanced_revision ) : ?>
    3849<div id="preview-action">
    3950<?php
    4051if ( 'publish' == $post->post_status ) {
     
    4354} else {
    4455        $preview_link = set_url_scheme( get_permalink( $post->ID ) );
    4556        $preview_link = esc_url( apply_filters( 'preview_post_link', add_query_arg( 'preview', 'true', $preview_link ) ) );
    46         $preview_button = __( 'Preview' );
     57        $preview_button = ( $is_advanced_revision ) ? __( 'Preview Changes' ) : __( 'Preview' );
    4758}
    4859?>
    4960<a class="preview button" href="<?php echo $preview_link; ?>" target="wp-preview" id="post-preview"><?php echo $preview_button; ?></a>
     
    5465</div><!-- #minor-publishing-actions -->
    5566
    5667<div id="misc-publishing-actions">
     68<?php if ( $is_advanced_revision ) : ?>
     69<?php else: ?>
    5770
    5871<div class="misc-pub-section"><label for="post_status"><?php _e('Status:') ?></label>
    5972<span id="post-status-display">
     
    181194<?php endif; ?>
    182195
    183196<?php do_action('post_submitbox_misc_actions'); ?>
    184 </div>
     197<?php endif; // $is_advanced_revision ?>
     198</div><!-- #misc-publishing-actions -->
    185199<div class="clear"></div>
    186200</div>
    187201
     
    194208                $delete_text = __('Delete Permanently');
    195209        else
    196210                $delete_text = __('Move to Trash');
     211
     212        $delete_link = get_delete_post_link( $post->ID );
     213        if ( $is_advanced_revision ) {
     214                $delete_text = __( 'Discard Changes' );
     215                $delete_link = add_query_arg( 'post', $post->ID, get_delete_post_link( $post->post_parent, '', true ) );
     216                $delete_link = wp_nonce_url( $delete_link, "delete-post_{$post->ID}" );
     217        }
    197218        ?>
    198 <a class="submitdelete deletion" href="<?php echo get_delete_post_link($post->ID); ?>"><?php echo $delete_text; ?></a><?php
     219<a class="submitdelete deletion" href="<?php echo esc_url( $delete_link ); ?>"><?php echo esc_html( $delete_text ); ?></a><?php
    199220} ?>
    200221</div>
    201222
     
    208229                <input name="original_publish" type="hidden" id="original_publish" value="<?php esc_attr_e('Schedule') ?>" />
    209230                <?php submit_button( __( 'Schedule' ), 'primary button-large', 'publish', false, array( 'accesskey' => 'p' ) ); ?>
    210231<?php   else : ?>
     232                <?php $publish_label = ( $is_advanced_revision ) ? __( 'Publish Changes' ) : __( 'Publish' ); ?>
     233                <?php if ( $is_advanced_revision ) : ?>
     234                <input name="publish_revision" type="hidden" value="1" />
     235                <?php endif; ?>
    211236                <input name="original_publish" type="hidden" id="original_publish" value="<?php esc_attr_e('Publish') ?>" />
    212                 <?php submit_button( __( 'Publish' ), 'primary button-large', 'publish', false, array( 'accesskey' => 'p' ) ); ?>
     237                <?php submit_button( $publish_label, 'primary button-large', 'publish', false, array( 'accesskey' => 'p' ) ); ?>
    213238<?php   endif;
    214239        else : ?>
    215240                <input name="original_publish" type="hidden" id="original_publish" value="<?php esc_attr_e('Submit for Review') ?>" />
  • wp-admin/post.php

     
    3131if ( $post ) {
    3232        $post_type = $post->post_type;
    3333        $post_type_object = get_post_type_object( $post_type );
     34
     35        if ( post_type_supports( $post_type, 'advanced-revisions' ) ) {
     36                $revisions = get_posts( array(
     37                        'post_parent' => $post->ID,
     38                        'post_type' => 'revision',
     39                        'post_status' => array( 'draft' ),
     40                ) );
     41
     42                if ( ! empty( $revisions ) && is_array( $revisions ) ) {
     43                        $revision = $revisions[0];
     44                        if ( current_user_can( 'edit_post', $revision->ID ) )
     45                                redirect_post( $revision->ID );
     46                }
     47        }
    3448}
    3549
    3650/**
     
    3953 * @param int $post_id Optional. Post ID.
    4054 */
    4155function redirect_post($post_id = '') {
    42         if ( isset($_POST['save']) || isset($_POST['publish']) ) {
     56        $post = get_post( $post_id );
     57
     58        $parent = null;
     59        $is_advanced_revision = false;
     60        if ( 'revision' == $post->post_type ) {
     61                $parent = get_post( $post->post_parent );
     62                if ( post_type_supports( $parent->post_type, 'advanced-revisions' ) )
     63                        $is_advanced_revision = true;
     64        }
     65
     66        if ( ( isset( $_POST['save'] ) || isset( $_POST['publish'] ) ) && ! $is_advanced_revision ) {
    4367                $status = get_post_status( $post_id );
    4468
    4569                if ( isset( $_POST['publish'] ) ) {
     
    5781                                $message = 'draft' == $status ? 10 : 1;
    5882                }
    5983
     84                if ( ! empty( $_POST['publish_revision'] ) )
     85                        $message = 13;
     86
    6087                $location = add_query_arg( 'message', $message, get_edit_post_link( $post_id, 'url' ) );
    6188        } elseif ( isset($_POST['addmeta']) && $_POST['addmeta'] ) {
    6289                $location = add_query_arg( 'message', 2, wp_get_referer() );
     
    6895                $location = $location[0] . '#postcustom';
    6996        } elseif ( 'post-quickpress-save-cont' == $_POST['action'] ) {
    7097                $location = "post.php?action=edit&post=$post_id&message=7";
     98        } elseif ( $is_advanced_revision ) {
     99                $location = add_query_arg( 'post', $post->ID, get_edit_post_link( $parent->ID, 'url' ) );
     100
     101                if ( ! empty( $_POST['save-version'] ) )
     102                        $message = 11;
     103                elseif ( ! empty( $_POST['save'] ) )
     104                        $message = 12;
     105
     106                if ( $message )
     107                        $location = add_query_arg( 'message', $message, $location );
    71108        } else {
    72109                $location = add_query_arg( 'message', 4, get_edit_post_link( $post_id, 'url' ) );
    73110        }
     
    253290                        wp_die( __('Error in deleting.') );
    254291        }
    255292
     293        if ( 'revision' == $post->post_type ) {
     294                $parent = get_post( $post->post_parent );
     295                $sendback = get_edit_post_link( $post->post_parent, 'url' );
     296                $sendback = add_query_arg( 'message', 14, $sendback );
     297        }
     298
    256299        wp_redirect( add_query_arg('deleted', 1, $sendback) );
    257300        exit();
    258301        break;
  • wp-admin/edit-form-advanced.php

     
    2424$user_ID = isset($user_ID) ? (int) $user_ID : 0;
    2525$action = isset($action) ? $action : '';
    2626
    27 if ( post_type_supports($post_type, 'editor') || post_type_supports($post_type, 'thumbnail') ) {
     27$parent = null;
     28$is_advanced_revision = false;
     29if ( 'revision' == $post->post_type ) {
     30        $parent = get_post( $post->post_parent );
     31        if ( post_type_supports( $parent->post_type, 'advanced-revisions' ) )
     32                $is_advanced_revision = true;
     33}
     34
     35if ( post_type_supports( $post_type, 'editor' ) || post_type_supports( $post_type, 'thumbnail' ) || ( $is_advanced_revision && post_type_supports( $parent->post_type, 'editor' ) ) ) {
    2836        add_thickbox();
    2937        wp_enqueue_media( array( 'post' => $post_ID ) );
    3038}
     
    4553                // translators: Publish box date format, see http://php.net/date
    4654                date_i18n( __( 'M j, Y @ G:i' ), strtotime( $post->post_date ) ), esc_url( get_permalink($post_ID) ) ),
    4755        10 => sprintf( __('Post draft updated. <a target="_blank" href="%s">Preview post</a>'), esc_url( add_query_arg( 'preview', 'true', get_permalink($post_ID) ) ) ),
     56        11 => __( 'A new version of this post has been created, but not published.' ),
     57        12 => __( 'Your changes have been saved, but not published.' ),
     58        13 => sprintf( __( 'Your changes have been saved and published. <a href="%s">View post</a>' ), esc_url( get_permalink( $post_ID ) ) ),
     59        14 => __( 'Your changes have been discarded.' ),
    4860);
    4961$messages['page'] = array(
    5062         0 => '', // Unused. Messages start at index 1.
     
    5870         8 => sprintf( __('Page submitted. <a target="_blank" href="%s">Preview page</a>'), esc_url( add_query_arg( 'preview', 'true', get_permalink($post_ID) ) ) ),
    5971         9 => sprintf( __('Page scheduled for: <strong>%1$s</strong>. <a target="_blank" href="%2$s">Preview page</a>'), date_i18n( __( 'M j, Y @ G:i' ), strtotime( $post->post_date ) ), esc_url( get_permalink($post_ID) ) ),
    6072        10 => sprintf( __('Page draft updated. <a target="_blank" href="%s">Preview page</a>'), esc_url( add_query_arg( 'preview', 'true', get_permalink($post_ID) ) ) ),
     73        11 => __( 'A new version of this page has been created, but not published.' ),
     74        12 => __( 'Your changes have been saved, but not published.' ),
     75        13 => sprintf( __( 'Your changes have been saved and published. <a href="%s">View page</a>' ), esc_url( get_permalink( $post_ID ) ) ),
     76        14 => __( 'Your changes have been discarded.' ),
    6177);
    6278$messages['attachment'] = array_fill( 1, 10, __( 'Media attachment updated.' ) ); // Hack, for now.
    6379
     
    135151if ( current_theme_supports( 'post-thumbnails', $post_type ) && post_type_supports( $post_type, 'thumbnail' ) )
    136152                add_meta_box('postimagediv', __('Featured Image'), 'post_thumbnail_meta_box', null, 'side', 'low');
    137153
    138 if ( post_type_supports($post_type, 'excerpt') )
     154if ( post_type_supports($post_type, 'excerpt') || ( $is_advanced_revision && post_type_supports( $parent->post_type, 'excerpt' ) ) )
    139155        add_meta_box('postexcerpt', __('Excerpt'), 'post_excerpt_meta_box', null, 'normal', 'core');
    140156
    141157if ( post_type_supports($post_type, 'trackbacks') )
     
    151167if ( ( 'publish' == get_post_status( $post ) || 'private' == get_post_status( $post ) ) && post_type_supports($post_type, 'comments') )
    152168        add_meta_box('commentsdiv', __('Comments'), 'post_comment_meta_box', null, 'normal', 'core');
    153169
    154 if ( ! ( 'pending' == get_post_status( $post ) && ! current_user_can( $post_type_object->cap->publish_posts ) ) )
     170if ( ! ( 'pending' == get_post_status( $post ) && ! current_user_can( $post_type_object->cap->publish_posts ) ) && ! $is_advanced_revision )
    155171        add_meta_box('slugdiv', __('Slug'), 'post_slug_meta_box', null, 'normal', 'core');
    156172
    157 if ( post_type_supports($post_type, 'author') ) {
     173if ( post_type_supports($post_type, 'author') && ! $is_advanced_revision ) {
    158174        if ( is_super_admin() || current_user_can( $post_type_object->cap->edit_others_posts ) )
    159175                add_meta_box('authordiv', __('Author'), 'post_author_meta_box', null, 'normal', 'core');
    160176}
     
    323339
    324340<div id="post-body" class="metabox-holder columns-<?php echo 1 == get_current_screen()->get_columns() ? '1' : '2'; ?>">
    325341<div id="post-body-content">
    326 <?php if ( post_type_supports($post_type, 'title') ) { ?>
     342<?php if ( post_type_supports( $post_type, 'title' ) || ( $is_advanced_revision && post_type_supports( $parent->post_type, 'title' ) ) ) { ?>
    327343<div id="titlediv">
    328344<div id="titlewrap">
    329345        <label class="screen-reader-text" id="title-prompt-text" for="title"><?php echo apply_filters( 'enter_title_here', __( 'Enter title here' ), $post ); ?></label>
     
    356372
    357373do_action( 'edit_form_after_title' );
    358374
    359 if ( post_type_supports($post_type, 'editor') ) {
     375if ( post_type_supports( $post_type, 'editor' ) || ( $is_advanced_revision && post_type_supports( $parent->post_type, 'editor' ) ) ) {
    360376?>
    361377<div id="postdivrich" class="postarea">
    362378