Skip to content

Commit 1167cf4

Browse files
Grouped backports to the 4.9 branch.
- Posts, Post types: Apply KSES to post-by-email content, - General: Validate host on "Are you sure?" screen, - Posts, Post types: Remove emails from post-by-email logs, - Media: Refactor search by filename within the admin, - Pings/trackbacks: Apply KSES to all trackbacks, - Comments: Apply kses when editing comments, - Customize: Escape blogname option in underscores templates, - REST API: Lockdown post parameter of the terms endpoint, - Mail: Reset PHPMailer properties between use, - Query: Validate relation in `WP_Date_Query`, - Widgets: Escape RSS error messages for display. Merges [54521], [54522], [54523], [54524], [54525], [54526], [54527], [54528], [54529], [54530], [54541] to the 4.9 branch. Props voldemortensen, johnbillion, paulkevan, peterwilsoncc, xknown, dd32, audrasjb, martinkrcho, vortfu, davidbaumwald, tykoted, timothyblynjacobs, johnjamesjacoby, ehtis, matveb, talldanwp. git-svn-id: https://develop.svn.wordpress.org/branches/4.9@54569 602fd350-edb4-49c9-b593-d223f7449a82
1 parent dea2dfd commit 1167cf4

19 files changed

+300
-69
lines changed

src/wp-admin/includes/ajax-actions.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2471,7 +2471,7 @@ function wp_ajax_query_attachments() {
24712471

24722472
// Filter query clauses to include filenames.
24732473
if ( isset( $query['s'] ) ) {
2474-
add_filter( 'posts_clauses', '_filter_query_attachment_filenames' );
2474+
add_filter( 'wp_allow_query_attachment_by_filename', '__return_true' );
24752475
}
24762476

24772477
/**

src/wp-admin/includes/post.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1174,7 +1174,7 @@ function wp_edit_attachments_query_vars( $q = false ) {
11741174

11751175
// Filter query clauses to include filenames.
11761176
if ( isset( $q['s'] ) ) {
1177-
add_filter( 'posts_clauses', '_filter_query_attachment_filenames' );
1177+
add_filter( 'wp_allow_query_attachment_by_filename', '__return_true' );
11781178
}
11791179

11801180
return $q;

src/wp-includes/class-wp-query.php

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,13 @@ class WP_Query {
437437

438438
private $compat_methods = array( 'init_query_flags', 'parse_tax_query' );
439439

440+
/**
441+
* Controls whether an attachment query should include filenames or not.
442+
*
443+
* @since 6.0.3
444+
* @var bool
445+
*/
446+
protected $allow_query_attachment_by_filename = false;
440447
/**
441448
* Resets query flags to false.
442449
*
@@ -1298,7 +1305,12 @@ protected function parse_search( &$q ) {
12981305
}
12991306

13001307
$like = $n . $wpdb->esc_like( $term ) . $n;
1301-
$search .= $wpdb->prepare( "{$searchand}(({$wpdb->posts}.post_title $like_op %s) $andor_op ({$wpdb->posts}.post_excerpt $like_op %s) $andor_op ({$wpdb->posts}.post_content $like_op %s))", $like, $like, $like );
1308+
1309+
if ( ! empty( $this->allow_query_attachment_by_filename ) ) {
1310+
$search .= $wpdb->prepare( "{$searchand}(({$wpdb->posts}.post_title $like_op %s) $andor_op ({$wpdb->posts}.post_excerpt $like_op %s) $andor_op ({$wpdb->posts}.post_content $like_op %s) $andor_op (sq1.meta_value $like_op %s))", $like, $like, $like, $like );
1311+
} else {
1312+
$search .= $wpdb->prepare( "{$searchand}(({$wpdb->posts}.post_title $like_op %s) $andor_op ({$wpdb->posts}.post_excerpt $like_op %s) $andor_op ({$wpdb->posts}.post_content $like_op %s))", $like, $like, $like );
1313+
}
13021314
$searchand = ' AND ';
13031315
}
13041316

@@ -1634,6 +1646,16 @@ public function get_posts() {
16341646
// Fill again in case pre_get_posts unset some vars.
16351647
$q = $this->fill_query_vars($q);
16361648

1649+
/**
1650+
* Filters whether an attachment query should include filenames or not.
1651+
*
1652+
* @since 6.0.3
1653+
*
1654+
* @param bool $allow_query_attachment_by_filename Whether or not to include filenames.
1655+
*/
1656+
$this->allow_query_attachment_by_filename = apply_filters( 'wp_allow_query_attachment_by_filename', false );
1657+
remove_all_filters( 'wp_allow_query_attachment_by_filename' );
1658+
16371659
// Parse meta query
16381660
$this->meta_query = new WP_Meta_Query();
16391661
$this->meta_query->parse_query_vars( $q );
@@ -2038,7 +2060,7 @@ public function get_posts() {
20382060
}
20392061
}
20402062

