1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-25 16:22:43 +01:00

Improve messages when no image formats are supported (due to GD not installed)

Summary:
When GD is not installed, trying to set a custom image for a project/blog/repository/user/etc displays unhelpful error messages (`This server only supports these image formats: .` and `Supported formats: `) due to the array of supported image formats being empty.

Display clearer messages instead.

Closes T15720

Test Plan: Do not have php-gd installed, go to `/project/manage/1/`, take a look at the string below the "Upload Picture" button, select {nav icon=picture, name=Edit Picture} in the sidebar, select `Custom: Choose Icon and Color...`, `Choose Background Color` and `Choose Icon`, then click the `Save Image` button. Also try to upload a custom image and look at the error message.

Reviewers: O1 Blessed Committers, valerio.bozzolan

Reviewed By: O1 Blessed Committers, valerio.bozzolan

Subscribers: tobiaswiese, valerio.bozzolan, Matthew, Cigaryno

Maniphest Tasks: T15720

Differential Revision: https://we.phorge.it/D25525
This commit is contained in:
Andre Klapper 2024-01-24 11:14:28 +01:00
parent 052b5f41c7
commit e2bec4c1f5
8 changed files with 64 additions and 40 deletions

View file

@ -24,6 +24,12 @@ final class ConpherenceRoomPictureController
$monogram = $conpherence->getMonogram();
$supported_formats = PhabricatorFile::getTransformableImageFormats();
if ($supported_formats) {
$supported_formats_message = pht('Supported image formats: %s.',
implode(', ', $supported_formats));
} else {
$supported_formats_message = pht('Server supports no image formats.');
}
$e_file = true;
$errors = array();
@ -56,9 +62,7 @@ final class ConpherenceRoomPictureController
if (!$errors && !$is_default) {
if (!$file->isTransformableImage()) {
$e_file = pht('Not Supported');
$errors[] = pht(
'This server only supports these image formats: %s.',
implode(', ', $supported_formats));
$errors[] = $supported_formats_message;
} else {
$xform = PhabricatorFileTransform::getTransformByKey(
PhabricatorFileThumbnailTransform::TRANSFORM_PROFILE);
@ -195,8 +199,7 @@ final class ConpherenceRoomPictureController
->setName('picture')
->setLabel(pht('Upload Picture'))
->setError($e_file)
->setCaption(
pht('Supported formats: %s', implode(', ', $supported_formats))))
->setCaption($supported_formats_message))
->appendChild(
id(new AphrontFormSubmitControl())
->addCancelButton('/'.$monogram)

View file

@ -24,6 +24,12 @@ final class DiffusionRepositoryProfilePictureController
}
$supported_formats = PhabricatorFile::getTransformableImageFormats();
if ($supported_formats) {
$supported_formats_message = pht('Supported image formats: %s.',
implode(', ', $supported_formats));
} else {
$supported_formats_message = pht('Server supports no image formats.');
}
$e_file = true;
$errors = array();
$done_uri = $repository->getURI();
@ -57,9 +63,7 @@ final class DiffusionRepositoryProfilePictureController
if (!$errors && !$is_default) {
if (!$file->isTransformableImage()) {
$e_file = pht('Not Supported');
$errors[] = pht(
'This server only supports these image formats: %s.',
implode(', ', $supported_formats));
$errors[] = $supported_formats_message;
} else {
$xform = PhabricatorFileTransform::getTransformByKey(
PhabricatorFileThumbnailTransform::TRANSFORM_PROFILE);
@ -213,8 +217,7 @@ final class DiffusionRepositoryProfilePictureController
->setName('picture')
->setLabel(pht('Upload Picture'))
->setError($e_file)
->setCaption(
pht('Supported formats: %s', implode(', ', $supported_formats))))
->setCaption($supported_formats_message))
->appendChild(
id(new AphrontFormSubmitControl())
->addCancelButton($done_uri)

View file

@ -27,6 +27,12 @@ final class PhabricatorPeopleProfilePictureController
$done_uri = '/p/'.$name.'/';
$supported_formats = PhabricatorFile::getTransformableImageFormats();
if ($supported_formats) {
$supported_formats_message = pht('Supported image formats: %s.',
implode(', ', $supported_formats));
} else {
$supported_formats_message = pht('Server supports no image formats.');
}
$e_file = true;
$errors = array();
@ -59,9 +65,7 @@ final class PhabricatorPeopleProfilePictureController
if (!$errors && !$is_default) {
if (!$file->isTransformableImage()) {
$e_file = pht('Not Supported');
$errors[] = pht(
'This server only supports these image formats: %s.',
implode(', ', $supported_formats));
$errors[] = $supported_formats_message;
} else {
$xform = PhabricatorFileTransform::getTransformByKey(
PhabricatorFileThumbnailTransform::TRANSFORM_PROFILE);
@ -250,8 +254,7 @@ final class PhabricatorPeopleProfilePictureController
->setName('picture')
->setLabel(pht('Upload Picture'))
->setError($e_file)
->setCaption(
pht('Supported formats: %s', implode(', ', $supported_formats))))
->setCaption($supported_formats_message))
->appendChild(
id(new AphrontFormSubmitControl())
->addCancelButton($done_uri)

View file

@ -24,6 +24,12 @@ final class PhameBlogHeaderPictureController
$blog_uri = '/phame/blog/manage/'.$id;
$supported_formats = PhabricatorFile::getTransformableImageFormats();
if ($supported_formats) {
$supported_formats_message = pht('Supported image formats: %s.',
implode(', ', $supported_formats));
} else {
$supported_formats_message = pht('Server supports no image formats.');
}
$e_file = true;
$errors = array();
$delete_header = ($request->getInt('delete') == 1);
@ -45,9 +51,7 @@ final class PhameBlogHeaderPictureController
if (!$errors && !$delete_header) {
if (!$file->isTransformableImage()) {
$e_file = pht('Not Supported');
$errors[] = pht(
'This server only supports these image formats: %s.',
implode(', ', $supported_formats));
$errors[] = $supported_formats_message;
}
}
@ -86,8 +90,7 @@ final class PhameBlogHeaderPictureController
->setName('header')
->setLabel(pht('Upload Header'))
->setError($e_file)
->setCaption(
pht('Supported formats: %s', implode(', ', $supported_formats))))
->setCaption($supported_formats_message))
->appendChild(
id(new AphrontFormCheckboxControl())
->setName('delete')

View file

@ -24,6 +24,12 @@ final class PhameBlogProfilePictureController
$blog_uri = '/phame/blog/manage/'.$id;
$supported_formats = PhabricatorFile::getTransformableImageFormats();
if ($supported_formats) {
$supported_formats_message = pht('Supported image formats: %s.',
implode(', ', $supported_formats));
} else {
$supported_formats_message = pht('Server supports no image formats.');
}
$e_file = true;
$errors = array();
@ -56,9 +62,7 @@ final class PhameBlogProfilePictureController
if (!$errors && !$is_default) {
if (!$file->isTransformableImage()) {
$e_file = pht('Not Supported');
$errors[] = pht(
'This server only supports these image formats: %s.',
implode(', ', $supported_formats));
$errors[] = $supported_formats_message;
} else {
$xform = PhabricatorFileTransform::getTransformByKey(
PhabricatorFileThumbnailTransform::TRANSFORM_PROFILE);
@ -196,8 +200,7 @@ final class PhameBlogProfilePictureController
->setName('picture')
->setLabel(pht('Upload Picture'))
->setError($e_file)
->setCaption(
pht('Supported formats: %s', implode(', ', $supported_formats))))
->setCaption($supported_formats_message))
->appendChild(
id(new AphrontFormSubmitControl())
->addCancelButton($blog_uri)

View file

@ -24,6 +24,12 @@ final class PhamePostHeaderPictureController
$post_uri = '/phame/post/view/'.$id;
$supported_formats = PhabricatorFile::getTransformableImageFormats();
if ($supported_formats) {
$supported_formats_message = pht('Supported image formats: %s.',
implode(', ', $supported_formats));
} else {
$supported_formats_message = pht('Server supports no image formats.');
}
$e_file = true;
$errors = array();
$delete_header = ($request->getInt('delete') == 1);
@ -45,9 +51,7 @@ final class PhamePostHeaderPictureController
if (!$errors && !$delete_header) {
if (!$file->isTransformableImage()) {
$e_file = pht('Not Supported');
$errors[] = pht(
'This server only supports these image formats: %s.',
implode(', ', $supported_formats));
$errors[] = $supported_formats_message;
}
}
@ -86,8 +90,7 @@ final class PhamePostHeaderPictureController
->setName('header')
->setLabel(pht('Upload Header'))
->setError($e_file)
->setCaption(
pht('Supported formats: %s', implode(', ', $supported_formats))))
->setCaption($supported_formats_message))
->appendChild(
id(new AphrontFormCheckboxControl())
->setName('delete')

View file

@ -14,6 +14,12 @@ final class PhortuneMerchantPictureController
$uri = $merchant->getDetailsURI();
$supported_formats = PhabricatorFile::getTransformableImageFormats();
if ($supported_formats) {
$supported_formats_message = pht('Supported image formats: %s.',
implode(', ', $supported_formats));
} else {
$supported_formats_message = pht('Server supports no image formats.');
}
$e_file = true;
$errors = array();
@ -46,9 +52,7 @@ final class PhortuneMerchantPictureController
if (!$errors && !$is_default) {
if (!$file->isTransformableImage()) {
$e_file = pht('Not Supported');
$errors[] = pht(
'This server only supports these image formats: %s.',
implode(', ', $supported_formats));
$errors[] = $supported_formats_message;
} else {
$xform = PhabricatorFileTransform::getTransformByKey(
PhabricatorFileThumbnailTransform::TRANSFORM_PROFILE);
@ -185,8 +189,7 @@ final class PhortuneMerchantPictureController
->setName('picture')
->setLabel(pht('Upload Logo'))
->setError($e_file)
->setCaption(
pht('Supported formats: %s', implode(', ', $supported_formats))))
->setCaption($supported_formats_message))
->appendChild(
id(new AphrontFormSubmitControl())
->addCancelButton($uri)

View file

@ -26,6 +26,12 @@ final class PhabricatorProjectEditPictureController
$manage_uri = $this->getApplicationURI('manage/'.$project->getID().'/');
$supported_formats = PhabricatorFile::getTransformableImageFormats();
if ($supported_formats) {
$supported_formats_message = pht('Supported image formats: %s.',
implode(', ', $supported_formats));
} else {
$supported_formats_message = pht('Server supports no image formats.');
}
$e_file = true;
$errors = array();
@ -58,9 +64,7 @@ final class PhabricatorProjectEditPictureController
if (!$errors && !$is_default) {
if (!$file->isTransformableImage()) {
$e_file = pht('Not Supported');
$errors[] = pht(
'This server only supports these image formats: %s.',
implode(', ', $supported_formats));
$errors[] = $supported_formats_message;
} else {
$xform = PhabricatorFileTransform::getTransformByKey(
PhabricatorFileThumbnailTransform::TRANSFORM_PROFILE);
@ -257,8 +261,7 @@ final class PhabricatorProjectEditPictureController
->setName('picture')
->setLabel(pht('Upload Picture'))
->setError($e_file)
->setCaption(
pht('Supported formats: %s', implode(', ', $supported_formats))))
->setCaption($supported_formats_message))
->appendChild(
id(new AphrontFormSubmitControl())
->addCancelButton($manage_uri)