Revisions: Updates to the new Revisions UI.

Various Updates including:
 * i18n fixes
 * Added tracking of what revision ID was restored
 * async fetching of diffs so that slider works sooner even with many revisions

See #23497 props adamsilverstein, ethitter


git-svn-id: http://core.svn.wordpress.org/trunk@23639 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Peter Westwood 2013-03-07 15:32:26 +00:00
parent 082e9342b7
commit 51db623107
6 changed files with 350 additions and 230 deletions

View File

@ -3722,10 +3722,25 @@ span#diff_left_count_inner,
.leftmodelloading #modelsloading,
.rightmodelloading #modelsloading,
.leftmodelloading #modelsloading .spinner,
.rightmodelloading #modelsloading .spinner {
.rightmodelloading #modelsloading .spinner,
{
display: inline;
}
.diff-loading {
margin-top: 50px;
width: 100%;
height: 200px;
}
.diff-loading .spinner
{
clear: both;
margin-left: auto;
margin-right: auto;
display: block;
float: none;
}
#difftitlefrom {
float: left;
display: none;

View File

@ -2131,84 +2131,53 @@ function wp_ajax_nopriv_heartbeat() {
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;
$single_revision_id = isset( $_GET['single_revision_id'] ) ? $_GET['single_revision_id'] : 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 ) );
$count = 1;
foreach ( $revisions as $revision ) :
if ( 'true' != $showautosaves && wp_is_post_autosave( $revision ) )
continue;
$revision_from_date_author = '';
$left_revision = get_post( $compareto );
$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');
$gravatar = get_avatar( $revision->post_author, 18 );
//single model fetch mode
if ( 0 != $single_revision_id ) {
$left_revision = get_post( $compare_to );
$right_revision = get_post( $single_revision_id );
$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
);
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 ) );
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 ) );
$revision_from_date_author = sprintf(
'%s %s, %s %s (%s)',
$compareto_gravatar,
$compareto_author,
$compare_to_gravatar,
$compare_to_author,
human_time_diff( strtotime( $left_revision->post_modified ), current_time( 'timestamp' ) ),
__( ' ago ' ),
$compareto_date
$compare_to_date
);
}
$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
//
@ -2230,32 +2199,70 @@ function wp_ajax_revisions_data() {
$args = array();
if ( 'true' == $showsplitview )
$args = array( 'showsplitview' => 'true' );
if ( ! empty( $show_split_view ) )
$args = array( 'show_split_view' => true );
$content .= wp_text_diff( $left_content, $right_content, $args );
}
$content = '' == $content ? __( 'No difference' ) : $content;
$alltherevisions = array (
'revisiondiff' => $content
);
echo json_encode( $alltherevisions );
exit();
}
//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 )
//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 ( $compare_two_mode )
array_unshift( $revisions, get_post( $post_id ) );
$count = -1;
foreach ( $revisions as $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' => $revision_date_author,
'revisiondiff' => sprintf('<div id="selfcomparisonerror">%s</div>', __( '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 )
continue;
}
$gravatar = get_avatar( $revision->post_author, 18 );
$author = get_the_author_meta( 'display_name', $revision->post_author );
$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
);
$restoreaction = wp_nonce_url(
add_query_arg(
array( 'revision' => $revision->ID,
'action' => 'restore' ),
admin_url( 'revision.php' )
),
"restore-post_{$compare_to}|{$revision->ID}"
);
$alltherevisions[] = array (
'ID' => $revision->ID,
'revision_date_author' => $revision_date_author,
'revisiondiff' => $content,
'revision_from_date_author' => $revision_from_date_author,
'restoreaction' => urldecode( $restoreaction ),
'revision_from_date_author' => $revision_from_date_author
'revision_toload' => true
);
endforeach;

View File

@ -6,16 +6,22 @@ window.wp = window.wp || {};
views : {},
Model : Backbone.Model.extend({
idAttribute : 'ID',
urlRoot : ajaxurl + '?action=revisions-data&compare_to=' + wpRevisionsSettings.post_id +
'&show_autosaves=false&show_split_view=true&nonce=' + wpRevisionsSettings.nonce,
defaults: {
ID : 0,
revision_date_author : '',
revisiondiff : '',
restoreaction: '',
diff_max : 0,
diff_count : 0,
diff_revision_to : 0,
revisiondiff : '<div class="diff-loading"><div class="spinner"></div></div>',
restoreaction : '',
revision_from_date_author : '',
revision_toload : false
},
url : function() {
return this.urlRoot + '&single_revision_id=' + this.id;
}
}),
app: _.extend({}, Backbone.Events),
@ -30,42 +36,68 @@ window.wp = window.wp || {};
_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
_left_model_loading : false, //keep track of model loads
_right_model_loading : false, //disallow slider interaction, also repeat loads, while loading
//TODO add ability to arrive on specific revision
routes : {
"viewrevision/:revision": "viewrevision",
},
viewrevision : function( revision ) {
//coming soon
},
reload_toload_revisions : function( model_collection, reverse_direction ) {
var self = this;
var revisions_to_load = model_collection.where( { revision_toload : true } );
//console.log(revisions_to_load);
var delay=0;
_.each(revisions_to_load, function( the_model ) {
the_model.urlRoot = model_collection.url;
_.delay( function() {
the_model.fetch( {
update : true,
add : false,
remove : false,
//async : false,
success : function( model ) {
//console.log(model.get( 'ID' ) +'-'+self._revisions.at( self._right_diff ).get( 'ID' ));
if ( model.get( 'ID' ) === self._revisions.at( self._right_diff - 1 ).get( 'ID' ) ) { //reload if current model refreshed
//console.log('render');
self._revisionView.render();
}
}
} );
}, delay ) ;
delay = delay + 200; //stagger model loads by 200 ms to avoid hammering server with requests
}
);
},
start_left_model_loading : function() {
this.left_model_loading = true;
this._left_model_loading = true;
$('.revisiondiffcontainer').addClass('leftmodelloading');
},
stop_left_model_loading : function() {
this.left_model_loading = false;
this._left_model_loading = false;
$('.revisiondiffcontainer').removeClass('leftmodelloading');
},
start_right_model_loading : function() {
this.right_model_loading = true;
this._right_model_loading = true;
$('.revisiondiffcontainer').addClass('rightmodelloading');
},
stop_right_model_loading : function() {
this.right_model_loading = false;
this._right_model_loading = false;
$('.revisiondiffcontainer').removeClass('rightmodelloading');
},
reloadmodel : function() {
if ( 2 == this._compareoneortwo ) {
if ( 2 === this._compareoneortwo ) {
this.reloadleftright();
} else {
this.reloadmodelsingle();
@ -74,9 +106,9 @@ window.wp = window.wp || {};
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
@ -85,92 +117,89 @@ window.wp = window.wp || {};
var revisioncount = self._revisions.length;
if ( self._right_diff > revisioncount ) //if right handle past rightmost, move
self._right_diff = revisioncount;
//TODO add a test for matchind left revision and push left, testing
//also reset the slider values here
self._revisionView.render();
$( '#slider' ).slider( 'option', 'max', revisioncount-1 ); //TODO test this
self.reload_toload_revisions( self._revisions );
$( '#slider' ).slider( 'option', 'max', revisioncount-1 ); //TODO test this, autsaves changed
},
error : function () {
self.stop_right_model_loading();
window.console && console.log( 'Error loading revision data' );
//console.log( 'Error loading revision data' );
}
});
},
reloadleftright : function() {
reloadleft : function() {
var self = this;
self.start_left_model_loading();
self.start_right_model_loading();
self._left_handle_revisions = new wp.revisions.Collection();
self._right_handle_revisions = new wp.revisions.Collection();
self._left_handle_revisions.url =
ajaxurl +
'?action=revisions-data&compare_to=' + self._revisions.at( self._right_diff - 1 ).get( 'ID' ) +
'&post_id=' + wpRevisionsSettings.post_id +
'&show_autosaves=' + self._autosaves +
'&show_split_view=' + self._show_split_view +
'&nonce=' + wpRevisionsSettings.nonce +
'&right_handle_at=' + ( self._right_diff );
if ( 0 == self._left_diff ) {
self._left_handle_revisions.fetch({
success : function(){
self.stop_left_model_loading();
self.reload_toload_revisions( self._left_handle_revisions );
},
error : function () {
//console.log( 'Error loading revision data' );
self.stop_left_model_loading();
}
});
},
reloadright : function() {
var self = this;
self.start_right_model_loading();
self._right_handle_revisions = new wp.revisions.Collection();
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' ) +
'&post_id=' + wpRevisionsSettings.post_id +
'&showautosaves=' + self._autosaves +
'&showsplitview=' + self._showsplitview +
'&nonce=' + wpRevisionsSettings.nonce;
self._left_handle_revisions.fetch({
xhr: function() {
var xhr = $.ajaxSettings.xhr();
xhr.onprogress = self.handleProgress;
return xhr;
},
handleProgress: function(evt){
var percentComplete = 0;
if (evt.lengthComputable) {
percentComplete = evt.loaded / evt.total;
window.console && console.log( Math.round( percentComplete * 100) + "%" );
}
},
success : function(){
self.stop_left_model_loading();
},
error : function () {
window.console && console.log( 'Error loading revision data' );
self.stop_left_model_loading();
}
});
self._right_handle_revisions.fetch({
success : function(){
self.stop_right_model_loading();
self.reload_toload_revisions( self._right_handle_revisions );
},
error : function () {
window.console && console.log( 'Error loading revision data' );
error : function ( response ) {
//console.log( 'Error loading revision data - ' + response.toSource() );
self.stop_right_model_loading();
}
});
},
reloadleftright : function() {
this.reloadleft();
this.reloadright();
},
/*
@ -194,22 +223,27 @@ window.wp = window.wp || {};
},
revisionDiffSetup : function() {
var self = this, slider;
this._revisionView = new wp.revisions.views.View({
model : this._revisions
});
this._revisionView.render();
$( '#diff_max, #diff_maxof' ).html( this._revisions.length );
$( '#diff_count' ).html( REVAPP._right_diff );
$( '#slider' ).slider( 'option', 'max', this._revisions.length - 1 );
this.reload_toload_revisions( this._revisions );
this._revisionsInteractions = new wp.revisions.views.Interact({
model : this._revisions
});
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,8 +251,12 @@ window.wp = window.wp || {};
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,
initialize : function() {
}
} );
_.extend(wp.revisions.views, {
//
@ -242,7 +280,7 @@ window.wp = window.wp || {};
render : function() {
var addhtml = '';
//compare two revisions mode?
if ( 2 == REVAPP._compareoneortwo ) {
if ( 2 === REVAPP._compareoneortwo ) {
this.comparetwochecked = 'checked';
if ( this.draggingleft ) {
if ( this.model.at( REVAPP._left_diff ) ) {
@ -260,16 +298,21 @@ window.wp = window.wp || {};
) );
}
}
} 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
) );
}
}
this.$el.html( addhtml );
if ( this.model.length < 3 ) {
$( 'div#comparetworevisions' ).hide(); //don't allow compare two if fewer than three revisions
}
//console.log ( (this.model.at( REVAPP._right_diff - 1 )).url());
return this;
},
@ -331,11 +374,9 @@ window.wp = window.wp || {};
} else {
REVAPP._autosaves = false ;
}
//refresh the model data
REVAPP.reloadmodel();
//TODO check for two handle mode
},
//
@ -345,10 +386,10 @@ window.wp = window.wp || {};
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,8 +405,14 @@ window.wp = window.wp || {};
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() {
@ -375,12 +422,13 @@ window.wp = window.wp || {};
this.$el.html( addhtml );
$( '#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 );
$( '#diff_left_count_inner' ).html( 0 === REVAPP._left_diff ? '' : 'revision' + REVAPP._left_diff );
self.reset_restore_button();
var modelcount = REVAPP._revisions.length;
slider = $("#slider");
if ( 1 == REVAPP._compareoneortwo ) {
slider = $( "#slider" );
if ( 1 === REVAPP._compareoneortwo ) {
//set up the slider with a single handle
slider.slider({
value : REVAPP._right_diff-1,
@ -390,12 +438,13 @@ window.wp = window.wp || {};
//slide interactions for one handles slider
slide : function( event, ui ) {
if ( REVAPP.right_model_loading ) //left model stoll loading, prevent sliding left handle
if ( REVAPP._right_model_loading ) //left model stoll loading, prevent sliding left handle
return false;
REVAPP._right_diff =( ui.value+1 );
$( '#diff_count' ).html( REVAPP._right_diff );
REVAPP._revisionView.render();
self.reset_restore_button();
}
});
$( '.revisiondiffcontainer' ).removeClass( 'comparetwo' );
@ -414,57 +463,58 @@ window.wp = window.wp || {};
switch ( index ) {
case 1: //left handle drag
if ( REVAPP.left_model_loading ) //left model stoll loading, prevent sliding left handle
if ( REVAPP._left_model_loading ) //left model stoll loading, prevent sliding left handle
return false;
if ( REVAPP._revisionView.model !== REVAPP._left_handle_revisions &&
null != REVAPP._left_handle_revisions )
null !== REVAPP._left_handle_revisions )
REVAPP._revisionView.model = REVAPP._left_handle_revisions;
REVAPP._revisionView.draggingleft = true;
REVAPP._left_diff_start = ui.values[ 0 ];
break;
case 2: //right
if ( REVAPP.right_model_loading ) //right model stoll loading, prevent sliding right handle
if ( REVAPP._right_model_loading ) //right model stoll loading, prevent sliding right handle
return false;
//one extra spot at left end when comparing two
if ( REVAPP._revisionView.model !== REVAPP._right_handle_revisions &&
null != REVAPP._right_handle_revisions )
null !== REVAPP._right_handle_revisions )
REVAPP._revisionView.model = REVAPP._right_handle_revisions;
REVAPP._revisionView.draggingleft = false;
REVAPP._right_diff = ui.values[1] - 1 ;
REVAPP._right_diff_start = ui.values[ 1 ];
break;
}
},
//when sliding in two handled mode change appropriate value
slide : function( event, ui ) {
if ( ui.values[0] == ui.values[1] ) //prevent compare to self
if ( ui.values[ 0 ] === ui.values[ 1 ] ) //prevent compare to self
return false;
var index = $( ui.handle ).index(); //0 (left) or 1 (right)
switch ( index ) {
case 1: //left
if ( REVAPP.left_model_loading ) //left model stoll loading, prevent sliding left handle
if ( REVAPP._left_model_loading ) //left model still loading, prevent sliding left handle
return false;
REVAPP._left_diff = ui.values[0] - 1; //one extra spot at left end when comparing two
REVAPP._left_diff = ui.values[ 0 ] - 1; //one extra spot at left end when comparing two
break;
case 2: //right
if ( REVAPP.right_model_loading ) //right model stoll loading, prevent sliding right handle
if ( REVAPP._right_model_loading ) //right model still loading, prevent sliding right handle
return false;
REVAPP._right_diff = ui.values[1] - 1 ;
REVAPP._right_diff = ui.values[ 1 ] - 1 ;
break;
}
$( '#diff_count' ).html( REVAPP._right_diff );
if ( 0 == REVAPP._left_diff ) {
if ( 0 === REVAPP._left_diff ) {
$( '.revisiondiffcontainer' ).addClass( 'currentversion' );
} else {
@ -473,15 +523,31 @@ window.wp = window.wp || {};
}
REVAPP._revisionView.render(); //render the diff view
self.reset_restore_button();
},
//when the user stops sliding in 2 handle mode, recalculate diffs
stop : function( event, ui ) {
if ( 2 == REVAPP._compareoneortwo ) {
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 ) ) {
REVAPP.reloadleftright();
var index = $( ui.handle ).index(); //0 (left) or 1 (right)
switch ( index ) {
case 1: //left
//left handle dragged & changed, reload right handle model
if ( ! ( REVAPP._left_diff_start === ui.values[ 0 ] || REVAPP._left_model_loading ) )
REVAPP.reloadright();
break;
case 2: //right
//right handle dragged & changed, reload left handle model if changed
if ( ! ( REVAPP._right_diff_start === ui.values[ 1 ] || REVAPP._right_model_loading ) ) {
REVAPP.reloadleft();
}
break;
}
}
}
@ -507,6 +573,7 @@ window.wp = window.wp || {};
$( '#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 +585,7 @@ window.wp = window.wp || {};
$( '#diff_count' ).html( REVAPP._right_diff );
$( '#slider' ).slider( 'value', REVAPP._right_diff - 1 ).trigger( 'slide' );
this.reset_restore_button();
}
})
});
@ -525,6 +593,6 @@ window.wp = window.wp || {};
//instantiate Revision Application
REVAPP = new wp.revisions.App();
//TODO consider enable back button to step back thru states?
Backbone.history.start();
//Backbone.history.start({pushState: true});
}(jQuery));

View File

@ -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()
);
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 @@ default :
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 @@ require_once( './admin-header.php' );
<script type="text/javascript">
var wpRevisionsSettings = <?php echo json_encode( array( 'post_id' => $post->ID, 'nonce' => wp_create_nonce( 'revisions-ajax-nonce' ) ) ); ?>;
</script>
<?php
$comparetworevisionslink = get_edit_post_link( $revision->ID );
?>
<div id="backbonerevisionsoptions"></div>
<br class="clear"/>
<div class="wrap">
<div class="icon32 icon32-posts-post" id="icon-edit"><br></div>
<div class="revisiondiffcontainer diffsplit currentversion rightmodelloading">
@ -94,10 +103,7 @@ var wpRevisionsSettings = <?php echo json_encode( array( 'post_id' => $post->ID,
<h2 class="long-header"><?php echo $h2; ?></h2>
<div id="backbonerevisionsinteract"></div>
<div id="backbonerevisionsdiff"></div>
<hr />
<?php
$comparetworevisionslink = get_edit_post_link( $revision->ID );
?>
<hr />
</div>
</div>
@ -107,9 +113,8 @@ var wpRevisionsSettings = <?php echo json_encode( array( 'post_id' => $post->ID,
<div id="difftitlefrom">{{{ data.revision_from_date_author }}} <?php _e( '- compared to -' ); ?></div>
<div id="difftitle">{{{ data.revision_date_author }}}</div>
<div id="diffcancel"><input class="button" onClick="document.location='<?php echo get_edit_post_link( $post->ID ); ?>'" type="submit" id="cancel" value="<?php esc_attr_e( 'Cancel' )?>" /></div>
<div id="diffrestore"><input class="button button-primary" onClick="document.location='{{{ data.restoreaction }}}'" type="submit" id="restore" value="<?php esc_attr_e( 'Restore' )?>" /></div>
<div id="comparetworevisions"><input type="checkbox" id="comparetwo" value="comparetwo" {{{ data.comparetwochecked }}} name="comparetwo"/> <?php esc_attr_e( 'Compare two revisions' )?></div>
</div>
<div id="diffrestore"><input class="button button-primary" onClick="document.location='{{{ data.restoreaction }}}'" type="submit" id="restore" value="<?php esc_attr_e( 'Restore revision ID' )?>" /></div>
<div id="comparetworevisions"><input type="checkbox" id="comparetwo" value="comparetwo" {{{ data.comparetwochecked }}} name="comparetwo"/> <label for="comparetwo"><?php esc_attr_e( 'Compare two revisions' ); ?></a></div> </div>
<div id="removedandadded">
<div id="removed"><?php _e( 'Removed -' ); ?></div>
<div id="added"><?php _e( 'Added +' ); ?></div>
@ -119,8 +124,8 @@ var wpRevisionsSettings = <?php echo json_encode( array( 'post_id' => $post->ID,
<script id="tmpl-revisionvinteract" type="text/html">
<div id="diffheader">
<div id="diffprevious"><input class="button" type="submit" id="previous" value="Previous" /></div>
<div id="diffnext"><input class="button" type="submit" id="next" value="Next" /></div>
<div id="diffprevious"><input class="button" type="submit" id="previous" value="<?php esc_attr_e( 'Previous' ); ?>" /></div>
<div id="diffnext"><input class="button" type="submit" id="next" value="<?php esc_attr_e( 'Next' ); ?>" /></div>
<div id="diffslider">
<div id="revisioncount">
<?php _e( 'Comparing' ); ?>

View File

@ -1719,7 +1719,7 @@ function wp_text_diff( $left_string, $right_string, $args = null ) {
$r = "<table class='diff'>\n";
if ( isset( $args[ 'showsplitview' ] ) && 'true' == $args[ 'showsplitview' ] ) {
if ( ! empty( $args[ 'show_split_view' ] ) ) {
$r .= "<col class='content diffsplit left' /><col class='content diffsplit middle' /><col class='content diffsplit right' />";
} else {
$r .= "<col class='content' />";

View File

@ -1468,7 +1468,32 @@ function wp_list_post_revisions( $post_id = 0, $args = null ) {
else :
echo "<ul class='post-revisions'>\n";
echo $rows;
//
// if the post was previously restored from a revision
// show the restore event details
//
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 ' );
?>
<hr />
<div id="revisions-meta-restored">
<?php
printf( 'Previously restored from Revision ID %d, %s by %s (%s)',
$restored_from_meta[ 'restored_revision_id'],
$timesince,
$author,
$date );
?>
</div>
<?php
echo "</ul>";
}
endif;
}