From f0e9df1fda2844713bdd70b33fe6e42666ec7460 Mon Sep 17 00:00:00 2001 From: epriestley Date: Wed, 14 Mar 2012 12:41:33 -0700 Subject: [PATCH] Improve UI hints and error messages for supported file types Summary: We give you a pretty bad error right now if your server doesn't have, say, png support, saying "only png is supportd loololloo". Instead, show you which formats are supported in the error messsage, and tell you upfront. Test Plan: Tried to upload supported and unsupported images, got appropriate errors and supported format text. Reviewers: btrahan Reviewed By: btrahan CC: aran, epriestley Maniphest Tasks: T981 Differential Revision: https://secure.phabricator.com/D1894 --- .../files/storage/file/PhabricatorFile.php | 18 ++++++++++++++++++ ...catorUserProfileSettingsPanelController.php | 12 +++++++++--- ...PhabricatorProjectProfileEditController.php | 13 ++++++++++--- 3 files changed, 37 insertions(+), 6 deletions(-) diff --git a/src/applications/files/storage/file/PhabricatorFile.php b/src/applications/files/storage/file/PhabricatorFile.php index 3a7f92bf2f..20fb09c7e0 100644 --- a/src/applications/files/storage/file/PhabricatorFile.php +++ b/src/applications/files/storage/file/PhabricatorFile.php @@ -286,6 +286,24 @@ final class PhabricatorFile extends PhabricatorFileDAO { } } + public static function getTransformableImageFormats() { + $supported = array(); + + if (function_exists('imagejpeg')) { + $supported[] = 'jpg'; + } + + if (function_exists('imagepng')) { + $supported[] = 'png'; + } + + if (function_exists('imagegif')) { + $supported[] = 'gif'; + } + + return $supported; + } + protected function instantiateStorageEngine() { $engines = id(new PhutilSymbolLoader()) ->setType('class') diff --git a/src/applications/people/controller/settings/panels/profile/PhabricatorUserProfileSettingsPanelController.php b/src/applications/people/controller/settings/panels/profile/PhabricatorUserProfileSettingsPanelController.php index fedd49b405..41ef344a91 100644 --- a/src/applications/people/controller/settings/panels/profile/PhabricatorUserProfileSettingsPanelController.php +++ b/src/applications/people/controller/settings/panels/profile/PhabricatorUserProfileSettingsPanelController.php @@ -32,6 +32,9 @@ final class PhabricatorUserProfileSettingsPanelController $profile->setUserPHID($user->getPHID()); } + $supported_formats = PhabricatorFile::getTransformableImageFormats(); + + $e_image = null; $errors = array(); if ($request->isFormPost()) { $profile->setTitle($request->getStr('title')); @@ -65,9 +68,10 @@ final class PhabricatorUserProfileSettingsPanelController $max_height = 50); $user->setProfileImagePHID($small_xformed->getPHID()); } else { + $e_image = 'Not Supported'; $errors[] = - 'Only valid image files (jpg, jpeg, png or gif) '. - 'will be accepted.'; + 'This server only supports these image formats: '. + implode(', ', $supported_formats).'.'; } } } @@ -148,7 +152,9 @@ final class PhabricatorUserProfileSettingsPanelController ->appendChild( id(new AphrontFormFileControl()) ->setLabel('Change Image') - ->setName('image')) + ->setName('image') + ->setError($e_image) + ->setCaption('Supported formats: '.implode(', ', $supported_formats))) ->appendChild( id(new AphrontFormSubmitControl()) ->setValue('Save') diff --git a/src/applications/project/controller/profileedit/PhabricatorProjectProfileEditController.php b/src/applications/project/controller/profileedit/PhabricatorProjectProfileEditController.php index a30a74fe79..1f504557cf 100644 --- a/src/applications/project/controller/profileedit/PhabricatorProjectProfileEditController.php +++ b/src/applications/project/controller/profileedit/PhabricatorProjectProfileEditController.php @@ -52,7 +52,11 @@ final class PhabricatorProjectProfileEditController $affiliations = $project->loadAffiliations(); $affiliations = mpull($affiliations, null, 'getUserPHID'); + $supported_formats = PhabricatorFile::getTransformableImageFormats(); + $e_name = true; + $e_image = null; + $errors = array(); $state = null; if ($request->isFormPost()) { @@ -106,9 +110,10 @@ final class PhabricatorProjectProfileEditController $y = 50); $profile->setProfileImagePHID($xformed->getPHID()); } else { + $e_image = 'Not Supported'; $errors[] = - 'Only valid image files (jpg, jpeg, png or gif) '. - 'will be accepted.'; + 'This server only supports these image formats: '. + implode(', ', $supported_formats).'.'; } } } @@ -249,7 +254,9 @@ final class PhabricatorProjectProfileEditController ->appendChild( id(new AphrontFormFileControl()) ->setLabel('Change Image') - ->setName('image')) + ->setName('image') + ->setError($e_image) + ->setCaption('Supported formats: '.implode(', ', $supported_formats))) ->appendChild( '

Resources

'. ''.