mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-27 01:02:42 +01:00
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
This commit is contained in:
parent
e0bd67f77b
commit
f0e9df1fda
3 changed files with 37 additions and 6 deletions
|
@ -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')
|
||||
|
|
|
@ -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')
|
||||
|
|
|
@ -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(
|
||||
'<h1>Resources</h1>'.
|
||||
'<input type="hidden" name="resources" id="resources" />'.
|
||||
|
|
Loading…
Reference in a new issue