Ticket #23497: 23497.17.diff
File 23497.17.diff, 34.6 KB (added by , 12 years ago) |
---|
-
wp-includes/post-template.php
1468 1468 else : 1469 1469 echo "<ul class='post-revisions'>\n"; 1470 1470 echo $rows; 1471 1472 // 1473 // if the post was previously restored from a revision 1474 // show the restore event details 1475 // 1476 if ( $restored_from_meta = get_post_meta( $post->ID, '_post_restored_from', true ) ) { 1477 $author = get_the_author_meta( 'display_name', $restored_from_meta[ 'restored_by_user' ] ); 1478 /* translators: revision date format, see http://php.net/date */ 1479 $datef = _x( 'j F, Y @ G:i:s', 'revision date format'); 1480 $date = date_i18n( $datef, strtotime( $restored_from_meta[ 'restored_time' ] ) ); 1481 $timesince = human_time_diff( $restored_from_meta[ 'restored_time' ], current_time( 'timestamp' ) ) . __( ' ago ' ); 1482 ?> 1483 <hr /> 1484 <div id="revisions-meta-restored"> 1485 <?php 1486 printf( 'Previously restored from Revision ID %d, %s by %s (%s)', 1487 $restored_from_meta[ 'restored_revision_id'], 1488 $timesince, 1489 $author, 1490 $date ); 1491 ?> 1492 </div> 1493 <?php 1471 1494 echo "</ul>"; 1495 } 1496 1472 1497 endif; 1473 1498 1474 1499 } -
wp-includes/pluggable.php
1719 1719 1720 1720 $r = "<table class='diff'>\n"; 1721 1721 1722 if ( isset( $args[ 'showsplitview' ] ) && 'true' == $args[ 'showsplitview' ]) {1722 if ( ! empty( $args[ 'show_split_view' ] ) ) { 1723 1723 $r .= "<col class='content diffsplit left' /><col class='content diffsplit middle' /><col class='content diffsplit right' />"; 1724 1724 } else { 1725 1725 $r .= "<col class='content' />"; -
wp-admin/includes/ajax-actions.php
2131 2131 function wp_ajax_revisions_data() { 2132 2132 check_ajax_referer( 'revisions-ajax-nonce', 'nonce' ); 2133 2133 2134 $compareto = isset( $_GET['compareto'] ) ? absint( $_GET['compareto'] ) : 0; 2135 $showautosaves = isset( $_GET['showautosaves'] ) ? $_GET['showautosaves'] : ''; 2136 $showsplitview = isset( $_GET['showsplitview'] ) ? $_GET['showsplitview'] : ''; 2137 $postid = isset( $_GET['post_id'] ) ? absint( $_GET['post_id'] ) : ''; 2134 $compare_to = isset( $_GET['compare_to'] ) ? absint( $_GET['compare_to'] ) : 0; 2135 $show_autosaves = isset( $_GET['show_autosaves'] ) ? $_GET['show_autosaves'] : ''; 2136 $show_split_view = isset( $_GET['show_split_view'] ) ? $_GET['show_split_view'] : ''; 2137 $post_id = isset( $_GET['post_id'] ) ? absint( $_GET['post_id'] ) : ''; 2138 $right_handle_at = isset( $_GET['right_handle_at'] ) ? $_GET['right_handle_at'] : 0; 2139 $left_handle_at = isset( $_GET['left_handle_at'] ) ? $_GET['left_handle_at'] : 0; 2140 $single_revision_id = isset( $_GET['single_revision_id'] ) ? $_GET['single_revision_id'] : 0; 2138 2141 2139 $compare twomode = ( '' == $postid ) ? false : true;2142 $compare_two_mode = ( '' == $post_id ) ? false : true; 2140 2143 // 2141 //TODO: currently code returns all possible comparisons for the indicated 'compare to' revision2144 //TODO: currently code returns all possible comparisons for the indicated 'compare_to' revision 2142 2145 //however, the front end prevents users from pulling the right handle past the left or the left pass the right, 2143 2146 //so only the possible diffs need be generated 2144 2147 // 2145 2148 $alltherevisions = array(); 2146 if ( '' == $post id )2147 $post id = $compareto;2149 if ( '' == $post_id ) 2150 $post_id = $compare_to; 2148 2151 2149 if ( ! current_user_can( 'read_post', $post id ) )2152 if ( ! current_user_can( 'read_post', $post_id ) ) 2150 2153 continue; 2151 2154 2152 if ( ! $revisions = wp_get_post_revisions( $post id ) )2155 if ( ! $revisions = wp_get_post_revisions( $post_id ) ) 2153 2156 return; 2154 2157 2158 /* translators: revision date format, see http://php.net/date */ 2159 $datef = _x( 'j F, Y @ G:i:s', 'revision date format'); 2155 2160 2156 // if we are comparing two revisions, the first 'revision' represented by the leftmost2157 //slider position is the current revision, prepend a comparison to this revision2158 if ( $comparetwomode )2159 array_unshift( $revisions, get_post( $postid ));2161 //single model fetch mode 2162 if ( 0 != $single_revision_id ) { 2163 $left_revision = get_post( $compare_to ); 2164 $right_revision = get_post( $single_revision_id ); 2160 2165 2161 $count = 1;2162 foreach ( $revisions as $revision ) :2163 if ( 'true' != $showautosaves && wp_is_post_autosave( $revision ) )2164 continue;2166 if ( $compare_two_mode ) { 2167 $compare_to_gravatar = get_avatar( $left_revision->post_author, 18 ); 2168 $compare_to_author = get_the_author_meta( 'display_name', $left_revision->post_author ); 2169 $compare_to_date = date_i18n( $datef, strtotime( $left_revision->post_modified ) ); 2165 2170 2166 $revision_from_date_author = ''; 2171 $revision_from_date_author = sprintf( 2172 '%s %s, %s %s (%s)', 2173 $compare_to_gravatar, 2174 $compare_to_author, 2175 human_time_diff( strtotime( $left_revision->post_modified ), current_time( 'timestamp' ) ), 2176 __( ' ago ' ), 2177 $compare_to_date 2178 ); 2179 } 2167 2180 2181 // 2182 //make sure the left revision is the most recent 2183 // 2184 if ( strtotime( $right_revision->post_modified_gmt ) < strtotime( $left_revision->post_modified_gmt ) ) { 2185 $temp = $left_revision; 2186 $left_revision = $right_revision; 2187 $right_revision = $temp; 2188 } 2168 2189 2169 $left_revision = get_post( $compareto ); 2170 $right_revision = get_post( $revision ); 2190 // 2191 //compare from left to right, passed from application 2192 // 2193 $content=''; 2194 foreach ( array_keys( _wp_post_revision_fields() ) as $field ) { 2195 $left_content = apply_filters( "_wp_post_revision_field_$field", $left_revision->$field, $field, $left_revision, 'left' ); 2196 $right_content = apply_filters( "_wp_post_revision_field_$field", $right_revision->$field, $field, $right_revision, 'right' ); 2171 2197 2172 $author = get_the_author_meta( 'display_name', $revision->post_author ); 2173 /* translators: revision date format, see http://php.net/date */ 2174 $datef = _x( 'j F, Y @ G:i:s', 'revision date format'); 2198 add_filter( "_wp_post_revision_field_$field", 'wp_kses_post' ); 2175 2199 2176 $gravatar = get_avatar( $revision->post_author, 18);2200 $args = array(); 2177 2201 2178 $date = date_i18n( $datef, strtotime( $revision->post_modified ) ); 2179 $revision_date_author = sprintf( 2180 '%s %s, %s %s (%s)', 2181 $gravatar, 2182 $author, 2183 human_time_diff( strtotime( $revision->post_modified ), current_time( 'timestamp' ) ), 2184 __( ' ago ' ), 2185 $date 2186 ); 2202 if ( ! empty( $show_split_view ) ) 2203 $args = array( 'show_split_view' => true ); 2187 2204 2188 if ( $comparetwomode ) { 2189 $compareto_gravatar = get_avatar( $left_revision->post_author, 18 ); 2190 $compareto_author = get_the_author_meta( 'display_name', $left_revision->post_author ); 2191 $compareto_date = date_i18n( $datef, strtotime( $left_revision->post_modified ) ); 2192 2193 $revision_from_date_author = sprintf( 2194 '%s %s, %s %s (%s)', 2195 $compareto_gravatar, 2196 $compareto_author, 2197 human_time_diff( strtotime( $left_revision->post_modified ), current_time( 'timestamp' ) ), 2198 __( ' ago ' ), 2199 $compareto_date 2200 ); 2205 $content .= wp_text_diff( $left_content, $right_content, $args ); 2206 } 2207 $content = '' == $content ? __( 'No difference' ) : $content; 2208 $alltherevisions = array ( 2209 'revisiondiff' => $content 2210 ); 2211 echo json_encode( $alltherevisions ); 2212 exit(); 2201 2213 } 2202 2214 2203 $restoreaction = wp_nonce_url( 2204 add_query_arg( 2205 array( 'revision' => $revision->ID, 2206 'action' => 'restore' ), 2207 '/wp-admin/revision.php' 2208 ), 2209 "restore-post_{$compareto}|{$revision->ID}" 2210 ); 2215 //if we are comparing two revisions, the first 'revision' represented by the leftmost 2216 //slider position is the current revision, prepend a comparison to this revision 2217 if ( $compare_two_mode ) 2218 array_unshift( $revisions, get_post( $post_id ) ); 2219 2211 2220 2212 // 2213 //make sure the left revision is the most recent 2214 // 2215 if ( strtotime( $right_revision->post_modified_gmt ) < strtotime( $left_revision->post_modified_gmt ) ) { 2216 $temp = $left_revision; 2217 $left_revision = $right_revision; 2218 $right_revision = $temp; 2219 } 2221 $count = -1; 2220 2222 2221 // 2222 //compare from left to right, passed from application 2223 // 2224 $content=''; 2225 foreach ( array_keys( _wp_post_revision_fields() ) as $field ) { 2226 $left_content = apply_filters( "_wp_post_revision_field_$field", $left_revision->$field, $field, $left_revision, 'left' ); 2227 $right_content = apply_filters( "_wp_post_revision_field_$field", $right_revision->$field, $field, $right_revision, 'right' ); 2223 foreach ( $revisions as $revision ) : 2224 if ( ! empty( $show_autosaves ) && wp_is_post_autosave( $revision ) ) 2225 continue; 2228 2226 2229 add_filter( "_wp_post_revision_field_$field", 'wp_kses_post' ); 2227 $revision_from_date_author = ''; 2228 $count++; 2229 // return blank data for diffs to the left of the left handle (for right handel model) 2230 // or to the right of the right handle (for left handel model) 2231 if ( ( 0 != $left_handle_at && $count <= $left_handle_at ) || 2232 ( 0 != $right_handle_at && $count > $right_handle_at )) { 2233 $alltherevisions[] = array ( 2234 'ID' => $revision->ID, 2235 ); 2236 2237 continue; 2238 } 2230 2239 2231 $args = array(); 2240 $gravatar = get_avatar( $revision->post_author, 18 ); 2241 $author = get_the_author_meta( 'display_name', $revision->post_author ); 2242 $date = date_i18n( $datef, strtotime( $revision->post_modified ) ); 2243 $revision_date_author = sprintf( 2244 '%s %s, %s %s (%s)', 2245 $gravatar, 2246 $author, 2247 human_time_diff( strtotime( $revision->post_modified ), current_time( 'timestamp' ) ), 2248 __( ' ago ' ), 2249 $date 2250 ); 2232 2251 2233 if ( 'true' == $showsplitview ) 2234 $args = array( 'showsplitview' => 'true' ); 2235 2236 $content .= wp_text_diff( $left_content, $right_content, $args ); 2237 } 2238 2239 //if we are comparing two revisions 2240 //and we are on the matching revision 2241 //add an error revision indicating unable to compare to self 2242 if ( $comparetwomode && $compareto == $revision->ID ) 2243 $alltherevisions[] = array ( 2244 'ID' => $revision->ID, 2245 'revision_date_author' => $revision_date_author, 2246 'revisiondiff' => sprintf('<div id="selfcomparisonerror">%s</div>', __( 'Cannot compare revision to itself' ) ), 2247 'restoreaction' => urldecode( $restoreaction ), 2248 'revision_from_date_author' => '' 2252 $restoreaction = wp_nonce_url( 2253 add_query_arg( 2254 array( 'revision' => $revision->ID, 2255 'action' => 'restore' ), 2256 admin_url( 'revision.php' ) 2257 ), 2258 "restore-post_{$compare_to}|{$revision->ID}" 2249 2259 ); 2250 2260 2251 //add to the return data only if there is a difference2252 if ( '' != $content )2253 2261 $alltherevisions[] = array ( 2254 'ID' => $revision->ID,2255 'revision_date_author' => $revision_date_author,2256 'revisiondiff' => $content,2257 'restoreaction' => urldecode( $restoreaction ),2258 'revision_from_date_author' => $revision_from_date_author2259 );2262 'ID' => $revision->ID, 2263 'revision_date_author' => $revision_date_author, 2264 'revision_from_date_author' => $revision_from_date_author, 2265 'restoreaction' => urldecode( $restoreaction ), 2266 'revision_toload' => true 2267 ); 2260 2268 2261 2269 endforeach; 2262 2270 -
wp-admin/js/revisions.js
6 6 views : {}, 7 7 8 8 Model : Backbone.Model.extend({ 9 idAttribute : 'ID', 10 urlRoot : ajaxurl + '?action=revisions-data&compare_to=' + wpRevisionsSettings.post_id + 11 '&show_autosaves=false&show_split_view=true&nonce=' + wpRevisionsSettings.nonce, 9 12 defaults: { 10 13 ID : 0, 11 14 revision_date_author : '', 12 revisiondiff : '', 13 restoreaction: '', 14 diff_max : 0, 15 diff_count : 0, 16 diff_revision_to : 0, 15 revisiondiff : '<div class="diff-loading"><div class="spinner"></div></div>', 16 restoreaction : '', 17 17 revision_from_date_author : '', 18 revision_toload : false 19 }, 20 21 url : function() { 22 return this.urlRoot + '&single_revision_id=' + this.id; 18 23 } 24 19 25 }), 20 26 21 27 app: _.extend({}, Backbone.Events), … … 30 36 _left_diff : 0, 31 37 _right_diff : 1, 32 38 _autosaves : false, 33 _show splitview : true,39 _show_split_view : true, 34 40 _compareoneortwo : 1, 35 left_model_loading : false, //keep track of model loads36 right_model_loading : false, //disallow slider interaction, also repeat loads, while loading41 _left_model_loading : false, //keep track of model loads 42 _right_model_loading : false, //disallow slider interaction, also repeat loads, while loading 37 43 38 44 //TODO add ability to arrive on specific revision 39 45 routes : { 40 "viewrevision/:revision": "viewrevision",41 46 }, 42 47 43 48 viewrevision : function( revision ) { 44 49 //coming soon 45 50 }, 46 51 52 reload_toload_revisions : function( model_collection ) { 53 var self = this; 54 var revisions_to_load = model_collection.where( { revision_toload : true } ); 55 //console.log(revisions_to_load); 56 var delay=0; 57 _.each(revisions_to_load, function( the_model ) { 58 the_model.urlRoot = model_collection.url; 59 _.delay( function() { (the_model.fetch( { 60 update : true, 61 add : false, 62 remove : false, 63 //async : false, 64 success : function( model ) { 65 //console.log(model.get( 'ID' ) +'-'+self._revisions.at( self._right_diff ).get( 'ID' )); 66 if ( model.get( 'ID' ) == self._revisions.at( self._right_diff - 1 ).get( 'ID' ) ) { //reload if current model refreshed 67 //console.log('render'); 68 self._revisionView.render(); 69 } 70 } 71 } ) )}, delay ) ; 72 delay = delay + 200; //stagger model loads by 200 ms to avoid hammering server with requests 73 } 74 75 ) 76 77 }, 78 47 79 start_left_model_loading : function() { 48 this. left_model_loading = true;80 this._left_model_loading = true; 49 81 $('.revisiondiffcontainer').addClass('leftmodelloading'); 50 82 }, 51 83 52 84 stop_left_model_loading : function() { 53 this. left_model_loading = false;85 this._left_model_loading = false; 54 86 $('.revisiondiffcontainer').removeClass('leftmodelloading'); 55 87 }, 56 88 57 89 start_right_model_loading : function() { 58 this. right_model_loading = true;90 this._right_model_loading = true; 59 91 $('.revisiondiffcontainer').addClass('rightmodelloading'); 60 92 }, 61 93 62 94 stop_right_model_loading : function() { 63 this. right_model_loading = false;95 this._right_model_loading = false; 64 96 $('.revisiondiffcontainer').removeClass('rightmodelloading'); 65 97 }, 66 98 … … 74 106 75 107 reloadmodelsingle : function() { 76 108 var self = this; 77 self._revisions.url = ajaxurl + '?action=revisions-data&compare to=' + wpRevisionsSettings.post_id +78 '&show autosaves=' + self.self_autosaves +79 '&show splitview=' + REVAPP._showsplitview +109 self._revisions.url = ajaxurl + '?action=revisions-data&compare_to=' + wpRevisionsSettings.post_id + 110 '&show_autosaves=' + self._autosaves + 111 '&show_split_view=' + REVAPP._show_split_view + 80 112 '&nonce=' + wpRevisionsSettings.nonce; 81 113 self.start_right_model_loading(); 82 114 this._revisions.fetch({ //reload revision data … … 85 117 var revisioncount = self._revisions.length; 86 118 if ( self._right_diff > revisioncount ) //if right handle past rightmost, move 87 119 self._right_diff = revisioncount; 88 //TODO add a test for matchind left revision and push left, testing89 //also reset the slider values here90 120 91 121 self._revisionView.render(); 92 $( '#slider' ).slider( 'option', 'max', revisioncount-1 ); //TODO test this 122 self.reload_toload_revisions( self._revisions ); 123 124 $( '#slider' ).slider( 'option', 'max', revisioncount-1 ); //TODO test this, autsaves changed 93 125 }, 94 126 95 127 error : function () { … … 100 132 }); 101 133 }, 102 134 103 reloadleft right: function() {135 reloadleft : function() { 104 136 var self = this; 105 137 self.start_left_model_loading(); 106 self.start_right_model_loading();107 108 138 self._left_handle_revisions = new wp.revisions.Collection(); 109 self._right_handle_revisions = new wp.revisions.Collection();110 111 if ( 0 == self._left_diff ) {112 self._right_handle_revisions.url =113 ajaxurl +114 '?action=revisions-data&compareto=' + wpRevisionsSettings.post_id +115 '&post_id=' + wpRevisionsSettings.post_id +116 '&showautosaves=' + self._autosaves +117 '&showsplitview=' + self._showsplitview +118 '&nonce=' + wpRevisionsSettings.nonce;119 } else {120 self._right_handle_revisions.url =121 ajaxurl +122 '?action=revisions-data&compareto=' + self._revisions.at( self._left_diff - 1 ).get( 'ID' ) +123 '&post_id=' + wpRevisionsSettings.post_id +124 '&showautosaves=' + self._autosaves +125 '&showsplitview=' + self._showsplitview +126 '&nonce=' + wpRevisionsSettings.nonce;127 }128 129 139 self._left_handle_revisions.url = 130 140 ajaxurl + 131 '?action=revisions-data&compare to=' + self._revisions.at( self._right_diff - 1 ).get( 'ID' ) +141 '?action=revisions-data&compare_to=' + self._revisions.at( self._right_diff - 1 ).get( 'ID' ) + 132 142 '&post_id=' + wpRevisionsSettings.post_id + 133 '&showautosaves=' + self._autosaves + 134 '&showsplitview=' + self._showsplitview + 135 '&nonce=' + wpRevisionsSettings.nonce; 143 '&show_autosaves=' + self._autosaves + 144 '&show_split_view=' + self._show_split_view + 145 '&nonce=' + wpRevisionsSettings.nonce + 146 '&right_handle_at=' + ( self._right_diff ); 136 147 137 148 self._left_handle_revisions.fetch({ 138 149 139 xhr: function() {140 var xhr = $.ajaxSettings.xhr();141 xhr.onprogress = self.handleProgress;142 return xhr;143 },144 145 handleProgress: function(evt){146 var percentComplete = 0;147 if (evt.lengthComputable) {148 percentComplete = evt.loaded / evt.total;149 window.console && console.log( Math.round( percentComplete * 100) + "%" );150 }151 },152 153 150 success : function(){ 154 151 self.stop_left_model_loading(); 152 self.reload_toload_revisions( self._left_handle_revisions ); 155 153 }, 156 154 157 155 error : function () { … … 159 157 self.stop_left_model_loading(); 160 158 } 161 159 }); 160 }, 162 161 162 reloadright : function() { 163 var self = this; 164 self.start_right_model_loading(); 165 self._right_handle_revisions = new wp.revisions.Collection(); 166 if ( 0 == self._left_diff ) { 167 self._right_handle_revisions.url = 168 ajaxurl + 169 '?action=revisions-data&compare_to=' + wpRevisionsSettings.post_id + 170 '&post_id=' + wpRevisionsSettings.post_id + 171 '&show_autosaves=' + self._autosaves + 172 '&show_split_view=' + self._show_split_view + 173 '&nonce=' + wpRevisionsSettings.nonce; 174 } else { 175 self._right_handle_revisions.url = 176 ajaxurl + 177 '?action=revisions-data&compare_to=' + self._revisions.at( self._left_diff - 1 ).get( 'ID' ) + 178 '&post_id=' + wpRevisionsSettings.post_id + 179 '&show_autosaves=' + self._autosaves + 180 '&show_split_view=' + self._show_split_view + 181 '&nonce=' + wpRevisionsSettings.nonce + 182 '&left_handle_at=' + (self._left_diff ) ; 183 } 184 163 185 self._right_handle_revisions.fetch({ 164 186 165 187 success : function(){ 166 188 self.stop_right_model_loading(); 189 self.reload_toload_revisions( self._right_handle_revisions ); 167 190 }, 168 191 169 error : function ( ) {170 window.console && console.log( 'Error loading revision data ');192 error : function ( response ) { 193 window.console && console.log( 'Error loading revision data - ' + response.toSource() ); 171 194 self.stop_right_model_loading(); 172 195 } 173 196 }); 197 174 198 }, 175 199 200 reloadleftright : function() { 201 this.reloadleft(); 202 this.reloadright(); 203 }, 204 176 205 /* 177 206 * initialize the revision application 178 207 */ … … 194 223 }, 195 224 196 225 revisionDiffSetup : function() { 197 var self = this, slider;198 199 226 this._revisionView = new wp.revisions.views.View({ 200 227 model : this._revisions 201 228 }); 202 229 this._revisionView.render(); 203 230 $( '#diff_max, #diff_maxof' ).html( this._revisions.length ); 231 $( '#diff_count' ).html( REVAPP._right_diff ); 232 $( '#slider' ).slider( 'option', 'max', this._revisions.length - 1 ); 233 234 this.reload_toload_revisions( this._revisions ); 204 235 this._revisionsInteractions = new wp.revisions.views.Interact({ 205 236 model : this._revisions 206 237 }); 207 238 this._revisionsInteractions.render(); 208 239 240 /* 241 //Options hidden for now, moving to screen options 209 242 this._revisionsOptions = new wp.revisions.views.Options({ 210 243 model : this._revisions 211 244 }); 212 245 this._revisionsOptions.render(); 246 */ 213 247 214 248 } 215 249 }) … … 217 251 218 252 wp.revisions.Collection = Backbone.Collection.extend({ 219 253 model : wp.revisions.Model, 220 url : ajaxurl + '?action=revisions-data&compareto=' + wpRevisionsSettings.post_id + '&showautosaves=false&showsplitview=true&nonce=' + wpRevisionsSettings.nonce 254 url : ajaxurl + '?action=revisions-data&compare_to=' + wpRevisionsSettings.post_id + 255 '&show_autosaves=false&show_split_view=true&nonce=' + wpRevisionsSettings.nonce, 256 257 initialize : function() { 258 }, 259 221 260 }); 222 261 223 262 _.extend(wp.revisions.views, { … … 260 299 ) ); 261 300 } 262 301 } 263 } else { //end compare two revisions mode, eg only one slider hand el302 } else { //end compare two revisions mode, eg only one slider handle 264 303 this.comparetwochecked = ''; 265 304 if ( this.model.at( REVAPP._right_diff - 1 ) ) { 266 305 addhtml = this.template( _.extend( 267 this.model.at( REVAPP._right_diff -1 ).toJSON(),268 { comparetwochecked : this.comparetwochecked } //keep the checkmark checked306 this.model.at( REVAPP._right_diff - 1 ).toJSON(), 307 { comparetwochecked : this.comparetwochecked } //keep the checkmark unchecked 269 308 ) ); 270 309 } 271 310 } 272 311 this.$el.html( addhtml ); 312 if ( this.model.length < 3 ) { 313 $( 'div#comparetworevisions' ).hide(); //don't allow compare two if fewer than three revisions 314 315 } 316 //console.log ( (this.model.at( REVAPP._right_diff - 1 )).url()); 273 317 return this; 274 318 }, 275 319 … … 331 375 } else { 332 376 REVAPP._autosaves = false ; 333 377 } 378 334 379 //refresh the model data 335 336 REVAPP.reloadmodel(); 337 //TODO check for two handle mode 338 380 REVAPP.reloadmodel(); 339 381 }, 340 382 341 383 // … … 345 387 var self = this; 346 388 347 389 if ( $( 'input#showsplitview' ).is( ':checked' ) ) { 348 REVAPP._show splitview = 'true';390 REVAPP._show_split_view = 'true'; 349 391 $('.revisiondiffcontainer').addClass('diffsplit'); 350 392 } else { 351 REVAPP._show splitview = '';393 REVAPP._show_split_view = ''; 352 394 $('.revisiondiffcontainer').removeClass('diffsplit'); 353 395 } 354 396 … … 364 406 tagName : 'revisionvinteract', 365 407 className : 'revisionvinteract-container', 366 408 template : wp.template('revisionvinteract'), 409 _restoreword : '', 367 410 368 411 initialize : function() { 412 this._restoreword = $( 'input#restore' ).attr( 'value' ); 369 413 }, 370 414 415 reset_restore_button : function() { 416 $( 'input#restore' ).attr( 'value', this._restoreword + ' ' + REVAPP._revisions.at( REVAPP._right_diff - 1 ).get( 'ID' ) ); 417 }, 418 371 419 render : function() { 372 420 var self = this; 373 421 … … 376 424 $( '#diff_max, #diff_maxof' ).html( this.model.length ); 377 425 $( '#diff_count' ).html( REVAPP._right_diff ); 378 426 $( '#diff_left_count_inner' ).html( 0 == REVAPP._left_diff ? '' : 'revision' + REVAPP._left_diff ); 427 self.reset_restore_button(); 379 428 380 429 var modelcount = REVAPP._revisions.length; 381 430 382 slider = $( "#slider");431 slider = $( "#slider" ); 383 432 if ( 1 == REVAPP._compareoneortwo ) { 384 433 //set up the slider with a single handle 385 434 slider.slider({ … … 390 439 391 440 //slide interactions for one handles slider 392 441 slide : function( event, ui ) { 393 if ( REVAPP. right_model_loading ) //left model stoll loading, prevent sliding left handle442 if ( REVAPP._right_model_loading ) //left model stoll loading, prevent sliding left handle 394 443 return false; 395 444 396 445 REVAPP._right_diff =( ui.value+1 ); 397 446 $( '#diff_count' ).html( REVAPP._right_diff ); 398 447 REVAPP._revisionView.render(); 448 self.reset_restore_button(); 399 449 } 400 450 }); 401 451 $( '.revisiondiffcontainer' ).removeClass( 'comparetwo' ); … … 414 464 415 465 switch ( index ) { 416 466 case 1: //left handle drag 417 if ( REVAPP. left_model_loading ) //left model stoll loading, prevent sliding left handle467 if ( REVAPP._left_model_loading ) //left model stoll loading, prevent sliding left handle 418 468 return false; 419 469 420 470 if ( REVAPP._revisionView.model !== REVAPP._left_handle_revisions && … … 422 472 REVAPP._revisionView.model = REVAPP._left_handle_revisions; 423 473 424 474 REVAPP._revisionView.draggingleft = true; 475 REVAPP._left_diff_start = ui.values[ 0 ]; 425 476 break; 426 477 427 478 case 2: //right 428 if ( REVAPP. right_model_loading ) //right model stoll loading, prevent sliding right handle479 if ( REVAPP._right_model_loading ) //right model stoll loading, prevent sliding right handle 429 480 return false; 430 481 431 482 //one extra spot at left end when comparing two … … 434 485 REVAPP._revisionView.model = REVAPP._right_handle_revisions; 435 486 436 487 REVAPP._revisionView.draggingleft = false; 437 REVAPP._right_diff = ui.values[1] - 1;488 REVAPP._right_diff_start = ui.values[ 1 ]; 438 489 break; 439 490 } 440 491 }, 441 492 442 493 //when sliding in two handled mode change appropriate value 443 494 slide : function( event, ui ) { 444 if ( ui.values[ 0] == ui.values[1] ) //prevent compare to self495 if ( ui.values[ 0 ] == ui.values[ 1 ] ) //prevent compare to self 445 496 return false; 446 497 447 498 var index = $( ui.handle ).index(); //0 (left) or 1 (right) 448 499 449 500 switch ( index ) { 450 501 case 1: //left 451 if ( REVAPP. left_model_loading ) //left model stoll loading, prevent sliding left handle502 if ( REVAPP._left_model_loading ) //left model still loading, prevent sliding left handle 452 503 return false; 453 504 454 REVAPP._left_diff = ui.values[ 0] - 1; //one extra spot at left end when comparing two505 REVAPP._left_diff = ui.values[ 0 ] - 1; //one extra spot at left end when comparing two 455 506 break; 456 507 457 508 case 2: //right 458 if ( REVAPP. right_model_loading ) //right model stoll loading, prevent sliding right handle509 if ( REVAPP._right_model_loading ) //right model still loading, prevent sliding right handle 459 510 return false; 460 511 461 REVAPP._right_diff = ui.values[ 1] - 1 ;512 REVAPP._right_diff = ui.values[ 1 ] - 1 ; 462 513 break; 463 514 } 464 515 465 516 $( '#diff_count' ).html( REVAPP._right_diff ); 466 517 518 519 467 520 if ( 0 == REVAPP._left_diff ) { 468 521 $( '.revisiondiffcontainer' ).addClass( 'currentversion' ); 469 522 … … 473 526 } 474 527 475 528 REVAPP._revisionView.render(); //render the diff view 529 self.reset_restore_button(); 476 530 }, 477 531 478 532 //when the user stops sliding in 2 handle mode, recalculate diffs … … 480 534 if ( 2 == REVAPP._compareoneortwo ) { 481 535 //calculate and generate a diff for comparing to the left handle 482 536 //and the right handle, swap out when dragging 483 if ( ! (REVAPP.left_model_loading && REVAPP.right_model.loading ) ) { 484 REVAPP.reloadleftright(); 537 538 var index = $( ui.handle ).index(); //0 (left) or 1 (right) 539 540 switch ( index ) { 541 case 1: //left 542 //left handle dragged & changed, reload right handle model 543 if ( ! ( REVAPP._left_diff_start == ui.values[ 0 ] || REVAPP._left_model_loading ) ) 544 REVAPP.reloadright(); 545 546 break; 547 548 case 2: //right 549 //right handle dragged & changed, reload left handle model if changed 550 if ( ! ( REVAPP._right_diff_start == ui.values[ 1 ] || REVAPP._right_model_loading ) ) { 551 REVAPP.reloadleft(); 552 } 553 break; 485 554 } 486 555 } 487 556 } … … 507 576 508 577 $( '#diff_count' ).html( REVAPP._right_diff ); 509 578 $( '#slider' ).slider( 'value', REVAPP._right_diff - 1 ).trigger( 'slide' ); 579 this.reset_restore_button(); 510 580 }, 511 581 512 582 //go the the previous revision … … 518 588 519 589 $( '#diff_count' ).html( REVAPP._right_diff ); 520 590 $( '#slider' ).slider( 'value', REVAPP._right_diff - 1 ).trigger( 'slide' ); 591 this.reset_restore_button(); 521 592 } 522 593 }) 523 594 }); … … 525 596 //instantiate Revision Application 526 597 REVAPP = new wp.revisions.App(); 527 598 //TODO consider enable back button to step back thru states? 528 Backbone.history.start();599 //Backbone.history.start({pushState: true}); 529 600 530 601 }(jQuery)); -
wp-admin/revision.php
10 10 require_once('./admin.php'); 11 11 wp_reset_vars( array( 'revision', 'action' ) ); 12 12 13 $revision_id = absint( $revision);13 $revision_id = absint( $revision ); 14 14 $redirect = 'edit.php'; 15 15 16 16 switch ( $action ) : 17 17 case 'restore' : 18 if ( ! $revision = wp_get_post_revision( $revision_id ) )18 if ( ! $revision = wp_get_post_revision( $revision_id ) ) 19 19 break; 20 if ( ! current_user_can( 'edit_post', $revision->post_parent ) )20 if ( ! current_user_can( 'edit_post', $revision->post_parent ) ) 21 21 break; 22 if ( ! $post = get_post( $revision->post_parent ) )22 if ( ! $post = get_post( $revision->post_parent ) ) 23 23 break; 24 24 25 25 // Revisions disabled and we're not looking at an autosave 26 if ( ( ! WP_POST_REVISIONS || ! post_type_supports($post->post_type, 'revisions') ) && !wp_is_post_autosave( $revision ) ) {26 if ( ( ! WP_POST_REVISIONS || ! post_type_supports( $post->post_type, 'revisions' ) ) && ! wp_is_post_autosave( $revision ) ) { 27 27 $redirect = 'edit.php?post_type=' . $post->post_type; 28 28 break; 29 29 } 30 30 check_admin_referer( "restore-post_{$post->ID}|{$revision->ID}" ); 31 31 32 //store revision event in post meta 33 $restore_details = array( 34 'restored_revision_id' => $revision->ID, 35 'restored_by_user' => get_current_user_id(), 36 'restored_time' => time() 37 ); 38 wp_update_post_meta( $post->ID, '_post_restored_from', $restore_details ); 39 32 40 wp_restore_post_revision( $revision->ID ); 33 41 $redirect = add_query_arg( array( 'message' => 5, 'revision' => $revision->ID ), get_edit_post_link( $post->ID, 'url' ) ); 34 42 break; 35 43 case 'view' : 36 44 case 'edit' : 37 45 default : 38 if ( ! $revision = wp_get_post_revision( $revision_id ) )46 if ( ! $revision = wp_get_post_revision( $revision_id ) ) 39 47 break; 40 if ( ! $post = get_post( $revision->post_parent ) )48 if ( ! $post = get_post( $revision->post_parent ) ) 41 49 break; 42 50 43 if ( ! current_user_can( 'read_post', $revision->ID ) || !current_user_can( 'read_post', $post->ID ) )51 if ( ! current_user_can( 'read_post', $revision->ID ) || ! current_user_can( 'read_post', $post->ID ) ) 44 52 break; 45 53 46 54 // Revisions disabled and we're not looking at an autosave … … 59 67 endswitch; 60 68 61 69 // Empty post_type means either malformed object found, or no valid parent was found. 62 if ( ! $redirect && empty($post->post_type) )70 if ( ! $redirect && empty( $post->post_type ) ) 63 71 $redirect = 'edit.php'; 64 72 65 if ( ! empty($redirect) ) {73 if ( ! empty( $redirect ) ) { 66 74 wp_redirect( $redirect ); 67 75 exit; 68 76 } 69 77 70 78 // This is so that the correct "Edit" menu item is selected. 71 if ( ! empty($post->post_type) && 'post' != $post->post_type )79 if ( ! empty( $post->post_type ) && 'post' != $post->post_type ) 72 80 $parent_file = $submenu_file = 'edit.php?post_type=' . $post->post_type; 73 81 else 74 82 $parent_file = $submenu_file = 'edit.php'; … … 83 91 <script type="text/javascript"> 84 92 var wpRevisionsSettings = <?php echo json_encode( array( 'post_id' => $post->ID, 'nonce' => wp_create_nonce( 'revisions-ajax-nonce' ) ) ); ?>; 85 93 </script> 94 <?php 95 $comparetworevisionslink = get_edit_post_link( $revision->ID ); 96 ?> 86 97 87 98 <div id="backbonerevisionsoptions"></div> 88 89 <br class="clear"/>90 99 <div class="wrap"> 91 100 <div class="icon32 icon32-posts-post" id="icon-edit"><br></div> 92 101 <div class="revisiondiffcontainer diffsplit currentversion rightmodelloading"> … … 94 103 <h2 class="long-header"><?php echo $h2; ?></h2> 95 104 <div id="backbonerevisionsinteract"></div> 96 105 <div id="backbonerevisionsdiff"></div> 97 <hr /> 98 <?php 99 $comparetworevisionslink = get_edit_post_link( $revision->ID ); 100 ?> 106 <hr /> 101 107 </div> 102 108 </div> 103 109 … … 107 113 <div id="difftitlefrom">{{{ data.revision_from_date_author }}} <?php _e( '- compared to -' ); ?></div> 108 114 <div id="difftitle">{{{ data.revision_date_author }}}</div> 109 115 <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> 110 <div id="diffrestore"><input class="button button-primary" onClick="document.location='{{{ data.restoreaction }}}'" type="submit" id="restore" value="<?php esc_attr_e( 'Restore' )?>" /></div> 111 <div id="comparetworevisions"><input type="checkbox" id="comparetwo" value="comparetwo" {{{ data.comparetwochecked }}} name="comparetwo"/> <?php esc_attr_e( 'Compare two revisions' )?></div> 112 </div> 116 <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> 117 <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> 113 118 <div id="removedandadded"> 114 119 <div id="removed"><?php _e( 'Removed -' ); ?></div> 115 120 <div id="added"><?php _e( 'Added +' ); ?></div> … … 119 124 120 125 <script id="tmpl-revisionvinteract" type="text/html"> 121 126 <div id="diffheader"> 122 <div id="diffprevious"><input class="button" type="submit" id="previous" value=" Previous" /></div>123 <div id="diffnext"><input class="button" type="submit" id="next" value=" Next" /></div>127 <div id="diffprevious"><input class="button" type="submit" id="previous" value="<?php esc_attr_e( 'Previous' ); ?>" /></div> 128 <div id="diffnext"><input class="button" type="submit" id="next" value="<?php esc_attr_e( 'Next' ); ?>" /></div> 124 129 <div id="diffslider"> 125 130 <div id="revisioncount"> 126 131 <?php _e( 'Comparing' ); ?> -
wp-admin/css/wp-admin.css
3727 3727 .leftmodelloading #modelsloading, 3728 3728 .rightmodelloading #modelsloading, 3729 3729 .leftmodelloading #modelsloading .spinner, 3730 .rightmodelloading #modelsloading .spinner { 3730 .rightmodelloading #modelsloading .spinner, 3731 { 3731 3732 display: inline; 3732 3733 } 3733 3734 3735 .diff-loading { 3736 margin-top: 50px; 3737 width: 100%; 3738 height: 200px; 3739 } 3740 .diff-loading .spinner 3741 { 3742 clear: both; 3743 margin-left: auto; 3744 margin-right: auto; 3745 display: block; 3746 float: none; 3747 } 3748 3734 3749 #difftitlefrom { 3735 3750 float: left; 3736 3751 display: none;