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());
|
|
|
|
|
2013-04-10 22:08:36 +02:00
|
|
|
$actions = $this->buildActionView($macro);
|
2016-03-02 19:16:19 +01:00
|
|
|
$subheader = $this->buildSubheaderView($macro);
|
|
|
|
$properties = $this->buildPropertyView($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
|
|
|
|
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)
|
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
|
|
|
->setHeader($title_long);
|
|
|
|
|
2015-01-06 20:13:04 +01:00
|
|
|
if (!$macro->getIsDisabled()) {
|
|
|
|
$header->setStatus('fa-check', 'bluegrey', pht('Active'));
|
|
|
|
} else {
|
|
|
|
$header->setStatus('fa-ban', 'red', 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
|
|
|
}
|
|
|
|
|
|
|
|
$is_serious = PhabricatorEnv::getEnvConfig('phabricator.serious-business');
|
|
|
|
|
2013-11-22 01:09:04 +01:00
|
|
|
$comment_header = $is_serious
|
|
|
|
? pht('Add Comment')
|
|
|
|
: pht('Grovel in Awe');
|
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-07-27 18:04:08 +02:00
|
|
|
$draft = PhabricatorDraft::newFromUserAndKey($viewer, $macro->getPHID());
|
2012-12-21 14:57:14 +01:00
|
|
|
|
2012-12-21 14:51:33 +01:00
|
|
|
$add_comment_form = id(new PhabricatorApplicationTransactionCommentView())
|
2015-07-27 18:04:08 +02:00
|
|
|
->setUser($viewer)
|
2013-07-29 03:21:22 +02:00
|
|
|
->setObjectPHID($macro->getPHID())
|
2012-12-21 14:57:14 +01:00
|
|
|
->setDraft($draft)
|
2013-11-22 01:09:04 +01:00
|
|
|
->setHeaderText($comment_header)
|
2012-12-21 14:51:33 +01:00
|
|
|
->setAction($this->getApplicationURI('/comment/'.$macro->getID().'/'))
|
2014-04-19 02:51:46 +02:00
|
|
|
->setSubmitButtonName(pht('Add Comment'));
|
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)
|
|
|
|
->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,
|
2013-11-22 01:09:04 +01:00
|
|
|
$add_comment_form,
|
2016-03-02 19:16:19 +01:00
|
|
|
))
|
|
|
|
->addPropertySection(pht('MACRO'), $file)
|
|
|
|
->addPropertySection(pht('DETAILS'), $details)
|
|
|
|
->setPropertyList($properties)
|
|
|
|
->setActionList($actions);
|
|
|
|
|
|
|
|
return $this->newPage()
|
|
|
|
->setTitle($title_short)
|
|
|
|
->setCrumbs($crumbs)
|
|
|
|
->setPageObjectPHIDs(array($macro->getPHID()))
|
|
|
|
->appendChild(
|
|
|
|
array(
|
|
|
|
$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
|
|
|
));
|
|
|
|
}
|
|
|
|
|
2016-03-02 19:16:19 +01:00
|
|
|
private function buildActionView(
|
|
|
|
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
|
|
|
|
2013-07-12 20:39:47 +02:00
|
|
|
$request = $this->getRequest();
|
|
|
|
$view = id(new PhabricatorActionListView())
|
|
|
|
->setUser($request->getUser())
|
|
|
|
->setObject($macro)
|
|
|
|
->addAction(
|
|
|
|
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
|
|
|
|
2013-09-28 01:01:37 +02:00
|
|
|
$view->addAction(
|
|
|
|
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()) {
|
|
|
|
$view->addAction(
|
|
|
|
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 {
|
|
|
|
$view->addAction(
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
return $view;
|
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
$content = pht('Masterfully imagined by %s on %s.', $author, $date);
|
|
|
|
|
|
|
|
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-02 19:16:19 +01:00
|
|
|
return $view;
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
private function buildPropertyView(
|
|
|
|
PhabricatorFileImageMacro $macro) {
|
|
|
|
$viewer = $this->getViewer();
|
|
|
|
|
|
|
|
$view = id(new PHUIPropertyListView())
|
|
|
|
->setUser($this->getRequest()->getUser())
|
|
|
|
->setObject($macro);
|
|
|
|
|
2013-07-08 22:41:10 +02:00
|
|
|
$view->invokeWillRenderEvent();
|
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
|
|
|
|
|
|
|
return $view;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|