<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[24273] trunk: Separate the nonces update from checking the post lock.</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://core.trac.wordpress.org/changeset/24273">24273</a></dd>
<dt>Author</dt> <dd>azaozz</dd>
<dt>Date</dt> <dd>2013-05-16 03:47:09 +0000 (Thu, 16 May 2013)</dd>
</dl>

<h3>Log Message</h3>
<pre>Separate the nonces update from checking the post lock. Fix scheduling the logged out check. See <a href="http://core.trac.wordpress.org/ticket/23697">#23697</a>, see <a href="http://core.trac.wordpress.org/ticket/23295">#23295</a>.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpadminincludesmiscphp">trunk/wp-admin/includes/misc.php</a></li>
<li><a href="#trunkwpadminjspostjs">trunk/wp-admin/js/post.js</a></li>
<li><a href="#trunkwpincludesjswpauthcheckjs">trunk/wp-includes/js/wp-auth-check.js</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwpadminincludesmiscphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/includes/misc.php (24272 => 24273)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/includes/misc.php 2013-05-16 02:58:55 UTC (rev 24272)
+++ trunk/wp-admin/includes/misc.php    2013-05-16 03:47:09 UTC (rev 24273)
</span><span class="lines">@@ -623,8 +623,30 @@
</span><span class="cx">                          $send['new_lock'] = implode( ':', $new_lock );
</span><span class="cx">          }
</span><span class="cx"> 
</span><ins>+               $response['wp-refresh-post-lock'] = $send;
+       }
+
+       return $response;
+}
+add_filter( 'heartbeat_received', 'wp_refresh_post_lock', 10, 3 );
+
+/**
+ * Check nonce expiration on the New/Edit Post screen and refresh if needed
+ *
+ * @since 3.6
+ */
+function wp_refresh_post_nonces( $response, $data, $screen_id ) {
+       if ( 'post' == $screen_id && array_key_exists( 'wp-refresh-post-nonces', $data ) ) {
+               $received = $data['wp-refresh-post-nonces'];
+
+               if ( ! $post_id = absint( $received['post_id'] ) )
+                       return $response;
+
+               if ( ! current_user_can('edit_post', $post_id) )
+                       return $response;
+
</ins><span class="cx">           if ( ! empty( $received['post_nonce'] ) && 2 === wp_verify_nonce( $received['post_nonce'], 'update-post_' . $post_id ) ) {
</span><del>-                       $send['update_nonces'] = array(
</del><ins>+                        $response['wp-refresh-post-nonces'] = array(
</ins><span class="cx">                           'replace-autosavenonce' => wp_create_nonce('autosave'),
</span><span class="cx">                          'replace-getpermalinknonce' => wp_create_nonce('getpermalink'),
</span><span class="cx">                          'replace-samplepermalinknonce' => wp_create_nonce('samplepermalink'),
</span><span class="lines">@@ -633,13 +655,11 @@
</span><span class="cx">                          'replace-_wpnonce' => wp_create_nonce( 'update-post_' . $post_id ),
</span><span class="cx">                  );
</span><span class="cx">          }
</span><del>-
-               $response['wp-refresh-post-lock'] = $send;
</del><span class="cx">   }
</span><span class="cx"> 
</span><span class="cx">  return $response;
</span><span class="cx"> }
</span><del>-add_filter( 'heartbeat_received', 'wp_refresh_post_lock', 10, 3 );
</del><ins>+add_filter( 'heartbeat_received', 'wp_refresh_post_nonces', 10, 3 );
</ins><span class="cx"> 
</span><span class="cx"> /**
</span><span class="cx">  * Output the HTML for restoring the post data from DOM storage
</span></span></pre></div>
<a id="trunkwpadminjspostjs"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/js/post.js (24272 => 24273)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/js/post.js        2013-05-16 02:58:55 UTC (rev 24272)
+++ trunk/wp-admin/js/post.js   2013-05-16 03:47:09 UTC (rev 24273)
</span><span class="lines">@@ -254,7 +254,6 @@
</span><span class="cx"> $(document).on( 'heartbeat-send.refresh-lock', function( e, data ) {
</span><span class="cx">  var lock = $('#active_post_lock').val(),
</span><span class="cx">          post_id = $('#post_ID').val(),
</span><del>-               post_nonce = $('#_wpnonce').val(),
</del><span class="cx">           send = {};
</span><span class="cx"> 
</span><span class="cx">  if ( !post_id )
</span><span class="lines">@@ -265,9 +264,6 @@
</span><span class="cx">  if ( lock )
</span><span class="cx">          send['lock'] = lock;
</span><span class="cx"> 
</span><del>-       if ( post_nonce )
-               send['post_nonce'] = post_nonce;
-
</del><span class="cx">   data['wp-refresh-post-lock'] = send;
</span><span class="cx"> });
</span><span class="cx"> 
</span><span class="lines">@@ -321,6 +317,42 @@
</span><span class="cx"> 
</span><span class="cx"> }(jQuery));
</span><span class="cx"> 
</span><ins>+(function($) {
+       var check, timeout;
+
+       function schedule() {
+               check = false;
+               window.clearTimeout( timeout );
+               timeout = window.setTimeout( function(){ check = 1; }, 3600000 );
+       }
+
+       $(document).on( 'heartbeat-send.wp-refresh-nonces', function( e, data ) { 
+               var nonce, post_id;
+
+               if ( check ) {
+                       if ( ( post_id = $('#post_ID').val() ) && ( nonce = $('#_wpnonce').val() ) ) {
+                               data['wp-refresh-post-nonces'] = {
+                                       post_id: post_id,
+                                       post_nonce: nonce
+                               };
+                       }
+                       check = 2;
+               }
+       }).on( 'heartbeat-tick.wp-refresh-nonces', function( e, data ) {
+               if ( check === 2 )
+                       schedule();
+
+               if ( data['wp-refresh-post-nonces'] ) {
+                       $.each( data['wp-refresh-post-nonces'], function( selector, value ) {
+                               if ( selector.match(/^replace-/) )
+                                       $( '#' + selector.replace('replace-', '') ).val( value );
+                       });
+               }
+       }).ready( function() {
+               schedule();
+       });
+}(jQuery));
+
</ins><span class="cx"> jQuery(document).ready( function($) {
</span><span class="cx">  var stamp, visibility, sticky = '', last = 0, co = $('#content');
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkwpincludesjswpauthcheckjs"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/js/wp-auth-check.js (24272 => 24273)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/js/wp-auth-check.js    2013-05-16 02:58:55 UTC (rev 24272)
+++ trunk/wp-includes/js/wp-auth-check.js       2013-05-16 03:47:09 UTC (rev 24273)
</span><span class="lines">@@ -72,11 +72,11 @@
</span><span class="cx">  function schedule() {
</span><span class="cx">          check = false;
</span><span class="cx">          window.clearTimeout( timeout );
</span><del>-               timeout = window.setTimeout( function(){ check = true; }, 180000 ); // 3 min.
</del><ins>+                timeout = window.setTimeout( function(){ check = 1; }, 180000 ); // 3 min.
</ins><span class="cx">   }
</span><span class="cx"> 
</span><span class="cx">  $( document ).on( 'heartbeat-tick.wp-auth-check', function( e, data ) {
</span><del>-               if ( check )
</del><ins>+                if ( check === 2 )
</ins><span class="cx">                   schedule();
</span><span class="cx"> 
</span><span class="cx">          if ( data['wp-auth-check'] && wrap.hasClass('hidden') ) {
</span><span class="lines">@@ -103,6 +103,9 @@
</span><span class="cx"> 
</span><span class="cx">                  if ( check || ! empty )
</span><span class="cx">                          data['wp-auth-check'] = 1;
</span><ins>+
+                       if ( check )
+                               check = 2;
</ins><span class="cx">           });
</span><span class="cx">  });
</span><span class="cx"> 
</span></span></pre>
</div>
</div>

</body>
</html>