From 3706405bff0cbc586e3e8d80adb4be3f16f4d2b1 Mon Sep 17 00:00:00 2001 From: Shannon Date: Tue, 4 Apr 2017 12:14:06 +1000 Subject: [PATCH] Obsoletes all methods that perform image manipulation and thumbnail generation, removes thumbnail generation from occurring, fixes the issue of getting the size for an image!! Argh, we were bypassing the Exif data reading and instead still loading the whole image in! --- src/Umbraco.Core/IO/MediaFileSystem.cs | 49 ++++---- .../Media/UploadAutoFillProperties.cs | 14 +-- src/Umbraco.Core/Services/IMediaService.cs | 7 +- src/Umbraco.Core/Services/MediaService.cs | 1 + .../controls/Images/ImageViewer.ascx.cs | 1 + .../ImageUrlProviders/ImageUrlProvider.cs | 4 +- .../FileUploadPropertyEditor.cs | 106 +----------------- .../controls/Images/ImageViewer.ascx.cs | 3 +- .../Images/ImageViewerUpdater.asmx.cs | 3 +- .../dialogs/mediaPicker.aspx.designer.cs | 5 +- .../umbraco/uQuery/MediaExtensions.cs | 22 ++-- .../businesslogic/Files/UmbracoFile.cs | 13 ++- 12 files changed, 66 insertions(+), 162 deletions(-) diff --git a/src/Umbraco.Core/IO/MediaFileSystem.cs b/src/Umbraco.Core/IO/MediaFileSystem.cs index bcb2ff8bfd..c57cf94cef 100644 --- a/src/Umbraco.Core/IO/MediaFileSystem.cs +++ b/src/Umbraco.Core/IO/MediaFileSystem.cs @@ -31,6 +31,7 @@ namespace Umbraco.Core.IO private long _folderCounter; private bool _folderCounterInitialized; + [Obsolete("This should no longer be used, image manipulation should be done via ImageProcessor, Umbraco no longer generates '_thumb' files for media")] private static readonly Dictionary DefaultSizes = new Dictionary { { 100, "thumb" }, @@ -263,7 +264,7 @@ namespace Umbraco.Core.IO var filename = Path.GetFileName(sourcepath); var filepath = GetMediaPath(filename, content.Key, propertyType.Key); this.CopyFile(sourcepath, filepath); - CopyThumbnails(sourcepath, filepath); + return filepath; } @@ -312,29 +313,17 @@ namespace Umbraco.Core.IO } } - // sets a file for the FileUpload property editor - // ie generates thumbnails and populates autofill properties + /// + /// Sets a file for the FileUpload property editor and populates autofill properties + /// + /// + /// + /// + /// private void SetUploadFile(IContentBase content, Property property, string filepath, Stream filestream) - { - // check if file is an image (and supports resizing and thumbnails etc) - var extension = Path.GetExtension(filepath); - var isImage = IsImageFile(extension); - - // specific stuff for images (thumbnails etc) - if (isImage) - { - using (var image = Image.FromStream(filestream)) - { - // use one image for all - GenerateThumbnails(image, filepath, property.PropertyType); - _uploadAutoFillProperties.Populate(content, property.Alias, filepath, filestream, image); - } - } - else - { - // will use filepath for extension, and filestream for length - _uploadAutoFillProperties.Populate(content, property.Alias, filepath, filestream); - } + { + // will use filepath for extension, and filestream for length + _uploadAutoFillProperties.Populate(content, property.Alias, filepath, filestream); } #endregion @@ -401,6 +390,7 @@ namespace Umbraco.Core.IO // note: this does not find 'custom' thumbnails? // will find _thumb and _big-thumb but NOT _custom? + [Obsolete("This should no longer be used, image manipulation should be done via ImageProcessor, Umbraco no longer generates '_thumb' files for media")] public IEnumerable GetThumbnails(string path) { var parentDirectory = Path.GetDirectoryName(path); @@ -421,12 +411,14 @@ namespace Umbraco.Core.IO DeleteThumbnails(path); } + [Obsolete("This should no longer be used, image manipulation should be done via ImageProcessor, Umbraco no longer generates '_thumb' files for media")] public void DeleteThumbnails(string path) { GetThumbnails(path) .ForEach(x => base.DeleteFile(x)); } + [Obsolete("This should no longer be used, image manipulation should be done via ImageProcessor, Umbraco no longer generates '_thumb' files for media")] public void CopyThumbnails(string sourcePath, string targetPath) { var targetPathBase = Path.GetDirectoryName(targetPath) ?? ""; @@ -479,6 +471,7 @@ namespace Umbraco.Core.IO #region GenerateThumbnails + [Obsolete("This should no longer be used, image manipulation should be done via ImageProcessor, Umbraco no longer generates '_thumb' files for media")] public IEnumerable GenerateThumbnails( Image image, string filepath, @@ -500,6 +493,7 @@ namespace Umbraco.Core.IO return GenerateThumbnails(image, filepath, additionalSizes); } + [Obsolete("This should no longer be used, image manipulation should be done via ImageProcessor, Umbraco no longer generates '_thumb' files for media")] public IEnumerable GenerateThumbnails( Image image, string filepath, @@ -522,6 +516,7 @@ namespace Umbraco.Core.IO .ToList(); // now } + [Obsolete("This should no longer be used, image manipulation should be done via ImageProcessor, Umbraco no longer generates '_thumb' files for media")] public IEnumerable GenerateThumbnails( Stream filestream, string filepath, @@ -535,6 +530,7 @@ namespace Umbraco.Core.IO } } + [Obsolete("This should no longer be used, image manipulation should be done via ImageProcessor, Umbraco no longer generates '_thumb' files for media")] public IEnumerable GenerateThumbnails( Image image, string filepath, @@ -556,16 +552,19 @@ namespace Umbraco.Core.IO #region GenerateResized - Generate at resized filepath derived from origin filepath + [Obsolete("This should no longer be used, image manipulation should be done via ImageProcessor, Umbraco no longer generates '_thumb' files for media")] public ResizedImage GenerateResized(Image originImage, string originFilepath, string sizeName, int maxWidthHeight) { return GenerateResized(originImage, originFilepath, sizeName, maxWidthHeight, -1, -1); } + [Obsolete("This should no longer be used, image manipulation should be done via ImageProcessor, Umbraco no longer generates '_thumb' files for media")] public ResizedImage GenerateResized(Image originImage, string originFilepath, string sizeName, int fixedWidth, int fixedHeight) { return GenerateResized(originImage, originFilepath, sizeName, -1, fixedWidth, fixedHeight); } + [Obsolete("This should no longer be used, image manipulation should be done via ImageProcessor, Umbraco no longer generates '_thumb' files for media")] public ResizedImage GenerateResized(Image originImage, string originFilepath, string sizeName, int maxWidthHeight, int fixedWidth, int fixedHeight) { if (string.IsNullOrWhiteSpace(sizeName)) @@ -581,16 +580,19 @@ namespace Umbraco.Core.IO #region GenerateResizedAt - Generate at specified resized filepath + [Obsolete("This should no longer be used, image manipulation should be done via ImageProcessor, Umbraco no longer generates '_thumb' files for media")] public ResizedImage GenerateResizedAt(Image originImage, string resizedFilepath, int maxWidthHeight) { return GenerateResizedAt(originImage, resizedFilepath, maxWidthHeight, -1, -1); } + [Obsolete("This should no longer be used, image manipulation should be done via ImageProcessor, Umbraco no longer generates '_thumb' files for media")] public ResizedImage GenerateResizedAt(Image originImage, int fixedWidth, int fixedHeight, string resizedFilepath) { return GenerateResizedAt(originImage, resizedFilepath, -1, fixedWidth, fixedHeight); } + [Obsolete("This should no longer be used, image manipulation should be done via ImageProcessor, Umbraco no longer generates '_thumb' files for media")] public ResizedImage GenerateResizedAt(Image originImage, string resizedFilepath, int maxWidthHeight, int fixedWidth, int fixedHeight) { // target dimensions @@ -699,6 +701,7 @@ namespace Umbraco.Core.IO #region Inner classes + [Obsolete("This should no longer be used, image manipulation should be done via ImageProcessor, Umbraco no longer generates '_thumb' files for media")] public class ResizedImage { public ResizedImage() diff --git a/src/Umbraco.Core/Media/UploadAutoFillProperties.cs b/src/Umbraco.Core/Media/UploadAutoFillProperties.cs index d0e7347848..bf6f7c59ad 100644 --- a/src/Umbraco.Core/Media/UploadAutoFillProperties.cs +++ b/src/Umbraco.Core/Media/UploadAutoFillProperties.cs @@ -96,8 +96,7 @@ namespace Umbraco.Core.Media /// The property type alias. /// The filesystem-relative filepath, or null to clear properties. /// The stream containing the file data. - /// The file data as an image object. - public void Populate(IContentBase content, string propertyTypeAlias, string filepath, Stream filestream, Image image = null) + public void Populate(IContentBase content, string propertyTypeAlias, string filepath, Stream filestream) { if (content == null) throw new ArgumentNullException("content"); if (propertyTypeAlias == null) throw new ArgumentNullException("propertyTypeAlias"); @@ -110,7 +109,7 @@ namespace Umbraco.Core.Media if (autoFillConfig == null) return; // nothing // populate - Populate(content, autoFillConfig, filepath, filestream, image); + Populate(content, autoFillConfig, filepath, filestream); } /// @@ -158,8 +157,7 @@ namespace Umbraco.Core.Media /// /// The filesystem-relative filepath, or null to clear properties. /// The stream containing the file data. - /// The file data as an image object. - public void Populate(IContentBase content, IImagingAutoFillUploadField autoFillConfig, string filepath, Stream filestream, Image image = null) + public void Populate(IContentBase content, IImagingAutoFillUploadField autoFillConfig, string filepath, Stream filestream) { if (content == null) throw new ArgumentNullException("content"); if (autoFillConfig == null) throw new ArgumentNullException("autoFillConfig"); @@ -172,11 +170,7 @@ namespace Umbraco.Core.Media else { var extension = (Path.GetExtension(filepath) ?? "").TrimStart('.'); - Size? size; - if (image == null) - size = _mediaFileSystem.IsImageFile(extension) ? (Size?) _mediaFileSystem.GetDimensions(filestream) : null; - else - size = new Size(image.Width, image.Height); + var size = _mediaFileSystem.IsImageFile(extension) ? (Size?)_mediaFileSystem.GetDimensions(filestream) : null; SetProperties(content, autoFillConfig, size, filestream.Length, extension); } } diff --git a/src/Umbraco.Core/Services/IMediaService.cs b/src/Umbraco.Core/Services/IMediaService.cs index 47e214d734..8cd2b0eed5 100644 --- a/src/Umbraco.Core/Services/IMediaService.cs +++ b/src/Umbraco.Core/Services/IMediaService.cs @@ -468,12 +468,7 @@ namespace Umbraco.Core.Services /// The filesystem path to the media. void DeleteMediaFile(string filepath); - /// - /// Generates thumbnails. - /// - /// The filesystem-relative path to the original image. - /// The property type. - /// This should be obsoleted, we should not generate thumbnails. + [Obsolete("This should no longer be used, thumbnail generation should be done via ImageProcessor, Umbraco no longer generates '_thumb' files for media")] void GenerateThumbnails(string filepath, PropertyType propertyType); } } diff --git a/src/Umbraco.Core/Services/MediaService.cs b/src/Umbraco.Core/Services/MediaService.cs index 7fb0f91a7d..522e7e732c 100644 --- a/src/Umbraco.Core/Services/MediaService.cs +++ b/src/Umbraco.Core/Services/MediaService.cs @@ -1431,6 +1431,7 @@ namespace Umbraco.Core.Services _mediaFileSystem.DeleteFile(filepath, true); } + [Obsolete("This should no longer be used, thumbnail generation should be done via ImageProcessor, Umbraco no longer generates '_thumb' files for media")] public void GenerateThumbnails(string filepath, PropertyType propertyType) { using (var filestream = _mediaFileSystem.OpenFile(filepath)) diff --git a/src/Umbraco.Web.UI/umbraco/controls/Images/ImageViewer.ascx.cs b/src/Umbraco.Web.UI/umbraco/controls/Images/ImageViewer.ascx.cs index d0cfd28d01..e031663e8a 100644 --- a/src/Umbraco.Web.UI/umbraco/controls/Images/ImageViewer.ascx.cs +++ b/src/Umbraco.Web.UI/umbraco/controls/Images/ImageViewer.ascx.cs @@ -2,6 +2,7 @@ namespace Umbraco.Web.UI.Umbraco.Controls.Images { + [Obsolete("This is no longer used and will be removed in future versions")] public partial class ImageViewer : global::umbraco.controls.Images.ImageViewer { } diff --git a/src/Umbraco.Web/Media/ImageUrlProviders/ImageUrlProvider.cs b/src/Umbraco.Web/Media/ImageUrlProviders/ImageUrlProvider.cs index 9777e39fe6..a8d541cebb 100644 --- a/src/Umbraco.Web/Media/ImageUrlProviders/ImageUrlProvider.cs +++ b/src/Umbraco.Web/Media/ImageUrlProviders/ImageUrlProvider.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Xml.XPath; using Umbraco.Core.Configuration; using Umbraco.Core.Media; @@ -7,6 +8,7 @@ using Umbraco.Core; namespace Umbraco.Web.Media.ImageUrlProviders { + [Obsolete("IImageUrlProvider is no longer used and will be removed in future versions")] public class ImageUrlProvider : IImageUrlProvider { public const string DefaultName = "umbracoUpload"; diff --git a/src/Umbraco.Web/PropertyEditors/FileUploadPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/FileUploadPropertyEditor.cs index bc4940f940..9ff4aaa1a2 100644 --- a/src/Umbraco.Web/PropertyEditors/FileUploadPropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/FileUploadPropertyEditor.cs @@ -30,16 +30,7 @@ namespace Umbraco.Web.PropertyEditors baseEditor.Validators.Add(new UploadFileTypeValidator()); return new FileUploadPropertyValueEditor(baseEditor, MediaFileSystem); } - - /// - /// Creates the corresponding preValue editor. - /// - /// The corresponding preValue editor. - protected override PreValueEditor CreatePreValueEditor() - { - return new FileUploadPreValueEditor(); - } - + /// /// Gets a value indicating whether a property is an upload field. /// @@ -143,100 +134,7 @@ namespace Umbraco.Web.PropertyEditors else MediaFileSystem.UploadAutoFillProperties.Populate(content, autoFillConfig, MediaFileSystem.GetRelativePath(svalue)); } - } - - /// - /// A custom pre-val editor to ensure that the data is stored how the legacy data was stored in - /// - internal class FileUploadPreValueEditor : ValueListPreValueEditor - { - public FileUploadPreValueEditor() - { - var field = Fields.First(); - field.Description = "Enter a max width/height for each thumbnail"; - field.Name = "Add thumbnail size"; - //need to have some custom validation happening here - field.Validators.Add(new ThumbnailListValidator()); - } - - /// - /// Format the persisted value to work with our multi-val editor. - /// - /// - /// - /// - public override IDictionary ConvertDbToEditor(IDictionary defaultPreVals, PreValueCollection persistedPreVals) - { - var result = new List(); - - //the pre-values just take up one field with a semi-colon delimiter so we'll just parse - var dictionary = persistedPreVals.FormatAsDictionary(); - if (dictionary.Any()) - { - //there should only be one val - var delimited = dictionary.First().Value.Value.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries); - var i = 0; - result.AddRange(delimited.Select(x => new PreValue(i++, x))); - } - - //the items list will be a dictionary of it's id -> value we need to use the id for persistence for backwards compatibility - return new Dictionary { { "items", result.ToDictionary(x => x.Id, PreValueAsDictionary) } }; - } - - private IDictionary PreValueAsDictionary(PreValue preValue) - { - return new Dictionary { { "value", preValue.Value }, { "sortOrder", preValue.SortOrder } }; - } - /// - /// Take the posted values and convert them to a semi-colon separated list so that its backwards compatible - /// - /// - /// - /// - public override IDictionary ConvertEditorToDb(IDictionary editorValue, PreValueCollection currentValue) - { - var result = base.ConvertEditorToDb(editorValue, currentValue); - - //this should just be a dictionary of values, we want to re-format this so that it is just one value in the dictionary that is - // semi-colon delimited - var values = result.Select(item => item.Value.Value).ToList(); - - result.Clear(); - result.Add("thumbs", new PreValue(string.Join(";", values))); - return result; - } - - internal class ThumbnailListValidator : IPropertyValidator - { - public IEnumerable Validate(object value, PreValueCollection preValues, PropertyEditor editor) - { - var json = value as JArray; - if (json == null) yield break; - - //validate each item which is a json object - for (var index = 0; index < json.Count; index++) - { - var i = json[index]; - var jItem = i as JObject; - if (jItem == null || jItem["value"] == null) continue; - - //NOTE: we will be removing empty values when persisting so no need to validate - var asString = jItem["value"].ToString(); - if (asString.IsNullOrWhiteSpace()) continue; - - int parsed; - if (int.TryParse(asString, out parsed) == false) - { - yield return new ValidationResult("The value " + asString + " is not a valid number", new[] - { - //we'll make the server field the index number of the value so it can be wired up to the view - "item_" + index.ToInvariantString() - }); - } - } - } - } - } + } #region Application event handler, used to bind to events on startup diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/controls/Images/ImageViewer.ascx.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/controls/Images/ImageViewer.ascx.cs index 98362dd638..09ac8518cc 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/controls/Images/ImageViewer.ascx.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/controls/Images/ImageViewer.ascx.cs @@ -7,7 +7,8 @@ using Umbraco.Core; namespace umbraco.controls.Images { - public partial class ImageViewer : UserControl + [Obsolete("This is no longer used and will be removed in future versions")] + public partial class ImageViewer : UserControl { public ImageViewer() diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/controls/Images/ImageViewerUpdater.asmx.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/controls/Images/ImageViewerUpdater.asmx.cs index d03a2a668b..4818edfd81 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/controls/Images/ImageViewerUpdater.asmx.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/controls/Images/ImageViewerUpdater.asmx.cs @@ -21,7 +21,8 @@ namespace umbraco.controls.Images [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] [ToolboxItem(false)] [ScriptService] - public class ImageViewerUpdater : System.Web.Services.WebService + [Obsolete("This is no longer used and will be removed in future versions")] + public class ImageViewerUpdater : System.Web.Services.WebService { /// diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/dialogs/mediaPicker.aspx.designer.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/dialogs/mediaPicker.aspx.designer.cs index 23024b07b7..e1342377a4 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/dialogs/mediaPicker.aspx.designer.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/dialogs/mediaPicker.aspx.designer.cs @@ -6,10 +6,11 @@ // the code is regenerated. // //------------------------------------------------------------------------------ +using System; namespace umbraco.presentation.umbraco.dialogs { - - + + [Obsolete("This is no longer used and will be removed in future versions")] public partial class mediaPicker { /// diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/uQuery/MediaExtensions.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/uQuery/MediaExtensions.cs index 411734ae99..42626d406f 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/uQuery/MediaExtensions.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/uQuery/MediaExtensions.cs @@ -7,10 +7,11 @@ using Umbraco.Core; namespace umbraco { - /// - /// Extension methods for umbraco.cms.businesslogic.media.Media - /// - public static class MediaExtensions + /// + /// Extension methods for umbraco.cms.businesslogic.media.Media + /// + [Obsolete("Obsolete, Use Umbraco.Core.Models.Media", false)] + public static class MediaExtensions { /// /// Functionally similar to the XPath axis 'ancestor' @@ -203,12 +204,13 @@ namespace umbraco return string.Empty; } - /// - /// Gets the image thumbnail URL. - /// - /// an umbraco.cms.businesslogic.media.Media object - /// - public static string GetImageThumbnailUrl(this Media media) + /// + /// Gets the image thumbnail URL. + /// + /// an umbraco.cms.businesslogic.media.Media object + /// + [Obsolete("This should no longer be used, thumbnail generation should be done via ImageProcessor, Umbraco no longer generates '_thumb' files for media")] + public static string GetImageThumbnailUrl(this Media media) { if (media.ContentType.Alias.Equals(Constants.Conventions.MediaTypes.Image)) { diff --git a/src/umbraco.cms/businesslogic/Files/UmbracoFile.cs b/src/umbraco.cms/businesslogic/Files/UmbracoFile.cs index 5822e8c72c..9ac5547af3 100644 --- a/src/umbraco.cms/businesslogic/Files/UmbracoFile.cs +++ b/src/umbraco.cms/businesslogic/Files/UmbracoFile.cs @@ -35,35 +35,38 @@ namespace umbraco.cms.businesslogic.Files #endregion #region Static Methods - - //MB: Do we really need all these overloads? looking through the code, only one of them is actually used - + + [Obsolete("This is no longer used and will be removed in future versions")] public static UmbracoFile Save(HttpPostedFile file, string path) { return new UmbracoFile(UmbracoMediaFile.Save(file.InputStream, path)); } + [Obsolete("This is no longer used and will be removed in future versions")] public static UmbracoFile Save(HttpPostedFileBase file, string path) { return new UmbracoFile(UmbracoMediaFile.Save(file.InputStream, path)); } + [Obsolete("This is no longer used and will be removed in future versions")] public static UmbracoFile Save(Stream inputStream, string path) { return new UmbracoFile(UmbracoMediaFile.Save(inputStream, path)); } + [Obsolete("This is no longer used and will be removed in future versions")] public static UmbracoFile Save(byte[] file, string relativePath) { return new UmbracoFile(UmbracoMediaFile.Save(new MemoryStream(file), relativePath)); } + [Obsolete("This is no longer used and will be removed in future versions")] public static UmbracoFile Save(HttpPostedFile file) { return new UmbracoFile(UmbracoMediaFile.Save(file)); } - //filebase overload... + [Obsolete("This is no longer used and will be removed in future versions")] public static UmbracoFile Save(HttpPostedFileBase file) { return new UmbracoFile(UmbracoMediaFile.Save(file)); @@ -118,11 +121,13 @@ namespace umbraco.cms.businesslogic.Files return new System.Tuple(size.Width, size.Height); } + [Obsolete("This is no longer used and will be removed in future versions")] public string Resize(int width, int height) { return _mediaFile.Resize(width, height); } + [Obsolete("This is no longer used and will be removed in future versions")] public string Resize(int maxWidthHeight, string fileNameAddition) { return _mediaFile.Resize(maxWidthHeight, fileNameAddition);