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,
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',

View file

@ -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(),
);
}
}

View file

@ -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 <strong>'.
'<a href="%s">create a new document here</a></strong>.',
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 <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');
} 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(
'<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);
$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(
'<div class="phriction-wrap">
<div class="phriction-content">
%s%s%s%s%s
</div>
<div class="phriction-fake-space"></div>
</div>',
$header,
$actions,
$byline,
$move_notice,
$core_content);
$page_content = hsprintf(
'<div class="phriction-wrap">
<div class="phriction-content">
%s%s%s%s%s
</div>
<div class="phriction-fake-space"></div>
</div>',
$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) {

View file

@ -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);
}
}

View file

@ -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());

View file

@ -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(),
);
}
}

View file

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

View file

@ -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;
}