1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2025-03-28 12:08:14 +01:00

Don't show meme Remarkup hint button if Macro application is not usable

Summary: See <https://phabricator.wikimedia.org/T906>. 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
This commit is contained in:
epriestley 2014-11-24 15:25:25 -08:00
parent e5777cc849
commit 10b86c2aa3
20 changed files with 66 additions and 32 deletions

View file

@ -87,10 +87,11 @@ final class ConpherenceNewController extends ConpherenceController {
->setError($e_participants)) ->setError($e_participants))
->appendChild( ->appendChild(
id(new PhabricatorRemarkupControl()) id(new PhabricatorRemarkupControl())
->setName('message') ->setUser($user)
->setValue($message) ->setName('message')
->setLabel(pht('Message')) ->setValue($message)
->setError($e_message)); ->setLabel(pht('Message'))
->setError($e_message));
$dialog->appendChild($form); $dialog->appendChild($form);

View file

@ -85,6 +85,7 @@ final class DifferentialRevertPlanField
public function renderEditControl(array $handles) { public function renderEditControl(array $handles) {
return id(new PhabricatorRemarkupControl()) return id(new PhabricatorRemarkupControl())
->setUser($this->getViewer())
->setName($this->getFieldKey()) ->setName($this->getFieldKey())
->setValue($this->getValue()) ->setValue($this->getValue())
->setLabel($this->getFieldName()); ->setLabel($this->getFieldName());

View file

@ -39,6 +39,7 @@ final class DifferentialSummaryField
public function renderEditControl(array $handles) { public function renderEditControl(array $handles) {
return id(new PhabricatorRemarkupControl()) return id(new PhabricatorRemarkupControl())
->setUser($this->getViewer())
->setName($this->getFieldKey()) ->setName($this->getFieldKey())
->setValue($this->getValue()) ->setValue($this->getValue())
->setError($this->getFieldError()) ->setError($this->getFieldError())

View file

@ -53,6 +53,7 @@ final class DifferentialTestPlanField
public function renderEditControl(array $handles) { public function renderEditControl(array $handles) {
return id(new PhabricatorRemarkupControl()) return id(new PhabricatorRemarkupControl())
->setUser($this->getViewer())
->setName($this->getFieldKey()) ->setName($this->getFieldKey())
->setValue($this->getValue()) ->setValue($this->getValue())
->setError($this->getFieldError()) ->setError($this->getFieldError())

View file

@ -120,6 +120,7 @@ final class DiffusionRepositoryEditBasicController
$form $form
->appendChild( ->appendChild(
id(new PhabricatorRemarkupControl()) id(new PhabricatorRemarkupControl())
->setUser($user)
->setName('description') ->setName('description')
->setLabel(pht('Description')) ->setLabel(pht('Description'))
->setValue($v_desc)) ->setValue($v_desc))

View file

@ -200,11 +200,13 @@ final class FundInitiativeEditController
->setOptions($merchant_options)) ->setOptions($merchant_options))
->appendChild( ->appendChild(
id(new PhabricatorRemarkupControl()) id(new PhabricatorRemarkupControl())
->setUser($viewer)
->setName('description') ->setName('description')
->setLabel(pht('Description')) ->setLabel(pht('Description'))
->setValue($v_desc)) ->setValue($v_desc))
->appendChild( ->appendChild(
id(new PhabricatorRemarkupControl()) id(new PhabricatorRemarkupControl())
->setUser($viewer)
->setName('risks') ->setName('risks')
->setLabel(pht('Risks/Challenges')) ->setLabel(pht('Risks/Challenges'))
->setValue($v_risk)) ->setValue($v_risk))

View file

@ -155,6 +155,7 @@ final class HarbormasterStepEditController extends HarbormasterController {
$form $form
->appendChild( ->appendChild(
id(new PhabricatorRemarkupControl()) id(new PhabricatorRemarkupControl())
->setUser($viewer)
->setName('description') ->setName('description')
->setLabel(pht('Description')) ->setLabel(pht('Description'))
->setError($e_description) ->setError($e_description)

View file

@ -143,20 +143,22 @@ final class LegalpadDocumentEditController extends LegalpadController {
$form $form
->appendChild( ->appendChild(
id(new PhabricatorRemarkupControl()) id(new PhabricatorRemarkupControl())
->setID('preamble') ->setUser($user)
->setLabel(pht('Preamble')) ->setID('preamble')
->setValue($v_preamble) ->setLabel(pht('Preamble'))
->setName('preamble') ->setValue($v_preamble)
->setCaption( ->setName('preamble')
pht('Optional help text for users signing this document.'))) ->setCaption(
pht('Optional help text for users signing this document.')))
->appendChild( ->appendChild(
id(new PhabricatorRemarkupControl()) id(new PhabricatorRemarkupControl())
->setID('document-text') ->setUser($user)
->setLabel(pht('Document Body')) ->setID('document-text')
->setError($e_text) ->setLabel(pht('Document Body'))
->setValue($text) ->setError($e_text)
->setHeight(AphrontFormTextAreaControl::HEIGHT_VERY_TALL) ->setValue($text)
->setName('text')); ->setHeight(AphrontFormTextAreaControl::HEIGHT_VERY_TALL)
->setName('text'));
$policies = id(new PhabricatorPolicyQuery()) $policies = id(new PhabricatorPolicyQuery())
->setViewer($user) ->setViewer($user)

View file

@ -254,6 +254,7 @@ final class ManiphestTaskDetailController extends ManiphestController {
->setControlStyle('display: none')) ->setControlStyle('display: none'))
->appendChild( ->appendChild(
id(new PhabricatorRemarkupControl()) id(new PhabricatorRemarkupControl())
->setUser($user)
->setLabel(pht('Comments')) ->setLabel(pht('Comments'))
->setName('comments') ->setName('comments')
->setValue($draft_text) ->setValue($draft_text)

View file

@ -52,6 +52,7 @@ final class PhabricatorUserBlurbField
public function renderEditControl(array $handles) { public function renderEditControl(array $handles) {
return id(new PhabricatorRemarkupControl()) return id(new PhabricatorRemarkupControl())
->setUser($this->getViewer())
->setName($this->getFieldKey()) ->setName($this->getFieldKey())
->setValue($this->value) ->setValue($this->value)
->setLabel($this->getFieldName()); ->setLabel($this->getFieldName());

View file

@ -122,12 +122,13 @@ final class PhameBlogEditController
->setError($e_name)) ->setError($e_name))
->appendChild( ->appendChild(
id(new PhabricatorRemarkupControl()) id(new PhabricatorRemarkupControl())
->setLabel(pht('Description')) ->setUser($user)
->setName('description') ->setLabel(pht('Description'))
->setValue($blog->getDescription()) ->setName('description')
->setID('blog-description') ->setValue($blog->getDescription())
->setUser($user) ->setID('blog-description')
->setDisableMacros(true)) ->setUser($user)
->setDisableMacros(true))
->appendChild( ->appendChild(
id(new AphrontFormPolicyControl()) id(new AphrontFormPolicyControl())
->setUser($user) ->setUser($user)

View file

@ -157,6 +157,7 @@ final class PholioInlineController extends PholioController {
$form $form
->appendChild( ->appendChild(
id(new PhabricatorRemarkupControl()) id(new PhabricatorRemarkupControl())
->setUser($viewer)
->setName('content') ->setName('content')
->setLabel(pht('Comment')) ->setLabel(pht('Comment'))
->setValue($v_content)); ->setValue($v_content));

View file

@ -32,6 +32,7 @@ final class PholioUploadedImageView extends AphrontView {
->setLabel(pht('Title')); ->setLabel(pht('Title'));
$description = id(new PhabricatorRemarkupControl()) $description = id(new PhabricatorRemarkupControl())
->setUser($this->getUser())
->setName('description_'.$phid) ->setName('description_'.$phid)
->setValue($image->getDescription()) ->setValue($image->getDescription())
->setSigil('image-description') ->setSigil('image-description')

View file

@ -131,6 +131,7 @@ final class PhortuneMerchantEditController
->setError($e_name)) ->setError($e_name))
->appendChild( ->appendChild(
id(new PhabricatorRemarkupControl()) id(new PhabricatorRemarkupControl())
->setUser($viewer)
->setName('desc') ->setName('desc')
->setLabel(pht('Description')) ->setLabel(pht('Description'))
->setValue($v_desc)) ->setValue($v_desc))

View file

@ -71,6 +71,7 @@ final class PonderAnswerEditController extends PonderController {
->setValue($question->getTitle())) ->setValue($question->getTitle()))
->appendChild( ->appendChild(
id(new PhabricatorRemarkupControl()) id(new PhabricatorRemarkupControl())
->setUser($viewer)
->setLabel(pht('Answer')) ->setLabel(pht('Answer'))
->setName('content') ->setName('content')
->setID($answer_content_id) ->setID($answer_content_id)

View file

@ -98,6 +98,7 @@ final class PonderQuestionEditController extends PonderController {
->setError($e_title)) ->setError($e_title))
->appendChild( ->appendChild(
id(new PhabricatorRemarkupControl()) id(new PhabricatorRemarkupControl())
->setUser($user)
->setName('content') ->setName('content')
->setID('content') ->setID('content')
->setValue($v_content) ->setValue($v_content)

View file

@ -163,6 +163,7 @@ final class PhabricatorSlowvoteEditController
->setError($e_question)) ->setError($e_question))
->appendChild( ->appendChild(
id(new PhabricatorRemarkupControl()) id(new PhabricatorRemarkupControl())
->setUser($user)
->setLabel(pht('Description')) ->setLabel(pht('Description'))
->setName('description') ->setName('description')
->setValue($v_description)) ->setValue($v_description))

View file

@ -73,6 +73,7 @@ final class PhabricatorApplicationTransactionCommentEditController
->setFullWidth(true) ->setFullWidth(true)
->appendChild( ->appendChild(
id(new PhabricatorRemarkupControl()) id(new PhabricatorRemarkupControl())
->setUser($user)
->setName('text') ->setName('text')
->setValue($xaction->getComment()->getContent()))); ->setValue($xaction->getComment()->getContent())));

View file

@ -9,6 +9,7 @@ final class PhabricatorStandardCustomFieldRemarkup
public function renderEditControl(array $handles) { public function renderEditControl(array $handles) {
return id(new PhabricatorRemarkupControl()) return id(new PhabricatorRemarkupControl())
->setUser($this->getViewer())
->setLabel($this->getFieldName()) ->setLabel($this->getFieldName())
->setName($this->getFieldKey()) ->setName($this->getFieldKey())
->setCaption($this->getCaption()) ->setCaption($this->getCaption())

View file

@ -22,6 +22,12 @@ final class PhabricatorRemarkupControl extends AphrontFormTextAreaControl {
$this->setID($id); $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 // We need to have this if previews render images, since Ajax can not
// currently ship JS or CSS. // currently ship JS or CSS.
require_celerity_resource('lightbox-attachment-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( $actions[] = array(
'spacer' => true, 'spacer' => true,
); );
@ -184,16 +200,13 @@ final class PhabricatorRemarkupControl extends AphrontFormTextAreaControl {
$monospaced_textareas = null; $monospaced_textareas = null;
$monospaced_textareas_class = null; $monospaced_textareas_class = null;
$user = $this->getUser();
if ($user) { $monospaced_textareas = $viewer
$monospaced_textareas = $user ->loadPreferences()
->loadPreferences() ->getPreference(
->getPreference( PhabricatorUserPreferences::PREFERENCE_MONOSPACED_TEXTAREAS);
PhabricatorUserPreferences::PREFERENCE_MONOSPACED_TEXTAREAS); if ($monospaced_textareas == 'enabled') {
if ($monospaced_textareas == 'enabled') { $monospaced_textareas_class = 'PhabricatorMonospaced';
$monospaced_textareas_class = 'PhabricatorMonospaced';
}
} }
$this->setCustomClass( $this->setCustomClass(