Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions RELEASE-NOTES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* [*] [Jetpack-only] Stats: Made optimizations to enhance scrolling performance. [#22847]
* [*] Simplify post list context menu sections [#23356]
* [*] Fix an issue with incorrect snackbar shown when saving drafts manually [#23358]
* [**] Support editing media metadata for sites not powered by Jetpack and reliant on XML-RPC [#23316]
* [*] Fix rare crash in the unsupported block editor [#23379]

25.1
Expand Down
2 changes: 2 additions & 0 deletions WordPress/Classes/Models/Blog.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ typedef NS_ENUM(NSUInteger, BlogFeature) {
BlogFeatureNoncePreviews,
/// Does the blog support editing media metadata?
BlogFeatureMediaMetadataEditing,
/// Does the blog support editing media alternative text?
BlogFeatureMediaAltEditing,
/// Does the blog support deleting media?
BlogFeatureMediaDeletion,
/// Does the blog support Stock Photos feature (free photos library)
Expand Down
7 changes: 6 additions & 1 deletion WordPress/Classes/Models/Blog.m
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,12 @@ - (BOOL)supports:(BlogFeature)feature
case BlogFeatureNoncePreviews:
return [self supportsRestApi] && ![self isHostedAtWPcom];
case BlogFeatureMediaMetadataEditing:
return [self supportsRestApi] && [self isAdmin];
return [self isAdmin];
case BlogFeatureMediaAltEditing:
// alt is not supported via XML-RPC API
// https://core.trac.wordpress.org/ticket/58582
// https://github.com/wordpress-mobile/WordPress-Android/issues/18514#issuecomment-1589752274
return [self supportsRestApi];
case BlogFeatureMediaDeletion:
return [self isAdmin];
case BlogFeatureHomepageSettings:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ final class MediaItemViewController: UITableViewController {
action: editAlt())

var mediaInfoRows = [titleRow, captionRow, descRow]
if media.mediaType == .image {
if media.mediaType == .image && media.blog.supports(BlogFeature.mediaAltEditing) {
mediaInfoRows.append(altRow)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,13 +183,13 @@ - (void)uploadMedia:(RemoteMedia *)media
success(remoteMedia);
}
}
} failure:^(NSError *error, NSHTTPURLResponse *httpResponse) {
} failure:^(NSError *error, NSHTTPURLResponse *httpResponse) {
if (failure) {
failure(error);
}
}];


if (progress) {
*progress = localProgress;
}
Expand All @@ -199,10 +199,44 @@ - (void)updateMedia:(RemoteMedia *)media
success:(void (^)(RemoteMedia *remoteMedia))success
failure:(void (^)(NSError *error))failure
{
//HACK: Sergio Estevao: 2016-04-06 this option doens't exist on XML-RPC so we will always say that all was good
if (success) {
success(media);
NSParameterAssert([media.mediaID longLongValue] > 0);

NSMutableDictionary *content = [NSMutableDictionary dictionary];

if (media.title != nil) {
content[@"post_title"] = media.title;
}

if (media.caption != nil) {
content[@"post_excerpt"] = media.caption;
}

if (media.descriptionText != nil) {
content[@"post_content"] = media.descriptionText;
}

NSArray *extraDefaults = @[media.mediaID];
NSArray *parameters = [self XMLRPCArgumentsWithExtraDefaults:extraDefaults andExtra:content];

[self.api callMethod:@"wp.editPost"
parameters:parameters
success:^(id responseObject, NSHTTPURLResponse *httpResponse) {
BOOL updated = [responseObject boolValue];
if (updated) {
if (success) {
success(media);
}
} else {
if (failure) {
NSError *error = [NSError errorWithDomain:NSURLErrorDomain code:NSURLErrorUnknown userInfo:nil];
failure(error);
}
}
} failure:^(NSError *error, NSHTTPURLResponse *httpResponse) {
if (failure) {
failure(error);
}
}];
}

- (void)deleteMedia:(RemoteMedia *)media
Expand Down Expand Up @@ -286,11 +320,11 @@ - (RemoteMedia *)remoteMediaFromXMLRPCDictionary:(NSDictionary*)xmlRPC
link = [xmlRPC stringForKeyPath:@"link"];
}
remoteMedia.file = [link lastPathComponent] ?: [[xmlRPC objectForKeyPath:@"file"] lastPathComponent];

if ([xmlRPC stringForKeyPath:@"metadata.sizes.large.file"] != nil) {
remoteMedia.largeURL = [NSURL URLWithString: [NSString stringWithFormat:@"%@%@", remoteMedia.url.URLByDeletingLastPathComponent, [xmlRPC stringForKeyPath:@"metadata.sizes.large.file"]]];
}

if ([xmlRPC stringForKeyPath:@"metadata.sizes.medium.file"] != nil) {
remoteMedia.mediumURL = [NSURL URLWithString: [NSString stringWithFormat:@"%@%@", remoteMedia.url.URLByDeletingLastPathComponent, [xmlRPC stringForKeyPath:@"metadata.sizes.medium.file"]]];
}
Expand Down