Privacy: add "Mine" filter for media similarly to posts and comments.

Props audrasjb.
Merged [43056], [43062], [43063] to the 4.9 branch.
Fixes #43820.
Built from https://develop.svn.wordpress.org/branches/4.9@43064


git-svn-id: http://core.svn.wordpress.org/branches/4.9@42893 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Sergey Biryukov 2018-05-01 22:04:28 +00:00
parent cf7288a673
commit ee43146223
9 changed files with 75 additions and 23 deletions

View File

@ -2442,7 +2442,7 @@ function wp_ajax_query_attachments() {
$query = isset( $_REQUEST['query'] ) ? (array) $_REQUEST['query'] : array();
$keys = array(
's', 'order', 'orderby', 'posts_per_page', 'paged', 'post_mime_type',
'post_parent', 'post__in', 'post__not_in', 'year', 'monthnum'
'post_parent', 'author', 'post__in', 'post__not_in', 'year', 'monthnum'
);
foreach ( get_taxonomies_for_attachments( 'objects' ) as $t ) {
if ( $t->query_var && isset( $query[ $t->query_var ] ) ) {

View File

@ -119,8 +119,15 @@ class WP_Media_List_Table extends WP_List_Table {
$label[0]
);
}
$type_links['detached'] = '<option value="detached"' . ( $this->detached ? ' selected="selected"' : '' ) . '>' . __( 'Unattached' ) . '</option>';
$type_links['mine'] = sprintf(
'<option value="mine"%s>%s</option>',
selected( 'mine' === $filter, true, false ),
_x( 'Mine', 'media items' )
);
if ( $this->is_trash || ( defined( 'MEDIA_TRASH') && MEDIA_TRASH ) ) {
$type_links['trash'] = sprintf(
'<option value="trash"%s>%s</option>',
@ -128,6 +135,7 @@ class WP_Media_List_Table extends WP_List_Table {
_x( 'Trash', 'attachment filter' )
);
}
return $type_links;
}

View File

@ -1147,6 +1147,10 @@ function wp_edit_attachments_query_vars( $q = false ) {
$q['post_parent'] = 0;
}
if ( isset( $q['mine'] ) || ( isset( $q['attachment-filter'] ) && 'mine' == $q['attachment-filter'] ) ) {
$q['author'] = get_current_user_id();
}
// Filter query clauses to include filenames.
if ( isset( $q['s'] ) ) {
add_filter( 'posts_clauses', '_filter_query_attachment_filenames' );

View File

@ -1121,7 +1121,7 @@ Query = Attachments.extend(/** @lends wp.media.model.Query.prototype */{
// Only observe when a limited number of query args are set. There
// are no filters for other properties, so observing will result in
// false positives in those queries.
allowed = [ 's', 'order', 'orderby', 'posts_per_page', 'post_mime_type', 'post_parent' ];
allowed = [ 's', 'order', 'orderby', 'posts_per_page', 'post_mime_type', 'post_parent', 'author' ];
if ( wp.Uploader && _( this.args ).chain().keys().difference( allowed ).isEmpty().value() ) {
this.observe( wp.Uploader.queue );
}
@ -1238,14 +1238,15 @@ Query = Attachments.extend(/** @lends wp.media.model.Query.prototype */{
* @readonly
*/
propmap: {
'search': 's',
'type': 'post_mime_type',
'perPage': 'posts_per_page',
'menuOrder': 'menu_order',
'uploadedTo': 'post_parent',
'status': 'post_status',
'include': 'post__in',
'exclude': 'post__not_in'
'search': 's',
'type': 'post_mime_type',
'perPage': 'posts_per_page',
'menuOrder': 'menu_order',
'uploadedTo': 'post_parent',
'status': 'post_status',
'include': 'post__in',
'exclude': 'post__not_in',
'author': 'author'
},
/**
* Creates and returns an Attachments Query collection given the properties.
@ -1267,6 +1268,7 @@ Query = Attachments.extend(/** @lends wp.media.model.Query.prototype */{
* @param {Object} [props.menu_order]
* @param {Object} [props.post_parent]
* @param {Object} [props.post_status]
* @param {Object} [props.author]
* @param {Object} [options]
*
* @returns {wp.media.model.Query} A new Attachments Query collection.

File diff suppressed because one or more lines are too long

View File

@ -7022,6 +7022,7 @@ Uploaded = wp.media.view.AttachmentFilters.extend(/** @lends wp.media.view.Attac
createFilters: function() {
var type = this.model.get('type'),
types = wp.media.view.settings.mimeTypes,
uid = window.userSettings ? parseInt( window.userSettings.uid, 10 ) : 0,
text;
if ( types && type ) {
@ -7034,7 +7035,8 @@ Uploaded = wp.media.view.AttachmentFilters.extend(/** @lends wp.media.view.Attac
props: {
uploadedTo: null,
orderby: 'date',
order: 'DESC'
order: 'DESC',
author: null
},
priority: 10
},
@ -7044,7 +7046,8 @@ Uploaded = wp.media.view.AttachmentFilters.extend(/** @lends wp.media.view.Attac
props: {
uploadedTo: wp.media.view.settings.post.id,
orderby: 'menuOrder',
order: 'ASC'
order: 'ASC',
author: null
},
priority: 20
},
@ -7054,11 +7057,24 @@ Uploaded = wp.media.view.AttachmentFilters.extend(/** @lends wp.media.view.Attac
props: {
uploadedTo: 0,
orderby: 'menuOrder',
order: 'ASC'
order: 'ASC',
author: null
},
priority: 50
}
};
if ( uid ) {
this.filters.mine = {
text: l10n.mine,
props: {
orderby: 'date',
order: 'DESC',
author: uid
},
priority: 50
};
}
}
});
@ -7085,7 +7101,8 @@ var l10n = wp.media.view.l10n,
*/
All = wp.media.view.AttachmentFilters.extend(/** @lends wp.media.view.AttachmentFilters.All.prototype */{
createFilters: function() {
var filters = {};
var filters = {},
uid = window.userSettings ? parseInt( window.userSettings.uid, 10 ) : 0;
_.each( wp.media.view.settings.mimeTypes || {}, function( text, key ) {
filters[ key ] = {
@ -7095,7 +7112,8 @@ All = wp.media.view.AttachmentFilters.extend(/** @lends wp.media.view.Attachment
type: key,
uploadedTo: null,
orderby: 'date',
order: 'DESC'
order: 'DESC',
author: null
}
};
});
@ -7107,7 +7125,8 @@ All = wp.media.view.AttachmentFilters.extend(/** @lends wp.media.view.Attachment
type: null,
uploadedTo: null,
orderby: 'date',
order: 'DESC'
order: 'DESC',
author: null
},
priority: 10
};
@ -7120,7 +7139,8 @@ All = wp.media.view.AttachmentFilters.extend(/** @lends wp.media.view.Attachment
type: null,
uploadedTo: wp.media.view.settings.post.id,
orderby: 'menuOrder',
order: 'ASC'
order: 'ASC',
author: null
},
priority: 20
};
@ -7133,11 +7153,27 @@ All = wp.media.view.AttachmentFilters.extend(/** @lends wp.media.view.Attachment
uploadedTo: 0,
type: null,
orderby: 'menuOrder',
order: 'ASC'
order: 'ASC',
author: null
},
priority: 50
};
if ( uid ) {
filters.mine = {
text: l10n.mine,
props: {
status: null,
type: null,
uploadedTo: null,
orderby: 'date',
order: 'DESC',
author: uid
},
priority: 50
};
}
if ( wp.media.view.settings.mediaTrash &&
this.controller.isModeActive( 'grid' ) ) {
@ -7148,7 +7184,8 @@ All = wp.media.view.AttachmentFilters.extend(/** @lends wp.media.view.Attachment
status: 'trash',
type: null,
orderby: 'date',
order: 'DESC'
order: 'DESC',
author: null
},
priority: 50
};

File diff suppressed because one or more lines are too long

View File

@ -3523,6 +3523,7 @@ function wp_enqueue_media( $args = array() ) {
'noItemsFound' => __( 'No items found.' ),
'insertIntoPost' => $post_type_object->labels->insert_into_item,
'unattached' => __( 'Unattached' ),
'mine' => _x( 'Mine', 'media items' ),
'trash' => _x( 'Trash', 'noun' ),
'uploadedToThisPost' => $post_type_object->labels->uploaded_to_this_item,
'warnDelete' => __( "You are about to permanently delete this item from your site.\nThis action cannot be undone.\n 'Cancel' to stop, 'OK' to delete." ),

View File

@ -4,7 +4,7 @@
*
* @global string $wp_version
*/
$wp_version = '4.9.6-alpha-43040';
$wp_version = '4.9.6-alpha-43064';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.