<!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>[28458] trunk/src/wp-includes/comment.php: Eliminate use of `extract()` in `WP_Comment_Query::query()`.</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/28458">28458</a></dd>
<dt>Author</dt> <dd>wonderboymusic</dd>
<dt>Date</dt> <dd>2014-05-16 19:32:05 +0000 (Fri, 16 May 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>Eliminate use of `extract()` in `WP_Comment_Query::query()`. 

See <a href="http://core.trac.wordpress.org/ticket/22400">#22400</a>.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpincludescommentphp">trunk/src/wp-includes/comment.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpincludescommentphp"></a>
<div class="modfile"><h4>Modified: trunk/src/wp-includes/comment.php (28457 => 28458)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/src/wp-includes/comment.php        2014-05-16 18:51:41 UTC (rev 28457)
+++ trunk/src/wp-includes/comment.php   2014-05-16 19:32:05 UTC (rev 28458)
</span><span class="lines">@@ -277,7 +277,7 @@
</span><span class="cx">          extract( $this->query_vars, EXTR_SKIP );
</span><span class="cx"> 
</span><span class="cx">          // $args can be whatever, only use the args defined in defaults to compute the key
</span><del>-               $key = md5( serialize( compact(array_keys($defaults)) )  );
</del><ins>+                $key = md5( serialize( compact( array_keys( $defaults ) ) )  );
</ins><span class="cx">           $last_changed = wp_cache_get( 'last_changed', 'comment' );
</span><span class="cx">          if ( ! $last_changed ) {
</span><span class="cx">                  $last_changed = microtime();
</span><span class="lines">@@ -285,24 +285,27 @@
</span><span class="cx">          }
</span><span class="cx">          $cache_key = "get_comments:$key:$last_changed";
</span><span class="cx"> 
</span><del>-               if ( $cache = wp_cache_get( $cache_key, 'comment' ) )
</del><ins>+                if ( $cache = wp_cache_get( $cache_key, 'comment' ) ) {
</ins><span class="cx">                   return $cache;
</span><ins>+               }
</ins><span class="cx"> 
</span><del>-               $post_id = absint($post_id);
-
-               if ( 'hold' == $status )
</del><ins>+                $status = $this->query_vars['status'];
+               if ( 'hold' == $status ) {
</ins><span class="cx">                   $approved = "comment_approved = '0'";
</span><del>-               elseif ( 'approve' == $status )
</del><ins>+                } elseif ( 'approve' == $status ) {
</ins><span class="cx">                   $approved = "comment_approved = '1'";
</span><del>-               elseif ( ! empty( $status ) && 'all' != $status )
</del><ins>+                } elseif ( ! empty( $status ) && 'all' != $status ) {
</ins><span class="cx">                   $approved = $wpdb->prepare( "comment_approved = %s", $status );
</span><del>-               else
</del><ins>+                } else {
</ins><span class="cx">                   $approved = "( comment_approved = '0' OR comment_approved = '1' )";
</span><ins>+               }
+               $order = ( 'ASC' == strtoupper( $this->query_vars['order'] ) ) ? 'ASC' : 'DESC';
</ins><span class="cx"> 
</span><del>-               $order = ( 'ASC' == strtoupper($order) ) ? 'ASC' : 'DESC';
</del><ins>+                if ( ! empty( $this->query_vars['orderby'] ) ) {
+                       $ordersby = is_array( $this->query_vars['orderby'] ) ?
+                               $this->query_vars['orderby'] :
+                               preg_split( '/[,\s]/', $this->query_vars['orderby'] );
</ins><span class="cx"> 
</span><del>-               if ( ! empty( $orderby ) ) {
-                       $ordersby = is_array($orderby) ? $orderby : preg_split('/[,\s]/', $orderby);
</del><span class="cx">                   $allowed_keys = array(
</span><span class="cx">                          'comment_agent',
</span><span class="cx">                          'comment_approved',
</span><span class="lines">@@ -338,52 +341,68 @@
</span><span class="cx">                  $orderby = 'comment_date_gmt';
</span><span class="cx">          }
</span><span class="cx"> 
</span><del>-               $number = absint($number);
-               $offset = absint($offset);
</del><ins>+                $number = absint( $this->query_vars['number'] );
+               $offset = absint( $this->query_vars['offset'] );
</ins><span class="cx"> 
</span><del>-               if ( !empty($number) ) {
-                       if ( $offset )
</del><ins>+                if ( ! empty( $number ) ) {
+                       if ( $offset ) {
</ins><span class="cx">                           $limits = 'LIMIT ' . $offset . ',' . $number;
</span><del>-                       else
</del><ins>+                        } else {
</ins><span class="cx">                           $limits = 'LIMIT ' . $number;
</span><ins>+                       }
</ins><span class="cx">           } else {
</span><span class="cx">                  $limits = '';
</span><span class="cx">          }
</span><span class="cx"> 
</span><del>-               if ( $count )
</del><ins>+                if ( $this->query_vars['count'] ) {
</ins><span class="cx">                   $fields = 'COUNT(*)';
</span><del>-               else
</del><ins>+                } else {
</ins><span class="cx">                   $fields = '*';
</span><del>-
</del><ins>+                }
</ins><span class="cx">           $join = '';
</span><span class="cx">          $where = $approved;
</span><span class="cx"> 
</span><del>-               if ( ! empty($post_id) )
</del><ins>+                $post_id = absint( $this->query_vars['post_id'] );
+               if ( ! empty( $post_id ) ) {
</ins><span class="cx">                   $where .= $wpdb->prepare( ' AND comment_post_ID = %d', $post_id );
</span><del>-               if ( '' !== $author_email )
-                       $where .= $wpdb->prepare( ' AND comment_author_email = %s', $author_email );
-               if ( '' !== $karma )
-                       $where .= $wpdb->prepare( ' AND comment_karma = %d', $karma );
-               if ( 'comment' == $type ) {
</del><ins>+                }
+
+               if ( '' !== $this->query_vars['author_email'] ) {
+                       $where .= $wpdb->prepare( ' AND comment_author_email = %s', $this->query_vars['author_email'] );
+               }
+
+               if ( '' !== $this->query_vars['karma'] ) {
+                       $where .= $wpdb->prepare( ' AND comment_karma = %d', $this->query_vars['karma'] );
+               }
+
+               if ( 'comment' == $this->query_vars['type'] ) {
</ins><span class="cx">                   $where .= " AND comment_type = ''";
</span><del>-               } elseif( 'pings' == $type ) {
</del><ins>+                } elseif( 'pings' == $this->query_vars['type'] ) {
</ins><span class="cx">                   $where .= ' AND comment_type IN ("pingback", "trackback")';
</span><del>-               } elseif ( ! empty( $type ) ) {
-                       $where .= $wpdb->prepare( ' AND comment_type = %s', $type );
</del><ins>+                } elseif ( ! empty( $this->query_vars['type'] ) ) {
+                       $where .= $wpdb->prepare( ' AND comment_type = %s', $this->query_vars['type'] );
</ins><span class="cx">           }
</span><del>-               if ( '' !== $parent )
-                       $where .= $wpdb->prepare( ' AND comment_parent = %d', $parent );
</del><span class="cx"> 
</span><del>-               if ( is_array( $user_id ) ) {
-                       $where .= ' AND user_id IN (' . implode( ',', array_map( 'absint', $user_id ) ) . ')';
-               } elseif ( '' !== $user_id ) {
-                       $where .= $wpdb->prepare( ' AND user_id = %d', $user_id );
</del><ins>+                if ( '' !== $this->query_vars['parent'] ) {
+                       $where .= $wpdb->prepare( ' AND comment_parent = %d', $this->query_vars['parent'] );
</ins><span class="cx">           }
</span><span class="cx"> 
</span><del>-               if ( '' !== $search )
-                       $where .= $this->get_search_sql( $search, array( 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_author_IP', 'comment_content' ) );
</del><ins>+                if ( is_array( $this->query_vars['user_id'] ) ) {
+                       $where .= ' AND user_id IN (' . implode( ',', array_map( 'absint', $this->query_vars['user_id'] ) ) . ')';
+               } elseif ( '' !== $this->query_vars['user_id'] ) {
+                       $where .= $wpdb->prepare( ' AND user_id = %d', $this->query_vars['user_id'] );
+               }
</ins><span class="cx"> 
</span><del>-               $post_fields = array_filter( compact( array( 'post_author', 'post_name', 'post_parent', 'post_status', 'post_type', ) ) );
</del><ins>+                if ( '' !== $this->query_vars['search'] ) {
+                       $where .= $this->get_search_sql(
+                               $this->query_vars['search'],
+                               array( 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_author_IP', 'comment_content' )
+                       );
+               }
+
+               $plucked = wp_array_slice_assoc( $this->query_vars, array( 'post_author', 'post_name', 'post_parent', 'post_status', 'post_type' ) );
+               $post_fields = array_filter( $plucked );
+
</ins><span class="cx">           if ( ! empty( $post_fields ) ) {
</span><span class="cx">                  $join = "JOIN $wpdb->posts ON $wpdb->posts.ID = $wpdb->comments.comment_post_ID";
</span><span class="cx">                  foreach( $post_fields as $field_name => $field_value )
</span><span class="lines">@@ -397,6 +416,7 @@
</span><span class="cx">                  $groupby = "{$wpdb->comments}.comment_ID";
</span><span class="cx">          }
</span><span class="cx"> 
</span><ins>+               $date_query = $this->query_vars['date_query'];
</ins><span class="cx">           if ( ! empty( $date_query ) && is_array( $date_query ) ) {
</span><span class="cx">                  $date_query_object = new WP_Date_Query( $date_query, 'comment_date' );
</span><span class="cx">                  $where .= $date_query_object->get_sql();
</span><span class="lines">@@ -415,24 +435,24 @@
</span><span class="cx">          foreach ( $pieces as $piece )
</span><span class="cx">                  $$piece = isset( $clauses[ $piece ] ) ? $clauses[ $piece ] : '';
</span><span class="cx"> 
</span><del>-               if ( $groupby )
</del><ins>+                if ( $groupby ) {
</ins><span class="cx">                   $groupby = 'GROUP BY ' . $groupby;
</span><del>-
</del><ins>+                }
</ins><span class="cx">           $query = "SELECT $fields FROM $wpdb->comments $join WHERE $where $groupby ORDER BY $orderby $order $limits";
</span><span class="cx"> 
</span><del>-               if ( $count )
</del><ins>+                if ( $this->query_vars['count'] ) {
</ins><span class="cx">                   return $wpdb->get_var( $query );
</span><del>-
-               $comments = $wpdb->get_results( $query );
</del><ins>+                }
+               $results = $wpdb->get_results( $query );
</ins><span class="cx">           /**
</span><span class="cx">           * Filter the comment query results.
</span><span class="cx">           *
</span><span class="cx">           * @since 3.1.0
</span><span class="cx">           *
</span><del>-                * @param array            $comments An array of comments.
</del><ins>+                 * @param array            $results  An array of comments.
</ins><span class="cx">            * @param WP_Comment_Query &$this    Current instance of WP_Comment_Query, passed by reference.
</span><span class="cx">           */
</span><del>-               $comments = apply_filters_ref_array( 'the_comments', array( $comments, &$this ) );
</del><ins>+                $comments = apply_filters_ref_array( 'the_comments', array( $results, &$this ) );
</ins><span class="cx"> 
</span><span class="cx">          wp_cache_add( $cache_key, $comments, 'comment' );
</span><span class="cx"> 
</span></span></pre>
</div>
</div>

</body>
</html>