Revisioning for pages from mdawaffe. see #6775

git-svn-id: http://svn.automattic.com/wordpress/trunk@7913 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2008-05-09 15:59:17 +00:00
parent 25b49b2ceb
commit 3c8cb2b079
7 changed files with 67 additions and 15 deletions

View File

@ -5,10 +5,9 @@ $messages[1] = sprintf( __( 'Page updated. Continue editing below or <a href="%s
$messages[2] = __('Custom field updated.');
$messages[3] = __('Custom field deleted.');
$messages[4] = __('Page updated.');
?>
<?php if (isset($_GET['message'])) : ?>
<div id="message" class="updated fade"><p><?php echo $messages[$_GET['message']]; ?></p></div>
<?php endif;
$notice = false;
$notices[1] = __( 'There is an autosave of this page that is more recent than the version below. <a href="%s">View the autosave</a>.' );
if (!isset($post_ID) || 0 == $post_ID) {
$form_action = 'post';
@ -20,6 +19,9 @@ if (!isset($post_ID) || 0 == $post_ID) {
$form_action = 'editpost';
$nonce_action = 'update-page_' . $post_ID;
$form_extra = "<input type='hidden' id='post_ID' name='post_ID' value='$post_ID' />";
$autosave = wp_get_autosave( $post_id );
if ( $autosave && mysql2date( 'U', $autosave->post_modified_gmt ) > mysql2date( 'U', $post->post_modified_gmt ) )
$notice = sprintf( $notices[1], get_edit_post_link( $autosave->ID ) );
}
$temp_ID = (int) $temp_ID;
@ -31,6 +33,13 @@ if ( 0 != $post_ID && $sendto == get_permalink($post_ID) )
$sendto = 'redo';
?>
<?php if ( $notice ) : ?>
<div id="notice" class="error"><p><?php echo $notice ?></p></div>
<?php endif; ?>
<?php if (isset($_GET['message'])) : ?>
<div id="message" class="updated fade"><p><?php echo $messages[$_GET['message']]; ?></p></div>
<?php endif; ?>
<form name="post" action="page.php" method="post" id="post">
<div class="wrap">
<h2><?php _e('Write Page') ?></h2>
@ -44,6 +53,7 @@ if (isset($mode) && 'bookmarklet' == $mode)
<input type="hidden" id="user-id" name="user_ID" value="<?php echo $user_ID ?>" />
<input type="hidden" id="hiddenaction" name="action" value='<?php echo $form_action ?>' />
<input type="hidden" id="originalaction" name="originalaction" value="<?php echo $form_action ?>" />
<input type="hidden" id="post_author" name="post_author" value="<?php echo attribute_escape( $post->post_author ); ?>" />
<?php echo $form_extra ?>
<input type="hidden" id="post_type" name="post_type" value="<?php echo $post->post_type ?>" />
<input type="hidden" id="original_post_status" name="original_post_status" value="<?php echo $post->post_status ?>" />
@ -282,6 +292,16 @@ if ( $authors && count( $authors ) > 1 ) :
</div>
<?php endif; ?>
<?php if ( isset($post_ID) && 0 < $post_ID && wp_get_post_revisions( $post_ID ) ) : ?>
<div id="revisionsdiv" class="postbox <?php echo postbox_classes('revisionsdiv', 'page'); ?>">
<h3><?php _e('Page Revisions'); ?></h3>
<div class="inside">
<?php wp_list_post_revisions(); ?>
</div>
</div>
<?php endif; ?>
<?php do_meta_boxes('page', 'advanced', $post); ?>
</div>

View File

@ -2,17 +2,18 @@
require_once('admin.php');
if ( !constant('WP_POST_REVISIONS') ) {
wp_redirect( 'edit.php' );
exit;
}
wp_reset_vars(array('revision', 'left', 'right', 'action'));
$revision_id = absint($revision);
$diff = absint($diff);
$left = absint($left);
$right = absint($right);
$parent_file = $redirect = 'edit.php';
$submenu_file = 'edit.php';
$title = __( 'Post Revision' );
switch ( $action ) :
case 'delete' : // stubs
@ -38,7 +39,7 @@ case 'diff' :
if ( !$right_revision = get_post( $right ) )
break;
if ( !current_user_can( 'edit_post', $left_revision->ID ) || !current_user_can( 'edit_post', $right_revision->ID ) )
if ( !current_user_can( 'read_post', $left_revision->ID ) || !current_user_can( 'read_post', $right_revision->ID ) )
break;
// Don't allow reverse diffs?
@ -80,7 +81,7 @@ default :
if ( !$post = get_post( $revision->post_parent ) )
break;
if ( !current_user_can( 'edit_post', $revision->ID ) || !current_user_can( 'edit_post', $post->ID ) )
if ( !current_user_can( 'read_post', $revision->ID ) || !current_user_can( 'read_post', $post->ID ) )
break;
$post_title = '<a href="' . get_edit_post_link() . '">' . get_the_title() . '</a>';
@ -95,11 +96,22 @@ default :
break;
endswitch;
if ( !$redirect && !in_array( $post->post_type, array( 'post', 'page' ) ) )
$redirect = 'edit.php';
if ( $redirect ) {
wp_redirect( $redirect );
exit;
}
if ( 'page' == $post->post_type ) {
$submenu_file = 'edit-pages.php';
$title = __( 'Page Revisions' );
} else {
$submenu_file = 'edit.php';
$title = __( 'Post Revisions' );
}
// Converts post_author ID# into name
add_filter( '_wp_revision_field_post_author', 'get_author_name' );
@ -163,7 +175,7 @@ endif;
<br class="clear" />
<h2><?php _e( 'Post Revisions' ); ?></h2>
<h2><?php echo $title; ?></h2>
<?php

View File

@ -180,9 +180,9 @@ var autosave = function() {
post_data["comment_status"] = 'open';
if ( jQuery("#ping_status").attr("checked") )
post_data["ping_status"] = 'open';
if ( jQuery("#excerpt") )
if ( jQuery("#excerpt").size() )
post_data["excerpt"] = jQuery("#excerpt").val();
if ( jQuery("#post_author") )
if ( jQuery("#post_author").size() )
post_data["post_author"] = jQuery("#post_author").val();
// Don't run while the TinyMCE spellcheck is on. Why? Who knows.

View File

@ -641,7 +641,11 @@ function wp_list_post_revisions( $post_id = 0, $args = null ) { // TODO? split i
$rows = '';
$class = false;
$can_edit_post = current_user_can( 'edit_post', $post->ID );
foreach ( $revisions as $revision ) {
if ( !current_user_can( 'read_post', $revision->ID ) )
continue;
$date = wp_post_revision_title( $revision );
$name = get_author_name( $revision->post_author );
@ -654,7 +658,7 @@ function wp_list_post_revisions( $post_id = 0, $args = null ) { // TODO? split i
$class = $class ? '' : " class='alternate'";
if ( $post->ID != $revision->ID && current_user_can( 'edit_post', $post->ID ) )
if ( $post->ID != $revision->ID && $can_edit_post )
$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>';
else
$actions = '';

View File

@ -957,6 +957,12 @@ function wp_delete_post($postid = 0) {
$wpdb->update( $wpdb->posts, $parent_data, $parent_where + array( 'post_type' => 'page' ) );
}
// Do raw query. wp_get_post_revisions() is filtered
$revision_ids = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_parent = %d AND post_type = 'revision'", $postid ) );
// Use wp_delete_post (via wp_delete_revision) again. Ensures any meta/misplaced data gets cleaned up.
foreach ( $revision_ids as $revision_id )
wp_delete_revision( $revision_id );
// Point all attachments to this post up one level
$wpdb->update( $wpdb->posts, $parent_data, $parent_where + array( 'post_type' => 'attachment' ) );
@ -3022,6 +3028,9 @@ function wp_save_revision( $post_id ) {
if ( @constant( 'DOING_AUTOSAVE' ) )
return;
if ( !constant('WP_POST_REVISIONS') )
return;
if ( !$post = get_post( $post_id, ARRAY_A ) )
return;
@ -3227,6 +3236,8 @@ function wp_delete_revision( $revision_id ) {
* @return array empty if no revisions
*/
function wp_get_post_revisions( $post_id = 0 ) {
if ( !constant('WP_POST_REVISIONS') )
return array();
if ( ( !$post = get_post( $post_id ) ) || empty( $post->ID ) )
return array();
if ( !$revisions = get_children( array( 'post_parent' => $post->ID, 'post_type' => 'revision', 'post_status' => 'inherit' ) ) )

View File

@ -47,7 +47,7 @@ class WP_Scripts {
'broken' => __('An unidentified error has occurred.')
) );
$this->add( 'autosave', '/wp-includes/js/autosave.js', array('schedule', 'wp-ajax-response'), '20080507' );
$this->add( 'autosave', '/wp-includes/js/autosave.js', array('schedule', 'wp-ajax-response'), '20080508' );
$this->add( 'wp-ajax', '/wp-includes/js/wp-ajax.js', array('prototype'), '20070306');
$this->localize( 'wp-ajax', 'WPAjaxL10n', array(

View File

@ -376,6 +376,11 @@ if ( defined('WP_CACHE') && function_exists('wp_cache_postload') )
do_action('plugins_loaded');
$default_constants = array( 'WP_POST_REVISIONS' => true );
foreach ( $default_constants as $c => $v )
@define( $c, $v ); // will fail if the constant is already defined
unset($default_constants, $c, $v);
// If already slashed, strip.
if ( get_magic_quotes_gpc() ) {
$_GET = stripslashes_deep($_GET );