Make WordPress Core

Ticket #23314: 23314.diff

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

     
    52455245
    52465246        $preview = wp_get_post_autosave($post->ID);
    52475247
     5248        $preview_id = (int) $_GET['preview_id'];
     5249        if ( $preview->ID != $preview_id ) {
     5250                $actual_preview = get_post( $preview_id );
     5251                if ( 'revision' == $actual_preview->post_type )
     5252                        $preview = $actual_preview;
     5253        }
     5254
    52485255        if ( ! is_object($preview) )
    52495256                return $post;
    52505257
  • wp-admin/includes/post.php

     
    243243
    244244        update_post_meta( $post_ID, '_edit_last', $GLOBALS['current_user']->ID );
    245245
    246         wp_update_post( $post_data );
     246        if ( ! empty( $_POST['save-as-draft'] ) ) {
     247                unset( $post_data['post_ID'], $post_data['ID'] );
     248                $post_data['post_type'] = 'revision';
     249                $post_data['post_parent'] = $post_ID;
     250                $post_data['post_status'] = 'draft';
     251        }
    247252
     253        if ( ! empty( $_POST['publish'] ) && 'revision' == $post->post_type && current_user_can( 'publish_posts' ) ) {
     254                $parent = get_post( $post->post_parent );
     255                if ( ! current_user_can( 'edit_post', $parent->ID ) )
     256                        wp_die( __( 'You are not allowed to edit this post.' ) );
     257
     258                unset( $post_data['post_parent'] );
     259                $post_data['post_type'] = $parent->post_type;
     260                $post_data['post_status'] = $parent->post_status;
     261                $post_data['post_ID'] = $parent->ID;
     262                $post_data['ID'] = $parent->ID;
     263
     264                // Discard the draft
     265                wp_delete_post( $post->ID, true );
     266        }
     267
     268        if ( ! empty( $post_data['post_ID'] ) )
     269                $post_ID = wp_update_post( $post_data );
     270        else
     271                $post_ID = wp_insert_post( $post_data );
     272
    248273        // Now that we have an ID we can fix any attachment anchor hrefs
    249274        _fix_attachment_links( $post_ID );
    250275
     
    12981323        if ( is_wp_error($id) )
    12991324                wp_die( $id->get_error_message() );
    13001325
    1301         if ( $_POST['post_status'] == 'draft'  ) {
     1326        $post_status = $_POST['post_status'];
     1327        $preview_id = $id;
     1328
     1329        if ( 'revision' == $post->post_type ) {
     1330                $parent = get_post( $post->post_parent );
     1331                $post_status = $parent->post_status;
     1332                $id = $parent->ID;
     1333                $preview_id = $post->ID;
     1334        }
     1335
     1336        if ( $post_status == 'draft'  ) {
    13021337                $url = add_query_arg( 'preview', 'true', get_permalink($id) );
    13031338        } else {
    1304                 $nonce = wp_create_nonce('post_preview_' . $id);
    1305                 $url = add_query_arg( array( 'preview' => 'true', 'preview_id' => $id, 'preview_nonce' => $nonce ), get_permalink($id) );
     1339                $nonce = wp_create_nonce('post_preview_' . $preview_id);
     1340                $url = add_query_arg( array( 'preview' => 'true', 'preview_id' => $preview_id, 'preview_nonce' => $nonce ), get_permalink($id) );
    13061341        }
    13071342
    13081343        return $url;
  • wp-admin/includes/meta-boxes.php

     
    1313        global $action;
    1414
    1515        $post_type = $post->post_type;
     16
     17        if ( 'revision' == $post_type ) {
     18                $parent = get_post( $post->post_parent );
     19                $post_type = $parent->post_type;
     20        }
     21
    1622        $post_type_object = get_post_type_object($post_type);
    1723        $can_publish = current_user_can($post_type_object->cap->publish_posts);
     24
     25        $revision = null;
     26        if ( 'publish' == $post->post_status ) {
     27                $revisions = get_posts( array(
     28                        'post_parent'    => $post->ID,
     29                        'post_type'      => 'revision',
     30                        'post_status'    => array( 'draft' ),
     31                        'posts_per_page' => 1,
     32                ) );
     33
     34                if ( ! empty( $revisions ) && is_array( $revisions ) ) {
     35                        $revision = $revisions[0];
     36                        $edit_revision_link = add_query_arg( 'post', $revision->ID, get_edit_post_link( $post->ID ) );
     37                }
     38        }
    1839?>
    1940<div class="submitbox" id="submitpost">
    2041
     
    3152<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" />
    3253<?php } elseif ( 'pending' == $post->post_status && $can_publish ) { ?>
    3354<input type="submit" name="save" id="save-post" value="<?php esc_attr_e('Save as Pending'); ?>" class="button" />
     55<?php } elseif ( 'publish' == $post->post_status && ( ! $revision || ! current_user_can( 'edit_post', $revision ) ) ) { ?>
     56<input type="submit" name="save-as-draft" id="save-post" value="<?php esc_attr_e('Save as Draft'); ?>" class="button" />
    3457<?php } ?>
    3558<span class="spinner"></span>
    3659</div>
     
    4568        $preview_link = esc_url( apply_filters( 'preview_post_link', add_query_arg( 'preview', 'true', $preview_link ) ) );
    4669        $preview_button = __( 'Preview' );
    4770}
     71
     72if ( 'revision' == $post->post_type )
     73        $preview_button = __( 'Preview Changes' );
    4874?>
    4975<a class="preview button" href="<?php echo $preview_link; ?>" target="wp-preview" id="post-preview"><?php echo $preview_button; ?></a>
    5076<input type="hidden" name="wp-preview" id="wp-preview" value="" />
     
    5581
    5682<div id="misc-publishing-actions">
    5783
     84<?php if ( 'revision' == $post->post_type ) : ?>
     85<?php else : ?>
    5886<div class="misc-pub-section"><label for="post_status"><?php _e('Status:') ?></label>
    5987<span id="post-status-display">
    6088<?php
     
    180208</div><?php // /misc-pub-section ?>
    181209<?php endif; ?>
    182210
     211<?php endif; // !revision ?>
     212
    183213<?php do_action('post_submitbox_misc_actions'); ?>
    184214</div>
    185215<div class="clear"></div>
     
    194224                $delete_text = __('Delete Permanently');
    195225        else
    196226                $delete_text = __('Move to Trash');
     227
     228        $delete_link = get_delete_post_link( $post->ID );
     229        if ( 'revision' == $post->post_type ) {
     230                $delete_text = __( 'Discard Changes' );
     231                $delete_link = add_query_arg( 'post', $post->ID, get_delete_post_link( $post->post_parent, '', true ) );
     232                $delete_link = wp_nonce_url( $delete_link, "delete-post_{$post->ID}" );
     233        }
    197234        ?>
    198 <a class="submitdelete deletion" href="<?php echo get_delete_post_link($post->ID); ?>"><?php echo $delete_text; ?></a><?php
     235<a class="submitdelete deletion" href="<?php echo esc_url( $delete_link ); ?>"><?php echo $delete_text; ?></a><?php
    199236} ?>
    200237</div>
    201238
     
    208245                <input name="original_publish" type="hidden" id="original_publish" value="<?php esc_attr_e('Schedule') ?>" />
    209246                <?php submit_button( __( 'Schedule' ), 'primary button-large', 'publish', false, array( 'accesskey' => 'p' ) ); ?>
    210247<?php   else : ?>
     248                <?php $publish_label = ( 'revision' == $post->post_type ) ? __( 'Publish Changes' ) : __( 'Publish' ); ?>
     249                <?php if ( 'revision' == $post->post_type ) : ?>
     250                <input type="hidden" name="publish-revision" value="1" />
     251                <?php endif; ?>
    211252                <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' ) ); ?>
     253                <?php submit_button( $publish_label, 'primary button-large', 'publish', false, array( 'accesskey' => 'p' ) ); ?>
    213254<?php   endif;
    214255        else : ?>
    215256                <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        $revisions = get_posts( array(
     36                'post_parent' => $post->ID,
     37                'post_type' => 'revision',
     38                'post_status' => array( 'draft' ),
     39        ) );
     40
     41        if ( ! empty( $revisions ) && is_array( $revisions ) ) {
     42                $revision = $revisions[0];
     43                if ( current_user_can( 'edit_post', $revision->ID ) ) {
     44                        redirect_post( $revision->ID );
     45                }
     46        }
    3447}
    3548
    3649/**
     
    3952 * @param int $post_id Optional. Post ID.
    4053 */
    4154function redirect_post($post_id = '') {
     55
     56        $post = get_post( $post_id );
     57        if ( 'revision' == $post->post_type )
     58                $post_id = $post->post_parent;
     59
    4260        if ( isset($_POST['save']) || isset($_POST['publish']) ) {
    4361                $status = get_post_status( $post_id );
    4462
     
    5371                                default:
    5472                                        $message = 6;
    5573                        }
     74
     75                        if ( ! empty( $_POST['publish-revision'] ) )
     76                                $message = 12;
    5677                } else {
    5778                                $message = 'draft' == $status ? 10 : 1;
    5879                }
     
    7293                $location = add_query_arg( 'message', 4, get_edit_post_link( $post_id, 'url' ) );
    7394        }
    7495
     96        if ( 'revision' == $post->post_type ) {
     97                $post_id = $post->ID;
     98                $location = add_query_arg( 'post', $post->ID, $location );
     99
     100                if ( ! empty( $_POST['save-as-draft'] ) || ! empty( $_POST['save'] ) )
     101                        $location = add_query_arg( 'message', 13, $location );
     102                else
     103                        $location = remove_query_arg( 'message', $location );
     104        }
     105
    75106        wp_redirect( apply_filters( 'redirect_post_location', $location, $post_id ) );
    76107        exit;
    77108}
     
    135166
    136167        $p = $post_id;
    137168
     169        $post_type = $post->post_type;
     170        if ( 'revision' == $post_type && ! empty( $post->post_parent ) ) {
     171                $parent = get_post( $post->post_parent );
     172                $post_type = $parent->post_type;
     173                $post_type_object = get_post_type_object( $post_type );
     174        }
     175
    138176        if ( empty($post->ID) )
    139177                wp_die( __('You attempted to edit an item that doesn&#8217;t exist. Perhaps it was deleted?') );
    140178
     
    147185        if ( 'trash' == $post->post_status )
    148186                wp_die( __('You can&#8217;t edit this item because it is in the Trash. Please restore it and try again.') );
    149187
    150         $post_type = $post->post_type;
    151188        if ( 'post' == $post_type ) {
    152189                $parent_file = "edit.php";
    153190                $submenu_file = "edit.php";
     
    182219                enqueue_comment_hotkeys_js();
    183220        }
    184221
     222        set_current_screen( $post_type );
     223
    185224        include('./edit-form-advanced.php');
    186225
    187226        break;
     
    243282        if ( !current_user_can($post_type_object->cap->delete_post, $post_id) )
    244283                wp_die( __('You are not allowed to delete this item.') );
    245284
     285        if ( 'revision' == $post->post_type ) {
     286                $sendback = add_query_arg( 'message', 11, get_edit_post_link( $post->post_parent, 'raw' ) );
     287        }
     288
    246289        $force = !EMPTY_TRASH_DAYS;
    247290        if ( $post->post_type == 'attachment' ) {
    248291                $force = ( $force || !MEDIA_TRASH );
     
    259302
    260303case 'preview':
    261304        check_admin_referer( 'autosave', 'autosavenonce' );
    262 
    263305        $url = post_preview();
    264306
    265307        wp_redirect($url);
  • wp-admin/edit-form-advanced.php

     
    4545                // translators: Publish box date format, see http://php.net/date
    4646                date_i18n( __( 'M j, Y @ G:i' ), strtotime( $post->post_date ) ), esc_url( get_permalink($post_ID) ) ),
    4747        10 => sprintf( __('Post draft updated. <a target="_blank" href="%s">Preview post</a>'), esc_url( add_query_arg( 'preview', 'true', get_permalink($post_ID) ) ) ),
     48        11 => __( 'Your changes have been discarded.' ),
     49        12 => sprintf( __( 'Your changes have been saved and published. <a href="%s">View post</a>' ), esc_url( get_permalink( $post_ID ) ) ),
     50        13 => __( 'Your changes have been saved, but not published.' ),
    4851);
    4952$messages['page'] = array(
    5053         0 => '', // Unused. Messages start at index 1.
     
    296299<?php if ( $message ) : ?>
    297300<div id="message" class="updated"><p><?php echo $message; ?></p></div>
    298301<?php endif; ?>
     302<?php
     303        $revision = null;
     304        $revisions = get_posts( array(
     305                'post_parent' => $post->ID,
     306                'post_type' => 'revision',
     307                'post_status' => array( 'draft' ),
     308        ) );
     309
     310        if ( ! empty( $revisions ) && is_array( $revisions ) ) {
     311                $revision = $revisions[0];
     312                $edit_revision_link = add_query_arg( 'post', $revision->ID, get_edit_post_link( $post->ID ) );
     313        }
     314?>
     315<?php if ( 'revision' == $post->post_type ) : ?>
     316<div class="updated">
     317        <p>These changes are not published. <a href="<?php echo esc_url( get_permalink( $post->post_parent ) ); ?>">View published post</a>.</p>
     318</div>
     319<?php endif; ?>
    299320<form name="post" action="post.php" method="post" id="post"<?php do_action('post_edit_form_tag'); ?>>
    300321<?php wp_nonce_field($nonce_action); ?>
    301322<input type="hidden" id="user-id" name="user_ID" value="<?php echo (int) $user_ID ?>" />
     
    336357if ( !empty($shortlink) )
    337358    $sample_permalink_html .= '<input id="shortlink" type="hidden" value="' . esc_attr($shortlink) . '" /><a href="#" class="button button-small" onclick="prompt(&#39;URL:&#39;, jQuery(\'#shortlink\').val()); return false;">' . __('Get Shortlink') . '</a>';
    338359
    339 if ( $post_type_object->public && ! ( 'pending' == get_post_status( $post ) && !current_user_can( $post_type_object->cap->publish_posts ) ) ) { ?>
     360if ( $post_type_object->public && ! ( 'pending' == get_post_status( $post ) && !current_user_can( $post_type_object->cap->publish_posts ) ) && 'revision' != $post->post_type ) { ?>
    340361        <div id="edit-slug-box" class="hide-if-no-js">
    341362        <?php
    342363                if ( $sample_permalink_html && 'auto-draft' != $post->post_status )