Changeset 7747
- Timestamp:
- 04/18/2008 11:38:21 PM (16 years ago)
- Location:
- trunk
- Files:
-
- 13 added
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/admin-ajax.php
r7660 r7747 461 461 break; 462 462 case 'autosave' : // The name of this action is hardcoded in edit_post() 463 define( 'DOING_AUTOSAVE', true ); 464 463 465 $nonce_age = check_ajax_referer( 'autosave', 'autosavenonce'); 464 466 global $current_user; -
trunk/wp-admin/css/colors-classic.css
r7518 r7747 3 3 } 4 4 5 body 5 body, .form-table pre { 6 6 background-color: #fff; 7 7 color: #333; … … 714 714 color: #333; 715 715 } 716 717 /* Diff */ 718 719 table.diff .diff-deletedline { 720 background-color: #ffdddd; 721 } 722 table.diff .diff-deletedline del { 723 background-color: #ff9999; 724 } 725 table.diff .diff-addedline { 726 background-color: #ddffdd; 727 } 728 table.diff .diff-addedline ins { 729 background-color: #99ff99; 730 } -
trunk/wp-admin/css/colors-fresh.css
r7538 r7747 3 3 } 4 4 5 body 5 body, .form-table pre { 6 6 background-color: #fff; 7 7 color: #333; … … 685 685 color: #333; 686 686 } 687 688 /* Diff */ 689 690 table.diff .diff-deletedline { 691 background-color: #ffdddd; 692 } 693 table.diff .diff-deletedline del { 694 background-color: #ff9999; 695 } 696 table.diff .diff-addedline { 697 background-color: #ddffdd; 698 } 699 table.diff .diff-addedline ins { 700 background-color: #99ff99; 701 } -
trunk/wp-admin/css/ie.css
r7502 r7747 112 112 display: block; 113 113 margin-top: -3px; 114 } 114 115 116 table.ie-fixed { 117 table-layout: fixed; 115 118 } 116 119 -
trunk/wp-admin/edit-form-advanced.php
r7740 r7747 7 7 $messages[3] = __('Custom field deleted.'); 8 8 $messages[4] = __('Post updated.'); 9 $messages[5] = sprintf( __('Post restored to revision from %s'), wp_post_revision_time( $_GET['revision'] ) ); 9 10 ?> 10 11 <?php if (isset($_GET['message'])) : ?> … … 337 338 <?php endif; ?> 338 339 340 <?php if ( isset($post_ID) && 0 < $post_ID && wp_get_post_revisions( $post_ID ) ) : ?> 341 <div id="revisionsdiv" class="postbox <?php echo postbox_classes('revisionsdiv', 'post'); ?>"> 342 <h3><?php _e('Post Revisions'); ?></h3> 343 <div class="inside"> 344 <?php wp_list_post_revisions(); ?> 345 </div> 346 </div> 347 <?php endif; ?> 348 339 349 <?php do_meta_boxes('post', 'advanced', $post); ?> 340 350 -
trunk/wp-admin/page.php
r7564 r7747 71 71 if ( empty($post->ID) ) wp_die( __("You attempted to edit a page that doesn't exist. Perhaps it was deleted?") ); 72 72 73 if ( 'p ost' == $post->post_type ) {74 wp_redirect( "post.php?action=edit&post=$post_ID");73 if ( 'page' != $post->post_type ) { 74 wp_redirect( get_edit_post_link( $post_ID, 'url' ) ); 75 75 exit(); 76 76 } -
trunk/wp-admin/post.php
r7564 r7747 78 78 if ( empty($post->ID) ) wp_die( __("You attempted to edit a post that doesn't exist. Perhaps it was deleted?") ); 79 79 80 if ( 'p age' == $post->post_type ) {81 wp_redirect( "page.php?action=edit&post=$post_ID");80 if ( 'post' != $post->post_type ) { 81 wp_redirect( get_edit_post_link( $post->ID, 'url' ) ); 82 82 exit(); 83 83 } -
trunk/wp-admin/wp-admin.css
r7720 r7747 893 893 #profile-page .form-table #rich_editing { 894 894 margin-right: 5px 895 } 896 897 .form-table pre { 898 padding: 8px; 899 margin: 0; 900 /* http://www.longren.org/2006/09/27/wrapping-text-inside-pre-tags/ */ 901 white-space: pre-wrap; /* css-3 */ 902 white-space: -moz-pre-wrap !important; /* Mozilla, since 1999 */ 903 white-space: -pre-wrap; /* Opera 4-6 */ 904 white-space: -o-pre-wrap; /* Opera 7 */ 905 word-wrap: break-word; /* Internet Explorer 5.5+ */ 906 } 907 908 table.form-table td .updated { 909 font-size: 13px; 895 910 } 896 911 … … 1465 1480 display: none; 1466 1481 } 1482 1483 /* Diff */ 1484 1485 table.diff { 1486 width: 100%; 1487 } 1488 1489 table.diff col.content { 1490 width: 50%; 1491 } 1492 1493 table.diff tr { 1494 background-color: transparent; 1495 } 1496 1497 table.diff td, table.diff th { 1498 padding: .5em; 1499 font-family: monospace; 1500 border: none; 1501 } 1502 1503 table.diff .diff-deletedline del, table.diff .diff-addedline ins { 1504 text-decoration: none; 1505 } -
trunk/wp-includes/default-filters.php
r7491 r7747 179 179 add_action( 'plugins_loaded', 'wp_maybe_load_widgets', 0 ); 180 180 add_action( 'shutdown', 'wp_ob_end_flush_all', 1); 181 add_action( 'pre_post_update', 'wp_save_revision' ); 181 182 add_action('publish_post', '_publish_post_hook', 5, 1); 182 183 add_action('future_post', '_future_post_hook', 5, 2); -
trunk/wp-includes/link-template.php
r7667 r7747 443 443 } 444 444 445 function get_edit_post_link( $id = 0 ) {445 function get_edit_post_link( $id = 0, $context = 'display' ) { 446 446 if ( !$post = &get_post( $id ) ) 447 447 return; 448 449 if ( 'display' == $context ) 450 $action = 'action=edit&'; 451 else 452 $action = 'action=edit&'; 448 453 449 454 switch ( $post->post_type ) : … … 460 465 $var = 'attachment_id'; 461 466 break; 467 case 'revision' : 468 if ( !current_user_can( 'edit_post', $post->ID ) ) 469 return; 470 $file = 'revision'; 471 $var = 'revision'; 472 $action = ''; 473 break; 462 474 default : 463 475 if ( !current_user_can( 'edit_post', $post->ID ) ) … … 468 480 endswitch; 469 481 470 return apply_filters( 'get_edit_post_link', get_bloginfo( 'wpurl' ) . "/wp-admin/$file.php? action=edit&$var=$post->ID", $post->ID );482 return apply_filters( 'get_edit_post_link', get_bloginfo( 'wpurl' ) . "/wp-admin/$file.php?{$action}$var=$post->ID", $post->ID ); 471 483 } 472 484 -
trunk/wp-includes/pluggable.php
r7642 r7747 1351 1351 endif; 1352 1352 1353 if ( !function_exists( 'wp_text_diff' ) ) : 1354 /** 1355 * wp_text_diff() - compares two strings and outputs a human readable HTML representation of their difference 1356 * 1357 * Basically a wrapper for man diff(1) 1358 * 1359 * Must accept an optional third parameter, $args @see wp_parse_args() 1360 * (string) title: optional. If present, titles the diff in a manner compatible with the output 1361 * 1362 * Must return the empty string if the two compared strings are found to be equivalent according to whatever metric 1363 * 1364 * @since 2.6 1365 * @uses Text_Diff 1366 * @uses WP_Text_Diff_Renderer_Table 1367 * 1368 * @param string $left_string "old" (left) version of string 1369 * @param string $right_string "new" (right) version of string 1370 * @param string|array $args @see wp_parse_args() 1371 * @return string human readable HTML of string differences. Empty string if strings are equivalent 1372 */ 1373 function wp_text_diff( $left_string, $right_string, $args = null ) { 1374 $defaults = array( 'title' => '' ); 1375 $args = wp_parse_args( $args, $defaults ); 1376 1377 // PEAR Text_Diff is lame; it includes things from include_path rather than it's own path. 1378 // Not sure of the ramifications of disttributing modified code. 1379 ini_set('include_path', '.' . PATH_SEPARATOR . ABSPATH . WPINC ); 1380 1381 if ( !class_exists( 'WP_Text_Diff_Renderer_Table' ) ) 1382 require( ABSPATH . WPINC . '/wp-diff.php' ); 1383 1384 // Normalize whitespace 1385 $left_string = trim($left_string); 1386 $right_string = trim($right_string); 1387 $left_string = str_replace("\r", "\n", $left_string); 1388 $right_string = str_replace("\r", "\n", $right_string); 1389 $left_string = preg_replace( array( '/\n+/', '/[ \t]+/' ), array( "\n", ' ' ), $left_string ); 1390 $right_string = preg_replace( array( '/\n+/', '/[ \t]+/' ), array( "\n", ' ' ), $right_string ); 1391 1392 $left_lines = split("\n", $left_string); 1393 $right_lines = split("\n", $right_string); 1394 1395 $text_diff = new Text_Diff($left_lines, $right_lines); 1396 $renderer = new WP_Text_Diff_Renderer_Table(); 1397 $diff = $renderer->render($text_diff); 1398 1399 ini_restore('include_path'); 1400 1401 if ( !$diff ) 1402 return ''; 1403 1404 $r = "<table class='diff'>\n"; 1405 $r .= "<col class='ltype' /><col class='content' /><col class='ltype' /><col class='content' />"; 1406 1407 if ( $args['title'] ) 1408 $r .= "<thead><tr><th colspan='4'>$args[title]</th></tr></thead>\n"; 1409 1410 $r .= "<tbody>\n$diff\n</tbody>\n"; 1411 $r .= "</table>"; 1412 1413 return $r; 1414 } 1415 endif; 1416 1353 1417 ?> -
trunk/wp-includes/post-template.php
r7492 r7747 565 565 } 566 566 567 ?> 567 /** 568 * wp_post_revision_time() - returns formatted datetimestamp of a revision 569 * 570 * @package WordPress 571 * @subpackage Post Revisions 572 * @since 2.6 573 * 574 * @uses wp_get_revision() 575 * @uses date_i18n() 576 * 577 * @param int|object $revision revision ID or revision object 578 * @return string i18n formatted datetimestamp or localized 'Corrent Revision' 579 */ 580 function wp_post_revision_time( $revision ) { 581 if ( !$revision = wp_get_revision( $revision ) ) { 582 if ( $revision = get_post( $revision ) ) 583 return __( 'Current Revision' ); 584 return $revision; 585 } 586 587 $datef = _c( 'j F, Y @ G:i|revision date format'); 588 return date_i18n( $datef, strtotime( $revision->post_date_gmt . ' +0000' ) ); 589 } 590 591 /** 592 * wp_list_post_revisions() - echoes list of a post's revisions 593 * 594 * Can output either a UL with edit links or a TABLE with diff interface, and restore action links 595 * 596 * Second argument controls parameters: 597 * (bool) parent : include the parent (the "Current Revision") in the list 598 * (string) format : 'list' or 'form-table'. 'list' outputs UL, 'form-table' outputs TABLE with UI 599 * (int) right : what revision is currently being viewed - used in form-table format 600 * (int) left : what revision is currently being diffed against right - used in form-table format 601 * 602 * @package WordPress 603 * @subpackage Post Revisions 604 * @since 2.6 605 * 606 * @uses wp_get_post_revisions() 607 * @uses wp_post_revision_time() 608 * @uses get_edit_post_link() 609 * @uses get_author_name() 610 * 611 * @param int|object $post_id post ID or post object 612 * @param string|array $args see description @see wp_parse_args() 613 */ 614 function wp_list_post_revisions( $post_id = 0, $args = null ) { // TODO? split into two functions (list, form-table) ? 615 if ( !$post = get_post( $post_id ) ) 616 return; 617 618 if ( !$revisions = wp_get_post_revisions( $post->ID ) ) 619 return; 620 621 $defaults = array( 'parent' => false, 'right' => false, 'left' => false, 'format' => 'list' ); 622 extract( wp_parse_args( $args, $defaults ), EXTR_SKIP ); 623 624 $titlef = _c( '%1$s by %2$s|post revision 1:datetime, 2:name' ); 625 626 if ( $parent ) 627 array_unshift( $revisions, $post ); 628 629 $rows = ''; 630 $class = false; 631 foreach ( $revisions as $revision ) { 632 $date = wp_post_revision_time( $revision ); 633 if ( $link = get_edit_post_link( $revision->ID ) ) 634 $date = "<a href='$link'>$date</a>"; 635 $name = get_author_name( $revision->post_author ); 636 637 if ( 'form-table' == $format ) { 638 if ( $left ) 639 $old_checked = $left == $revision->ID ? ' checked="checked"' : ''; 640 else 641 $old_checked = $new_checked ? ' checked="checked"' : ''; 642 $new_checked = $right == $revision->ID ? ' checked="checked"' : ''; 643 644 $class = $class ? '' : " class='alternate'"; 645 646 if ( $post->ID != $revision->ID && current_user_can( 'edit_post', $post->ID ) ) 647 $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>'; 648 else 649 $actions = ''; 650 651 $rows .= "<tr$class>\n"; 652 $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"; 653 $rows .= "\t<td>$date</td>\n"; 654 $rows .= "\t<td>$name</td>\n"; 655 $rows .= "\t<td class='action-links'>$actions</td>\n"; 656 $rows .= "</tr>\n"; 657 } else { 658 $rows .= "\t<li>" . sprintf( $titlef, $date, $name ). "</li>\n"; 659 } 660 } 661 662 if ( 'form-table' == $format ) : ?> 663 664 <form action="revision.php" method="get"> 665 666 <div class="tablenav"> 667 <div class="alignleft"> 668 <input type="submit" class="button-secondary" value="<?php _e( 'Compare Revisions' ); ?>" /> 669 </div> 670 </div> 671 672 <br class="clear" /> 673 674 <table class="widefat post-revisions"> 675 <col /> 676 <col style="width: 33%" /> 677 <col style="width: 33%" /> 678 <col style="width: 33%" /> 679 <thead> 680 <th scope="col"></th> 681 <th scope="col"><?php _e( 'Date Created' ); ?></th> 682 <th scope="col"><?php _e( 'Author' ); ?></th> 683 <th scope="col" class="action-links"><?php _e( 'Actions' ); ?></th> 684 </thead> 685 <tbody> 686 687 <?php echo $rows; ?> 688 689 </tbody> 690 </table> 691 692 <?php 693 else : 694 echo "<ul class='post-revisions'>\n"; 695 echo $rows; 696 echo "</ul>"; 697 endif; 698 699 } -
trunk/wp-includes/post.php
r7746 r7747 2991 2991 } 2992 2992 2993 /* Post Revisions */ 2994 2995 /** 2996 * _wp_revision_fields() - determines which fields of posts are to be saved in revisions 2997 * 2998 * Does two things. If passed a postn *array*, it will return a post array ready to be 2999 * insterted into the posts table as a post revision. 3000 * Otherwise, returns an array whose keys are the post fields to be saved post revisions. 3001 * 3002 * @package WordPress 3003 * @subpackage Post Revisions 3004 * @since 2.6 3005 * 3006 * @param array $post optional a post array to be processed for insertion as a post revision 3007 * @return array post array ready to be inserted as a post revision or array of fields that can be versioned 3008 */ 3009 function _wp_revision_fields( $post = null ) { 3010 static $fields = false; 3011 3012 if ( !$fields ) { 3013 // Allow these to be versioned 3014 $fields = array( 3015 'post_title' => __( 'Title' ), 3016 'post_author' => __( 'Author' ), 3017 'post_content' => __( 'Content' ), 3018 'post_excerpt' => __( 'Excerpt' ), 3019 ); 3020 3021 // WP uses these internally either in versioning or elsewhere - they cannot be versioned 3022 foreach ( array( 'ID', 'post_name', 'post_parent', 'post_date', 'post_date_gmt', 'post_status', 'post_type', 'comment_count' ) as $protect ) 3023 unset( $fields[$protect] ); 3024 } 3025 3026 if ( !is_array($post) ) 3027 return $fields; 3028 3029 $return = array(); 3030 foreach ( array_intersect( array_keys( $post ), array_keys( $fields ) ) as $field ) 3031 $return[$field] = $post[$field]; 3032 3033 $return['post_parent'] = $post['ID']; 3034 $return['post_status'] = 'inherit'; 3035 $return['post_type'] = 'revision'; 3036 $return['post_name'] = "$post[ID]-revision"; 3037 $return['post_date'] = $post['post_modified']; 3038 $return['post_date_gmt'] = $post['post_modified_gmt']; 3039 3040 return $return; 3041 } 3042 3043 /** 3044 * wp_save_revision() - Saves an already existing post as a post revision. Typically used immediately prior to post updates. 3045 * 3046 * @package WordPress 3047 * @subpackage Post Revisions 3048 * @since 2.6 3049 * 3050 * @uses _wp_put_revision() 3051 * 3052 * @param int $post_id The ID of the post to save as a revision 3053 * @return mixed null or 0 if error, new revision ID if success 3054 */ 3055 function wp_save_revision( $post_id ) { 3056 // TODO: rework autosave to use special type of post revision 3057 if ( @constant( 'DOING_AUTOSAVE' ) ) 3058 return; 3059 3060 if ( !$post = get_post( $post_id, ARRAY_A ) ) 3061 return; 3062 3063 // TODO: open this up for pages also 3064 if ( 'post' != $post->post_type ) 3065 retun; 3066 3067 return _wp_put_revision( $post ); 3068 } 3069 3070 /** 3071 * _wp_put_revision() - Inserts post data into the posts table as a post revision 3072 * 3073 * @package WordPress 3074 * @subpackage Post Revisions 3075 * @since 2.6 3076 * 3077 * @uses wp_insert_post() 3078 * 3079 * @param int|object|array $post post ID, post object OR post array 3080 * @return mixed null or 0 if error, new revision ID if success 3081 */ 3082 function _wp_put_revision( $post = null ) { 3083 if ( is_object($post) ) 3084 $post = get_object_vars( $post ); 3085 elseif ( !is_array($post) ) 3086 $post = get_post($post, ARRAY_A); 3087 3088 if ( !$post || empty($post['ID']) ) 3089 return; 3090 3091 if ( isset($post['post_type']) && 'revision' == $post_post['type'] ) 3092 return new WP_Error( 'post_type', __( 'Cannot create a revision of a revision' ) ); 3093 3094 $post = _wp_revision_fields( $post ); 3095 3096 if ( $revision_id = wp_insert_post( $post ) ) 3097 do_action( '_wp_put_revision', $revision_id ); 3098 3099 return $revision_id; 3100 } 3101 3102 /** 3103 * wp_get_revision() - Gets a post revision 3104 * 3105 * @package WordPress 3106 * @subpackage Post Revisions 3107 * @since 2.6 3108 * 3109 * @uses get_post() 3110 * 3111 * @param int|object $post post ID or post object 3112 * @param $output optional OBJECT, ARRAY_A, or ARRAY_N 3113 * @param string $filter optional sanitation filter. @see sanitize_post() 3114 * @return mixed null if error or post object if success 3115 */ 3116 function &wp_get_revision(&$post, $output = OBJECT, $filter = 'raw') { 3117 $null = null; 3118 if ( !$revision = get_post( $post, OBJECT, $filter ) ) 3119 return $revision; 3120 if ( 'revision' !== $revision->post_type ) 3121 return $null; 3122 3123 if ( $output == OBJECT ) { 3124 return $revision; 3125 } elseif ( $output == ARRAY_A ) { 3126 $_revision = get_object_vars($revision); 3127 return $_revision; 3128 } elseif ( $output == ARRAY_N ) { 3129 $_revision = array_values(get_object_vars($revision)); 3130 return $_revision; 3131 } 3132 3133 return $revision; 3134 } 3135 3136 /** 3137 * wp_restore_revision() - Restores a post to the specified revision 3138 * 3139 * Can restore a past using all fields of the post revision, or only selected fields. 3140 * 3141 * @package WordPress 3142 * @subpackage Post Revisions 3143 * @since 2.6 3144 * 3145 * @uses wp_get_revision() 3146 * @uses wp_update_post() 3147 * 3148 * @param int|object $revision_id revision ID or revision object 3149 * @param array $fields optional What fields to restore from. Defaults to all. 3150 * @return mixed null if error, false if no fields to restore, (int) post ID if success 3151 */ 3152 function wp_restore_revision( $revision_id, $fields = null ) { 3153 if ( !$revision = wp_get_revision( $revision_id, ARRAY_A ) ) 3154 return $revision; 3155 3156 if ( !is_array( $fields ) ) 3157 $fields = array_keys( _wp_revision_fields() ); 3158 3159 $update = array(); 3160 foreach( array_intersect( array_keys( $revision ), $fields ) as $field ) 3161 $update[$field] = $revision[$field]; 3162 3163 if ( !$update ) 3164 return false; 3165 3166 $update['ID'] = $revision['post_parent']; 3167 3168 if ( $post_id = wp_update_post( $update ) ) 3169 do_action( 'wp_restore_revision', $post_id, $revision['ID'] ); 3170 3171 return $post_id; 3172 } 3173 3174 /** 3175 * wp_delete_revision() - Deletes a revision. 3176 * 3177 * Deletes the row from the posts table corresponding to the specified revision 3178 * 3179 * @package WordPress 3180 * @subpackage Post Revisions 3181 * @since 2.6 3182 * 3183 * @uses wp_get_revision() 3184 * @uses wp_delete_post() 3185 * 3186 * @param int|object $revision_id revision ID or revision object 3187 * @param array $fields optional What fields to restore from. Defaults to all. 3188 * @return mixed null if error, false if no fields to restore, (int) post ID if success 3189 */ 3190 function wp_delete_revision( $revision_id ) { 3191 if ( !$revision = wp_get_revision( $revision_id ) ) 3192 return $revision; 3193 3194 if ( $delete = wp_delete_post( $revision->ID ) ) 3195 do_action( 'wp_delete_revision', $revision->ID, $revision ); 3196 3197 return $delete; 3198 } 3199 3200 /** 3201 * wp_get_post_revisions() - Returns all revisions of specified post 3202 * 3203 * @package WordPress 3204 * @subpackage Post Revisions 3205 * @since 2.6 3206 * 3207 * @uses get_children() 3208 * 3209 * @param int|object $post_id post ID or post object 3210 * @return array empty if no revisions 3211 */ 3212 function wp_get_post_revisions( $post_id = 0 ) { 3213 if ( ( !$post = get_post( $post_id ) ) || empty( $post->ID ) ) 3214 return array(); 3215 3216 if ( !$revisions = get_children( array( 'post_parent' => $post->ID, 'post_type' => 'revision' ) ) ) 3217 return array(); 3218 return $revisions; 3219 } 3220 2993 3221 ?>
Note: See TracChangeset
for help on using the changeset viewer.