1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-10 08:52:39 +01:00

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
This commit is contained in:
deedydas 2013-05-09 14:40:43 -07:00 committed by epriestley
parent 78a8079f59
commit 3d16eb5e57
8 changed files with 128 additions and 115 deletions

View file

@ -162,7 +162,9 @@ final class PhamePostViewController extends PhameController {
PhamePost $post, PhamePost $post,
PhabricatorUser $user) { PhabricatorUser $user) {
$properties = new PhabricatorPropertyListView(); $properties = id(new PhabricatorPropertyListView())
->setUser($user)
->setObject($post);
$descriptions = PhabricatorPolicyQuery::renderPolicyDescriptions( $descriptions = PhabricatorPolicyQuery::renderPolicyDescriptions(
$user, $user,
@ -193,6 +195,8 @@ final class PhamePostViewController extends PhameController {
->addObject($post, PhamePost::MARKUP_FIELD_BODY) ->addObject($post, PhamePost::MARKUP_FIELD_BODY)
->process(); ->process();
$properties->invokeWillRenderEvent();
$properties->addTextContent( $properties->addTextContent(
phutil_tag( phutil_tag(
'div', 'div',

View file

@ -4,7 +4,10 @@
* @group phame * @group phame
*/ */
final class PhamePost extends PhameDAO final class PhamePost extends PhameDAO
implements PhabricatorPolicyInterface, PhabricatorMarkupInterface { implements
PhabricatorPolicyInterface,
PhabricatorMarkupInterface,
PhabricatorTokenReceiverInterface {
const MARKUP_FIELD_BODY = 'markup:body'; const MARKUP_FIELD_BODY = 'markup:body';
const MARKUP_FIELD_SUMMARY = 'markup:summary'; const MARKUP_FIELD_SUMMARY = 'markup:summary';
@ -182,4 +185,12 @@ final class PhamePost extends PhameDAO
return (bool)$this->getPHID(); return (bool)$this->getPHID();
} }
/* -( PhabricatorTokenReceiverInterface )---------------------------------- */
public function getUsersToNotifyOfTokenGiven() {
return array(
$this->getBloggerPHID(),
);
}
} }

View file

@ -31,8 +31,8 @@ final class PhrictionDocumentController
$version_note = null; $version_note = null;
$core_content = ''; $core_content = '';
$byline = '';
$move_notice = ''; $move_notice = '';
$properties = null;
if (!$document) { if (!$document) {
@ -48,22 +48,17 @@ final class PhrictionDocumentController
} }
$create_uri = '/phriction/edit/?slug='.$slug; $create_uri = '/phriction/edit/?slug='.$slug;
$no_content_head = pht('No content here!'); $notice = new AphrontErrorView();
$no_content_body = pht( $notice->setSeverity(AphrontErrorView::SEVERITY_NODATA);
'No document found at %s. You can <strong>'. $notice->setTitle(pht('No content here!'));
'<a href="%s">create a new document here</a></strong>.', $notice->appendChild(
phutil_tag('tt', array(), $slug), pht(
$create_uri); 'No document found at %s. You can <strong>'.
'<a href="%s">create a new document here</a></strong>.',
phutil_tag('tt', array(), $slug),
$create_uri));
$core_content = $notice;
$no_content_text = hsprintf(
'<em>%s</em><br />%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'); $page_title = pht('Page Not Found');
} else { } else {
$version = $request->getInt('v'); $version = $request->getInt('v');
@ -90,75 +85,10 @@ final class PhrictionDocumentController
} }
$page_title = $content->getTitle(); $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( $subscribers = PhabricatorSubscribersQuery::loadSubscribersForPHID(
$document->getPHID()); $document->getPHID());
$properties = $this
$phids = array_filter( ->buildPropertyListView($document, $content, $slug, $subscribers);
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(
'<br />%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('<br />Subscribers: '),
$subcriber_list,
);
}
$byline = hsprintf(
'<div class="phriction-byline">%s%s%s</div>',
pht('Last updated %s by %s.',
$when,
$handles[$content->getAuthorPHID()]->renderLink()),
$project_info,
$subscriber_view);
$doc_status = $document->getStatus(); $doc_status = $document->getStatus();
$current_status = $content->getChangeType(); $current_status = $content->getChangeType();
@ -213,7 +143,6 @@ final class PhrictionDocumentController
phutil_tag('a', array('href' => $slug_uri), $slug_uri))) phutil_tag('a', array('href' => $slug_uri), $slug_uri)))
->render(); ->render();
} }
} }
if ($version_note) { if ($version_note) {
@ -234,18 +163,18 @@ final class PhrictionDocumentController
$header = id(new PhabricatorHeaderView()) $header = id(new PhabricatorHeaderView())
->setHeader($page_title); ->setHeader($page_title);
$page_content = hsprintf( $page_content = hsprintf(
'<div class="phriction-wrap"> '<div class="phriction-wrap">
<div class="phriction-content"> <div class="phriction-content">
%s%s%s%s%s %s%s%s%s%s
</div> </div>
<div class="phriction-fake-space"></div> <div class="phriction-fake-space"></div>
</div>', </div>',
$header, $header,
$actions, $actions,
$byline, $properties,
$move_notice, $move_notice,
$core_content); $core_content);
$core_page = phutil_tag( $core_page = phutil_tag(
'div', '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( private function buildActionView(
PhabricatorUser $user, PhabricatorUser $user,
PhrictionDocument $document) { PhrictionDocument $document) {

View file

@ -4,7 +4,10 @@
* @group phriction * @group phriction
*/ */
final class PhrictionDocument extends PhrictionDAO final class PhrictionDocument extends PhrictionDAO
implements PhabricatorPolicyInterface, PhabricatorSubscribableInterface { implements
PhabricatorPolicyInterface,
PhabricatorSubscribableInterface,
PhabricatorTokenReceiverInterface {
protected $id; protected $id;
protected $phid; protected $phid;
@ -129,4 +132,10 @@ final class PhrictionDocument extends PhrictionDAO
public function isAutomaticallySubscribed($phid) { public function isAutomaticallySubscribed($phid) {
return false; return false;
} }
/* -( PhabricatorTokenReceiverInterface )---------------------------------- */
public function getUsersToNotifyOfTokenGiven() {
return PhabricatorSubscribersQuery::loadSubscribersForPHID($this->phid);
}
} }

View file

@ -113,8 +113,9 @@ final class PonderQuestionViewController extends PonderController {
array $subscribers) { array $subscribers) {
$viewer = $this->getRequest()->getUser(); $viewer = $this->getRequest()->getUser();
$view = new PhabricatorPropertyListView(); $view = id(new PhabricatorPropertyListView())
->setUser($viewer)
->setObject($question);
$view->addProperty( $view->addProperty(
pht('Author'), pht('Author'),
$this->getHandle($question->getAuthorPHID())->renderLink()); $this->getHandle($question->getAuthorPHID())->renderLink());

View file

@ -5,7 +5,8 @@ final class PonderQuestion extends PonderDAO
PhabricatorMarkupInterface, PhabricatorMarkupInterface,
PonderVotableInterface, PonderVotableInterface,
PhabricatorSubscribableInterface, PhabricatorSubscribableInterface,
PhabricatorPolicyInterface { PhabricatorPolicyInterface,
PhabricatorTokenReceiverInterface {
const MARKUP_FIELD_CONTENT = 'markup:content'; const MARKUP_FIELD_CONTENT = 'markup:content';
@ -190,4 +191,12 @@ final class PonderQuestion extends PonderDAO
return false; return false;
} }
/* -( PhabricatorTokenReceiverInterface )---------------------------------- */
public function getUsersToNotifyOfTokenGiven() {
return array(
$this->getAuthorPHID(),
);
}
} }

View file

@ -49,6 +49,4 @@ final class PhabricatorSubscribersQuery extends PhabricatorQuery {
return $results; return $results;
} }
} }

View file

@ -62,17 +62,6 @@
padding: 20px; 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 { .device-phone .phriction-content .phabricator-remarkup {
padding: 10px; padding: 10px;
} }