Ticket #23497: 23497.19.diff
File 23497.19.diff, 36.0 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 2220 $count = -1; 2211 2221 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 } 2222 foreach ( $revisions as $revision ) : 2223 if ( ! empty( $show_autosaves ) && wp_is_post_autosave( $revision ) ) 2224 continue; 2220 2225 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' ); 2226 $revision_from_date_author = ''; 2227 $count++; 2228 // return blank data for diffs to the left of the left handle (for right handel model) 2229 // or to the right of the right handle (for left handel model) 2230 if ( ( 0 != $left_handle_at && $count <= $left_handle_at ) || 2231 ( 0 != $right_handle_at && $count > $right_handle_at )) { 2232 $alltherevisions[] = array ( 2233 'ID' => $revision->ID, 2234 ); 2235 2236 continue; 2237 } 2228 2238 2229 add_filter( "_wp_post_revision_field_$field", 'wp_kses_post' ); 2239 $gravatar = get_avatar( $revision->post_author, 18 ); 2240 $author = get_the_author_meta( 'display_name', $revision->post_author ); 2241 $date = date_i18n( $datef, strtotime( $revision->post_modified ) ); 2242 $revision_date_author = sprintf( 2243 '%s %s, %s %s (%s)', 2244 $gravatar, 2245 $author, 2246 human_time_diff( strtotime( $revision->post_modified ), current_time( 'timestamp' ) ), 2247 __( ' ago ' ), 2248 $date 2249 ); 2230 2250 2231 $args = array(); 2232 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' => '' 2251 $restoreaction = wp_nonce_url( 2252 add_query_arg( 2253 array( 'revision' => $revision->ID, 2254 'action' => 'restore' ), 2255 admin_url( 'revision.php' ) 2256 ), 2257 "restore-post_{$compare_to}|{$revision->ID}" 2249 2258 ); 2250 2259 2251 //add to the return data only if there is a difference2252 if ( '' != $content )2253 2260 $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 );2261 'ID' => $revision->ID, 2262 'revision_date_author' => $revision_date_author, 2263 'revision_from_date_author' => $revision_from_date_author, 2264 'restoreaction' => urldecode( $restoreaction ), 2265 'revision_toload' => true 2266 ); 2260 2267 2261 2268 endforeach; 2262 2269 -
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, reverse_direction ) { 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() { 60 the_model.fetch( { 61 update : true, 62 add : false, 63 remove : false, 64 //async : false, 65 success : function( model ) { 66 //console.log(model.get( 'ID' ) +'-'+self._revisions.at( self._right_diff ).get( 'ID' )); 67 if ( model.get( 'ID' ) === self._revisions.at( self._right_diff - 1 ).get( 'ID' ) ) { //reload if current model refreshed 68 //console.log('render'); 69 self._revisionView.render(); 70 } 71 } 72 } ); 73 }, delay ) ; 74 delay = delay + 200; //stagger model loads by 200 ms to avoid hammering server with requests 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 67 99 reloadmodel : function() { 68 if ( 2 == this._compareoneortwo ) {100 if ( 2 === this._compareoneortwo ) { 69 101 this.reloadleftright(); 70 102 } else { 71 103 this.reloadmodelsingle(); … … 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 () { 96 128 self.stop_right_model_loading(); 97 window.console &&console.log( 'Error loading revision data' );129 //console.log( 'Error loading revision data' ); 98 130 } 99 131 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 () { 158 window.console &&console.log( 'Error loading revision data' );156 //console.log( 'Error loading revision data' ); 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 //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(); 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 ); 203 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&compare to=' + wpRevisionsSettings.post_id + '&showautosaves=false&showsplitview=true&nonce=' + wpRevisionsSettings.nonce221 });254 url : ajaxurl + '?action=revisions-data&compare_to=' + wpRevisionsSettings.post_id + 255 '&show_autosaves=false&show_split_view=true&nonce=' + wpRevisionsSettings.nonce, 222 256 257 initialize : function() { 258 } 259 } ); 260 223 261 _.extend(wp.revisions.views, { 224 262 // 225 263 //primary revision diff view … … 242 280 render : function() { 243 281 var addhtml = ''; 244 282 //compare two revisions mode? 245 if ( 2 == REVAPP._compareoneortwo ) {283 if ( 2 === REVAPP._compareoneortwo ) { 246 284 this.comparetwochecked = 'checked'; 247 285 if ( this.draggingleft ) { 248 286 if ( this.model.at( REVAPP._left_diff ) ) { … … 260 298 ) ); 261 299 } 262 300 } 263 } else { //end compare two revisions mode, eg only one slider hand el301 } else { //end compare two revisions mode, eg only one slider handle 264 302 this.comparetwochecked = ''; 265 303 if ( this.model.at( REVAPP._right_diff - 1 ) ) { 266 304 addhtml = this.template( _.extend( 267 this.model.at( REVAPP._right_diff -1 ).toJSON(),268 { comparetwochecked : this.comparetwochecked } //keep the checkmark checked305 this.model.at( REVAPP._right_diff - 1 ).toJSON(), 306 { comparetwochecked : this.comparetwochecked } //keep the checkmark unchecked 269 307 ) ); 270 308 } 271 309 } 272 310 this.$el.html( addhtml ); 311 if ( this.model.length < 3 ) { 312 $( 'div#comparetworevisions' ).hide(); //don't allow compare two if fewer than three revisions 313 314 } 315 //console.log ( (this.model.at( REVAPP._right_diff - 1 )).url()); 273 316 return this; 274 317 }, 275 318 … … 322 365 }, 323 366 324 367 // 325 //toggle include autosaves 368 //toggle include autosaves 326 369 // 327 370 toggleshowautosaves : function() { 328 371 var self = this; … … 331 374 } else { 332 375 REVAPP._autosaves = false ; 333 376 } 377 334 378 //refresh the model data 335 336 379 REVAPP.reloadmodel(); 337 //TODO check for two handle mode338 339 380 }, 340 381 341 382 // … … 345 386 var self = this; 346 387 347 388 if ( $( 'input#showsplitview' ).is( ':checked' ) ) { 348 REVAPP._show splitview = 'true';389 REVAPP._show_split_view = 'true'; 349 390 $('.revisiondiffcontainer').addClass('diffsplit'); 350 391 } else { 351 REVAPP._show splitview = '';392 REVAPP._show_split_view = ''; 352 393 $('.revisiondiffcontainer').removeClass('diffsplit'); 353 394 } 354 395 … … 364 405 tagName : 'revisionvinteract', 365 406 className : 'revisionvinteract-container', 366 407 template : wp.template('revisionvinteract'), 408 _restoreword : '', 367 409 368 410 initialize : function() { 411 this._restoreword = $( 'input#restore' ).attr( 'value' ); 369 412 }, 370 413 414 reset_restore_button : function() { 415 $( 'input#restore' ).attr( 'value', this._restoreword + ' ' + REVAPP._revisions.at( REVAPP._right_diff - 1 ).get( 'ID' ) ); 416 }, 417 371 418 render : function() { 372 419 var self = this; 373 420 … … 375 422 this.$el.html( addhtml ); 376 423 $( '#diff_max, #diff_maxof' ).html( this.model.length ); 377 424 $( '#diff_count' ).html( REVAPP._right_diff ); 378 $( '#diff_left_count_inner' ).html( 0 == REVAPP._left_diff ? '' : 'revision' + REVAPP._left_diff ); 425 $( '#diff_left_count_inner' ).html( 0 === REVAPP._left_diff ? '' : 'revision' + REVAPP._left_diff ); 426 self.reset_restore_button(); 379 427 380 428 var modelcount = REVAPP._revisions.length; 381 429 382 slider = $( "#slider");383 if ( 1 == REVAPP._compareoneortwo ) {430 slider = $( "#slider" ); 431 if ( 1 === REVAPP._compareoneortwo ) { 384 432 //set up the slider with a single handle 385 433 slider.slider({ 386 434 value : REVAPP._right_diff-1, … … 390 438 391 439 //slide interactions for one handles slider 392 440 slide : function( event, ui ) { 393 if ( REVAPP. right_model_loading ) //left model stoll loading, prevent sliding left handle441 if ( REVAPP._right_model_loading ) //left model stoll loading, prevent sliding left handle 394 442 return false; 395 443 396 444 REVAPP._right_diff =( ui.value+1 ); 397 445 $( '#diff_count' ).html( REVAPP._right_diff ); 398 446 REVAPP._revisionView.render(); 447 self.reset_restore_button(); 399 448 } 400 449 }); 401 450 $( '.revisiondiffcontainer' ).removeClass( 'comparetwo' ); … … 414 463 415 464 switch ( index ) { 416 465 case 1: //left handle drag 417 if ( REVAPP. left_model_loading ) //left model stoll loading, prevent sliding left handle466 if ( REVAPP._left_model_loading ) //left model stoll loading, prevent sliding left handle 418 467 return false; 419 468 420 469 if ( REVAPP._revisionView.model !== REVAPP._left_handle_revisions && 421 null != REVAPP._left_handle_revisions )470 null !== REVAPP._left_handle_revisions ) 422 471 REVAPP._revisionView.model = REVAPP._left_handle_revisions; 423 472 424 473 REVAPP._revisionView.draggingleft = true; 474 REVAPP._left_diff_start = ui.values[ 0 ]; 425 475 break; 426 476 427 477 case 2: //right 428 if ( REVAPP. right_model_loading ) //right model stoll loading, prevent sliding right handle478 if ( REVAPP._right_model_loading ) //right model stoll loading, prevent sliding right handle 429 479 return false; 430 480 431 481 //one extra spot at left end when comparing two 432 482 if ( REVAPP._revisionView.model !== REVAPP._right_handle_revisions && 433 null != REVAPP._right_handle_revisions )483 null !== REVAPP._right_handle_revisions ) 434 484 REVAPP._revisionView.model = REVAPP._right_handle_revisions; 435 485 436 486 REVAPP._revisionView.draggingleft = false; 437 REVAPP._right_diff = ui.values[1] - 1;487 REVAPP._right_diff_start = ui.values[ 1 ]; 438 488 break; 439 489 } 440 490 }, 441 491 442 492 //when sliding in two handled mode change appropriate value 443 493 slide : function( event, ui ) { 444 if ( ui.values[ 0] == ui.values[1] ) //prevent compare to self494 if ( ui.values[ 0 ] === ui.values[ 1 ] ) //prevent compare to self 445 495 return false; 446 496 447 497 var index = $( ui.handle ).index(); //0 (left) or 1 (right) 448 498 449 499 switch ( index ) { 450 500 case 1: //left 451 if ( REVAPP. left_model_loading ) //left model stoll loading, prevent sliding left handle501 if ( REVAPP._left_model_loading ) //left model still loading, prevent sliding left handle 452 502 return false; 453 503 454 REVAPP._left_diff = ui.values[ 0] - 1; //one extra spot at left end when comparing two504 REVAPP._left_diff = ui.values[ 0 ] - 1; //one extra spot at left end when comparing two 455 505 break; 456 506 457 507 case 2: //right 458 if ( REVAPP. right_model_loading ) //right model stoll loading, prevent sliding right handle508 if ( REVAPP._right_model_loading ) //right model still loading, prevent sliding right handle 459 509 return false; 460 510 461 REVAPP._right_diff = ui.values[ 1] - 1 ;511 REVAPP._right_diff = ui.values[ 1 ] - 1 ; 462 512 break; 463 513 } 464 514 465 515 $( '#diff_count' ).html( REVAPP._right_diff ); 466 516 467 if ( 0 == REVAPP._left_diff ) {517 if ( 0 === REVAPP._left_diff ) { 468 518 $( '.revisiondiffcontainer' ).addClass( 'currentversion' ); 469 519 470 520 } else { … … 473 523 } 474 524 475 525 REVAPP._revisionView.render(); //render the diff view 526 self.reset_restore_button(); 476 527 }, 477 528 478 529 //when the user stops sliding in 2 handle mode, recalculate diffs 479 530 stop : function( event, ui ) { 480 if ( 2 == REVAPP._compareoneortwo ) {531 if ( 2 === REVAPP._compareoneortwo ) { 481 532 //calculate and generate a diff for comparing to the left handle 482 533 //and the right handle, swap out when dragging 483 if ( ! (REVAPP.left_model_loading && REVAPP.right_model.loading ) ) { 484 REVAPP.reloadleftright(); 534 535 var index = $( ui.handle ).index(); //0 (left) or 1 (right) 536 537 switch ( index ) { 538 case 1: //left 539 //left handle dragged & changed, reload right handle model 540 if ( ! ( REVAPP._left_diff_start === ui.values[ 0 ] || REVAPP._left_model_loading ) ) 541 REVAPP.reloadright(); 542 543 break; 544 545 case 2: //right 546 //right handle dragged & changed, reload left handle model if changed 547 if ( ! ( REVAPP._right_diff_start === ui.values[ 1 ] || REVAPP._right_model_loading ) ) { 548 REVAPP.reloadleft(); 549 } 550 break; 485 551 } 486 552 } 487 553 } … … 507 573 508 574 $( '#diff_count' ).html( REVAPP._right_diff ); 509 575 $( '#slider' ).slider( 'value', REVAPP._right_diff - 1 ).trigger( 'slide' ); 576 this.reset_restore_button(); 510 577 }, 511 578 512 579 //go the the previous revision … … 518 585 519 586 $( '#diff_count' ).html( REVAPP._right_diff ); 520 587 $( '#slider' ).slider( 'value', REVAPP._right_diff - 1 ).trigger( 'slide' ); 588 this.reset_restore_button(); 521 589 } 522 590 }) 523 591 }); … … 525 593 //instantiate Revision Application 526 594 REVAPP = new wp.revisions.App(); 527 595 //TODO consider enable back button to step back thru states? 528 Backbone.history.start();596 //Backbone.history.start({pushState: true}); 529 597 530 598 }(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 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
3723 3723 .leftmodelloading #modelsloading, 3724 3724 .rightmodelloading #modelsloading, 3725 3725 .leftmodelloading #modelsloading .spinner, 3726 .rightmodelloading #modelsloading .spinner { 3726 .rightmodelloading #modelsloading .spinner, 3727 { 3727 3728 display: inline; 3728 3729 } 3729 3730 3731 .diff-loading { 3732 margin-top: 50px; 3733 width: 100%; 3734 height: 200px; 3735 } 3736 .diff-loading .spinner 3737 { 3738 clear: both; 3739 margin-left: auto; 3740 margin-right: auto; 3741 display: block; 3742 float: none; 3743 } 3744 3730 3745 #difftitlefrom { 3731 3746 float: left; 3732 3747 display: none;