Modernize Macro application
Summary: Adds feed, email, notifications, comments, partial editing, subscriptions, enable/disable, flags and crumbs to Macro.
Test Plan:
{F26839}
{F26840}
{F26841}
{F26842}
{F26843}
{F26844}
{F26845}
Reviewers: vrana, btrahan, chad
Reviewed By: vrana
CC: aran
Maniphest Tasks: T2157, T175, T2104
Differential Revision: https://secure.phabricator.com/D4141
2012-12-11 23:01:03 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class PhabricatorMacroViewController
|
|
|
|
extends PhabricatorMacroController {
|
|
|
|
|
2014-08-07 00:20:33 +02:00
|
|
|
public function shouldAllowPublic() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-07-27 18:04:08 +02:00
|
|
|
public function handleRequest(AphrontRequest $request) {
|
|
|
|
$viewer = $request->getViewer();
|
|
|
|
$id = $request->getURIData('id');
|
Modernize Macro application
Summary: Adds feed, email, notifications, comments, partial editing, subscriptions, enable/disable, flags and crumbs to Macro.
Test Plan:
{F26839}
{F26840}
{F26841}
{F26842}
{F26843}
{F26844}
{F26845}
Reviewers: vrana, btrahan, chad
Reviewed By: vrana
CC: aran
Maniphest Tasks: T2157, T175, T2104
Differential Revision: https://secure.phabricator.com/D4141
2012-12-11 23:01:03 +01:00
|
|
|
|
2013-03-22 21:07:20 +01:00
|
|
|
$macro = id(new PhabricatorMacroQuery())
|
2015-07-27 18:04:08 +02:00
|
|
|
->setViewer($viewer)
|
|
|
|
->withIDs(array($id))
|
Reduce the cost of loading large numbers of macros
Summary:
Ref T6013. I accidentally made this cost explosviely huge when fixing macros for logged out users in D10411.
Specifically, we'd load all the macros, which would load all the files, which would load all the macros (to do policy checks), which would fill out of cache I think (but maybe only some of the time?). Anyway, bad news.
Instead, only load the files if we need them.
Test Plan: Viewed macro main page, macro detail, used a macro, used a meme, edited a macro, edited audio.
Reviewers: btrahan, csilvers
Reviewed By: csilvers
Subscribers: epriestley, spicyj
Maniphest Tasks: T6013
Differential Revision: https://secure.phabricator.com/D10428
2014-09-06 02:30:26 +02:00
|
|
|
->needFiles(true)
|
2013-03-22 21:07:20 +01:00
|
|
|
->executeOne();
|
Modernize Macro application
Summary: Adds feed, email, notifications, comments, partial editing, subscriptions, enable/disable, flags and crumbs to Macro.
Test Plan:
{F26839}
{F26840}
{F26841}
{F26842}
{F26843}
{F26844}
{F26845}
Reviewers: vrana, btrahan, chad
Reviewed By: vrana
CC: aran
Maniphest Tasks: T2157, T175, T2104
Differential Revision: https://secure.phabricator.com/D4141
2012-12-11 23:01:03 +01:00
|
|
|
if (!$macro) {
|
|
|
|
return new Aphront404Response();
|
|
|
|
}
|
|
|
|
|
|
|
|
$title_short = pht('Macro "%s"', $macro->getName());
|
|
|
|
$title_long = pht('Image Macro "%s"', $macro->getName());
|
|
|
|
|
2016-03-06 19:08:49 +01:00
|
|
|
$curtain = $this->buildCurtain($macro);
|
2016-03-02 19:16:19 +01:00
|
|
|
$subheader = $this->buildSubheaderView($macro);
|
|
|
|
$file = $this->buildFileView($macro);
|
|
|
|
$details = $this->buildPropertySectionView($macro);
|
Modernize Macro application
Summary: Adds feed, email, notifications, comments, partial editing, subscriptions, enable/disable, flags and crumbs to Macro.
Test Plan:
{F26839}
{F26840}
{F26841}
{F26842}
{F26843}
{F26844}
{F26845}
Reviewers: vrana, btrahan, chad
Reviewed By: vrana
CC: aran
Maniphest Tasks: T2157, T175, T2104
Differential Revision: https://secure.phabricator.com/D4141
2012-12-11 23:01:03 +01:00
|
|
|
|
|
|
|
$crumbs = $this->buildApplicationCrumbs();
|
2016-03-02 19:16:19 +01:00
|
|
|
$crumbs->addTextCrumb($macro->getName());
|
|
|
|
$crumbs->setBorder(true);
|
Modernize Macro application
Summary: Adds feed, email, notifications, comments, partial editing, subscriptions, enable/disable, flags and crumbs to Macro.
Test Plan:
{F26839}
{F26840}
{F26841}
{F26842}
{F26843}
{F26844}
{F26845}
Reviewers: vrana, btrahan, chad
Reviewed By: vrana
CC: aran
Maniphest Tasks: T2157, T175, T2104
Differential Revision: https://secure.phabricator.com/D4141
2012-12-11 23:01:03 +01:00
|
|
|
|
2014-12-03 22:16:15 +01:00
|
|
|
$timeline = $this->buildTransactionTimeline(
|
|
|
|
$macro,
|
|
|
|
new PhabricatorMacroTransactionQuery());
|
Modernize Macro application
Summary: Adds feed, email, notifications, comments, partial editing, subscriptions, enable/disable, flags and crumbs to Macro.
Test Plan:
{F26839}
{F26840}
{F26841}
{F26842}
{F26843}
{F26844}
{F26845}
Reviewers: vrana, btrahan, chad
Reviewed By: vrana
CC: aran
Maniphest Tasks: T2157, T175, T2104
Differential Revision: https://secure.phabricator.com/D4141
2012-12-11 23:01:03 +01:00
|
|
|
|
2017-05-03 20:26:14 +02:00
|
|
|
$comment_form = $this->buildCommentForm($macro, $timeline);
|
|
|
|
|
2013-09-17 18:12:37 +02:00
|
|
|
$header = id(new PHUIHeaderView())
|
2015-07-27 18:04:08 +02:00
|
|
|
->setUser($viewer)
|
2013-10-16 19:35:52 +02:00
|
|
|
->setPolicyObject($macro)
|
2016-03-05 21:28:56 +01:00
|
|
|
->setHeader($macro->getName())
|
|
|
|
->setHeaderIcon('fa-file-image-o');
|
Modernize Macro application
Summary: Adds feed, email, notifications, comments, partial editing, subscriptions, enable/disable, flags and crumbs to Macro.
Test Plan:
{F26839}
{F26840}
{F26841}
{F26842}
{F26843}
{F26844}
{F26845}
Reviewers: vrana, btrahan, chad
Reviewed By: vrana
CC: aran
Maniphest Tasks: T2157, T175, T2104
Differential Revision: https://secure.phabricator.com/D4141
2012-12-11 23:01:03 +01:00
|
|
|
|
2015-01-06 20:13:04 +01:00
|
|
|
if (!$macro->getIsDisabled()) {
|
|
|
|
$header->setStatus('fa-check', 'bluegrey', pht('Active'));
|
|
|
|
} else {
|
2017-05-02 00:19:00 +02:00
|
|
|
$header->setStatus('fa-ban', 'indigo', pht('Archived'));
|
Modernize Macro application
Summary: Adds feed, email, notifications, comments, partial editing, subscriptions, enable/disable, flags and crumbs to Macro.
Test Plan:
{F26839}
{F26840}
{F26841}
{F26842}
{F26843}
{F26844}
{F26845}
Reviewers: vrana, btrahan, chad
Reviewed By: vrana
CC: aran
Maniphest Tasks: T2157, T175, T2104
Differential Revision: https://secure.phabricator.com/D4141
2012-12-11 23:01:03 +01:00
|
|
|
}
|
|
|
|
|
2016-03-02 19:16:19 +01:00
|
|
|
$view = id(new PHUITwoColumnView())
|
2013-09-29 00:55:38 +02:00
|
|
|
->setHeader($header)
|
2016-03-02 19:16:19 +01:00
|
|
|
->setSubheader($subheader)
|
2016-03-06 19:08:49 +01:00
|
|
|
->setCurtain($curtain)
|
2016-03-02 19:16:19 +01:00
|
|
|
->setMainColumn(array(
|
Modernize Macro application
Summary: Adds feed, email, notifications, comments, partial editing, subscriptions, enable/disable, flags and crumbs to Macro.
Test Plan:
{F26839}
{F26840}
{F26841}
{F26842}
{F26843}
{F26844}
{F26845}
Reviewers: vrana, btrahan, chad
Reviewed By: vrana
CC: aran
Maniphest Tasks: T2157, T175, T2104
Differential Revision: https://secure.phabricator.com/D4141
2012-12-11 23:01:03 +01:00
|
|
|
$timeline,
|
2017-05-03 20:26:14 +02:00
|
|
|
$comment_form,
|
2016-03-02 19:16:19 +01:00
|
|
|
))
|
2016-04-07 00:20:53 +02:00
|
|
|
->addPropertySection(pht('Macro'), $file)
|
|
|
|
->addPropertySection(pht('Details'), $details);
|
2016-03-02 19:16:19 +01:00
|
|
|
|
|
|
|
return $this->newPage()
|
|
|
|
->setTitle($title_short)
|
|
|
|
->setCrumbs($crumbs)
|
|
|
|
->setPageObjectPHIDs(array($macro->getPHID()))
|
2016-03-06 19:08:49 +01:00
|
|
|
->appendChild($view);
|
Modernize Macro application
Summary: Adds feed, email, notifications, comments, partial editing, subscriptions, enable/disable, flags and crumbs to Macro.
Test Plan:
{F26839}
{F26840}
{F26841}
{F26842}
{F26843}
{F26844}
{F26845}
Reviewers: vrana, btrahan, chad
Reviewed By: vrana
CC: aran
Maniphest Tasks: T2157, T175, T2104
Differential Revision: https://secure.phabricator.com/D4141
2012-12-11 23:01:03 +01:00
|
|
|
}
|
|
|
|
|
2017-05-03 20:26:14 +02:00
|
|
|
private function buildCommentForm(
|
|
|
|
PhabricatorFileImageMacro $macro, $timeline) {
|
|
|
|
$viewer = $this->getViewer();
|
|
|
|
|
|
|
|
return id(new PhabricatorMacroEditEngine())
|
|
|
|
->setViewer($viewer)
|
|
|
|
->buildEditEngineCommentView($macro)
|
|
|
|
->setTransactionTimeline($timeline);
|
|
|
|
}
|
|
|
|
|
2016-03-06 19:08:49 +01:00
|
|
|
private function buildCurtain(
|
2016-03-02 19:16:19 +01:00
|
|
|
PhabricatorFileImageMacro $macro) {
|
2013-10-16 19:35:52 +02:00
|
|
|
$can_manage = $this->hasApplicationCapability(
|
2014-07-25 00:20:39 +02:00
|
|
|
PhabricatorMacroManageCapability::CAPABILITY);
|
2013-10-16 19:35:52 +02:00
|
|
|
|
2016-03-06 19:08:49 +01:00
|
|
|
$curtain = $this->newCurtainView($macro);
|
|
|
|
|
|
|
|
$curtain->addAction(
|
2013-07-12 20:39:47 +02:00
|
|
|
id(new PhabricatorActionView())
|
2013-01-24 04:36:23 +01:00
|
|
|
->setName(pht('Edit Macro'))
|
Modernize Macro application
Summary: Adds feed, email, notifications, comments, partial editing, subscriptions, enable/disable, flags and crumbs to Macro.
Test Plan:
{F26839}
{F26840}
{F26841}
{F26842}
{F26843}
{F26844}
{F26845}
Reviewers: vrana, btrahan, chad
Reviewed By: vrana
CC: aran
Maniphest Tasks: T2157, T175, T2104
Differential Revision: https://secure.phabricator.com/D4141
2012-12-11 23:01:03 +01:00
|
|
|
->setHref($this->getApplicationURI('/edit/'.$macro->getID().'/'))
|
2013-10-16 19:35:52 +02:00
|
|
|
->setDisabled(!$can_manage)
|
|
|
|
->setWorkflow(!$can_manage)
|
2014-05-12 19:08:32 +02:00
|
|
|
->setIcon('fa-pencil'));
|
Modernize Macro application
Summary: Adds feed, email, notifications, comments, partial editing, subscriptions, enable/disable, flags and crumbs to Macro.
Test Plan:
{F26839}
{F26840}
{F26841}
{F26842}
{F26843}
{F26844}
{F26845}
Reviewers: vrana, btrahan, chad
Reviewed By: vrana
CC: aran
Maniphest Tasks: T2157, T175, T2104
Differential Revision: https://secure.phabricator.com/D4141
2012-12-11 23:01:03 +01:00
|
|
|
|
2016-03-06 19:08:49 +01:00
|
|
|
$curtain->addAction(
|
2013-09-28 01:01:37 +02:00
|
|
|
id(new PhabricatorActionView())
|
|
|
|
->setName(pht('Edit Audio'))
|
|
|
|
->setHref($this->getApplicationURI('/audio/'.$macro->getID().'/'))
|
2013-10-16 19:35:52 +02:00
|
|
|
->setDisabled(!$can_manage)
|
|
|
|
->setWorkflow(!$can_manage)
|
2014-05-12 19:08:32 +02:00
|
|
|
->setIcon('fa-music'));
|
2013-09-28 01:01:37 +02:00
|
|
|
|
Modernize Macro application
Summary: Adds feed, email, notifications, comments, partial editing, subscriptions, enable/disable, flags and crumbs to Macro.
Test Plan:
{F26839}
{F26840}
{F26841}
{F26842}
{F26843}
{F26844}
{F26845}
Reviewers: vrana, btrahan, chad
Reviewed By: vrana
CC: aran
Maniphest Tasks: T2157, T175, T2104
Differential Revision: https://secure.phabricator.com/D4141
2012-12-11 23:01:03 +01:00
|
|
|
if ($macro->getIsDisabled()) {
|
2016-03-06 19:08:49 +01:00
|
|
|
$curtain->addAction(
|
Modernize Macro application
Summary: Adds feed, email, notifications, comments, partial editing, subscriptions, enable/disable, flags and crumbs to Macro.
Test Plan:
{F26839}
{F26840}
{F26841}
{F26842}
{F26843}
{F26844}
{F26845}
Reviewers: vrana, btrahan, chad
Reviewed By: vrana
CC: aran
Maniphest Tasks: T2157, T175, T2104
Differential Revision: https://secure.phabricator.com/D4141
2012-12-11 23:01:03 +01:00
|
|
|
id(new PhabricatorActionView())
|
2015-01-06 20:13:04 +01:00
|
|
|
->setName(pht('Activate Macro'))
|
Modernize Macro application
Summary: Adds feed, email, notifications, comments, partial editing, subscriptions, enable/disable, flags and crumbs to Macro.
Test Plan:
{F26839}
{F26840}
{F26841}
{F26842}
{F26843}
{F26844}
{F26845}
Reviewers: vrana, btrahan, chad
Reviewed By: vrana
CC: aran
Maniphest Tasks: T2157, T175, T2104
Differential Revision: https://secure.phabricator.com/D4141
2012-12-11 23:01:03 +01:00
|
|
|
->setHref($this->getApplicationURI('/disable/'.$macro->getID().'/'))
|
|
|
|
->setWorkflow(true)
|
2013-10-16 19:35:52 +02:00
|
|
|
->setDisabled(!$can_manage)
|
2015-01-06 20:13:04 +01:00
|
|
|
->setIcon('fa-check'));
|
Modernize Macro application
Summary: Adds feed, email, notifications, comments, partial editing, subscriptions, enable/disable, flags and crumbs to Macro.
Test Plan:
{F26839}
{F26840}
{F26841}
{F26842}
{F26843}
{F26844}
{F26845}
Reviewers: vrana, btrahan, chad
Reviewed By: vrana
CC: aran
Maniphest Tasks: T2157, T175, T2104
Differential Revision: https://secure.phabricator.com/D4141
2012-12-11 23:01:03 +01:00
|
|
|
} else {
|
2016-03-06 19:08:49 +01:00
|
|
|
$curtain->addAction(
|
Modernize Macro application
Summary: Adds feed, email, notifications, comments, partial editing, subscriptions, enable/disable, flags and crumbs to Macro.
Test Plan:
{F26839}
{F26840}
{F26841}
{F26842}
{F26843}
{F26844}
{F26845}
Reviewers: vrana, btrahan, chad
Reviewed By: vrana
CC: aran
Maniphest Tasks: T2157, T175, T2104
Differential Revision: https://secure.phabricator.com/D4141
2012-12-11 23:01:03 +01:00
|
|
|
id(new PhabricatorActionView())
|
2015-01-06 20:13:04 +01:00
|
|
|
->setName(pht('Archive Macro'))
|
Modernize Macro application
Summary: Adds feed, email, notifications, comments, partial editing, subscriptions, enable/disable, flags and crumbs to Macro.
Test Plan:
{F26839}
{F26840}
{F26841}
{F26842}
{F26843}
{F26844}
{F26845}
Reviewers: vrana, btrahan, chad
Reviewed By: vrana
CC: aran
Maniphest Tasks: T2157, T175, T2104
Differential Revision: https://secure.phabricator.com/D4141
2012-12-11 23:01:03 +01:00
|
|
|
->setHref($this->getApplicationURI('/disable/'.$macro->getID().'/'))
|
|
|
|
->setWorkflow(true)
|
2013-10-16 19:35:52 +02:00
|
|
|
->setDisabled(!$can_manage)
|
2014-05-12 19:08:32 +02:00
|
|
|
->setIcon('fa-ban'));
|
Modernize Macro application
Summary: Adds feed, email, notifications, comments, partial editing, subscriptions, enable/disable, flags and crumbs to Macro.
Test Plan:
{F26839}
{F26840}
{F26841}
{F26842}
{F26843}
{F26844}
{F26845}
Reviewers: vrana, btrahan, chad
Reviewed By: vrana
CC: aran
Maniphest Tasks: T2157, T175, T2104
Differential Revision: https://secure.phabricator.com/D4141
2012-12-11 23:01:03 +01:00
|
|
|
}
|
|
|
|
|
2016-03-06 19:08:49 +01:00
|
|
|
return $curtain;
|
Modernize Macro application
Summary: Adds feed, email, notifications, comments, partial editing, subscriptions, enable/disable, flags and crumbs to Macro.
Test Plan:
{F26839}
{F26840}
{F26841}
{F26842}
{F26843}
{F26844}
{F26845}
Reviewers: vrana, btrahan, chad
Reviewed By: vrana
CC: aran
Maniphest Tasks: T2157, T175, T2104
Differential Revision: https://secure.phabricator.com/D4141
2012-12-11 23:01:03 +01:00
|
|
|
}
|
|
|
|
|
2016-03-02 19:16:19 +01:00
|
|
|
private function buildSubheaderView(
|
|
|
|
PhabricatorFileImageMacro $macro) {
|
|
|
|
$viewer = $this->getViewer();
|
|
|
|
|
|
|
|
$author_phid = $macro->getAuthorPHID();
|
|
|
|
|
|
|
|
$author = $viewer->renderHandle($author_phid)->render();
|
|
|
|
$date = phabricator_datetime($macro->getDateCreated(), $viewer);
|
|
|
|
$author = phutil_tag('strong', array(), $author);
|
|
|
|
|
|
|
|
$handles = $viewer->loadHandles(array($author_phid));
|
|
|
|
$image_uri = $handles[$author_phid]->getImageURI();
|
|
|
|
$image_href = $handles[$author_phid]->getURI();
|
|
|
|
|
2019-04-19 02:14:38 +02:00
|
|
|
if (!$date) {
|
|
|
|
$content = pht(
|
|
|
|
'Masterfully imagined by %s in ages long past.', $author);
|
|
|
|
} else {
|
|
|
|
$content = pht('Masterfully imagined by %s on %s.', $author, $date);
|
|
|
|
}
|
2016-03-02 19:16:19 +01:00
|
|
|
|
|
|
|
return id(new PHUIHeadThingView())
|
|
|
|
->setImage($image_uri)
|
|
|
|
->setImageHref($image_href)
|
|
|
|
->setContent($content);
|
|
|
|
}
|
|
|
|
|
|
|
|
private function buildPropertySectionView(
|
|
|
|
PhabricatorFileImageMacro $macro) {
|
2015-03-30 16:55:33 +02:00
|
|
|
$viewer = $this->getViewer();
|
Modernize Macro application
Summary: Adds feed, email, notifications, comments, partial editing, subscriptions, enable/disable, flags and crumbs to Macro.
Test Plan:
{F26839}
{F26840}
{F26841}
{F26842}
{F26843}
{F26844}
{F26845}
Reviewers: vrana, btrahan, chad
Reviewed By: vrana
CC: aran
Maniphest Tasks: T2157, T175, T2104
Differential Revision: https://secure.phabricator.com/D4141
2012-12-11 23:01:03 +01:00
|
|
|
|
2013-10-11 16:53:56 +02:00
|
|
|
$view = id(new PHUIPropertyListView())
|
2016-03-02 19:16:19 +01:00
|
|
|
->setUser($viewer);
|
Modernize Macro application
Summary: Adds feed, email, notifications, comments, partial editing, subscriptions, enable/disable, flags and crumbs to Macro.
Test Plan:
{F26839}
{F26840}
{F26841}
{F26842}
{F26843}
{F26844}
{F26845}
Reviewers: vrana, btrahan, chad
Reviewed By: vrana
CC: aran
Maniphest Tasks: T2157, T175, T2104
Differential Revision: https://secure.phabricator.com/D4141
2012-12-11 23:01:03 +01:00
|
|
|
|
2013-09-28 01:01:37 +02:00
|
|
|
switch ($macro->getAudioBehavior()) {
|
|
|
|
case PhabricatorFileImageMacro::AUDIO_BEHAVIOR_ONCE:
|
|
|
|
$view->addProperty(pht('Audio Behavior'), pht('Play Once'));
|
|
|
|
break;
|
|
|
|
case PhabricatorFileImageMacro::AUDIO_BEHAVIOR_LOOP:
|
|
|
|
$view->addProperty(pht('Audio Behavior'), pht('Loop'));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
$audio_phid = $macro->getAudioPHID();
|
|
|
|
if ($audio_phid) {
|
|
|
|
$view->addProperty(
|
|
|
|
pht('Audio'),
|
2015-03-30 16:55:33 +02:00
|
|
|
$viewer->renderHandle($audio_phid));
|
2013-09-28 01:01:37 +02:00
|
|
|
}
|
|
|
|
|
2016-03-05 21:28:56 +01:00
|
|
|
if ($view->hasAnyProperties()) {
|
|
|
|
return $view;
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
2016-03-02 19:16:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private function buildFileView(
|
|
|
|
PhabricatorFileImageMacro $macro) {
|
|
|
|
$viewer = $this->getViewer();
|
|
|
|
|
|
|
|
$view = id(new PHUIPropertyListView())
|
|
|
|
->setUser($viewer);
|
|
|
|
|
|
|
|
$file = $macro->getFile();
|
|
|
|
if ($file) {
|
|
|
|
$view->addImageContent(
|
|
|
|
phutil_tag(
|
|
|
|
'img',
|
|
|
|
array(
|
|
|
|
'src' => $file->getViewURI(),
|
|
|
|
'class' => 'phabricator-image-macro-hero',
|
|
|
|
)));
|
|
|
|
return $view;
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
Modernize Macro application
Summary: Adds feed, email, notifications, comments, partial editing, subscriptions, enable/disable, flags and crumbs to Macro.
Test Plan:
{F26839}
{F26840}
{F26841}
{F26842}
{F26843}
{F26844}
{F26845}
Reviewers: vrana, btrahan, chad
Reviewed By: vrana
CC: aran
Maniphest Tasks: T2157, T175, T2104
Differential Revision: https://secure.phabricator.com/D4141
2012-12-11 23:01:03 +01:00
|
|
|
}
|