From 10b86c2aa34dc00c47155b587da2b48cf3660192 Mon Sep 17 00:00:00 2001 From: epriestley Date: Mon, 24 Nov 2014 15:25:25 -0800 Subject: [PATCH] Don't show meme Remarkup hint button if Macro application is not usable Summary: See . This behavior is a bug; we should remove the button if the user can't use the application. Test Plan: - With Macro uninstalled, did these things verifying the button vanished: - Sent a user a message. - Edited a revision. - Edited repository basic information. - Edited an initiative. - Edited a Harbormaster build step. - Added task comments. - Edited profile blurb. - Edited blog description. - Commented on Pholio mock. - Uploaded Pholio image. - Edited Phortune merchant. - Edited Phriction document. - Edited Ponder answer. - Edited Ponder question. - Edited Slowvote poll. - Edited a comment. - Reinstalled Macro and saw button come back. - Used button to put silly text on a funny picture. Reviewers: btrahan, chad Reviewed By: chad Subscribers: epriestley Differential Revision: https://secure.phabricator.com/D10900 --- .../controller/ConpherenceNewController.php | 9 ++--- .../DifferentialRevertPlanField.php | 1 + .../customfield/DifferentialSummaryField.php | 1 + .../customfield/DifferentialTestPlanField.php | 1 + ...DiffusionRepositoryEditBasicController.php | 1 + .../FundInitiativeEditController.php | 2 ++ .../HarbormasterStepEditController.php | 1 + .../LegalpadDocumentEditController.php | 26 ++++++++------- .../ManiphestTaskDetailController.php | 1 + .../customfield/PhabricatorUserBlurbField.php | 1 + .../blog/PhameBlogEditController.php | 13 ++++---- .../controller/PholioInlineController.php | 1 + .../pholio/view/PholioUploadedImageView.php | 1 + .../PhortuneMerchantEditController.php | 1 + .../controller/PonderAnswerEditController.php | 1 + .../PonderQuestionEditController.php | 1 + .../PhabricatorSlowvoteEditController.php | 1 + ...cationTransactionCommentEditController.php | 1 + ...PhabricatorStandardCustomFieldRemarkup.php | 1 + .../control/PhabricatorRemarkupControl.php | 33 +++++++++++++------ 20 files changed, 66 insertions(+), 32 deletions(-) diff --git a/src/applications/conpherence/controller/ConpherenceNewController.php b/src/applications/conpherence/controller/ConpherenceNewController.php index dad9a95608..1a600a7fee 100644 --- a/src/applications/conpherence/controller/ConpherenceNewController.php +++ b/src/applications/conpherence/controller/ConpherenceNewController.php @@ -87,10 +87,11 @@ final class ConpherenceNewController extends ConpherenceController { ->setError($e_participants)) ->appendChild( id(new PhabricatorRemarkupControl()) - ->setName('message') - ->setValue($message) - ->setLabel(pht('Message')) - ->setError($e_message)); + ->setUser($user) + ->setName('message') + ->setValue($message) + ->setLabel(pht('Message')) + ->setError($e_message)); $dialog->appendChild($form); diff --git a/src/applications/differential/customfield/DifferentialRevertPlanField.php b/src/applications/differential/customfield/DifferentialRevertPlanField.php index 8934bc01cb..6b159d9d86 100644 --- a/src/applications/differential/customfield/DifferentialRevertPlanField.php +++ b/src/applications/differential/customfield/DifferentialRevertPlanField.php @@ -85,6 +85,7 @@ final class DifferentialRevertPlanField public function renderEditControl(array $handles) { return id(new PhabricatorRemarkupControl()) + ->setUser($this->getViewer()) ->setName($this->getFieldKey()) ->setValue($this->getValue()) ->setLabel($this->getFieldName()); diff --git a/src/applications/differential/customfield/DifferentialSummaryField.php b/src/applications/differential/customfield/DifferentialSummaryField.php index 8498ae5234..f0f06341fc 100644 --- a/src/applications/differential/customfield/DifferentialSummaryField.php +++ b/src/applications/differential/customfield/DifferentialSummaryField.php @@ -39,6 +39,7 @@ final class DifferentialSummaryField public function renderEditControl(array $handles) { return id(new PhabricatorRemarkupControl()) + ->setUser($this->getViewer()) ->setName($this->getFieldKey()) ->setValue($this->getValue()) ->setError($this->getFieldError()) diff --git a/src/applications/differential/customfield/DifferentialTestPlanField.php b/src/applications/differential/customfield/DifferentialTestPlanField.php index efc3bfc1a0..aef7937330 100644 --- a/src/applications/differential/customfield/DifferentialTestPlanField.php +++ b/src/applications/differential/customfield/DifferentialTestPlanField.php @@ -53,6 +53,7 @@ final class DifferentialTestPlanField public function renderEditControl(array $handles) { return id(new PhabricatorRemarkupControl()) + ->setUser($this->getViewer()) ->setName($this->getFieldKey()) ->setValue($this->getValue()) ->setError($this->getFieldError()) diff --git a/src/applications/diffusion/controller/DiffusionRepositoryEditBasicController.php b/src/applications/diffusion/controller/DiffusionRepositoryEditBasicController.php index 4457df8d23..d29aeb0be6 100644 --- a/src/applications/diffusion/controller/DiffusionRepositoryEditBasicController.php +++ b/src/applications/diffusion/controller/DiffusionRepositoryEditBasicController.php @@ -120,6 +120,7 @@ final class DiffusionRepositoryEditBasicController $form ->appendChild( id(new PhabricatorRemarkupControl()) + ->setUser($user) ->setName('description') ->setLabel(pht('Description')) ->setValue($v_desc)) diff --git a/src/applications/fund/controller/FundInitiativeEditController.php b/src/applications/fund/controller/FundInitiativeEditController.php index b6b69945b6..5b3adf1679 100644 --- a/src/applications/fund/controller/FundInitiativeEditController.php +++ b/src/applications/fund/controller/FundInitiativeEditController.php @@ -200,11 +200,13 @@ final class FundInitiativeEditController ->setOptions($merchant_options)) ->appendChild( id(new PhabricatorRemarkupControl()) + ->setUser($viewer) ->setName('description') ->setLabel(pht('Description')) ->setValue($v_desc)) ->appendChild( id(new PhabricatorRemarkupControl()) + ->setUser($viewer) ->setName('risks') ->setLabel(pht('Risks/Challenges')) ->setValue($v_risk)) diff --git a/src/applications/harbormaster/controller/HarbormasterStepEditController.php b/src/applications/harbormaster/controller/HarbormasterStepEditController.php index 62a8ac0e68..12631db71a 100644 --- a/src/applications/harbormaster/controller/HarbormasterStepEditController.php +++ b/src/applications/harbormaster/controller/HarbormasterStepEditController.php @@ -155,6 +155,7 @@ final class HarbormasterStepEditController extends HarbormasterController { $form ->appendChild( id(new PhabricatorRemarkupControl()) + ->setUser($viewer) ->setName('description') ->setLabel(pht('Description')) ->setError($e_description) diff --git a/src/applications/legalpad/controller/LegalpadDocumentEditController.php b/src/applications/legalpad/controller/LegalpadDocumentEditController.php index 20002c4c77..d8b7d7c31b 100644 --- a/src/applications/legalpad/controller/LegalpadDocumentEditController.php +++ b/src/applications/legalpad/controller/LegalpadDocumentEditController.php @@ -143,20 +143,22 @@ final class LegalpadDocumentEditController extends LegalpadController { $form ->appendChild( id(new PhabricatorRemarkupControl()) - ->setID('preamble') - ->setLabel(pht('Preamble')) - ->setValue($v_preamble) - ->setName('preamble') - ->setCaption( - pht('Optional help text for users signing this document.'))) + ->setUser($user) + ->setID('preamble') + ->setLabel(pht('Preamble')) + ->setValue($v_preamble) + ->setName('preamble') + ->setCaption( + pht('Optional help text for users signing this document.'))) ->appendChild( id(new PhabricatorRemarkupControl()) - ->setID('document-text') - ->setLabel(pht('Document Body')) - ->setError($e_text) - ->setValue($text) - ->setHeight(AphrontFormTextAreaControl::HEIGHT_VERY_TALL) - ->setName('text')); + ->setUser($user) + ->setID('document-text') + ->setLabel(pht('Document Body')) + ->setError($e_text) + ->setValue($text) + ->setHeight(AphrontFormTextAreaControl::HEIGHT_VERY_TALL) + ->setName('text')); $policies = id(new PhabricatorPolicyQuery()) ->setViewer($user) diff --git a/src/applications/maniphest/controller/ManiphestTaskDetailController.php b/src/applications/maniphest/controller/ManiphestTaskDetailController.php index 1caba00d46..3472870a35 100644 --- a/src/applications/maniphest/controller/ManiphestTaskDetailController.php +++ b/src/applications/maniphest/controller/ManiphestTaskDetailController.php @@ -254,6 +254,7 @@ final class ManiphestTaskDetailController extends ManiphestController { ->setControlStyle('display: none')) ->appendChild( id(new PhabricatorRemarkupControl()) + ->setUser($user) ->setLabel(pht('Comments')) ->setName('comments') ->setValue($draft_text) diff --git a/src/applications/people/customfield/PhabricatorUserBlurbField.php b/src/applications/people/customfield/PhabricatorUserBlurbField.php index 8bd903e57c..3221a33202 100644 --- a/src/applications/people/customfield/PhabricatorUserBlurbField.php +++ b/src/applications/people/customfield/PhabricatorUserBlurbField.php @@ -52,6 +52,7 @@ final class PhabricatorUserBlurbField public function renderEditControl(array $handles) { return id(new PhabricatorRemarkupControl()) + ->setUser($this->getViewer()) ->setName($this->getFieldKey()) ->setValue($this->value) ->setLabel($this->getFieldName()); diff --git a/src/applications/phame/controller/blog/PhameBlogEditController.php b/src/applications/phame/controller/blog/PhameBlogEditController.php index e8ec34d19c..1363cf8343 100644 --- a/src/applications/phame/controller/blog/PhameBlogEditController.php +++ b/src/applications/phame/controller/blog/PhameBlogEditController.php @@ -122,12 +122,13 @@ final class PhameBlogEditController ->setError($e_name)) ->appendChild( id(new PhabricatorRemarkupControl()) - ->setLabel(pht('Description')) - ->setName('description') - ->setValue($blog->getDescription()) - ->setID('blog-description') - ->setUser($user) - ->setDisableMacros(true)) + ->setUser($user) + ->setLabel(pht('Description')) + ->setName('description') + ->setValue($blog->getDescription()) + ->setID('blog-description') + ->setUser($user) + ->setDisableMacros(true)) ->appendChild( id(new AphrontFormPolicyControl()) ->setUser($user) diff --git a/src/applications/pholio/controller/PholioInlineController.php b/src/applications/pholio/controller/PholioInlineController.php index b17679c758..782383cdb8 100644 --- a/src/applications/pholio/controller/PholioInlineController.php +++ b/src/applications/pholio/controller/PholioInlineController.php @@ -157,6 +157,7 @@ final class PholioInlineController extends PholioController { $form ->appendChild( id(new PhabricatorRemarkupControl()) + ->setUser($viewer) ->setName('content') ->setLabel(pht('Comment')) ->setValue($v_content)); diff --git a/src/applications/pholio/view/PholioUploadedImageView.php b/src/applications/pholio/view/PholioUploadedImageView.php index 766264ee9b..fb8a82431e 100644 --- a/src/applications/pholio/view/PholioUploadedImageView.php +++ b/src/applications/pholio/view/PholioUploadedImageView.php @@ -32,6 +32,7 @@ final class PholioUploadedImageView extends AphrontView { ->setLabel(pht('Title')); $description = id(new PhabricatorRemarkupControl()) + ->setUser($this->getUser()) ->setName('description_'.$phid) ->setValue($image->getDescription()) ->setSigil('image-description') diff --git a/src/applications/phortune/controller/PhortuneMerchantEditController.php b/src/applications/phortune/controller/PhortuneMerchantEditController.php index fa7b5391d1..2b66209761 100644 --- a/src/applications/phortune/controller/PhortuneMerchantEditController.php +++ b/src/applications/phortune/controller/PhortuneMerchantEditController.php @@ -131,6 +131,7 @@ final class PhortuneMerchantEditController ->setError($e_name)) ->appendChild( id(new PhabricatorRemarkupControl()) + ->setUser($viewer) ->setName('desc') ->setLabel(pht('Description')) ->setValue($v_desc)) diff --git a/src/applications/ponder/controller/PonderAnswerEditController.php b/src/applications/ponder/controller/PonderAnswerEditController.php index 30f97e1177..80273bb053 100644 --- a/src/applications/ponder/controller/PonderAnswerEditController.php +++ b/src/applications/ponder/controller/PonderAnswerEditController.php @@ -71,6 +71,7 @@ final class PonderAnswerEditController extends PonderController { ->setValue($question->getTitle())) ->appendChild( id(new PhabricatorRemarkupControl()) + ->setUser($viewer) ->setLabel(pht('Answer')) ->setName('content') ->setID($answer_content_id) diff --git a/src/applications/ponder/controller/PonderQuestionEditController.php b/src/applications/ponder/controller/PonderQuestionEditController.php index 557c2c8910..117eefa461 100644 --- a/src/applications/ponder/controller/PonderQuestionEditController.php +++ b/src/applications/ponder/controller/PonderQuestionEditController.php @@ -98,6 +98,7 @@ final class PonderQuestionEditController extends PonderController { ->setError($e_title)) ->appendChild( id(new PhabricatorRemarkupControl()) + ->setUser($user) ->setName('content') ->setID('content') ->setValue($v_content) diff --git a/src/applications/slowvote/controller/PhabricatorSlowvoteEditController.php b/src/applications/slowvote/controller/PhabricatorSlowvoteEditController.php index 57e18d760f..d84b255086 100644 --- a/src/applications/slowvote/controller/PhabricatorSlowvoteEditController.php +++ b/src/applications/slowvote/controller/PhabricatorSlowvoteEditController.php @@ -163,6 +163,7 @@ final class PhabricatorSlowvoteEditController ->setError($e_question)) ->appendChild( id(new PhabricatorRemarkupControl()) + ->setUser($user) ->setLabel(pht('Description')) ->setName('description') ->setValue($v_description)) diff --git a/src/applications/transactions/controller/PhabricatorApplicationTransactionCommentEditController.php b/src/applications/transactions/controller/PhabricatorApplicationTransactionCommentEditController.php index 0b4d0b615e..1cb38b1768 100644 --- a/src/applications/transactions/controller/PhabricatorApplicationTransactionCommentEditController.php +++ b/src/applications/transactions/controller/PhabricatorApplicationTransactionCommentEditController.php @@ -73,6 +73,7 @@ final class PhabricatorApplicationTransactionCommentEditController ->setFullWidth(true) ->appendChild( id(new PhabricatorRemarkupControl()) + ->setUser($user) ->setName('text') ->setValue($xaction->getComment()->getContent()))); diff --git a/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldRemarkup.php b/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldRemarkup.php index d67c51bb29..3c56bf75c0 100644 --- a/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldRemarkup.php +++ b/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldRemarkup.php @@ -9,6 +9,7 @@ final class PhabricatorStandardCustomFieldRemarkup public function renderEditControl(array $handles) { return id(new PhabricatorRemarkupControl()) + ->setUser($this->getViewer()) ->setLabel($this->getFieldName()) ->setName($this->getFieldKey()) ->setCaption($this->getCaption()) diff --git a/src/view/form/control/PhabricatorRemarkupControl.php b/src/view/form/control/PhabricatorRemarkupControl.php index 3d37c7d671..e1041c409e 100644 --- a/src/view/form/control/PhabricatorRemarkupControl.php +++ b/src/view/form/control/PhabricatorRemarkupControl.php @@ -22,6 +22,12 @@ final class PhabricatorRemarkupControl extends AphrontFormTextAreaControl { $this->setID($id); } + $viewer = $this->getUser(); + if (!$viewer) { + throw new Exception( + pht('Call setUser() before rendering a PhabricatorRemarkupControl!')); + } + // We need to have this if previews render images, since Ajax can not // currently ship JS or CSS. require_celerity_resource('lightbox-attachment-css'); @@ -82,7 +88,17 @@ final class PhabricatorRemarkupControl extends AphrontFormTextAreaControl { ), ); - if (!$this->disableMacro and function_exists('imagettftext')) { + $can_use_macros = + (!$this->disableMacro) && + (function_exists('imagettftext')); + + if ($can_use_macros) { + $can_use_macros = PhabricatorApplication::isClassInstalledForViewer( + 'PhabricatorMacroApplication', + $viewer); + } + + if ($can_use_macros) { $actions[] = array( 'spacer' => true, ); @@ -184,16 +200,13 @@ final class PhabricatorRemarkupControl extends AphrontFormTextAreaControl { $monospaced_textareas = null; $monospaced_textareas_class = null; - $user = $this->getUser(); - if ($user) { - $monospaced_textareas = $user - ->loadPreferences() - ->getPreference( - PhabricatorUserPreferences::PREFERENCE_MONOSPACED_TEXTAREAS); - if ($monospaced_textareas == 'enabled') { - $monospaced_textareas_class = 'PhabricatorMonospaced'; - } + $monospaced_textareas = $viewer + ->loadPreferences() + ->getPreference( + PhabricatorUserPreferences::PREFERENCE_MONOSPACED_TEXTAREAS); + if ($monospaced_textareas == 'enabled') { + $monospaced_textareas_class = 'PhabricatorMonospaced'; } $this->setCustomClass(