mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-23 15:22:41 +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() {
|
protected function instantiateStorageEngine() {
|
||||||
$engines = id(new PhutilSymbolLoader())
|
$engines = id(new PhutilSymbolLoader())
|
||||||
->setType('class')
|
->setType('class')
|
||||||
|
|
|
@ -32,6 +32,9 @@ final class PhabricatorUserProfileSettingsPanelController
|
||||||
$profile->setUserPHID($user->getPHID());
|
$profile->setUserPHID($user->getPHID());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$supported_formats = PhabricatorFile::getTransformableImageFormats();
|
||||||
|
|
||||||
|
$e_image = null;
|
||||||
$errors = array();
|
$errors = array();
|
||||||
if ($request->isFormPost()) {
|
if ($request->isFormPost()) {
|
||||||
$profile->setTitle($request->getStr('title'));
|
$profile->setTitle($request->getStr('title'));
|
||||||
|
@ -65,9 +68,10 @@ final class PhabricatorUserProfileSettingsPanelController
|
||||||
$max_height = 50);
|
$max_height = 50);
|
||||||
$user->setProfileImagePHID($small_xformed->getPHID());
|
$user->setProfileImagePHID($small_xformed->getPHID());
|
||||||
} else {
|
} else {
|
||||||
|
$e_image = 'Not Supported';
|
||||||
$errors[] =
|
$errors[] =
|
||||||
'Only valid image files (jpg, jpeg, png or gif) '.
|
'This server only supports these image formats: '.
|
||||||
'will be accepted.';
|
implode(', ', $supported_formats).'.';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -148,7 +152,9 @@ final class PhabricatorUserProfileSettingsPanelController
|
||||||
->appendChild(
|
->appendChild(
|
||||||
id(new AphrontFormFileControl())
|
id(new AphrontFormFileControl())
|
||||||
->setLabel('Change Image')
|
->setLabel('Change Image')
|
||||||
->setName('image'))
|
->setName('image')
|
||||||
|
->setError($e_image)
|
||||||
|
->setCaption('Supported formats: '.implode(', ', $supported_formats)))
|
||||||
->appendChild(
|
->appendChild(
|
||||||
id(new AphrontFormSubmitControl())
|
id(new AphrontFormSubmitControl())
|
||||||
->setValue('Save')
|
->setValue('Save')
|
||||||
|
|
|
@ -52,7 +52,11 @@ final class PhabricatorProjectProfileEditController
|
||||||
$affiliations = $project->loadAffiliations();
|
$affiliations = $project->loadAffiliations();
|
||||||
$affiliations = mpull($affiliations, null, 'getUserPHID');
|
$affiliations = mpull($affiliations, null, 'getUserPHID');
|
||||||
|
|
||||||
|
$supported_formats = PhabricatorFile::getTransformableImageFormats();
|
||||||
|
|
||||||
$e_name = true;
|
$e_name = true;
|
||||||
|
$e_image = null;
|
||||||
|
|
||||||
$errors = array();
|
$errors = array();
|
||||||
$state = null;
|
$state = null;
|
||||||
if ($request->isFormPost()) {
|
if ($request->isFormPost()) {
|
||||||
|
@ -106,9 +110,10 @@ final class PhabricatorProjectProfileEditController
|
||||||
$y = 50);
|
$y = 50);
|
||||||
$profile->setProfileImagePHID($xformed->getPHID());
|
$profile->setProfileImagePHID($xformed->getPHID());
|
||||||
} else {
|
} else {
|
||||||
|
$e_image = 'Not Supported';
|
||||||
$errors[] =
|
$errors[] =
|
||||||
'Only valid image files (jpg, jpeg, png or gif) '.
|
'This server only supports these image formats: '.
|
||||||
'will be accepted.';
|
implode(', ', $supported_formats).'.';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -249,7 +254,9 @@ final class PhabricatorProjectProfileEditController
|
||||||
->appendChild(
|
->appendChild(
|
||||||
id(new AphrontFormFileControl())
|
id(new AphrontFormFileControl())
|
||||||
->setLabel('Change Image')
|
->setLabel('Change Image')
|
||||||
->setName('image'))
|
->setName('image')
|
||||||
|
->setError($e_image)
|
||||||
|
->setCaption('Supported formats: '.implode(', ', $supported_formats)))
|
||||||
->appendChild(
|
->appendChild(
|
||||||
'<h1>Resources</h1>'.
|
'<h1>Resources</h1>'.
|
||||||
'<input type="hidden" name="resources" id="resources" />'.
|
'<input type="hidden" name="resources" id="resources" />'.
|
||||||
|
|
Loading…
Reference in a new issue