2041-
if ( !empty( $this->tax_query->queries ) || !empty( $this->meta_query->queries ) ) {
2063+
if ( ! empty( $this->tax_query->queries ) || ! empty( $this->meta_query->queries ) || ! empty( $this->allow_query_attachment_by_filename ) ) {
20422064
$groupby = "{$wpdb->posts}.ID";
20432065
}
20442066

@@ -2111,6 +2133,10 @@ public function get_posts() {
21112133
}
21122134
$where .= $search . $whichauthor . $whichmimetype;
21132135

2136+
if ( ! empty( $this->allow_query_attachment_by_filename ) ) {
2137+
$join .= " LEFT JOIN {$wpdb->postmeta} AS sq1 ON ( {$wpdb->posts}.ID = sq1.post_id AND sq1.meta_key = '_wp_attached_file' )";
2138+
}
2139+
21142140
if ( ! empty( $this->meta_query->queries ) ) {
21152141
$clauses = $this->meta_query->get_sql( 'post', $wpdb->posts, 'ID', $this );
21162142
$join .= $clauses['join'];

src/wp-includes/comment.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2195,6 +2195,15 @@ function wp_update_comment($commentarr) {
21952195
return 0;
21962196
}
21972197

2198+
$filter_comment = false;
2199+
if ( ! has_filter( 'pre_comment_content', 'wp_filter_kses' ) ) {
2200+
$filter_comment = ! user_can( isset( $comment['user_id'] ) ? $comment['user_id'] : 0, 'unfiltered_html' );
2201+
}
2202+
2203+
if ( $filter_comment ) {
2204+
add_filter( 'pre_comment_content', 'wp_filter_kses' );
2205+
}
2206+
21982207
// Escape data pulled from DB.
21992208
$comment = wp_slash($comment);
22002209

@@ -2205,6 +2214,10 @@ function wp_update_comment($commentarr) {
22052214

22062215
$commentarr = wp_filter_comment( $commentarr );
22072216

2217+
if ( $filter_comment ) {
2218+
remove_filter( 'pre_comment_content', 'wp_filter_kses' );
2219+
}
2220+
22082221
// Now extract the merged array.
22092222
$data = wp_unslash( $commentarr );
22102223

src/wp-includes/customize/class-wp-customize-header-image-control.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,10 @@ public function print_header_image_template() {
103103
<# } else { #>
104104

105105
<button type="button" class="choice thumbnail"
106-
data-customize-image-value="{{{data.header.url}}}"
106+
data-customize-image-value="{{data.header.url}}"
107107
data-customize-header-image-data="{{JSON.stringify(data.header)}}">
108108
<span class="screen-reader-text"><?php _e( 'Set image' ); ?></span>
109-
<img src="{{{data.header.thumbnail_url}}}" alt="{{{data.header.alt_text || data.header.description}}}">
109+
<img src="{{data.header.thumbnail_url}}" alt="{{data.header.alt_text || data.header.description}}" />
110110
</button>
111111

112112
<# if ( data.type === 'uploaded' ) { #>

src/wp-includes/customize/class-wp-customize-site-icon-control.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public function content_template() {
6666
<div class="favicon">
6767
<img src="{{ data.attachment.sizes.full ? data.attachment.sizes.full.url : data.attachment.url }}" alt="<?php esc_attr_e( 'Preview as a browser icon' ); ?>"/>
6868
</div>
69-
<span class="browser-title" aria-hidden="true"><?php bloginfo( 'name' ); ?></span>
69+
<span class="browser-title" aria-hidden="true"><?php echo esc_js( get_bloginfo( 'name' ) ); ?></span>
7070
</div>
7171
<img class="app-icon-preview" src="{{ data.attachment.sizes.full ? data.attachment.sizes.full.url : data.attachment.url }}" alt="<?php esc_attr_e( 'Preview as an app icon' ); ?>"/>
7272
</div>

src/wp-includes/date.php

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,8 @@ class WP_Date_Query {
145145
* 'comment_date', 'comment_date_gmt'.
146146
*/
147147
public function __construct( $date_query, $default_column = 'post_date' ) {
148-
if ( isset( $date_query['relation'] ) && 'OR' === strtoupper( $date_query['relation'] ) ) {
149-
$this->relation = 'OR';
148+
if ( isset( $date_query['relation'] ) ) {
149+
$this->relation = $this->sanitize_relation( $date_query['relation'] );
150150
} else {
151151
$this->relation = 'AND';
152152
}
@@ -225,6 +225,9 @@ public function sanitize_query( $queries, $parent_query = null ) {
225225
$this->validate_date_values( $queries );
226226
}
227227

228+
// Sanitize the relation parameter.
229+
$queries['relation'] = $this->sanitize_relation( $queries['relation'] );
230+
228231
foreach ( $queries as $key => $q ) {
229232
if ( ! is_array( $q ) || in_array( $key, $this->time_keys, true ) ) {
230233
// This is a first-order query. Trust the values and sanitize when building SQL.
@@ -998,4 +1001,20 @@ public function build_time_query( $column, $compare, $hour = null, $minute = nul
9981001

9991002
return $wpdb->prepare( "DATE_FORMAT( $column, %s ) $compare %f", $format, $time );
10001003
}
1004+
1005+
/**
1006+
* Sanitizes a 'relation' operator.
1007+
*
1008+
* @since 6.0.3
1009+
*
1010+
* @param string $relation Raw relation key from the query argument.
1011+
* @return string Sanitized relation ('AND' or 'OR').
1012+
*/
1013+
public function sanitize_relation( $relation ) {
1014+
if ( 'OR' === strtoupper( $relation ) ) {
1015+
return 'OR';
1016+
} else {
1017+
return 'AND';
1018+
}
1019+
}
10011020
}

src/wp-includes/deprecated.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3944,3 +3944,21 @@ function wp_ajax_press_this_add_category() {
39443944
wp_send_json_error( array( 'errorMessage' => __( 'The Press This plugin is required.' ) ) );
39453945
}
39463946
}
3947+
3948+
/**
3949+
* Filter the SQL clauses of an attachment query to include filenames.
3950+
*
3951+
* @since 4.7.0
3952+
* @deprecated 6.0.3
3953+
* @access private
3954+
*
3955+
* @param array $clauses An array including WHERE, GROUP BY, JOIN, ORDER BY,
3956+
* DISTINCT, fields (SELECT), and LIMITS clauses.
3957+
* @return array The unmodified clauses.
3958+
*/
3959+
function _filter_query_attachment_filenames( $clauses ) {
3960+
_deprecated_function( __FUNCTION__, '6.0.3', 'add_filter( "wp_allow_query_attachment_by_filename", "__return_true" )');
3961+
remove_filter( 'posts_clauses', __FUNCTION__ );
3962+
return $clauses;
3963+
}
3964+

src/wp-includes/functions.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2377,7 +2377,7 @@ function wp_check_filetype_and_ext( $file, $filename, $mimes = null ) {
23772377
} else {
23782378
if ( $type !== $real_mime ) {
23792379
/*
2380-
* Everything else including image/* and application/*:
2380+
* Everything else including image/* and application/*:
23812381
* If the real content type doesn't match the file extension, assume it's dangerous.
23822382
*/
23832383
$type = $ext = false;
@@ -2386,7 +2386,7 @@ function wp_check_filetype_and_ext( $file, $filename, $mimes = null ) {
23862386
}
23872387
}
23882388

2389-
// The mime type must be allowed
2389+
// The mime type must be allowed
23902390
if ( $type ) {
23912391
$allowed = get_allowed_mime_types();
23922392

@@ -2660,9 +2660,12 @@ function wp_nonce_ays( $action ) {
26602660
} else {
26612661
$html = __( 'The link you followed has expired.' );
26622662
if ( wp_get_referer() ) {
2663-
$html .= '</p><p>';
2664-
$html .= sprintf( '<a href="%s">%s</a>',
2665-
esc_url( remove_query_arg( 'updated', wp_get_referer() ) ),
2663+
$wp_http_referer = remove_query_arg( 'updated', wp_get_referer() );
2664+
$wp_http_referer = wp_validate_redirect( esc_url_raw( $wp_http_referer ) );
2665+
$html .= '</p><p>';
2666+
$html .= sprintf(
2667+
'<a href="%s">%s</a>',
2668+
esc_url( $wp_http_referer ),
26662669
__( 'Please try again.' )
26672670
);
26682671
}

src/wp-includes/media-template.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1252,7 +1252,7 @@ function wp_print_media_templates() {
12521252
<div class="favicon">
12531253
<img id="preview-favicon" src="{{ data.url }}" alt="<?php esc_attr_e( 'Preview as a browser icon' ); ?>"/>
12541254
</div>
1255-
<span class="browser-title" aria-hidden="true"><?php bloginfo( 'name' ); ?></span>
1255+
<span class="browser-title" aria-hidden="true"><?php echo esc_js( get_bloginfo( 'name' ) ); ?></span>
12561256
</div>
12571257

12581258
<strong aria-hidden="true"><?php _e( 'As an app icon' ); ?></strong>

0 commit comments

Comments
 (0)