From 3d16eb5e57a76786223fe58a1ddc8e11ffac313c Mon Sep 17 00:00:00 2001 From: deedydas Date: Thu, 9 May 2013 14:40:43 -0700 Subject: [PATCH] Token support for Phriction Documents, Ponder Questions, and Phame Blogs Summary: Ref T3023 Token support for Phriction Documents, Ponder Questions, and Phame Blogs Test Plan: Token notifications and visual display seems to be working for the above types Reviewers: epriestley Reviewed By: epriestley CC: aran, Korvin, AnhNhan Maniphest Tasks: T3023 Differential Revision: https://secure.phabricator.com/D5862 --- .../post/PhamePostViewController.php | 6 +- src/applications/phame/storage/PhamePost.php | 13 +- .../PhrictionDocumentController.php | 184 +++++++++--------- .../phriction/storage/PhrictionDocument.php | 11 +- .../PonderQuestionViewController.php | 5 +- .../ponder/storage/PonderQuestion.php | 11 +- .../query/PhabricatorSubscribersQuery.php | 2 - .../phriction/phriction-document-css.css | 11 -- 8 files changed, 128 insertions(+), 115 deletions(-) diff --git a/src/applications/phame/controller/post/PhamePostViewController.php b/src/applications/phame/controller/post/PhamePostViewController.php index e39176955a..1240351f11 100644 --- a/src/applications/phame/controller/post/PhamePostViewController.php +++ b/src/applications/phame/controller/post/PhamePostViewController.php @@ -162,7 +162,9 @@ final class PhamePostViewController extends PhameController { PhamePost $post, PhabricatorUser $user) { - $properties = new PhabricatorPropertyListView(); + $properties = id(new PhabricatorPropertyListView()) + ->setUser($user) + ->setObject($post); $descriptions = PhabricatorPolicyQuery::renderPolicyDescriptions( $user, @@ -193,6 +195,8 @@ final class PhamePostViewController extends PhameController { ->addObject($post, PhamePost::MARKUP_FIELD_BODY) ->process(); + $properties->invokeWillRenderEvent(); + $properties->addTextContent( phutil_tag( 'div', diff --git a/src/applications/phame/storage/PhamePost.php b/src/applications/phame/storage/PhamePost.php index 62414a60ec..3809679c94 100644 --- a/src/applications/phame/storage/PhamePost.php +++ b/src/applications/phame/storage/PhamePost.php @@ -4,7 +4,10 @@ * @group phame */ final class PhamePost extends PhameDAO - implements PhabricatorPolicyInterface, PhabricatorMarkupInterface { + implements + PhabricatorPolicyInterface, + PhabricatorMarkupInterface, + PhabricatorTokenReceiverInterface { const MARKUP_FIELD_BODY = 'markup:body'; const MARKUP_FIELD_SUMMARY = 'markup:summary'; @@ -182,4 +185,12 @@ final class PhamePost extends PhameDAO return (bool)$this->getPHID(); } +/* -( PhabricatorTokenReceiverInterface )---------------------------------- */ + + public function getUsersToNotifyOfTokenGiven() { + return array( + $this->getBloggerPHID(), + ); + } + } diff --git a/src/applications/phriction/controller/PhrictionDocumentController.php b/src/applications/phriction/controller/PhrictionDocumentController.php index 3cb431dbee..58e1252dab 100644 --- a/src/applications/phriction/controller/PhrictionDocumentController.php +++ b/src/applications/phriction/controller/PhrictionDocumentController.php @@ -31,8 +31,8 @@ final class PhrictionDocumentController $version_note = null; $core_content = ''; - $byline = ''; $move_notice = ''; + $properties = null; if (!$document) { @@ -48,22 +48,17 @@ final class PhrictionDocumentController } $create_uri = '/phriction/edit/?slug='.$slug; - $no_content_head = pht('No content here!'); - $no_content_body = pht( - 'No document found at %s. You can '. - 'create a new document here.', - phutil_tag('tt', array(), $slug), - $create_uri); + $notice = new AphrontErrorView(); + $notice->setSeverity(AphrontErrorView::SEVERITY_NODATA); + $notice->setTitle(pht('No content here!')); + $notice->appendChild( + pht( + 'No document found at %s. You can '. + 'create a new document here.', + phutil_tag('tt', array(), $slug), + $create_uri)); + $core_content = $notice; - $no_content_text = hsprintf( - '%s
%s', - $no_content_head, - $no_content_body); - - $page_content = phutil_tag( - 'div', - array('class' => 'phriction-content'), - $no_content_text); $page_title = pht('Page Not Found'); } else { $version = $request->getInt('v'); @@ -90,75 +85,10 @@ final class PhrictionDocumentController } $page_title = $content->getTitle(); - $project_phid = null; - if (PhrictionDocument::isProjectSlug($slug)) { - $project = id(new PhabricatorProject())->loadOneWhere( - 'phrictionSlug = %s', - PhrictionDocument::getProjectSlugIdentifier($slug)); - if ($project) { - $project_phid = $project->getPHID(); - } - } - $subscribers = PhabricatorSubscribersQuery::loadSubscribersForPHID( $document->getPHID()); - - $phids = array_filter( - array( - $content->getAuthorPHID(), - $project_phid, - )); - - if ($subscribers) { - $phids = array_merge($phids, $subscribers); - } - - $handles = $this->loadViewerHandles($phids); - - $age = time() - $content->getDateCreated(); - $age = floor($age / (60 * 60 * 24)); - - if ($age < 1) { - $when = pht('today'); - } else if ($age == 1) { - $when = pht('yesterday'); - } else { - $when = pht("%d days ago", $age); - } - - - $project_info = null; - if ($project_phid) { - $project_info = hsprintf( - '
%s', - pht('This document is about the project %s.', - $handles[$project_phid]->renderLink())); - } - - $subscriber_view = null; - if ($subscribers) { - $subcriber_list = array(); - foreach ($subscribers as $subscriber) { - $subcriber_list[] = $handles[$subscriber]; - } - - $subcriber_list = phutil_implode_html(', ', - mpull($subcriber_list, 'renderLink')); - - $subscriber_view = array( - hsprintf('
Subscribers: '), - $subcriber_list, - ); - } - - $byline = hsprintf( - '
%s%s%s
', - pht('Last updated %s by %s.', - $when, - $handles[$content->getAuthorPHID()]->renderLink()), - $project_info, - $subscriber_view); - + $properties = $this + ->buildPropertyListView($document, $content, $slug, $subscribers); $doc_status = $document->getStatus(); $current_status = $content->getChangeType(); @@ -213,7 +143,6 @@ final class PhrictionDocumentController phutil_tag('a', array('href' => $slug_uri), $slug_uri))) ->render(); } - } if ($version_note) { @@ -234,18 +163,18 @@ final class PhrictionDocumentController $header = id(new PhabricatorHeaderView()) ->setHeader($page_title); - $page_content = hsprintf( - '
-
- %s%s%s%s%s -
-
-
', - $header, - $actions, - $byline, - $move_notice, - $core_content); + $page_content = hsprintf( + '
+
+ %s%s%s%s%s +
+
+
', + $header, + $actions, + $properties, + $move_notice, + $core_content); $core_page = phutil_tag( 'div', @@ -270,6 +199,69 @@ final class PhrictionDocumentController } + private function buildPropertyListView( + PhrictionDocument $document, + PhrictionContent $content, + $slug, + array $subscribers) { + + $viewer = $this->getRequest()->getUser(); + $view = id(new PhabricatorPropertyListView()) + ->setUser($viewer) + ->setObject($document); + + $project_phid = null; + if (PhrictionDocument::isProjectSlug($slug)) { + $project = id(new PhabricatorProject())->loadOneWhere( + 'phrictionSlug = %s', + PhrictionDocument::getProjectSlugIdentifier($slug)); + if ($project) { + $project_phid = $project->getPHID(); + } + } + + $phids = array_filter( + array( + $content->getAuthorPHID(), + $project_phid, + )); + + if ($subscribers) { + $phids = array_merge($phids, $subscribers); + } + + $this->loadHandles($phids); + + $project_info = null; + if ($project_phid) { + $view->addProperty( + pht('Project Info'), + $this->getHandle($project_phid)->renderLink()); + } + + $view->addProperty( + pht('Last Author'), + $this->getHandle($content->getAuthorPHID())->renderLink()); + + $age = time() - $content->getDateCreated(); + $age = floor($age / (60 * 60 * 24)); + if ($age < 1) { + $when = pht('Today'); + } else if ($age == 1) { + $when = pht('Yesterday'); + } else { + $when = pht("%d Days Ago", $age); + } + $view->addProperty(pht('Last Updated'), $when); + + if ($subscribers) { + $subscribers = $this->renderHandlesForPHIDs($subscribers); + $view->addProperty(pht('Subscribers'), $subscribers); + } + + return $view; + } + private function buildActionView( PhabricatorUser $user, PhrictionDocument $document) { diff --git a/src/applications/phriction/storage/PhrictionDocument.php b/src/applications/phriction/storage/PhrictionDocument.php index f3bc38a705..af74769f29 100644 --- a/src/applications/phriction/storage/PhrictionDocument.php +++ b/src/applications/phriction/storage/PhrictionDocument.php @@ -4,7 +4,10 @@ * @group phriction */ final class PhrictionDocument extends PhrictionDAO - implements PhabricatorPolicyInterface, PhabricatorSubscribableInterface { + implements + PhabricatorPolicyInterface, + PhabricatorSubscribableInterface, + PhabricatorTokenReceiverInterface { protected $id; protected $phid; @@ -129,4 +132,10 @@ final class PhrictionDocument extends PhrictionDAO public function isAutomaticallySubscribed($phid) { return false; } + +/* -( PhabricatorTokenReceiverInterface )---------------------------------- */ + + public function getUsersToNotifyOfTokenGiven() { + return PhabricatorSubscribersQuery::loadSubscribersForPHID($this->phid); + } } diff --git a/src/applications/ponder/controller/PonderQuestionViewController.php b/src/applications/ponder/controller/PonderQuestionViewController.php index 758a0a6673..29ad9532c1 100644 --- a/src/applications/ponder/controller/PonderQuestionViewController.php +++ b/src/applications/ponder/controller/PonderQuestionViewController.php @@ -113,8 +113,9 @@ final class PonderQuestionViewController extends PonderController { array $subscribers) { $viewer = $this->getRequest()->getUser(); - $view = new PhabricatorPropertyListView(); - + $view = id(new PhabricatorPropertyListView()) + ->setUser($viewer) + ->setObject($question); $view->addProperty( pht('Author'), $this->getHandle($question->getAuthorPHID())->renderLink()); diff --git a/src/applications/ponder/storage/PonderQuestion.php b/src/applications/ponder/storage/PonderQuestion.php index 9028681059..88160a35a1 100644 --- a/src/applications/ponder/storage/PonderQuestion.php +++ b/src/applications/ponder/storage/PonderQuestion.php @@ -5,7 +5,8 @@ final class PonderQuestion extends PonderDAO PhabricatorMarkupInterface, PonderVotableInterface, PhabricatorSubscribableInterface, - PhabricatorPolicyInterface { + PhabricatorPolicyInterface, + PhabricatorTokenReceiverInterface { const MARKUP_FIELD_CONTENT = 'markup:content'; @@ -190,4 +191,12 @@ final class PonderQuestion extends PonderDAO return false; } +/* -( PhabricatorTokenReceiverInterface )---------------------------------- */ + + public function getUsersToNotifyOfTokenGiven() { + return array( + $this->getAuthorPHID(), + ); + } + } diff --git a/src/applications/subscriptions/query/PhabricatorSubscribersQuery.php b/src/applications/subscriptions/query/PhabricatorSubscribersQuery.php index 0870fe27ee..73a5bf5a4b 100644 --- a/src/applications/subscriptions/query/PhabricatorSubscribersQuery.php +++ b/src/applications/subscriptions/query/PhabricatorSubscribersQuery.php @@ -49,6 +49,4 @@ final class PhabricatorSubscribersQuery extends PhabricatorQuery { return $results; } - - } diff --git a/webroot/rsrc/css/application/phriction/phriction-document-css.css b/webroot/rsrc/css/application/phriction/phriction-document-css.css index f2ea174839..899ae2b476 100644 --- a/webroot/rsrc/css/application/phriction/phriction-document-css.css +++ b/webroot/rsrc/css/application/phriction/phriction-document-css.css @@ -62,17 +62,6 @@ padding: 20px; } -.phriction-byline { - padding: 10px 20px; - color: #777; - font-size: 11px; - background: #f7f7f7; -} - -.device-phone .phriction-byline { - padding: 10px; -} - .device-phone .phriction-content .phabricator-remarkup { padding: 10px; }