@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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

+64 -40
+8 -5
src/applications/conpherence/controller/ConpherenceRoomPictureController.php
··· 24 24 $monogram = $conpherence->getMonogram(); 25 25 26 26 $supported_formats = PhabricatorFile::getTransformableImageFormats(); 27 + if ($supported_formats) { 28 + $supported_formats_message = pht('Supported image formats: %s.', 29 + implode(', ', $supported_formats)); 30 + } else { 31 + $supported_formats_message = pht('Server supports no image formats.'); 32 + } 27 33 $e_file = true; 28 34 $errors = array(); 29 35 ··· 56 62 if (!$errors && !$is_default) { 57 63 if (!$file->isTransformableImage()) { 58 64 $e_file = pht('Not Supported'); 59 - $errors[] = pht( 60 - 'This server only supports these image formats: %s.', 61 - implode(', ', $supported_formats)); 65 + $errors[] = $supported_formats_message; 62 66 } else { 63 67 $xform = PhabricatorFileTransform::getTransformByKey( 64 68 PhabricatorFileThumbnailTransform::TRANSFORM_PROFILE); ··· 195 199 ->setName('picture') 196 200 ->setLabel(pht('Upload Picture')) 197 201 ->setError($e_file) 198 - ->setCaption( 199 - pht('Supported formats: %s', implode(', ', $supported_formats)))) 202 + ->setCaption($supported_formats_message)) 200 203 ->appendChild( 201 204 id(new AphrontFormSubmitControl()) 202 205 ->addCancelButton('/'.$monogram)
+8 -5
src/applications/diffusion/controller/DiffusionRepositoryProfilePictureController.php
··· 24 24 } 25 25 26 26 $supported_formats = PhabricatorFile::getTransformableImageFormats(); 27 + if ($supported_formats) { 28 + $supported_formats_message = pht('Supported image formats: %s.', 29 + implode(', ', $supported_formats)); 30 + } else { 31 + $supported_formats_message = pht('Server supports no image formats.'); 32 + } 27 33 $e_file = true; 28 34 $errors = array(); 29 35 $done_uri = $repository->getURI(); ··· 57 63 if (!$errors && !$is_default) { 58 64 if (!$file->isTransformableImage()) { 59 65 $e_file = pht('Not Supported'); 60 - $errors[] = pht( 61 - 'This server only supports these image formats: %s.', 62 - implode(', ', $supported_formats)); 66 + $errors[] = $supported_formats_message; 63 67 } else { 64 68 $xform = PhabricatorFileTransform::getTransformByKey( 65 69 PhabricatorFileThumbnailTransform::TRANSFORM_PROFILE); ··· 213 217 ->setName('picture') 214 218 ->setLabel(pht('Upload Picture')) 215 219 ->setError($e_file) 216 - ->setCaption( 217 - pht('Supported formats: %s', implode(', ', $supported_formats)))) 220 + ->setCaption($supported_formats_message)) 218 221 ->appendChild( 219 222 id(new AphrontFormSubmitControl()) 220 223 ->addCancelButton($done_uri)
+8 -5
src/applications/people/controller/PhabricatorPeopleProfilePictureController.php
··· 27 27 $done_uri = '/p/'.$name.'/'; 28 28 29 29 $supported_formats = PhabricatorFile::getTransformableImageFormats(); 30 + if ($supported_formats) { 31 + $supported_formats_message = pht('Supported image formats: %s.', 32 + implode(', ', $supported_formats)); 33 + } else { 34 + $supported_formats_message = pht('Server supports no image formats.'); 35 + } 30 36 $e_file = true; 31 37 $errors = array(); 32 38 ··· 59 65 if (!$errors && !$is_default) { 60 66 if (!$file->isTransformableImage()) { 61 67 $e_file = pht('Not Supported'); 62 - $errors[] = pht( 63 - 'This server only supports these image formats: %s.', 64 - implode(', ', $supported_formats)); 68 + $errors[] = $supported_formats_message; 65 69 } else { 66 70 $xform = PhabricatorFileTransform::getTransformByKey( 67 71 PhabricatorFileThumbnailTransform::TRANSFORM_PROFILE); ··· 250 254 ->setName('picture') 251 255 ->setLabel(pht('Upload Picture')) 252 256 ->setError($e_file) 253 - ->setCaption( 254 - pht('Supported formats: %s', implode(', ', $supported_formats)))) 257 + ->setCaption($supported_formats_message)) 255 258 ->appendChild( 256 259 id(new AphrontFormSubmitControl()) 257 260 ->addCancelButton($done_uri)
+8 -5
src/applications/phame/controller/blog/PhameBlogHeaderPictureController.php
··· 24 24 $blog_uri = '/phame/blog/manage/'.$id; 25 25 26 26 $supported_formats = PhabricatorFile::getTransformableImageFormats(); 27 + if ($supported_formats) { 28 + $supported_formats_message = pht('Supported image formats: %s.', 29 + implode(', ', $supported_formats)); 30 + } else { 31 + $supported_formats_message = pht('Server supports no image formats.'); 32 + } 27 33 $e_file = true; 28 34 $errors = array(); 29 35 $delete_header = ($request->getInt('delete') == 1); ··· 45 51 if (!$errors && !$delete_header) { 46 52 if (!$file->isTransformableImage()) { 47 53 $e_file = pht('Not Supported'); 48 - $errors[] = pht( 49 - 'This server only supports these image formats: %s.', 50 - implode(', ', $supported_formats)); 54 + $errors[] = $supported_formats_message; 51 55 } 52 56 } 53 57 ··· 86 90 ->setName('header') 87 91 ->setLabel(pht('Upload Header')) 88 92 ->setError($e_file) 89 - ->setCaption( 90 - pht('Supported formats: %s', implode(', ', $supported_formats)))) 93 + ->setCaption($supported_formats_message)) 91 94 ->appendChild( 92 95 id(new AphrontFormCheckboxControl()) 93 96 ->setName('delete')
+8 -5
src/applications/phame/controller/blog/PhameBlogProfilePictureController.php
··· 24 24 $blog_uri = '/phame/blog/manage/'.$id; 25 25 26 26 $supported_formats = PhabricatorFile::getTransformableImageFormats(); 27 + if ($supported_formats) { 28 + $supported_formats_message = pht('Supported image formats: %s.', 29 + implode(', ', $supported_formats)); 30 + } else { 31 + $supported_formats_message = pht('Server supports no image formats.'); 32 + } 27 33 $e_file = true; 28 34 $errors = array(); 29 35 ··· 56 62 if (!$errors && !$is_default) { 57 63 if (!$file->isTransformableImage()) { 58 64 $e_file = pht('Not Supported'); 59 - $errors[] = pht( 60 - 'This server only supports these image formats: %s.', 61 - implode(', ', $supported_formats)); 65 + $errors[] = $supported_formats_message; 62 66 } else { 63 67 $xform = PhabricatorFileTransform::getTransformByKey( 64 68 PhabricatorFileThumbnailTransform::TRANSFORM_PROFILE); ··· 196 200 ->setName('picture') 197 201 ->setLabel(pht('Upload Picture')) 198 202 ->setError($e_file) 199 - ->setCaption( 200 - pht('Supported formats: %s', implode(', ', $supported_formats)))) 203 + ->setCaption($supported_formats_message)) 201 204 ->appendChild( 202 205 id(new AphrontFormSubmitControl()) 203 206 ->addCancelButton($blog_uri)
+8 -5
src/applications/phame/controller/post/PhamePostHeaderPictureController.php
··· 24 24 $post_uri = '/phame/post/view/'.$id; 25 25 26 26 $supported_formats = PhabricatorFile::getTransformableImageFormats(); 27 + if ($supported_formats) { 28 + $supported_formats_message = pht('Supported image formats: %s.', 29 + implode(', ', $supported_formats)); 30 + } else { 31 + $supported_formats_message = pht('Server supports no image formats.'); 32 + } 27 33 $e_file = true; 28 34 $errors = array(); 29 35 $delete_header = ($request->getInt('delete') == 1); ··· 45 51 if (!$errors && !$delete_header) { 46 52 if (!$file->isTransformableImage()) { 47 53 $e_file = pht('Not Supported'); 48 - $errors[] = pht( 49 - 'This server only supports these image formats: %s.', 50 - implode(', ', $supported_formats)); 54 + $errors[] = $supported_formats_message; 51 55 } 52 56 } 53 57 ··· 86 90 ->setName('header') 87 91 ->setLabel(pht('Upload Header')) 88 92 ->setError($e_file) 89 - ->setCaption( 90 - pht('Supported formats: %s', implode(', ', $supported_formats)))) 93 + ->setCaption($supported_formats_message)) 91 94 ->appendChild( 92 95 id(new AphrontFormCheckboxControl()) 93 96 ->setName('delete')
+8 -5
src/applications/phortune/controller/merchant/PhortuneMerchantPictureController.php
··· 14 14 $uri = $merchant->getDetailsURI(); 15 15 16 16 $supported_formats = PhabricatorFile::getTransformableImageFormats(); 17 + if ($supported_formats) { 18 + $supported_formats_message = pht('Supported image formats: %s.', 19 + implode(', ', $supported_formats)); 20 + } else { 21 + $supported_formats_message = pht('Server supports no image formats.'); 22 + } 17 23 $e_file = true; 18 24 $errors = array(); 19 25 ··· 46 52 if (!$errors && !$is_default) { 47 53 if (!$file->isTransformableImage()) { 48 54 $e_file = pht('Not Supported'); 49 - $errors[] = pht( 50 - 'This server only supports these image formats: %s.', 51 - implode(', ', $supported_formats)); 55 + $errors[] = $supported_formats_message; 52 56 } else { 53 57 $xform = PhabricatorFileTransform::getTransformByKey( 54 58 PhabricatorFileThumbnailTransform::TRANSFORM_PROFILE); ··· 185 189 ->setName('picture') 186 190 ->setLabel(pht('Upload Logo')) 187 191 ->setError($e_file) 188 - ->setCaption( 189 - pht('Supported formats: %s', implode(', ', $supported_formats)))) 192 + ->setCaption($supported_formats_message)) 190 193 ->appendChild( 191 194 id(new AphrontFormSubmitControl()) 192 195 ->addCancelButton($uri)
+8 -5
src/applications/project/controller/PhabricatorProjectEditPictureController.php
··· 26 26 $manage_uri = $this->getApplicationURI('manage/'.$project->getID().'/'); 27 27 28 28 $supported_formats = PhabricatorFile::getTransformableImageFormats(); 29 + if ($supported_formats) { 30 + $supported_formats_message = pht('Supported image formats: %s.', 31 + implode(', ', $supported_formats)); 32 + } else { 33 + $supported_formats_message = pht('Server supports no image formats.'); 34 + } 29 35 $e_file = true; 30 36 $errors = array(); 31 37 ··· 58 64 if (!$errors && !$is_default) { 59 65 if (!$file->isTransformableImage()) { 60 66 $e_file = pht('Not Supported'); 61 - $errors[] = pht( 62 - 'This server only supports these image formats: %s.', 63 - implode(', ', $supported_formats)); 67 + $errors[] = $supported_formats_message; 64 68 } else { 65 69 $xform = PhabricatorFileTransform::getTransformByKey( 66 70 PhabricatorFileThumbnailTransform::TRANSFORM_PROFILE); ··· 257 261 ->setName('picture') 258 262 ->setLabel(pht('Upload Picture')) 259 263 ->setError($e_file) 260 - ->setCaption( 261 - pht('Supported formats: %s', implode(', ', $supported_formats)))) 264 + ->setCaption($supported_formats_message)) 262 265 ->appendChild( 263 266 id(new AphrontFormSubmitControl()) 264 267 ->addCancelButton($manage_uri)