Ticket #6775: 6775.2.diff
File 6775.2.diff, 34.4 KB (added by , 17 years ago) |
---|
-
wp-includes/post-template.php
566 566 } 567 567 568 568 /** 569 * wp_post_revision_ti me() - returns formatted datetimestamp of a revision569 * wp_post_revision_title() - returns formatted datetimestamp of a revision (linked to that revisions's page) 570 570 * 571 571 * @package WordPress 572 572 * @subpackage Post Revisions 573 573 * @since 2.6 574 574 * 575 * @uses wp_get_revision()576 575 * @uses date_i18n() 577 576 * 578 577 * @param int|object $revision revision ID or revision object 578 * @param bool $link optional Link to revisions's page? 579 579 * @return string i18n formatted datetimestamp or localized 'Corrent Revision' 580 580 */ 581 function wp_post_revision_time( $revision ) { 582 if ( !$revision = wp_get_revision( $revision ) ) { 583 if ( $revision = get_post( $revision ) ) 584 return __( 'Current Revision' ); 581 function wp_post_revision_title( $revision, $link = true ) { 582 if ( !$revision = get_post( $revision ) ) 585 583 return $revision; 586 }587 584 588 $datef = _c( 'j F, Y @ G:i|revision date format'); 589 return date_i18n( $datef, strtotime( $revision->post_date_gmt . ' +0000' ) ); 585 if ( !in_array( $revision->post_type, array( 'post', 'page', 'revision' ) ) ) 586 return false; 587 588 $datef = _c( 'j F, Y @ G:i|revision date format'); 589 $autosavef = __( '%s [Autosave]' ); 590 $currentf = __( '%s [Current Revision]' ); 591 592 $date = date_i18n( $datef, strtotime( $revision->post_modified_gmt . ' +0000' ) ); 593 if ( $link && current_user_can( 'edit_post', $revision->ID ) && $link = get_edit_post_link( $revision->ID ) ) 594 $date = "<a href='$link'>$date</a>"; 595 596 if ( 'revision' != $revision->post_type ) 597 $date = sprintf( $currentf, $date ); 598 elseif ( "{$revision->post_parent}-autosave" == $revision->post_name ) 599 $date = sprintf( $autosavef, $date ); 600 601 return $date; 590 602 } 591 603 592 604 /** … … 605 617 * @since 2.6 606 618 * 607 619 * @uses wp_get_post_revisions() 608 * @uses wp_post_revision_ti me()620 * @uses wp_post_revision_title() 609 621 * @uses get_edit_post_link() 610 622 * @uses get_author_name() 611 623 * … … 630 642 $rows = ''; 631 643 $class = false; 632 644 foreach ( $revisions as $revision ) { 633 $date = wp_post_revision_time( $revision ); 634 if ( $link = get_edit_post_link( $revision->ID ) ) 635 $date = "<a href='$link'>$date</a>"; 645 $date = wp_post_revision_title( $revision ); 636 646 $name = get_author_name( $revision->post_author ); 637 647 638 648 if ( 'form-table' == $format ) { 639 649 if ( $left ) 640 $ old_checked = $left == $revision->ID ? ' checked="checked"' : '';650 $left_checked = $left == $revision->ID ? ' checked="checked"' : ''; 641 651 else 642 $ old_checked = $new_checked ? ' checked="checked"' : '';643 $ new_checked = $right == $revision->ID ? ' checked="checked"' : '';652 $left_checked = $right_checked ? ' checked="checked"' : ''; // [sic] (the next one) 653 $right_checked = $right == $revision->ID ? ' checked="checked"' : ''; 644 654 645 655 $class = $class ? '' : " class='alternate'"; 646 656 647 657 if ( $post->ID != $revision->ID && current_user_can( 'edit_post', $post->ID ) ) 648 $actions = '<a href="' . wp_nonce_url( add_query_arg( array( 'revision' => $revision->ID, 'diff' => false, ' restore' => 'restore' ) ), "restore-post_$post->ID|$revision->ID" ) . '">' . __( 'Restore' ) . '</a>';658 $actions = '<a href="' . wp_nonce_url( add_query_arg( array( 'revision' => $revision->ID, 'diff' => false, 'action' => 'restore' ) ), "restore-post_$post->ID|$revision->ID" ) . '">' . __( 'Restore' ) . '</a>'; 649 659 else 650 660 $actions = ''; 651 661 652 662 $rows .= "<tr$class>\n"; 653 $rows .= "\t<th style='white-space: nowrap' scope='row'><input type='radio' name=' diff' value='$revision->ID'$old_checked /><input type='radio' name='revision' value='$revision->ID'$new_checked />\n";663 $rows .= "\t<th style='white-space: nowrap' scope='row'><input type='radio' name='left' value='$revision->ID'$left_checked /><input type='radio' name='right' value='$revision->ID'$right_checked />\n"; 654 664 $rows .= "\t<td>$date</td>\n"; 655 665 $rows .= "\t<td>$name</td>\n"; 656 666 $rows .= "\t<td class='action-links'>$actions</td>\n"; 657 667 $rows .= "</tr>\n"; 658 668 } else { 659 $rows .= "\t<li>" . sprintf( $titlef, $date, $name ). "</li>\n"; 669 $title = sprintf( $titlef, $date, $name ); 670 $rows .= "\t<li>$title</li>\n"; 660 671 } 661 672 } 662 673 … … 667 678 <div class="tablenav"> 668 679 <div class="alignleft"> 669 680 <input type="submit" class="button-secondary" value="<?php _e( 'Compare Revisions' ); ?>" /> 681 <input type="hidden" name="action" value="diff" /> 670 682 </div> 671 683 </div> 672 684 -
wp-includes/post.php
88 88 $r = wp_parse_args( $args, $defaults ); 89 89 90 90 $children = get_posts( $r ); 91 92 91 if ( !$children ) 93 92 return false; 94 93 … … 2957 2956 /** 2958 2957 * _wp_revision_fields() - determines which fields of posts are to be saved in revisions 2959 2958 * 2960 * Does two things. If passed a post n*array*, it will return a post array ready to be2959 * Does two things. If passed a post *array*, it will return a post array ready to be 2961 2960 * insterted into the posts table as a post revision. 2962 * Otherwise, returns an array whose keys are the post fields to be saved post revisions.2961 * Otherwise, returns an array whose keys are the post fields to be saved for post revisions. 2963 2962 * 2964 2963 * @package WordPress 2965 2964 * @subpackage Post Revisions 2966 2965 * @since 2.6 2967 2966 * 2968 2967 * @param array $post optional a post array to be processed for insertion as a post revision 2968 * @param bool $autosave optional Is the revision an autosave? 2969 2969 * @return array post array ready to be inserted as a post revision or array of fields that can be versioned 2970 2970 */ 2971 function _wp_revision_fields( $post = null ) {2971 function _wp_revision_fields( $post = null, $autosave = false ) { 2972 2972 static $fields = false; 2973 2973 2974 2974 if ( !$fields ) { … … 2980 2980 'post_excerpt' => __( 'Excerpt' ), 2981 2981 ); 2982 2982 2983 // Runs only once 2984 $fields = apply_filters( '_wp_revision_fields', $fields ); 2985 2983 2986 // WP uses these internally either in versioning or elsewhere - they cannot be versioned 2984 2987 foreach ( array( 'ID', 'post_name', 'post_parent', 'post_date', 'post_date_gmt', 'post_status', 'post_type', 'comment_count' ) as $protect ) 2985 2988 unset( $fields[$protect] ); … … 2995 2998 $return['post_parent'] = $post['ID']; 2996 2999 $return['post_status'] = 'inherit'; 2997 3000 $return['post_type'] = 'revision'; 2998 $return['post_name'] = "$post[ID]-revision";3001 $return['post_name'] = $autosave ? "$post[ID]-autosave" : "$post[ID]-revision"; 2999 3002 $return['post_date'] = $post['post_modified']; 3000 3003 $return['post_date_gmt'] = $post['post_modified_gmt']; 3001 3004 … … 3015 3018 * @return mixed null or 0 if error, new revision ID if success 3016 3019 */ 3017 3020 function wp_save_revision( $post_id ) { 3018 // TODO: rework autosave to use special type of post revision3021 // We do autosaves manually with wp_create_autosave() 3019 3022 if ( @constant( 'DOING_AUTOSAVE' ) ) 3020 3023 return; 3021 3024 3022 3025 if ( !$post = get_post( $post_id, ARRAY_A ) ) 3023 3026 return; 3024 3027 3025 // TODO: open this up for pages also 3026 if ( 'post' != $post->post_type ) 3028 if ( !in_array( $post['post_type'], array( 'post', 'page' ) ) ) 3027 3029 return; 3028 3030 3029 3031 return _wp_put_revision( $post ); 3030 3032 } 3031 3033 3032 3034 /** 3035 * wp_get_autosave() - returns the autosaved data of the specified post. 3036 * 3037 * Returns a post object containing the information that was autosaved for the specified post. 3038 * 3039 * @package WordPress 3040 * @subpackage Post Revisions 3041 * @since 2.6 3042 * 3043 * @param int $post_id The post ID 3044 * @return object|bool the autosaved data or false on failure or when no autosave exists 3045 */ 3046 function wp_get_autosave( $post_id ) { 3047 global $wpdb; 3048 if ( !$post = get_post( $post_id ) ) 3049 return false; 3050 3051 $q = array( 3052 'name' => "{$post->ID}-autosave", 3053 'post_parent' => $post->ID, 3054 'post_type' => 'revision', 3055 'post_status' => 'inherit' 3056 ); 3057 3058 // Use WP_Query so that the result gets cached 3059 $autosave_query = new WP_Query; 3060 3061 add_action( 'parse_query', '_wp_get_autosave_hack' ); 3062 $autosave = $autosave_query->query( $q ); 3063 remove_action( 'parse_query', '_wp_get_autosave_hack' ); 3064 3065 if ( $autosave && is_array($autosave) && is_object($autosave[0]) ) 3066 return $autosave[0]; 3067 3068 return false; 3069 } 3070 3071 // Internally used to hack WP_Query into submission 3072 function _wp_get_autosave_hack( $query ) { 3073 $query->is_single = false; 3074 } 3075 3076 /** 3033 3077 * _wp_put_revision() - Inserts post data into the posts table as a post revision 3034 3078 * 3035 3079 * @package WordPress … … 3039 3083 * @uses wp_insert_post() 3040 3084 * 3041 3085 * @param int|object|array $post post ID, post object OR post array 3086 * @param bool $autosave optional Is the revision an autosave? 3042 3087 * @return mixed null or 0 if error, new revision ID if success 3043 3088 */ 3044 function _wp_put_revision( $post = null ) {3089 function _wp_put_revision( $post = null, $autosave = false ) { 3045 3090 if ( is_object($post) ) 3046 3091 $post = get_object_vars( $post ); 3047 3092 elseif ( !is_array($post) ) 3048 3093 $post = get_post($post, ARRAY_A); 3049 3050 3094 if ( !$post || empty($post['ID']) ) 3051 3095 return; 3052 3096 3053 3097 if ( isset($post['post_type']) && 'revision' == $post_post['type'] ) 3054 3098 return new WP_Error( 'post_type', __( 'Cannot create a revision of a revision' ) ); 3055 3099 3056 $post = _wp_revision_fields( $post );3100 $post = _wp_revision_fields( $post, $autosave ); 3057 3101 3058 if ( $revision_id = wp_insert_post( $post ) ) 3102 $revision_id = wp_insert_post( $post ); 3103 if ( is_wp_error($revision_id) ) 3104 return $revision_id; 3105 3106 if ( $revision_id ) 3059 3107 do_action( '_wp_put_revision', $revision_id ); 3060 3061 3108 return $revision_id; 3062 3109 } 3063 3110 … … 3127 3174 3128 3175 $update['ID'] = $revision['post_parent']; 3129 3176 3130 if ( $post_id = wp_update_post( $update ) ) 3177 $post_id = wp_update_post( $update ); 3178 if ( is_wp_error( $post_id ) ) 3179 return $post_id; 3180 3181 if ( $post_id ) 3131 3182 do_action( 'wp_restore_revision', $post_id, $revision['ID'] ); 3132 3183 3133 3184 return $post_id; … … 3153 3204 if ( !$revision = wp_get_revision( $revision_id ) ) 3154 3205 return $revision; 3155 3206 3156 if ( $delete = wp_delete_post( $revision->ID ) ) 3207 $delete = wp_delete_post( $revision->ID ); 3208 if ( is_wp_error( $delete ) ) 3209 return $delete; 3210 3211 if ( $delete ) 3157 3212 do_action( 'wp_delete_revision', $revision->ID, $revision ); 3158 3213 3159 3214 return $delete; … … 3174 3229 function wp_get_post_revisions( $post_id = 0 ) { 3175 3230 if ( ( !$post = get_post( $post_id ) ) || empty( $post->ID ) ) 3176 3231 return array(); 3177 3178 if ( !$revisions = get_children( array( 'post_parent' => $post->ID, 'post_type' => 'revision' ) ) ) 3232 if ( !$revisions = get_children( array( 'post_parent' => $post->ID, 'post_type' => 'revision', 'post_status' => 'inherit' ) ) ) 3179 3233 return array(); 3180 3234 return $revisions; 3181 3235 } 3182 3183 ?> -
wp-includes/js/autosave.js
168 168 autosave_disable_buttons(); 169 169 170 170 var origStatus = jQuery('#original_post_status').val(); 171 if ( 'draft' != origStatus ) // autosave currently only turned on for drafts172 doAutoSave = false;173 171 174 172 autosaveLast = jQuery("#title").val()+jQuery("#content").val(); 175 173 goodcats = ([]); -
wp-includes/pluggable.php
1392 1392 * @return string human readable HTML of string differences. Empty string if strings are equivalent 1393 1393 */ 1394 1394 function wp_text_diff( $left_string, $right_string, $args = null ) { 1395 $defaults = array( 'title' => '' );1395 $defaults = array( 'title' => '', 'title_left' => '', 'title_right' => '' ); 1396 1396 $args = wp_parse_args( $args, $defaults ); 1397 1397 1398 1398 // PEAR Text_Diff is lame; it includes things from include_path rather than it's own path. … … 1425 1425 $r = "<table class='diff'>\n"; 1426 1426 $r .= "<col class='ltype' /><col class='content' /><col class='ltype' /><col class='content' />"; 1427 1427 1428 if ( $args['title'] || $args['title_left'] || $args['title_right'] ) 1429 $r .= "<thead>"; 1428 1430 if ( $args['title'] ) 1429 $r .= "<thead><tr><th colspan='4'>$args[title]</th></tr></thead>\n"; 1431 $r .= "<tr class='diff-title'><th colspan='4'>$args[title]</th></tr>\n"; 1432 if ( $args['title_left'] || $args['title_right'] ) { 1433 $r .= "<tr class='diff-sub-title'>\n"; 1434 $r .= "\t<td></td><th>$args[title_left]</th>\n"; 1435 $r .= "\t<td></td><th>$args[title_right]</th>\n"; 1436 $r .= "</tr>\n"; 1437 } 1438 if ( $args['title'] || $args['title_left'] || $args['title_right'] ) 1439 $r .= "</thead>\n"; 1430 1440 1431 1441 $r .= "<tbody>\n$diff\n</tbody>\n"; 1432 1442 $r .= "</table>"; -
wp-includes/script-loader.php
47 47 'broken' => __('An unidentified error has occurred.') 48 48 ) ); 49 49 50 $this->add( 'autosave', '/wp-includes/js/autosave.js', array('schedule', 'wp-ajax-response'), '20080 424' );50 $this->add( 'autosave', '/wp-includes/js/autosave.js', array('schedule', 'wp-ajax-response'), '20080507' ); 51 51 52 52 $this->add( 'wp-ajax', '/wp-includes/js/wp-ajax.js', array('prototype'), '20070306'); 53 53 $this->localize( 'wp-ajax', 'WPAjaxL10n', array( -
wp-admin/admin-ajax.php
461 461 case 'autosave' : // The name of this action is hardcoded in edit_post() 462 462 define( 'DOING_AUTOSAVE', true ); 463 463 464 $nonce_age = check_ajax_referer( 'autosave', 'autosavenonce' );464 $nonce_age = check_ajax_referer( 'autosave', 'autosavenonce' ); 465 465 global $current_user; 466 466 467 $_POST['post_status'] = 'draft';468 467 $_POST['post_category'] = explode(",", $_POST['catslist']); 469 468 $_POST['tags_input'] = explode(",", $_POST['tags_input']); 470 469 if($_POST['post_type'] == 'page' || empty($_POST['post_category'])) … … 478 477 479 478 $supplemental = array(); 480 479 481 $id = 0;480 $id = $revision_id = 0; 482 481 if($_POST['post_ID'] < 0) { 482 $_POST['post_status'] = 'draft'; 483 483 $_POST['temp_ID'] = $_POST['post_ID']; 484 484 if ( $do_autosave ) { 485 485 $id = wp_write_post(); … … 510 510 if ( !current_user_can('edit_post', $post_ID) ) 511 511 die(__('You are not allowed to edit this post.')); 512 512 } 513 513 514 if ( $do_autosave ) { 514 $id = edit_post(); 515 // Drafts are just overwritten by autosave 516 if ( 'draft' == $post->post_status ) { 517 $id = edit_post(); 518 } else { // Non drafts are not overwritten. The autosave is stored in a special post revision. 519 $revision_id = wp_create_autosave( $post->ID ); 520 if ( is_wp_error($revision_id) ) 521 $id = $revision_id; 522 else 523 $id = $post->ID; 524 } 515 525 $data = $message; 516 526 } else { 517 527 $id = $post->ID; -
wp-admin/includes/post.php
1 1 <?php 2 2 3 // Update an existing post with values provided in $_POST. 4 function edit_post() { 5 6 $post_ID = (int) $_POST['post_ID']; 7 8 if ( 'page' == $_POST['post_type'] ) { 9 if ( !current_user_can( 'edit_page', $post_ID ) ) 10 wp_die( __('You are not allowed to edit this page.' )); 11 } else { 12 if ( !current_user_can( 'edit_post', $post_ID ) ) 13 wp_die( __('You are not allowed to edit this post.' )); 14 } 15 16 // Autosave shouldn't save too soon after a real save 17 if ( 'autosave' == $_POST['action'] ) { 18 $post =& get_post( $post_ID ); 19 $now = time(); 20 $then = strtotime($post->post_date_gmt . ' +0000'); 21 $delta = AUTOSAVE_INTERVAL / 2; 22 if ( ($now - $then) < $delta ) 23 return $post_ID; 24 } 25 26 // Rename. 27 $_POST['ID'] = (int) $_POST['post_ID']; 3 /** 4 * _wp_translate_postdata() - Rename $_POST data from form names to DB post columns. 5 * 6 * Manipulates $_POST directly. 7 * 8 * @package WordPress 9 * @since 2.6 10 * 11 * @param bool $update Are we updating a pre-existing post? 12 * @return object|bool WP_Error on failure, true on success. 13 */ 14 function _wp_translate_postdata( $update = false ) { 15 if ( $update ) 16 $_POST['ID'] = (int) $_POST['post_ID']; 28 17 $_POST['post_content'] = $_POST['content']; 29 18 $_POST['post_excerpt'] = $_POST['excerpt']; 30 19 $_POST['post_parent'] = isset($_POST['parent_id'])? $_POST['parent_id'] : ''; … … 32 21 33 22 if (!empty ( $_POST['post_author_override'] ) ) { 34 23 $_POST['post_author'] = (int) $_POST['post_author_override']; 35 } else 24 } else { 36 25 if (!empty ( $_POST['post_author'] ) ) { 37 26 $_POST['post_author'] = (int) $_POST['post_author']; 38 27 } else { 39 28 $_POST['post_author'] = (int) $_POST['user_ID']; 40 29 } 30 } 41 31 42 32 if ( $_POST['post_author'] != $_POST['user_ID'] ) { 43 33 if ( 'page' == $_POST['post_type'] ) { 44 if ( !current_user_can( 'edit_others_pages' ) ) 45 wp_die( __('You are not allowed to edit pages as this user.' )); 34 if ( !current_user_can( 'edit_others_pages' ) ) { 35 return new WP_Error( 'edit_others_pages', $update ? 36 __( 'You are not allowed to edit pages as this user.' ) : 37 __( 'You are not allowed to create pages as this user.' ) 38 ); 39 } 46 40 } else { 47 if ( !current_user_can( 'edit_others_posts' ) ) 48 wp_die( __('You are not allowed to edit posts as this user.' )); 49 41 if ( !current_user_can( 'edit_others_posts' ) ) { 42 return new WP_Error( 'edit_others_posts', $update ? 43 __( 'You are not allowed to edit posts as this user.' ) : 44 __( 'You are not allowed to post as this user.' ) 45 ); 46 } 50 47 } 51 48 } 52 49 … … 61 58 $_POST['post_status'] = 'draft'; 62 59 63 60 if ( 'page' == $_POST['post_type'] ) { 64 if ( 'publish' == $_POST['post_status'] && !current_user_can( 'publish_pages' ))61 if ( 'publish' == $_POST['post_status'] && !current_user_can( 'publish_pages' ) ) 65 62 $_POST['post_status'] = 'pending'; 66 63 } else { 67 if ( 'publish' == $_POST['post_status'] && !current_user_can( 'publish_posts' ))64 if ( 'publish' == $_POST['post_status'] && !current_user_can( 'publish_posts' ) ) 68 65 $_POST['post_status'] = 'pending'; 69 66 } 70 67 … … 74 71 if (!isset( $_POST['ping_status'] )) 75 72 $_POST['ping_status'] = 'closed'; 76 73 77 foreach ( array 74 foreach ( array('aa', 'mm', 'jj', 'hh', 'mn') as $timeunit ) { 78 75 if ( !empty( $_POST['hidden_' . $timeunit] ) && $_POST['hidden_' . $timeunit] != $_POST[$timeunit] ) { 79 76 $_POST['edit_date'] = '1'; 80 77 break; 81 78 } 82 79 } 83 80 84 if ( !empty( $_POST['edit_date'] ) ) {81 if ( !empty( $_POST['edit_date'] ) ) { 85 82 $aa = $_POST['aa']; 86 83 $mm = $_POST['mm']; 87 84 $jj = $_POST['jj']; … … 92 89 $hh = ($hh > 23 ) ? $hh -24 : $hh; 93 90 $mn = ($mn > 59 ) ? $mn -60 : $mn; 94 91 $ss = ($ss > 59 ) ? $ss -60 : $ss; 95 $_POST['post_date'] = "$aa-$mm-$jj $hh:$mn:$ss";96 $_POST['post_date_gmt'] = get_gmt_from_date( "$aa-$mm-$jj $hh:$mn:$ss");92 $_POST['post_date'] = sprintf( "%04d-%02d-%02d %02d:%02d:%02d", $aa, $mm, $jj, $hh, $mn, $ss ); 93 $_POST['post_date_gmt'] = get_gmt_from_date( $_POST['post_date'] ); 97 94 } 98 95 96 return true; 97 } 98 99 100 // Update an existing post with values provided in $_POST. 101 function edit_post() { 102 103 $post_ID = (int) $_POST['post_ID']; 104 105 if ( 'page' == $_POST['post_type'] ) { 106 if ( !current_user_can( 'edit_page', $post_ID ) ) 107 wp_die( __('You are not allowed to edit this page.' )); 108 } else { 109 if ( !current_user_can( 'edit_post', $post_ID ) ) 110 wp_die( __('You are not allowed to edit this post.' )); 111 } 112 113 // Autosave shouldn't save too soon after a real save 114 if ( 'autosave' == $_POST['action'] ) { 115 $post =& get_post( $post_ID ); 116 $now = time(); 117 $then = strtotime($post->post_date_gmt . ' +0000'); 118 $delta = AUTOSAVE_INTERVAL / 2; 119 if ( ($now - $then) < $delta ) 120 return $post_ID; 121 } 122 123 $translated = _wp_translate_postdata( true ); 124 if ( is_wp_error($translated) ) 125 wp_die( $translated->get_error_message() ); 126 99 127 // Meta Stuff 100 128 if ( isset($_POST['meta']) && $_POST['meta'] ) { 101 129 foreach ( $_POST['meta'] as $key => $value ) … … 236 264 } 237 265 } 238 266 239 // Rename. 240 $_POST['post_content'] = $_POST['content']; 241 $_POST['post_excerpt'] = $_POST['excerpt']; 242 $_POST['post_parent'] = isset($_POST['parent_id'])? $_POST['parent_id'] : ''; 243 $_POST['to_ping'] = $_POST['trackback_url']; 267 $translated = _wp_translate_postdata( false ); 268 if ( is_wp_error($translated) ) 269 return $translated; 244 270 245 if (!empty ( $_POST['post_author_override'] ) ) {246 $_POST['post_author'] = (int) $_POST['post_author_override'];247 } else {248 if (!empty ( $_POST['post_author'] ) ) {249 $_POST['post_author'] = (int) $_POST['post_author'];250 } else {251 $_POST['post_author'] = (int) $_POST['user_ID'];252 }253 254 }255 256 if ( $_POST['post_author'] != $_POST['user_ID'] ) {257 if ( 'page' == $_POST['post_type'] ) {258 if ( !current_user_can( 'edit_others_pages' ) )259 return new WP_Error( 'edit_others_pages', __( 'You are not allowed to create pages as this user.' ) );260 } else {261 if ( !current_user_can( 'edit_others_posts' ) )262 return new WP_Error( 'edit_others_posts', __( 'You are not allowed to post as this user.' ) );263 264 }265 }266 267 // What to do based on which button they pressed268 if ( isset($_POST['saveasdraft']) && '' != $_POST['saveasdraft'] )269 $_POST['post_status'] = 'draft';270 if ( isset($_POST['saveasprivate']) && '' != $_POST['saveasprivate'] )271 $_POST['post_status'] = 'private';272 if ( isset($_POST['publish']) && ( '' != $_POST['publish'] ) && ( $_POST['post_status'] != 'private' ) )273 $_POST['post_status'] = 'publish';274 if ( isset($_POST['advanced']) && '' != $_POST['advanced'] )275 $_POST['post_status'] = 'draft';276 277 if ( 'page' == $_POST['post_type'] ) {278 if ('publish' == $_POST['post_status'] && !current_user_can( 'publish_pages' ) )279 $_POST['post_status'] = 'pending';280 } else {281 if ('publish' == $_POST['post_status'] && !current_user_can( 'publish_posts' ) )282 $_POST['post_status'] = 'pending';283 }284 285 if (!isset( $_POST['comment_status'] ))286 $_POST['comment_status'] = 'closed';287 288 if (!isset( $_POST['ping_status'] ))289 $_POST['ping_status'] = 'closed';290 291 foreach ( array ('aa', 'mm', 'jj', 'hh', 'mn') as $timeunit ) {292 if ( !empty( $_POST['hidden_' . $timeunit] ) && $_POST['hidden_' . $timeunit] != $_POST[$timeunit] ) {293 $_POST['edit_date'] = '1';294 break;295 }296 }297 298 if (!empty ( $_POST['edit_date'] ) ) {299 $aa = $_POST['aa'];300 $mm = $_POST['mm'];301 $jj = $_POST['jj'];302 $hh = $_POST['hh'];303 $mn = $_POST['mn'];304 $ss = $_POST['ss'];305 $jj = ($jj > 31 ) ? 31 : $jj;306 $hh = ($hh > 23 ) ? $hh -24 : $hh;307 $mn = ($mn > 59 ) ? $mn -60 : $mn;308 $ss = ($ss > 59 ) ? $ss -60 : $ss;309 $_POST['post_date'] = sprintf( "%04d-%02d-%02d %02d:%02d:%02d", $aa, $mm, $jj, $hh, $mn, $ss );310 $_POST['post_date_gmt'] = get_gmt_from_date( $_POST['post_date'] );311 }312 313 271 // Create the post. 314 272 $post_ID = wp_insert_post( $_POST ); 315 273 if ( is_wp_error( $post_ID ) ) … … 687 645 update_post_meta( $post->ID, '_edit_last', $current_user->ID ); 688 646 } 689 647 690 ?> 648 /** 649 * wp_create_autosave() - creates autosave data for the specified post from $_POST data 650 * 651 * @package WordPress 652 * @subpackage Post Revisions 653 * @since 2.6 654 * 655 * @uses _wp_translate_postdata() 656 * @uses _wp_revision_fields() 657 */ 658 function wp_create_autosave( $post_id ) { 659 $translated = _wp_translate_postdata( true ); 660 if ( is_wp_error( $translated ) ) 661 return $translated; 662 663 // Only store one autosave. If there is already an autosave, overwrite it. 664 if ( $old_autosave = wp_get_autosave( $post_id ) ) { 665 $new_autosave = _wp_revision_fields( $_POST, true ); 666 $new_autosave['ID'] = $old_autosave->ID; 667 return wp_update_post( $new_autosave ); 668 } 669 670 // Otherwise create the new autosave as a special post revision 671 return _wp_put_revision( $_POST, true ); 672 } -
wp-admin/revision.php
2 2 3 3 require_once('admin.php'); 4 4 5 $parent_file = 'edit.php'; 5 wp_reset_vars(array('revision', 'left', 'right', 'action')); 6 $revision_id = absint($revision); 7 $diff = absint($diff); 8 $left = absint($left); 9 $right = absint($right); 10 11 12 $parent_file = $redirect = 'edit.php'; 6 13 $submenu_file = 'edit.php'; 14 $title = __( 'Post Revision' ); 7 15 8 wp_reset_vars(array('revision', 'diff', 'restore'));9 16 10 $revision_id = absint($revision); 11 $diff = absint($diff); 17 switch ( $action ) : 18 case 'delete' : // stubs 19 case 'edit' : 20 $redirect = remove_query_arg( 'action' ); 21 break; 22 case 'restore' : 23 if ( !current_user_can( 'edit_post', $revision->post_parent ) ) 24 break; 25 if ( !$revision = wp_get_revision( $revision_id ) ) 26 break; 27 if ( !$post = get_post( $revision->post_parent ) ) 28 break; 12 29 13 if ( $diff ) { 14 $restore = false; 15 $revision = get_post( $revision_id ); 16 $post = 'revision' == $revision->post_type ? get_post( $revision->post_parent ) : get_post( $revision_id ); 17 $left_revision = get_post( $diff ); 30 check_admin_referer( "restore-post_$post->ID|$revision->ID" ); 18 31 32 wp_restore_revision( $revision->ID ); 33 $redirect = add_query_arg( array( 'message' => 5, 'revision' => $revision->ID ), get_edit_post_link( $post->ID, 'url' ) ); 34 break; 35 case 'diff' : 36 if ( !$left_revision = get_post( $left ) ) 37 break; 38 if ( !$right_revision = get_post( $right ) ) 39 break; 40 41 if ( !current_user_can( 'edit_post', $left_revision->ID ) || !current_user_can( 'edit_post', $right_revision->ID ) ) 42 break; 43 19 44 // Don't allow reverse diffs? 20 if ( strtotime($re vision->post_modified_gmt) < strtotime($left_revision->post_modified_gmt) ) {21 wp_redirect( add_query_arg( array( 'diff' => $revision->ID, 'revision' => $diff )) );22 exit;45 if ( strtotime($reght_revision->post_modified_gmt) < strtotime($left_revision->post_modified_gmt) ) { 46 $redirect = add_query_arg( array( 'left' => $right, 'right' => $left ) ); 47 break; 23 48 } 24 49 25 $h2 = __( 'Compare Revisions of “%1$s”' ); 26 $right = $revision->ID; 27 $left = $left_revision->ID; 50 if ( $left_revision->ID == $right_revision->post_parent ) // right is a revision of left 51 $post =& $left_revision; 52 elseif ( $left_revision->post_parent == $right_revision->ID ) // left is a revision of right 53 $post =& $right_revision; 54 elseif ( $left_revision->post_parent == $right_revision->post_parent ) // both are revisions of common parent 55 $post = get_post( $left_revision->post_parent ); 56 else 57 break; // Don't diff two unrelated revisions 28 58 29 59 if ( 30 60 // They're the same 31 $left_revision->ID == $r evision->ID61 $left_revision->ID == $right_revision->ID 32 62 || 33 // They don't have a comment parent (and we're not comparing a revision to it's post)34 ( $left_revision->ID != $revision->post_parent && $left_revision->post_parent != $revision->ID && $left_revision->post_parent != $revision->post_parent )35 ||36 63 // Neither is a revision 37 ( !wp_get_revision( $left_revision->ID ) && !wp_get_revision( $revision->ID ) ) 38 ) { 39 wp_redirect( get_edit_post_link( $revision->ID, 'url' ) ); 40 exit(); 41 } 42 } else { 43 $revision = wp_get_revision( $revision_id ); 44 $post = get_post( $revision->post_parent ); 45 $h2 = __( 'Post Revision for “%1$s” created on %2$s' ); 64 ( !wp_get_revision( $left_revision->ID ) && !wp_get_revision( $right_revision->ID ) ) 65 ) 66 break; 67 68 $post_title = '<a href="' . get_edit_post_link() . '">' . get_the_title() . '</a>'; 69 $h2 = sprintf( __( 'Compare Revisions of “%1$s”' ), $post_title ); 70 71 $left = $left_revision->ID; 72 $right = $right_revision->ID; 73 74 $redirect = false; 75 break; 76 case 'view' : 77 default : 78 if ( !$revision = wp_get_revision( $revision_id ) ) 79 break; 80 if ( !$post = get_post( $revision->post_parent ) ) 81 break; 82 83 if ( !current_user_can( 'edit_post', $revision->ID ) || !current_user_can( 'edit_post', $post->ID ) ) 84 break; 85 86 $post_title = '<a href="' . get_edit_post_link() . '">' . get_the_title() . '</a>'; 87 $revision_title = wp_post_revision_title( $revision, false ); 88 $h2 = sprintf( __( 'Post Revision for “%1$s” created on %2$s' ), $post_title, $revision_title ); 89 90 // Sets up the diff radio buttons 91 $left = $revision->ID; 46 92 $right = $post->ID; 47 $left = $revision->ID;48 }49 93 50 if ( !$revision || !$post ) { 51 wp_redirect("edit.php"); 52 exit(); 53 } 94 $redirect = false; 95 break; 96 endswitch; 54 97 55 if ( $restore && current_user_can( 'edit_post', $revision->post_parent ) ) { 56 check_admin_referer( "restore-post_$post->ID|$revision->ID" ); 57 wp_restore_revision( $revision->ID ); 58 wp_redirect( add_query_arg( array( 'message' => 5, 'revision' => $revision->ID ), get_edit_post_link( $post->ID, 'url' ) ) ); 98 if ( $redirect ) { 99 wp_redirect( $redirect ); 59 100 exit; 60 101 } 61 102 103 // Converts post_author ID# into name 62 104 add_filter( '_wp_revision_field_post_author', 'get_author_name' ); 63 105 64 $title = __( 'Post Revision' );65 66 106 require_once( 'admin-header.php' ); 67 107 68 $post_title = '<a href="' . get_edit_post_link() . '">' . get_the_title() . '</a>';69 $revision_time = wp_post_revision_time( $revision );70 108 ?> 71 109 72 110 <div class="wrap"> 73 111 74 <h2 style="padding-right: 0"><?php printf( $h2, $post_title, $revision_time ); ?></h2>112 <h2 class="long-header"><?php echo $h2; ?></h2> 75 113 76 114 <table class="form-table ie-fixed"> 77 115 <col class="th" /> 78 <?php if ( $diff ) : ?> 79 116 <?php if ( 'diff' == $action ) : ?> 80 117 <tr id="revision"> 81 118 <th scope="row"></th> 82 <th scope="col" class="th-full"><?php printf( __('Older: %s'), wp_post_revision_time( $left_revision ) ); ?></td> 83 <th scope="col" class="th-full"><?php printf( __('Newer: %s'), wp_post_revision_time( $revision ) ); ?></td> 119 <th scope="col" class="th-full"> 120 <span class="alignleft"><?php printf( __('Older: %s'), wp_post_revision_title( $left_revision ) ); ?></span> 121 <span class="alignright"><?php printf( __('Newer: %s'), wp_post_revision_title( $right_revision ) ); ?></span> 122 </td> 84 123 </tr> 85 86 124 <?php endif; 87 125 88 // use get_post_to_edit ?126 // use get_post_to_edit filters? 89 127 $identical = true; 90 128 foreach ( _wp_revision_fields() as $field => $field_title ) : 91 if ( !$diff ) 129 if ( 'diff' == $action ) { 130 $left_content = apply_filters( "_wp_revision_field_$field", $left_revision->$field, $field ); 131 $right_content = apply_filters( "_wp_revision_field_$field", $right_revision->$field, $field ); 132 if ( !$content = wp_text_diff( $left_content, $right_content ) ) 133 continue; // There is no difference between left and right 134 $identical = false; 135 } else { 92 136 add_filter( "_wp_revision_field_$field", 'htmlspecialchars' ); 93 $content = apply_filters( "_wp_revision_field_$field", $revision->$field, $field ); 94 if ( $diff ) { 95 $left_content = apply_filters( "_wp_revision_field_$field", $left_revision->$field, $field ); 96 if ( !$content = wp_text_diff( $left_content, $content ) ) 97 continue; 137 $content = apply_filters( "_wp_revision_field_$field", $revision->$field, $field ); 98 138 } 99 $identical = false;100 139 ?> 101 140 102 <tr id="revision-field-<?php echo $field; ?>" ?>141 <tr id="revision-field-<?php echo $field; ?>"> 103 142 <th scope="row"><?php echo wp_specialchars( $field_title ); ?></th> 104 <td colspan="2"><pre><?php echo $content; ?></pre></td>143 <td><pre><?php echo $content; ?></pre></td> 105 144 </tr> 106 145 107 146 <?php 108 147 109 148 endforeach; 110 149 111 if ( $diff&& $identical ) :150 if ( 'diff' == $action && $identical ) : 112 151 113 152 ?> 114 153 115 <tr><td colspan=" 3"><div class="updated"><p><?php _e( 'These revisions are identical' ); ?></p></div></td></tr>154 <tr><td colspan="2"><div class="updated"><p><?php _e( 'These revisions are identical.' ); ?></p></div></td></tr> 116 155 117 156 <?php 118 157 … … 127 166 <h2><?php _e( 'Post Revisions' ); ?></h2> 128 167 129 168 <?php 130 wp_list_post_revisions( $post, array( 'format' => 'form-table', 'exclude' => $revision->ID, 'parent' => true, 'right' => $right, 'left' => $left ) );131 169 132 require_once( 'admin-footer.php' ); 170 wp_list_post_revisions( $post, array( 'format' => 'form-table', 'parent' => true, 'right' => $right, 'left' => $left ) ); 171 172 require_once( 'admin-footer.php' ); -
wp-admin/edit-form-advanced.php
1 <?php 2 $action = isset($action)? $action : ''; 1 <?php 2 3 $action = isset($action) ? $action : ''; 3 4 if ( isset($_GET['message']) ) 4 5 $_GET['message'] = absint( $_GET['message'] ); 5 6 $messages[1] = sprintf( __( 'Post updated. Continue editing below or <a href="%s">go back</a>.' ), attribute_escape( stripslashes( $_GET['_wp_original_http_referer'] ) ) ); 6 7 $messages[2] = __('Custom field updated.'); 7 8 $messages[3] = __('Custom field deleted.'); 8 9 $messages[4] = __('Post updated.'); 9 $messages[5] = sprintf( __('Post restored to revision from %s'), wp_post_revision_time( $_GET['revision'] ) ); 10 $messages[5] = sprintf( __('Post restored to revision from %s'), wp_post_revision_title( $_GET['revision'], false ) ); 11 12 $notice = false; 13 $notices[1] = __( 'There is an autosave of this post that is more recent than the version below. <a href="%s">View the autosave</a>.' ); 14 15 if ( !isset($post_ID) || 0 == $post_ID ) { 16 $form_action = 'post'; 17 $temp_ID = -1 * time(); // don't change this formula without looking at wp_write_post() 18 $form_extra = "<input type='hidden' id='post_ID' name='temp_ID' value='$temp_ID' />"; 19 $autosave = false; 20 } else { 21 $post_ID = (int) $post_ID; 22 $form_action = 'editpost'; 23 $form_extra = "<input type='hidden' id='post_ID' name='post_ID' value='$post_ID' />"; 24 $autosave = wp_get_autosave( $post_id ); 25 if ( $autosave && mysql2date( 'U', $autosave->post_modified_gmt ) > mysql2date( 'U', $post->post_modified_gmt ) ) 26 $notice = sprintf( $notices[1], get_edit_post_link( $autosave->ID ) ); 27 } 28 10 29 ?> 30 <?php if ( $notice ) : ?> 31 <div id="notice" class="error"><p><?php echo $notice ?></p></div> 32 <?php endif; ?> 11 33 <?php if (isset($_GET['message'])) : ?> 12 34 <div id="message" class="updated fade"><p><?php echo $messages[$_GET['message']]; ?></p></div> 13 35 <?php endif; ?> … … 21 43 <h2><?php _e('Write Post') ?></h2> 22 44 <?php 23 45 24 if (!isset($post_ID) || 0 == $post_ID) { 25 $form_action = 'post'; 26 $temp_ID = -1 * time(); // don't change this formula without looking at wp_write_post() 27 $form_extra = "<input type='hidden' id='post_ID' name='temp_ID' value='$temp_ID' />"; 46 if ( !isset($post_ID) || 0 == $post_ID) 28 47 wp_nonce_field('add-post'); 29 } else { 30 $post_ID = (int) $post_ID; 31 $form_action = 'editpost'; 32 $form_extra = "<input type='hidden' id='post_ID' name='post_ID' value='$post_ID' />"; 48 else 33 49 wp_nonce_field('update-post_' . $post_ID); 34 }35 50 36 51 $form_pingback = '<input type="hidden" name="post_pingback" value="' . (int) get_option('default_pingback_flag') . '" id="post_pingback" />'; 37 52 -
wp-admin/css/global.css
194 194 padding-bottom: 7px; 195 195 padding-right: 280px; 196 196 } 197 198 .wrap h2.long-header { 199 padding-right: 0; 200 }