From 3c8cb2b0795f35636086b640d03556352b0b05e1 Mon Sep 17 00:00:00 2001 From: ryan Date: Fri, 9 May 2008 15:59:17 +0000 Subject: [PATCH] Revisioning for pages from mdawaffe. see #6775 git-svn-id: http://svn.automattic.com/wordpress/trunk@7913 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/edit-page-form.php | 28 ++++++++++++++++++++++++---- wp-admin/revision.php | 26 +++++++++++++++++++------- wp-includes/js/autosave.js | 4 ++-- wp-includes/post-template.php | 6 +++++- wp-includes/post.php | 11 +++++++++++ wp-includes/script-loader.php | 2 +- wp-settings.php | 5 +++++ 7 files changed, 67 insertions(+), 15 deletions(-) diff --git a/wp-admin/edit-page-form.php b/wp-admin/edit-page-form.php index ef75406673..53e0a188e7 100644 --- a/wp-admin/edit-page-form.php +++ b/wp-admin/edit-page-form.php @@ -5,10 +5,9 @@ $messages[1] = sprintf( __( 'Page updated. Continue editing below or

-View the autosave
.' ); 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 = ""; + $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'; ?> + +

+ + +

+ +

@@ -44,6 +53,7 @@ if (isset($mode) && 'bookmarklet' == $mode) + @@ -282,6 +292,16 @@ if ( $authors && count( $authors ) > 1 ) :
+ +
+

+
+ +
+
+ + + diff --git a/wp-admin/revision.php b/wp-admin/revision.php index a2ddef5631..b5e0d31f02 100644 --- a/wp-admin/revision.php +++ b/wp-admin/revision.php @@ -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 = '' . get_the_title() . ''; @@ -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;
-

+

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 = 'ID|$revision->ID" ) . '">' . __( 'Restore' ) . ''; else $actions = ''; diff --git a/wp-includes/post.php b/wp-includes/post.php index 7733794f8a..977e0823fd 100644 --- a/wp-includes/post.php +++ b/wp-includes/post.php @@ -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' ) ) ) diff --git a/wp-includes/script-loader.php b/wp-includes/script-loader.php index b9208a0dfc..7f95f0f25d 100644 --- a/wp-includes/script-loader.php +++ b/wp-includes/script-loader.php @@ -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( diff --git a/wp-settings.php b/wp-settings.php index 1480288e0a..cfb6844706 100644 --- a/wp-settings.php +++ b/wp-settings.php @@ -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 );