Index: wp-includes/post-template.php
===================================================================
--- wp-includes/post-template.php (revision 23582)
+++ wp-includes/post-template.php (working copy)
@@ -1468,7 +1468,27 @@
else :
echo "
\n";
echo $rows;
+ if ( $restored_from_meta = get_post_meta( $post->ID, '_post_restored_from', true ) ) {
+ $author = get_the_author_meta( 'display_name', $restored_from_meta[ 'restored_by_user' ] );
+ /* translators: revision date format, see http://php.net/date */
+ $datef = _x( 'j F, Y @ G:i:s', 'revision date format');
+ $date = date_i18n( $datef, strtotime( $restored_from_meta[ 'restored_time' ] ) );
+ $timesince = human_time_diff( $restored_from_meta[ 'restored_time' ], current_time( 'timestamp' ) ) . __( ' ago ' );
+ ?>
+
+
+
+
+ ";
+ }
+
endif;
}
Index: wp-includes/pluggable.php
===================================================================
--- wp-includes/pluggable.php (revision 23582)
+++ wp-includes/pluggable.php (working copy)
@@ -1722,7 +1722,7 @@
$r = "\n";
- if ( isset( $args[ 'showsplitview' ] ) && 'true' == $args[ 'showsplitview' ] ) {
+ if ( ! empty( $args[ 'show_split_view' ] ) ) {
$r .= "";
} else {
$r .= "";
Index: wp-admin/includes/ajax-actions.php
===================================================================
--- wp-admin/includes/ajax-actions.php (revision 23582)
+++ wp-admin/includes/ajax-actions.php (working copy)
@@ -2131,133 +2131,150 @@
function wp_ajax_revisions_data() {
check_ajax_referer( 'revisions-ajax-nonce', 'nonce' );
- $compareto = isset( $_GET['compareto'] ) ? absint( $_GET['compareto'] ) : 0;
- $showautosaves = isset( $_GET['showautosaves'] ) ? $_GET['showautosaves'] : '';
- $showsplitview = isset( $_GET['showsplitview'] ) ? $_GET['showsplitview'] : '';
- $postid = isset( $_GET['post_id'] ) ? absint( $_GET['post_id'] ) : '';
+ $compare_to = isset( $_GET['compare_to'] ) ? absint( $_GET['compare_to'] ) : 0;
+ $show_autosaves = isset( $_GET['show_autosaves'] ) ? $_GET['show_autosaves'] : '';
+ $show_split_view = isset( $_GET['show_split_view'] ) ? $_GET['show_split_view'] : '';
+ $post_id = isset( $_GET['post_id'] ) ? absint( $_GET['post_id'] ) : '';
+ $right_handle_at = isset( $_GET['right_handle_at'] ) ? $_GET['right_handle_at'] : 0;
+ $left_handle_at = isset( $_GET['left_handle_at'] ) ? $_GET['left_handle_at'] : 0;
- $comparetwomode = ( '' == $postid ) ? false : true;
+ $compare_two_mode = ( '' == $post_id ) ? false : true;
//
- //TODO: currently code returns all possible comparisons for the indicated 'compareto' revision
+ //TODO: currently code returns all possible comparisons for the indicated 'compare_to' revision
//however, the front end prevents users from pulling the right handle past the left or the left pass the right,
//so only the possible diffs need be generated
//
$alltherevisions = array();
- if ( '' == $postid )
- $postid = $compareto;
+ if ( '' == $post_id )
+ $post_id = $compare_to;
- if ( ! current_user_can( 'read_post', $postid ) )
+ if ( ! current_user_can( 'read_post', $post_id ) )
continue;
- if ( ! $revisions = wp_get_post_revisions( $postid ) )
+ if ( ! $revisions = wp_get_post_revisions( $post_id ) )
return;
//if we are comparing two revisions, the first 'revision' represented by the leftmost
//slider position is the current revision, prepend a comparison to this revision
- if ( $comparetwomode )
- array_unshift( $revisions, get_post( $postid ) );
+ if ( $compare_two_mode )
+ array_unshift( $revisions, get_post( $post_id ) );
- $count = 1;
+ $count = -1;
foreach ( $revisions as $revision ) :
- if ( 'true' != $showautosaves && wp_is_post_autosave( $revision ) )
+ if ( ! empty( $show_autosaves ) && wp_is_post_autosave( $revision ) )
+ continue;
+
+ $revision_from_date_author = '';
+ $count++;
+ // return blank data for diffs to the left of the left handle (for right handel model)
+ // or to the right of the right handle (for left handel model)
+ if ( ( 0 != $left_handle_at && $count <= $left_handle_at ) ||
+ ( 0 != $right_handle_at && $count > $right_handle_at )) {
+ $alltherevisions[] = array (
+ 'ID' => $revision->ID,
+ 'revision_date_author' => '',
+ 'revisiondiff' => '',
+ 'restoreaction' => '',
+ 'revision_from_date_author' => ''
+ );
+
continue;
+ }
+
- $revision_from_date_author = '';
+ $left_revision = get_post( $compare_to );
+ $right_revision = get_post( $revision );
+ $author = get_the_author_meta( 'display_name', $revision->post_author );
+ /* translators: revision date format, see http://php.net/date */
+ $datef = _x( 'j F, Y @ G:i:s', 'revision date format');
- $left_revision = get_post( $compareto );
- $right_revision = get_post( $revision );
+ $gravatar = get_avatar( $revision->post_author, 18 );
- $author = get_the_author_meta( 'display_name', $revision->post_author );
- /* translators: revision date format, see http://php.net/date */
- $datef = _x( 'j F, Y @ G:i:s', 'revision date format');
+ $date = date_i18n( $datef, strtotime( $revision->post_modified ) );
+ $revision_date_author = sprintf(
+ '%s %s, %s %s (%s)',
+ $gravatar,
+ $author,
+ human_time_diff( strtotime( $revision->post_modified ), current_time( 'timestamp' ) ),
+ __( ' ago ' ),
+ $date
+ );
- $gravatar = get_avatar( $revision->post_author, 18 );
+ if ( $compare_two_mode ) {
+ $compare_to_gravatar = get_avatar( $left_revision->post_author, 18 );
+ $compare_to_author = get_the_author_meta( 'display_name', $left_revision->post_author );
+ $compare_to_date = date_i18n( $datef, strtotime( $left_revision->post_modified ) );
- $date = date_i18n( $datef, strtotime( $revision->post_modified ) );
- $revision_date_author = sprintf(
- '%s %s, %s %s (%s)',
- $gravatar,
- $author,
- human_time_diff( strtotime( $revision->post_modified ), current_time( 'timestamp' ) ),
- __( ' ago ' ),
- $date
- );
+ $revision_from_date_author = sprintf(
+ '%s %s, %s %s (%s)',
+ $compare_to_gravatar,
+ $compare_to_author,
+ human_time_diff( strtotime( $left_revision->post_modified ), current_time( 'timestamp' ) ),
+ __( ' ago ' ),
+ $compare_to_date
+ );
+ }
- if ( $comparetwomode ) {
- $compareto_gravatar = get_avatar( $left_revision->post_author, 18 );
- $compareto_author = get_the_author_meta( 'display_name', $left_revision->post_author );
- $compareto_date = date_i18n( $datef, strtotime( $left_revision->post_modified ) );
-
- $revision_from_date_author = sprintf(
- '%s %s, %s %s (%s)',
- $compareto_gravatar,
- $compareto_author,
- human_time_diff( strtotime( $left_revision->post_modified ), current_time( 'timestamp' ) ),
- __( ' ago ' ),
- $compareto_date
+ $restoreaction = wp_nonce_url(
+ add_query_arg(
+ array( 'revision' => $revision->ID,
+ 'action' => 'restore' ),
+ '/wp-admin/revision.php'
+ ),
+ "restore-post_{$compare_to}|{$revision->ID}"
);
- }
- $restoreaction = wp_nonce_url(
- add_query_arg(
- array( 'revision' => $revision->ID,
- 'action' => 'restore' ),
- '/wp-admin/revision.php'
- ),
- "restore-post_{$compareto}|{$revision->ID}"
- );
+ //
+ //make sure the left revision is the most recent
+ //
+ if ( strtotime( $right_revision->post_modified_gmt ) < strtotime( $left_revision->post_modified_gmt ) ) {
+ $temp = $left_revision;
+ $left_revision = $right_revision;
+ $right_revision = $temp;
+ }
- //
- //make sure the left revision is the most recent
- //
- if ( strtotime( $right_revision->post_modified_gmt ) < strtotime( $left_revision->post_modified_gmt ) ) {
- $temp = $left_revision;
- $left_revision = $right_revision;
- $right_revision = $temp;
- }
+ //
+ //compare from left to right, passed from application
+ //
+ $content='';
+ foreach ( array_keys( _wp_post_revision_fields() ) as $field ) {
+ $left_content = apply_filters( "_wp_post_revision_field_$field", $left_revision->$field, $field, $left_revision, 'left' );
+ $right_content = apply_filters( "_wp_post_revision_field_$field", $right_revision->$field, $field, $right_revision, 'right' );
- //
- //compare from left to right, passed from application
- //
- $content='';
- foreach ( array_keys( _wp_post_revision_fields() ) as $field ) {
- $left_content = apply_filters( "_wp_post_revision_field_$field", $left_revision->$field, $field, $left_revision, 'left' );
- $right_content = apply_filters( "_wp_post_revision_field_$field", $right_revision->$field, $field, $right_revision, 'right' );
+ add_filter( "_wp_post_revision_field_$field", 'wp_kses_post' );
- add_filter( "_wp_post_revision_field_$field", 'wp_kses_post' );
+ $args = array();
- $args = array();
+ if ( ! empty( $show_split_view ) )
+ $args = array( 'show_split_view' => true );
- if ( 'true' == $showsplitview )
- $args = array( 'showsplitview' => 'true' );
+ $content .= wp_text_diff( $left_content, $right_content, $args );
+ }
- $content .= wp_text_diff( $left_content, $right_content, $args );
- }
+ //if we are comparing two revisions
+ //and we are on the matching revision
+ //add an error revision indicating unable to compare to self
+ if ( $compare_two_mode && $compare_to == $revision->ID )
+ $alltherevisions[] = array (
+ 'ID' => $revision->ID,
+ 'revision_date_author' => $revision_date_author,
+ 'revisiondiff' => sprintf('%s
', __( 'Cannot compare revision to itself' ) ),
+ 'restoreaction' => urldecode( $restoreaction ),
+ 'revision_from_date_author' => ''
+ );
- //if we are comparing two revisions
- //and we are on the matching revision
- //add an error revision indicating unable to compare to self
- if ( $comparetwomode && $compareto == $revision->ID )
- $alltherevisions[] = array (
- 'ID' => $revision->ID,
- 'revision_date_author' => $revision_date_author,
- 'revisiondiff' => sprintf('%s
', __( 'Cannot compare revision to itself' ) ),
- 'restoreaction' => urldecode( $restoreaction ),
- 'revision_from_date_author' => ''
- );
+ //add to the return data only if there is a difference
+ if ( '' != $content )
+ $alltherevisions[] = array (
+ 'ID' => $revision->ID,
+ 'revision_date_author' => $revision_date_author,
+ 'revisiondiff' => $content,
+ 'restoreaction' => urldecode( $restoreaction ),
+ 'revision_from_date_author' => $revision_from_date_author
+ );
- //add to the return data only if there is a difference
- if ( '' != $content )
- $alltherevisions[] = array (
- 'ID' => $revision->ID,
- 'revision_date_author' => $revision_date_author,
- 'revisiondiff' => $content,
- 'restoreaction' => urldecode( $restoreaction ),
- 'revision_from_date_author' => $revision_from_date_author
- );
-
endforeach;
echo json_encode( $alltherevisions );
Index: wp-admin/js/revisions.js
===================================================================
--- wp-admin/js/revisions.js (revision 23582)
+++ wp-admin/js/revisions.js (working copy)
@@ -30,7 +30,7 @@
_left_diff : 0,
_right_diff : 1,
_autosaves : false,
- _showsplitview : true,
+ _show_split_view : true,
_compareoneortwo : 1,
left_model_loading : false, //keep track of model loads
right_model_loading : false, //disallow slider interaction, also repeat loads, while loading
@@ -74,9 +74,9 @@
reloadmodelsingle : function() {
var self = this;
- self._revisions.url = ajaxurl + '?action=revisions-data&compareto=' + wpRevisionsSettings.post_id +
- '&showautosaves=' + self.self_autosaves +
- '&showsplitview=' + REVAPP._showsplitview +
+ self._revisions.url = ajaxurl + '?action=revisions-data&compare_to=' + wpRevisionsSettings.post_id +
+ '&show_autosaves=' + self._autosaves +
+ '&show_split_view=' + REVAPP._show_split_view +
'&nonce=' + wpRevisionsSettings.nonce;
self.start_right_model_loading();
this._revisions.fetch({ //reload revision data
@@ -108,34 +108,40 @@
self._left_handle_revisions = new wp.revisions.Collection();
self._right_handle_revisions = new wp.revisions.Collection();
- if ( 0 == self._left_diff ) {
+ if ( 0 == self._left_diff ) {
self._right_handle_revisions.url =
ajaxurl +
- '?action=revisions-data&compareto=' + wpRevisionsSettings.post_id +
+ '?action=revisions-data&compare_to=' + wpRevisionsSettings.post_id +
'&post_id=' + wpRevisionsSettings.post_id +
- '&showautosaves=' + self._autosaves +
- '&showsplitview=' + self._showsplitview +
+ '&show_autosaves=' + self._autosaves +
+ '&show_split_view=' + self._show_split_view +
'&nonce=' + wpRevisionsSettings.nonce;
} else {
self._right_handle_revisions.url =
ajaxurl +
- '?action=revisions-data&compareto=' + self._revisions.at( self._left_diff - 1 ).get( 'ID' ) +
+ '?action=revisions-data&compare_to=' + self._revisions.at( self._left_diff - 1 ).get( 'ID' ) +
'&post_id=' + wpRevisionsSettings.post_id +
- '&showautosaves=' + self._autosaves +
- '&showsplitview=' + self._showsplitview +
- '&nonce=' + wpRevisionsSettings.nonce;
+ '&show_autosaves=' + self._autosaves +
+ '&show_split_view=' + self._show_split_view +
+ '&nonce=' + wpRevisionsSettings.nonce +
+ '&left_handle_at=' + (self._left_diff ) ;
}
self._left_handle_revisions.url =
ajaxurl +
- '?action=revisions-data&compareto=' + self._revisions.at( self._right_diff - 1 ).get( 'ID' ) +
+ '?action=revisions-data&compare_to=' + self._revisions.at( self._right_diff - 1 ).get( 'ID' ) +
'&post_id=' + wpRevisionsSettings.post_id +
- '&showautosaves=' + self._autosaves +
- '&showsplitview=' + self._showsplitview +
- '&nonce=' + wpRevisionsSettings.nonce;
+ '&show_autosaves=' + self._autosaves +
+ '&show_split_view=' + self._show_split_view +
+ '&nonce=' + wpRevisionsSettings.nonce +
+ '&right_handle_at=' + (self._right_diff - 1);
+ //console.log (self._left_handle_revisions.url);
self._left_handle_revisions.fetch({
+ /*
+ //TODO - add a load progress bar for fetch
+ //
xhr: function() {
var xhr = $.ajaxSettings.xhr();
xhr.onprogress = self.handleProgress;
@@ -149,7 +155,7 @@
window.console && console.log( Math.round( percentComplete * 100) + "%" );
}
},
-
+ */
success : function(){
self.stop_left_model_loading();
},
@@ -166,8 +172,8 @@
self.stop_right_model_loading();
},
- error : function () {
- window.console && console.log( 'Error loading revision data' );
+ error : function ( response ) {
+ window.console && console.log( 'Error loading revision data - ' + response.toSource() );
self.stop_right_model_loading();
}
});
@@ -195,7 +201,6 @@
revisionDiffSetup : function() {
var self = this, slider;
-
this._revisionView = new wp.revisions.views.View({
model : this._revisions
});
@@ -206,10 +211,13 @@
});
this._revisionsInteractions.render();
+ /*
+ //Options hidden for now, moving to screen options
this._revisionsOptions = new wp.revisions.views.Options({
model : this._revisions
});
this._revisionsOptions.render();
+ */
}
})
@@ -217,7 +225,8 @@
wp.revisions.Collection = Backbone.Collection.extend({
model : wp.revisions.Model,
- url : ajaxurl + '?action=revisions-data&compareto=' + wpRevisionsSettings.post_id + '&showautosaves=false&showsplitview=true&nonce=' + wpRevisionsSettings.nonce
+ url : ajaxurl + '?action=revisions-data&compare_to=' + wpRevisionsSettings.post_id +
+ '&show_autosaves=false&show_split_view=true&nonce=' + wpRevisionsSettings.nonce
});
_.extend(wp.revisions.views, {
@@ -260,12 +269,12 @@
) );
}
}
- } else { //end compare two revisions mode, eg only one slider handel
+ } else { //end compare two revisions mode, eg only one slider handle
this.comparetwochecked = '';
if ( this.model.at( REVAPP._right_diff - 1 ) ) {
addhtml = this.template( _.extend(
- this.model.at( REVAPP._right_diff-1 ).toJSON(),
- { comparetwochecked : this.comparetwochecked } //keep the checkmark checked
+ this.model.at( REVAPP._right_diff - 1 ).toJSON(),
+ { comparetwochecked : this.comparetwochecked } //keep the checkmark unchecked
) );
}
}
@@ -345,10 +354,10 @@
var self = this;
if ( $( 'input#showsplitview' ).is( ':checked' ) ) {
- REVAPP._showsplitview = 'true';
+ REVAPP._show_split_view = 'true';
$('.revisiondiffcontainer').addClass('diffsplit');
} else {
- REVAPP._showsplitview = '';
+ REVAPP._show_split_view = '';
$('.revisiondiffcontainer').removeClass('diffsplit');
}
@@ -364,10 +373,16 @@
tagName : 'revisionvinteract',
className : 'revisionvinteract-container',
template : wp.template('revisionvinteract'),
+ _restoreword : '',
initialize : function() {
+ this._restoreword = $( 'input#restore' ).attr( 'value' );
},
+ reset_restore_button : function() {
+ $( 'input#restore' ).attr( 'value', this._restoreword + ' ' + REVAPP._revisions.at( REVAPP._right_diff - 1 ).get( 'ID' ) );
+ },
+
render : function() {
var self = this;
@@ -376,10 +391,11 @@
$( '#diff_max, #diff_maxof' ).html( this.model.length );
$( '#diff_count' ).html( REVAPP._right_diff );
$( '#diff_left_count_inner' ).html( 0 == REVAPP._left_diff ? '' : 'revision' + REVAPP._left_diff );
+ self.reset_restore_button();
var modelcount = REVAPP._revisions.length;
- slider = $("#slider");
+ slider = $( "#slider" );
if ( 1 == REVAPP._compareoneortwo ) {
//set up the slider with a single handle
slider.slider({
@@ -396,6 +412,7 @@
REVAPP._right_diff =( ui.value+1 );
$( '#diff_count' ).html( REVAPP._right_diff );
REVAPP._revisionView.render();
+ self.reset_restore_button();
}
});
$( '.revisiondiffcontainer' ).removeClass( 'comparetwo' );
@@ -473,6 +490,7 @@
}
REVAPP._revisionView.render(); //render the diff view
+ self.reset_restore_button();
},
//when the user stops sliding in 2 handle mode, recalculate diffs
@@ -480,7 +498,7 @@
if ( 2 == REVAPP._compareoneortwo ) {
//calculate and generate a diff for comparing to the left handle
//and the right handle, swap out when dragging
- if ( ! (REVAPP.left_model_loading && REVAPP.right_model.loading ) ) {
+ if ( ! ( REVAPP.left_model_loading && REVAPP.right_model_loading ) ) {
REVAPP.reloadleftright();
}
}
@@ -507,6 +525,7 @@
$( '#diff_count' ).html( REVAPP._right_diff );
$( '#slider' ).slider( 'value', REVAPP._right_diff - 1 ).trigger( 'slide' );
+ this.reset_restore_button();
},
//go the the previous revision
@@ -518,6 +537,7 @@
$( '#diff_count' ).html( REVAPP._right_diff );
$( '#slider' ).slider( 'value', REVAPP._right_diff - 1 ).trigger( 'slide' );
+ this.reset_restore_button();
}
})
});
Index: wp-admin/revision.php
===================================================================
--- wp-admin/revision.php (revision 23582)
+++ wp-admin/revision.php (working copy)
@@ -10,37 +10,45 @@
require_once('./admin.php');
wp_reset_vars( array( 'revision', 'action' ) );
-$revision_id = absint($revision);
+$revision_id = absint( $revision );
$redirect = 'edit.php';
switch ( $action ) :
case 'restore' :
- if ( !$revision = wp_get_post_revision( $revision_id ) )
+ if ( ! $revision = wp_get_post_revision( $revision_id ) )
break;
- if ( !current_user_can( 'edit_post', $revision->post_parent ) )
+ if ( ! current_user_can( 'edit_post', $revision->post_parent ) )
break;
- if ( !$post = get_post( $revision->post_parent ) )
+ if ( ! $post = get_post( $revision->post_parent ) )
break;
// Revisions disabled and we're not looking at an autosave
- if ( ( ! WP_POST_REVISIONS || !post_type_supports($post->post_type, 'revisions') ) && !wp_is_post_autosave( $revision ) ) {
+ if ( ( ! WP_POST_REVISIONS || ! post_type_supports( $post->post_type, 'revisions' ) ) && ! wp_is_post_autosave( $revision ) ) {
$redirect = 'edit.php?post_type=' . $post->post_type;
break;
}
check_admin_referer( "restore-post_{$post->ID}|{$revision->ID}" );
+ //store revision event in post meta
+ $restore_details = array(
+ 'restored_revision_id' => $revision->ID,
+ 'restored_by_user' => get_current_user_id(),
+ 'restored_time' => time()
+ );
+ wp_update_post_meta( $post->ID, '_post_restored_from', $restore_details );
+
wp_restore_post_revision( $revision->ID );
$redirect = add_query_arg( array( 'message' => 5, 'revision' => $revision->ID ), get_edit_post_link( $post->ID, 'url' ) );
break;
case 'view' :
case 'edit' :
default :
- if ( !$revision = wp_get_post_revision( $revision_id ) )
+ if ( ! $revision = wp_get_post_revision( $revision_id ) )
break;
- if ( !$post = get_post( $revision->post_parent ) )
+ if ( ! $post = get_post( $revision->post_parent ) )
break;
- if ( !current_user_can( 'read_post', $revision->ID ) || !current_user_can( 'read_post', $post->ID ) )
+ if ( ! current_user_can( 'read_post', $revision->ID ) || ! current_user_can( 'read_post', $post->ID ) )
break;
// Revisions disabled and we're not looking at an autosave
@@ -59,16 +67,16 @@
endswitch;
// Empty post_type means either malformed object found, or no valid parent was found.
-if ( !$redirect && empty($post->post_type) )
+if ( ! $redirect && empty( $post->post_type ) )
$redirect = 'edit.php';
-if ( !empty($redirect) ) {
+if ( ! empty( $redirect ) ) {
wp_redirect( $redirect );
exit;
}
// This is so that the correct "Edit" menu item is selected.
-if ( !empty($post->post_type) && 'post' != $post->post_type )
+if ( ! empty( $post->post_type ) && 'post' != $post->post_type )
$parent_file = $submenu_file = 'edit.php?post_type=' . $post->post_type;
else
$parent_file = $submenu_file = 'edit.php';
@@ -83,10 +91,11 @@
+ID );
+?>
-
-
@@ -94,10 +103,7 @@
-
-ID );
-?>
+
@@ -107,7 +113,7 @@
{{{ data.revision_from_date_author }}}
{{{ data.revision_date_author }}}
-
+
@@ -119,8 +125,8 @@