Page MenuHomestyx hydra

No OneTemporary

diff --git a/src/applications/badges/view/PhabricatorBadgesRecipientsListView.php b/src/applications/badges/view/PhabricatorBadgesRecipientsListView.php
index 6b633bed5b..68633a6a29 100644
--- a/src/applications/badges/view/PhabricatorBadgesRecipientsListView.php
+++ b/src/applications/badges/view/PhabricatorBadgesRecipientsListView.php
@@ -1,61 +1,60 @@
<?php
final class PhabricatorBadgesRecipientsListView extends AphrontView {
private $badge;
private $handles;
public function setBadge(PhabricatorBadgesBadge $badge) {
$this->badge = $badge;
return $this;
}
public function setHandles(array $handles) {
$this->handles = $handles;
return $this;
}
public function render() {
-
- $viewer = $this->user;
+ $viewer = $this->getViewer();
$badge = $this->badge;
$handles = $this->handles;
$can_edit = PhabricatorPolicyFilter::hasCapability(
$viewer,
$badge,
PhabricatorPolicyCapability::CAN_EDIT);
$list = id(new PHUIObjectItemListView())
->setNoDataString(pht('This badge does not have any recipients.'));
foreach ($handles as $handle) {
$remove_uri = '/badges/recipients/'.
$badge->getID().'/remove/?phid='.$handle->getPHID();
$item = id(new PHUIObjectItemView())
->setHeader($handle->getFullName())
->setHref($handle->getURI())
->setImageURI($handle->getImageURI());
if ($can_edit) {
$item->addAction(
id(new PHUIListItemView())
->setIcon('fa-times')
->setName(pht('Remove'))
->setHref($remove_uri)
->setWorkflow(true));
}
$list->addItem($item);
}
$box = id(new PHUIObjectBoxView())
->setHeaderText(pht('Recipients'))
->setObjectList($list);
return $box;
}
}
diff --git a/src/applications/daemon/view/PhabricatorDaemonLogEventsView.php b/src/applications/daemon/view/PhabricatorDaemonLogEventsView.php
index 4c0caa6fd7..039906e718 100644
--- a/src/applications/daemon/view/PhabricatorDaemonLogEventsView.php
+++ b/src/applications/daemon/view/PhabricatorDaemonLogEventsView.php
@@ -1,134 +1,131 @@
<?php
final class PhabricatorDaemonLogEventsView extends AphrontView {
private $events;
private $combinedLog;
private $showFullMessage;
public function setShowFullMessage($show_full_message) {
$this->showFullMessage = $show_full_message;
return $this;
}
public function setEvents(array $events) {
assert_instances_of($events, 'PhabricatorDaemonLogEvent');
$this->events = $events;
return $this;
}
public function setCombinedLog($is_combined) {
$this->combinedLog = $is_combined;
return $this;
}
public function render() {
+ $viewer = $this->getViewer();
$rows = array();
- if (!$this->user) {
- throw new PhutilInvalidStateException('setUser');
- }
-
foreach ($this->events as $event) {
// Limit display log size. If a daemon gets stuck in an output loop this
// page can be like >100MB if we don't truncate stuff. Try to do cheap
// line-based truncation first, and fall back to expensive UTF-8 character
// truncation if that doesn't get things short enough.
$message = $event->getMessage();
$more = null;
if (!$this->showFullMessage) {
$more_lines = null;
$more_chars = null;
$line_limit = 12;
if (substr_count($message, "\n") > $line_limit) {
$message = explode("\n", $message);
$more_lines = count($message) - $line_limit;
$message = array_slice($message, 0, $line_limit);
$message = implode("\n", $message);
}
$char_limit = 8192;
if (strlen($message) > $char_limit) {
$message = phutil_utf8v($message);
$more_chars = count($message) - $char_limit;
$message = array_slice($message, 0, $char_limit);
$message = implode('', $message);
}
if ($more_chars) {
$more = new PhutilNumber($more_chars);
$more = pht('Show %d more character(s)...', $more);
} else if ($more_lines) {
$more = new PhutilNumber($more_lines);
$more = pht('Show %d more line(s)...', $more);
}
if ($more) {
$id = $event->getID();
$more = array(
"\n...\n",
phutil_tag(
'a',
array(
'href' => "/daemon/event/{$id}/",
),
$more),
);
}
}
$row = array(
$event->getLogType(),
- phabricator_date($event->getEpoch(), $this->user),
- phabricator_time($event->getEpoch(), $this->user),
+ phabricator_date($event->getEpoch(), $viewer),
+ phabricator_time($event->getEpoch(), $viewer),
array(
$message,
$more,
),
);
if ($this->combinedLog) {
array_unshift(
$row,
phutil_tag(
'a',
array(
'href' => '/daemon/log/'.$event->getLogID().'/',
),
pht('Daemon %s', $event->getLogID())));
}
$rows[] = $row;
}
$classes = array(
'',
'',
'right',
'wide prewrap',
);
$headers = array(
'Type',
'Date',
'Time',
'Message',
);
if ($this->combinedLog) {
array_unshift($classes, 'pri');
array_unshift($headers, 'Daemon');
}
$log_table = new AphrontTableView($rows);
$log_table->setHeaders($headers);
$log_table->setColumnClasses($classes);
return $log_table->render();
}
}
diff --git a/src/applications/daemon/view/PhabricatorDaemonLogListView.php b/src/applications/daemon/view/PhabricatorDaemonLogListView.php
index 6c96509505..046d1a29f5 100644
--- a/src/applications/daemon/view/PhabricatorDaemonLogListView.php
+++ b/src/applications/daemon/view/PhabricatorDaemonLogListView.php
@@ -1,80 +1,78 @@
<?php
final class PhabricatorDaemonLogListView extends AphrontView {
private $daemonLogs;
public function setDaemonLogs(array $daemon_logs) {
assert_instances_of($daemon_logs, 'PhabricatorDaemonLog');
$this->daemonLogs = $daemon_logs;
return $this;
}
public function render() {
- $rows = array();
+ $viewer = $this->getViewer();
- if (!$this->user) {
- throw new PhutilInvalidStateException('setUser');
- }
+ $rows = array();
$list = new PHUIObjectItemListView();
$list->setFlush(true);
foreach ($this->daemonLogs as $log) {
$id = $log->getID();
$epoch = $log->getDateCreated();
$item = id(new PHUIObjectItemView())
->setObjectName(pht('Daemon %s', $id))
->setHeader($log->getDaemon())
->setHref("/daemon/log/{$id}/")
- ->addIcon('none', phabricator_datetime($epoch, $this->user));
+ ->addIcon('none', phabricator_datetime($epoch, $viewer));
$status = $log->getStatus();
switch ($status) {
case PhabricatorDaemonLog::STATUS_RUNNING:
$item->setStatusIcon('fa-rocket green');
$item->addAttribute(pht('This daemon is running.'));
break;
case PhabricatorDaemonLog::STATUS_DEAD:
$item->setStatusIcon('fa-warning red');
$item->addAttribute(
pht(
'This daemon is lost or exited uncleanly, and is presumed '.
'dead.'));
$item->addIcon('fa-times grey', pht('Dead'));
break;
case PhabricatorDaemonLog::STATUS_EXITING:
$item->addAttribute(pht('This daemon is exiting.'));
$item->addIcon('fa-check', pht('Exiting'));
break;
case PhabricatorDaemonLog::STATUS_EXITED:
$item->setDisabled(true);
$item->addAttribute(pht('This daemon exited cleanly.'));
$item->addIcon('fa-check grey', pht('Exited'));
break;
case PhabricatorDaemonLog::STATUS_WAIT:
$item->setStatusIcon('fa-clock-o blue');
$item->addAttribute(
pht(
'This daemon encountered an error recently and is waiting a '.
'moment to restart.'));
$item->addIcon('fa-clock-o grey', pht('Waiting'));
break;
case PhabricatorDaemonLog::STATUS_UNKNOWN:
default:
$item->setStatusIcon('fa-warning orange');
$item->addAttribute(
pht(
'This daemon has not reported its status recently. It may '.
'have exited uncleanly.'));
$item->addIcon('fa-warning', pht('Unknown'));
break;
}
$list->addItem($item);
}
return $list;
}
}
diff --git a/src/applications/differential/view/DifferentialAddCommentView.php b/src/applications/differential/view/DifferentialAddCommentView.php
index 5524869a77..2d586e7be4 100644
--- a/src/applications/differential/view/DifferentialAddCommentView.php
+++ b/src/applications/differential/view/DifferentialAddCommentView.php
@@ -1,198 +1,199 @@
<?php
final class DifferentialAddCommentView extends AphrontView {
private $revision;
private $actions;
private $actionURI;
private $draft;
private $reviewers = array();
private $ccs = array();
private $errorView;
public function setInfoView(PHUIInfoView $error_view) {
$this->errorView = $error_view;
return $this;
}
public function getErrorView() {
return $this->errorView;
}
public function setRevision($revision) {
$this->revision = $revision;
return $this;
}
public function setActions(array $actions) {
$this->actions = $actions;
return $this;
}
public function setActionURI($uri) {
$this->actionURI = $uri;
return $this;
}
public function setDraft(PhabricatorDraft $draft = null) {
$this->draft = $draft;
return $this;
}
public function setReviewers(array $names) {
$this->reviewers = $names;
return $this;
}
public function setCCs(array $names) {
$this->ccs = $names;
return $this;
}
public function render() {
+ $viewer = $this->getViewer();
$this->requireResource('differential-revision-add-comment-css');
$revision = $this->revision;
$action = null;
if ($this->draft) {
$action = idx($this->draft->getMetadata(), 'action');
}
$enable_reviewers = DifferentialAction::allowReviewers($action);
$enable_ccs = ($action == DifferentialAction::ACTION_ADDCCS);
$add_reviewers_labels = array(
'add_reviewers' => pht('Add Reviewers'),
'request_review' => pht('Add Reviewers'),
'resign' => pht('Suggest Reviewers'),
);
$mailable_source = new PhabricatorMetaMTAMailableDatasource();
$reviewer_source = new PhabricatorProjectOrUserDatasource();
$form = new AphrontFormView();
$form
->setWorkflow(true)
- ->setUser($this->user)
+ ->setViewer($viewer)
->setAction($this->actionURI)
->addHiddenInput('revision_id', $revision->getID())
->appendChild(
id(new AphrontFormSelectControl())
->setLabel(pht('Action'))
->setName('action')
->setValue($action)
->setID('comment-action')
->setOptions($this->actions))
->appendControl(
id(new AphrontFormTokenizerControl())
->setLabel($enable_reviewers ? $add_reviewers_labels[$action] :
$add_reviewers_labels['add_reviewers'])
->setName('reviewers')
->setControlID('add-reviewers')
->setControlStyle($enable_reviewers ? null : 'display: none')
->setID('add-reviewers-tokenizer')
->setDisableBehavior(true)
->setDatasource($reviewer_source))
->appendControl(
id(new AphrontFormTokenizerControl())
->setLabel(pht('Add Subscribers'))
->setName('ccs')
->setControlID('add-ccs')
->setControlStyle($enable_ccs ? null : 'display: none')
->setID('add-ccs-tokenizer')
->setDisableBehavior(true)
->setDatasource($mailable_source))
->appendChild(
id(new PhabricatorRemarkupControl())
->setName('comment')
->setID('comment-content')
->setLabel(pht('Comment'))
->setValue($this->draft ? $this->draft->getDraft() : null)
- ->setUser($this->user))
+ ->setViewer($viewer))
->appendChild(
id(new AphrontFormSubmitControl())
->setValue(pht('Submit')));
Javelin::initBehavior(
'differential-add-reviewers-and-ccs',
array(
'dynamic' => array(
'add-reviewers-tokenizer' => array(
'actions' => array(
'request_review' => 1,
'add_reviewers' => 1,
'resign' => 1,
),
'src' => $reviewer_source->getDatasourceURI(),
'value' => $this->reviewers,
'row' => 'add-reviewers',
'labels' => $add_reviewers_labels,
'placeholder' => $reviewer_source->getPlaceholderText(),
),
'add-ccs-tokenizer' => array(
'actions' => array('add_ccs' => 1),
'src' => $mailable_source->getDatasourceURI(),
'value' => $this->ccs,
'row' => 'add-ccs',
'placeholder' => $mailable_source->getPlaceholderText(),
),
),
'select' => 'comment-action',
));
$diff = $revision->loadActiveDiff();
$rev_id = $revision->getID();
Javelin::initBehavior(
'differential-feedback-preview',
array(
'uri' => '/differential/comment/preview/'.$rev_id.'/',
'preview' => 'comment-preview',
'action' => 'comment-action',
'content' => 'comment-content',
'previewTokenizers' => array(
'reviewers' => 'add-reviewers-tokenizer',
'ccs' => 'add-ccs-tokenizer',
),
'inlineuri' => '/differential/comment/inline/preview/'.$rev_id.'/',
'inline' => 'inline-comment-preview',
));
$is_serious = PhabricatorEnv::getEnvConfig('phabricator.serious-business');
$header_text = $is_serious
? pht('Add Comment')
: pht('Leap Into Action');
$header = id(new PHUIHeaderView())
->setHeader($header_text);
$anchor = id(new PhabricatorAnchorView())
->setAnchorName('comment')
->setNavigationMarker(true);
$loading = phutil_tag(
'span',
array('class' => 'aphront-panel-preview-loading-text'),
pht('Loading comment preview...'));
$preview = phutil_tag_div(
'aphront-panel-preview aphront-panel-flush',
array(
phutil_tag('div', array('id' => 'comment-preview'), $loading),
phutil_tag('div', array('id' => 'inline-comment-preview')),
));
$comment_box = id(new PHUIObjectBoxView())
->setHeader($header)
->appendChild($anchor)
->appendChild($form);
if ($this->errorView) {
$comment_box->setInfoView($this->errorView);
}
return array($comment_box, $preview);
}
}
diff --git a/src/applications/differential/view/DifferentialChangesetListView.php b/src/applications/differential/view/DifferentialChangesetListView.php
index ec509d62dd..0cd2923018 100644
--- a/src/applications/differential/view/DifferentialChangesetListView.php
+++ b/src/applications/differential/view/DifferentialChangesetListView.php
@@ -1,340 +1,342 @@
<?php
final class DifferentialChangesetListView extends AphrontView {
private $changesets = array();
private $visibleChangesets = array();
private $references = array();
private $inlineURI;
private $renderURI = '/differential/changeset/';
private $whitespace;
private $standaloneURI;
private $leftRawFileURI;
private $rightRawFileURI;
private $symbolIndexes = array();
private $repository;
private $branch;
private $diff;
private $vsMap = array();
private $title;
private $parser;
public function setParser(DifferentialChangesetParser $parser) {
$this->parser = $parser;
return $this;
}
public function getParser() {
return $this->parser;
}
public function setTitle($title) {
$this->title = $title;
return $this;
}
private function getTitle() {
return $this->title;
}
public function setBranch($branch) {
$this->branch = $branch;
return $this;
}
private function getBranch() {
return $this->branch;
}
public function setChangesets($changesets) {
$this->changesets = $changesets;
return $this;
}
public function setVisibleChangesets($visible_changesets) {
$this->visibleChangesets = $visible_changesets;
return $this;
}
public function setInlineCommentControllerURI($uri) {
$this->inlineURI = $uri;
return $this;
}
public function setRepository(PhabricatorRepository $repository) {
$this->repository = $repository;
return $this;
}
public function setDiff(DifferentialDiff $diff) {
$this->diff = $diff;
return $this;
}
public function setRenderingReferences(array $references) {
$this->references = $references;
return $this;
}
public function setSymbolIndexes(array $indexes) {
$this->symbolIndexes = $indexes;
return $this;
}
public function setRenderURI($render_uri) {
$this->renderURI = $render_uri;
return $this;
}
public function setWhitespace($whitespace) {
$this->whitespace = $whitespace;
return $this;
}
public function setVsMap(array $vs_map) {
$this->vsMap = $vs_map;
return $this;
}
public function getVsMap() {
return $this->vsMap;
}
public function setStandaloneURI($uri) {
$this->standaloneURI = $uri;
return $this;
}
public function setRawFileURIs($l, $r) {
$this->leftRawFileURI = $l;
$this->rightRawFileURI = $r;
return $this;
}
public function render() {
+ $viewer = $this->getViewer();
+
$this->requireResource('differential-changeset-view-css');
$changesets = $this->changesets;
Javelin::initBehavior('differential-toggle-files', array(
'pht' => array(
'undo' => pht('Undo'),
'collapsed' => pht('This file content has been collapsed.'),
),
));
Javelin::initBehavior(
'differential-dropdown-menus',
array(
'pht' => array(
'Open in Editor' => pht('Open in Editor'),
'Show All Context' => pht('Show All Context'),
'All Context Shown' => pht('All Context Shown'),
"Can't Toggle Unloaded File" => pht("Can't Toggle Unloaded File"),
'Expand File' => pht('Expand File'),
'Collapse File' => pht('Collapse File'),
'Browse in Diffusion' => pht('Browse in Diffusion'),
'View Standalone' => pht('View Standalone'),
'Show Raw File (Left)' => pht('Show Raw File (Left)'),
'Show Raw File (Right)' => pht('Show Raw File (Right)'),
'Configure Editor' => pht('Configure Editor'),
'Load Changes' => pht('Load Changes'),
'View Side-by-Side' => pht('View Side-by-Side'),
'View Unified' => pht('View Unified'),
'Change Text Encoding...' => pht('Change Text Encoding...'),
'Highlight As...' => pht('Highlight As...'),
),
));
$renderer = DifferentialChangesetParser::getDefaultRendererForViewer(
- $this->getUser());
+ $viewer);
$output = array();
$ids = array();
foreach ($changesets as $key => $changeset) {
$file = $changeset->getFilename();
$class = 'differential-changeset';
if (!$this->inlineURI) {
$class .= ' differential-changeset-noneditable';
}
$ref = $this->references[$key];
$detail = id(new DifferentialChangesetDetailView())
- ->setUser($this->getUser());
+ ->setUser($viewer);
$uniq_id = 'diff-'.$changeset->getAnchorName();
$detail->setID($uniq_id);
$view_options = $this->renderViewOptionsDropdown(
$detail,
$ref,
$changeset);
$detail->setChangeset($changeset);
$detail->addButton($view_options);
$detail->setSymbolIndex(idx($this->symbolIndexes, $key));
$detail->setVsChangesetID(idx($this->vsMap, $changeset->getID()));
$detail->setEditable(true);
$detail->setRenderingRef($ref);
$detail->setRenderURI($this->renderURI);
$detail->setWhitespace($this->whitespace);
$detail->setRenderer($renderer);
if ($this->getParser()) {
$detail->appendChild($this->getParser()->renderChangeset());
$detail->setLoaded(true);
} else {
$detail->setAutoload(isset($this->visibleChangesets[$key]));
if (isset($this->visibleChangesets[$key])) {
$load = pht('Loading...');
} else {
$load = javelin_tag(
'a',
array(
'class' => 'button grey',
'href' => '#'.$uniq_id,
'sigil' => 'differential-load',
'meta' => array(
'id' => $detail->getID(),
'kill' => true,
),
'mustcapture' => true,
),
pht('Load File'));
}
$detail->appendChild(
phutil_tag(
'div',
array(
'id' => $uniq_id,
),
phutil_tag(
'div',
array('class' => 'differential-loading'),
$load)));
}
$output[] = $detail->render();
$ids[] = $detail->getID();
}
$this->requireResource('aphront-tooltip-css');
$this->initBehavior('differential-populate', array(
'changesetViewIDs' => $ids,
));
$this->initBehavior('differential-comment-jump', array());
if ($this->inlineURI) {
Javelin::initBehavior('differential-edit-inline-comments', array(
'uri' => $this->inlineURI,
'stage' => 'differential-review-stage',
'revealIcon' => hsprintf('%s', new PHUIDiffRevealIconView()),
));
}
$header = id(new PHUIHeaderView())
->setHeader($this->getTitle());
$content = phutil_tag(
'div',
array(
'class' => 'differential-review-stage',
'id' => 'differential-review-stage',
),
$output);
$object_box = id(new PHUIObjectBoxView())
->setHeader($header)
->setCollapsed(true)
->appendChild($content);
return $object_box;
}
private function renderViewOptionsDropdown(
DifferentialChangesetDetailView $detail,
$ref,
DifferentialChangeset $changeset) {
+ $viewer = $this->getViewer();
$meta = array();
$qparams = array(
'ref' => $ref,
'whitespace' => $this->whitespace,
);
if ($this->standaloneURI) {
$uri = new PhutilURI($this->standaloneURI);
$uri->setQueryParams($uri->getQueryParams() + $qparams);
$meta['standaloneURI'] = (string)$uri;
}
$repository = $this->repository;
if ($repository) {
try {
$meta['diffusionURI'] =
(string)$repository->getDiffusionBrowseURIForPath(
- $this->user,
+ $viewer,
$changeset->getAbsoluteRepositoryPath($repository, $this->diff),
idx($changeset->getMetadata(), 'line:first'),
$this->getBranch());
} catch (DiffusionSetupException $e) {
// Ignore
}
}
$change = $changeset->getChangeType();
if ($this->leftRawFileURI) {
if ($change != DifferentialChangeType::TYPE_ADD) {
$uri = new PhutilURI($this->leftRawFileURI);
$uri->setQueryParams($uri->getQueryParams() + $qparams);
$meta['leftURI'] = (string)$uri;
}
}
if ($this->rightRawFileURI) {
if ($change != DifferentialChangeType::TYPE_DELETE &&
$change != DifferentialChangeType::TYPE_MULTICOPY) {
$uri = new PhutilURI($this->rightRawFileURI);
$uri->setQueryParams($uri->getQueryParams() + $qparams);
$meta['rightURI'] = (string)$uri;
}
}
- $user = $this->user;
- if ($user && $repository) {
+ if ($viewer && $repository) {
$path = ltrim(
$changeset->getAbsoluteRepositoryPath($repository, $this->diff),
'/');
$line = idx($changeset->getMetadata(), 'line:first', 1);
- $editor_link = $user->loadEditorLink($path, $line, $repository);
+ $editor_link = $viewer->loadEditorLink($path, $line, $repository);
if ($editor_link) {
$meta['editor'] = $editor_link;
} else {
$meta['editorConfigure'] = '/settings/panel/display/';
}
}
$meta['containerID'] = $detail->getID();
$caret = phutil_tag('span', array('class' => 'caret'), '');
return javelin_tag(
'a',
array(
'class' => 'button grey dropdown',
'meta' => $meta,
'href' => idx($meta, 'detailURI', '#'),
'target' => '_blank',
'sigil' => 'differential-view-options',
),
array(pht('View Options'), $caret));
}
}
diff --git a/src/applications/differential/view/DifferentialLocalCommitsView.php b/src/applications/differential/view/DifferentialLocalCommitsView.php
index 4da850539d..ebacabc3f3 100644
--- a/src/applications/differential/view/DifferentialLocalCommitsView.php
+++ b/src/applications/differential/view/DifferentialLocalCommitsView.php
@@ -1,156 +1,153 @@
<?php
final class DifferentialLocalCommitsView extends AphrontView {
private $localCommits;
private $commitsForLinks = array();
public function setLocalCommits($local_commits) {
$this->localCommits = $local_commits;
return $this;
}
public function setCommitsForLinks(array $commits) {
assert_instances_of($commits, 'PhabricatorRepositoryCommit');
$this->commitsForLinks = $commits;
return $this;
}
public function render() {
- $user = $this->user;
- if (!$user) {
- throw new PhutilInvalidStateException('setUser');
- }
+ $viewer = $this->getViewer();
$local = $this->localCommits;
if (!$local) {
return null;
}
$has_tree = false;
$has_local = false;
foreach ($local as $commit) {
if (idx($commit, 'tree')) {
$has_tree = true;
}
if (idx($commit, 'local')) {
$has_local = true;
}
}
$rows = array();
foreach ($local as $commit) {
$row = array();
if (idx($commit, 'commit')) {
$commit_link = $this->buildCommitLink($commit['commit']);
} else if (isset($commit['rev'])) {
$commit_link = $this->buildCommitLink($commit['rev']);
} else {
$commit_link = null;
}
$row[] = $commit_link;
if ($has_tree) {
$row[] = $this->buildCommitLink($commit['tree']);
}
if ($has_local) {
$row[] = $this->buildCommitLink($commit['local']);
}
$parents = idx($commit, 'parents', array());
foreach ($parents as $k => $parent) {
if (is_array($parent)) {
$parent = idx($parent, 'rev');
}
$parents[$k] = $this->buildCommitLink($parent);
}
$parents = phutil_implode_html(phutil_tag('br'), $parents);
$row[] = $parents;
$author = nonempty(
idx($commit, 'user'),
idx($commit, 'author'));
$row[] = $author;
$message = idx($commit, 'message');
$summary = idx($commit, 'summary');
$summary = id(new PhutilUTF8StringTruncator())
->setMaximumGlyphs(80)
->truncateString($summary);
$view = new AphrontMoreView();
$view->setSome($summary);
if ($message && (trim($summary) != trim($message))) {
$view->setMore(phutil_escape_html_newlines($message));
}
$row[] = $view->render();
$date = nonempty(
idx($commit, 'date'),
idx($commit, 'time'));
if ($date) {
- $date = phabricator_datetime($date, $user);
+ $date = phabricator_datetime($date, $viewer);
}
$row[] = $date;
$rows[] = $row;
}
$column_classes = array('');
if ($has_tree) {
$column_classes[] = '';
}
if ($has_local) {
$column_classes[] = '';
}
$column_classes[] = '';
$column_classes[] = '';
$column_classes[] = 'wide';
$column_classes[] = 'date';
$table = id(new AphrontTableView($rows))
->setColumnClasses($column_classes);
$headers = array();
$headers[] = pht('Commit');
if ($has_tree) {
$headers[] = pht('Tree');
}
if ($has_local) {
$headers[] = pht('Local');
}
$headers[] = pht('Parents');
$headers[] = pht('Author');
$headers[] = pht('Summary');
$headers[] = pht('Date');
$table->setHeaders($headers);
return id(new PHUIObjectBoxView())
->setHeaderText(pht('Local Commits'))
->setTable($table);
}
private static function formatCommit($commit) {
return substr($commit, 0, 12);
}
private function buildCommitLink($hash) {
$commit_for_link = idx($this->commitsForLinks, $hash);
$commit_hash = self::formatCommit($hash);
if ($commit_for_link) {
$link = phutil_tag(
'a',
array(
'href' => $commit_for_link->getURI(),
),
$commit_hash);
} else {
$link = $commit_hash;
}
return $link;
}
}
diff --git a/src/applications/differential/view/DifferentialRevisionListView.php b/src/applications/differential/view/DifferentialRevisionListView.php
index 2c14bbc4a5..92394fcb3e 100644
--- a/src/applications/differential/view/DifferentialRevisionListView.php
+++ b/src/applications/differential/view/DifferentialRevisionListView.php
@@ -1,212 +1,209 @@
<?php
/**
* Render a table of Differential revisions.
*/
final class DifferentialRevisionListView extends AphrontView {
private $revisions;
private $handles;
private $highlightAge;
private $header;
private $noDataString;
private $noBox;
public function setNoDataString($no_data_string) {
$this->noDataString = $no_data_string;
return $this;
}
public function setHeader($header) {
$this->header = $header;
return $this;
}
public function setRevisions(array $revisions) {
assert_instances_of($revisions, 'DifferentialRevision');
$this->revisions = $revisions;
return $this;
}
public function setHighlightAge($bool) {
$this->highlightAge = $bool;
return $this;
}
public function setNoBox($box) {
$this->noBox = $box;
return $this;
}
public function getRequiredHandlePHIDs() {
$phids = array();
foreach ($this->revisions as $revision) {
$phids[] = array($revision->getAuthorPHID());
// TODO: Switch to getReviewerStatus(), but not all callers pass us
// revisions with this data loaded.
$phids[] = $revision->getReviewers();
}
return array_mergev($phids);
}
public function setHandles(array $handles) {
assert_instances_of($handles, 'PhabricatorObjectHandle');
$this->handles = $handles;
return $this;
}
public function render() {
- $user = $this->user;
- if (!$user) {
- throw new PhutilInvalidStateException('setUser');
- }
+ $viewer = $this->getViewer();
$fresh = PhabricatorEnv::getEnvConfig('differential.days-fresh');
if ($fresh) {
$fresh = PhabricatorCalendarHoliday::getNthBusinessDay(
time(),
-$fresh);
}
$stale = PhabricatorEnv::getEnvConfig('differential.days-stale');
if ($stale) {
$stale = PhabricatorCalendarHoliday::getNthBusinessDay(
time(),
-$stale);
}
$this->initBehavior('phabricator-tooltips', array());
$this->requireResource('aphront-tooltip-css');
$list = new PHUIObjectItemListView();
foreach ($this->revisions as $revision) {
$item = id(new PHUIObjectItemView())
- ->setUser($user);
+ ->setUser($viewer);
$icons = array();
$phid = $revision->getPHID();
- $flag = $revision->getFlag($user);
+ $flag = $revision->getFlag($viewer);
if ($flag) {
$flag_class = PhabricatorFlagColor::getCSSClass($flag->getColor());
$icons['flag'] = phutil_tag(
'div',
array(
'class' => 'phabricator-flag-icon '.$flag_class,
),
'');
}
- if ($revision->getDrafts($user)) {
+ if ($revision->getDrafts($viewer)) {
$icons['draft'] = true;
}
$modified = $revision->getDateModified();
$status = $revision->getStatus();
$show_age = ($fresh || $stale) &&
$this->highlightAge &&
!$revision->isClosed();
if ($stale && $modified < $stale) {
$object_age = PHUIObjectItemView::AGE_OLD;
} else if ($fresh && $modified < $fresh) {
$object_age = PHUIObjectItemView::AGE_STALE;
} else {
$object_age = PHUIObjectItemView::AGE_FRESH;
}
$status_name =
ArcanistDifferentialRevisionStatus::getNameForRevisionStatus($status);
if (isset($icons['flag'])) {
$item->addHeadIcon($icons['flag']);
}
$item->setObjectName('D'.$revision->getID());
$item->setHeader($revision->getTitle());
$item->setHref('/D'.$revision->getID());
if (isset($icons['draft'])) {
$draft = id(new PHUIIconView())
->setIcon('fa-comment yellow')
->addSigil('has-tooltip')
->setMetadata(
array(
'tip' => pht('Unsubmitted Comments'),
));
$item->addAttribute($draft);
}
/* Most things 'Need Review', so accept it's the default */
if ($status != ArcanistDifferentialRevisionStatus::NEEDS_REVIEW) {
$item->addAttribute($status_name);
}
// Author
$author_handle = $this->handles[$revision->getAuthorPHID()];
$item->addByline(pht('Author: %s', $author_handle->renderLink()));
$reviewers = array();
// TODO: As above, this should be based on `getReviewerStatus()`.
foreach ($revision->getReviewers() as $reviewer) {
$reviewers[] = $this->handles[$reviewer]->renderLink();
}
if (!$reviewers) {
$reviewers = phutil_tag('em', array(), pht('None'));
} else {
$reviewers = phutil_implode_html(', ', $reviewers);
}
$item->addAttribute(pht('Reviewers: %s', $reviewers));
$item->setEpoch($revision->getDateModified(), $object_age);
switch ($status) {
case ArcanistDifferentialRevisionStatus::NEEDS_REVIEW:
$item->setStatusIcon('fa-code grey', pht('Needs Review'));
break;
case ArcanistDifferentialRevisionStatus::NEEDS_REVISION:
$item->setStatusIcon('fa-refresh red', pht('Needs Revision'));
break;
case ArcanistDifferentialRevisionStatus::CHANGES_PLANNED:
$item->setStatusIcon('fa-headphones red', pht('Changes Planned'));
break;
case ArcanistDifferentialRevisionStatus::ACCEPTED:
$item->setStatusIcon('fa-check green', pht('Accepted'));
break;
case ArcanistDifferentialRevisionStatus::CLOSED:
$item->setDisabled(true);
$item->setStatusIcon('fa-check-square-o black', pht('Closed'));
break;
case ArcanistDifferentialRevisionStatus::ABANDONED:
$item->setDisabled(true);
$item->setStatusIcon('fa-plane black', pht('Abandoned'));
break;
}
$list->addItem($item);
}
$list->setNoDataString($this->noDataString);
if ($this->header && !$this->noBox) {
$list->setFlush(true);
$list = id(new PHUIObjectBoxView())
->setObjectList($list);
if ($this->header instanceof PHUIHeaderView) {
$list->setHeader($this->header);
} else {
$list->setHeaderText($this->header);
}
} else {
$list->setHeader($this->header);
}
return $list;
}
}
diff --git a/src/applications/diffusion/view/DiffusionTagListView.php b/src/applications/diffusion/view/DiffusionTagListView.php
index 3b27284f5e..923fa30fc5 100644
--- a/src/applications/diffusion/view/DiffusionTagListView.php
+++ b/src/applications/diffusion/view/DiffusionTagListView.php
@@ -1,138 +1,138 @@
<?php
final class DiffusionTagListView extends DiffusionView {
private $tags;
private $commits = array();
private $handles = array();
public function setTags($tags) {
$this->tags = $tags;
return $this;
}
public function setCommits(array $commits) {
$this->commits = mpull($commits, null, 'getCommitIdentifier');
return $this;
}
public function setHandles(array $handles) {
$this->handles = $handles;
return $this;
}
public function getRequiredHandlePHIDs() {
return array_filter(mpull($this->commits, 'getAuthorPHID'));
}
public function render() {
$drequest = $this->getDiffusionRequest();
$repository = $drequest->getRepository();
$buildables = $this->loadBuildables($this->commits);
$has_builds = false;
$rows = array();
foreach ($this->tags as $tag) {
$commit = idx($this->commits, $tag->getCommitIdentifier());
$tag_link = phutil_tag(
'a',
array(
'href' => $drequest->generateURI(
array(
'action' => 'browse',
'commit' => $tag->getName(),
)),
),
$tag->getName());
$commit_link = phutil_tag(
'a',
array(
'href' => $drequest->generateURI(
array(
'action' => 'commit',
'commit' => $tag->getCommitIdentifier(),
)),
),
$repository->formatCommitName(
$tag->getCommitIdentifier()));
$author = null;
if ($commit && $commit->getAuthorPHID()) {
$author = $this->handles[$commit->getAuthorPHID()]->renderLink();
} else if ($commit && $commit->getCommitData()) {
$author = self::renderName($commit->getCommitData()->getAuthorName());
} else {
$author = self::renderName($tag->getAuthor());
}
$description = null;
if ($tag->getType() == 'git/tag') {
// In Git, a tag may be a "real" tag, or just a reference to a commit.
// If it's a real tag, use the message on the tag, since this may be
// unique data which isn't otherwise available.
$description = $tag->getDescription();
} else {
if ($commit) {
$description = $commit->getSummary();
} else {
$description = $tag->getDescription();
}
}
$build = null;
if ($commit) {
$buildable = idx($buildables, $commit->getPHID());
if ($buildable) {
$build = $this->renderBuildable($buildable);
$has_builds = true;
}
}
$history = $this->linkTagHistory($tag->getName());
$rows[] = array(
$history,
$tag_link,
$commit_link,
$build,
$author,
$description,
- phabricator_datetime($tag->getEpoch(), $this->user),
+ phabricator_datetime($tag->getEpoch(), $this->getViewer()),
);
}
$table = id(new AphrontTableView($rows))
->setHeaders(
array(
null,
pht('Tag'),
pht('Commit'),
null,
pht('Author'),
pht('Description'),
pht('Created'),
))
->setColumnClasses(
array(
'nudgeright',
'pri',
'',
'',
'',
'wide',
))
->setColumnVisibility(
array(
true,
true,
true,
$has_builds,
));
return $table->render();
}
}
diff --git a/src/applications/phame/view/PhameBlogListView.php b/src/applications/phame/view/PhameBlogListView.php
index 0d897b730a..5aa58ee8f9 100644
--- a/src/applications/phame/view/PhameBlogListView.php
+++ b/src/applications/phame/view/PhameBlogListView.php
@@ -1,100 +1,94 @@
<?php
final class PhameBlogListView extends AphrontTagView {
private $blogs;
- private $viewer;
public function setBlogs($blogs) {
assert_instances_of($blogs, 'PhameBlog');
$this->blogs = $blogs;
return $this;
}
- public function setViewer($viewer) {
- $this->viewer = $viewer;
- return $this;
- }
-
protected function getTagAttributes() {
$classes = array();
$classes[] = 'phame-blog-list';
return array('class' => implode(' ', $classes));
}
protected function getTagContent() {
require_celerity_resource('phame-css');
$list = array();
foreach ($this->blogs as $blog) {
$image_uri = $blog->getProfileImageURI();
$image = phutil_tag(
'a',
array(
'class' => 'phame-blog-list-image',
'style' => 'background-image: url('.$image_uri.');',
'href' => $blog->getViewURI(),
));
$title = phutil_tag(
'a',
array(
'class' => 'phame-blog-list-title',
'href' => $blog->getViewURI(),
),
$blog->getName());
$icon = id(new PHUIIconView())
->setIcon('fa-plus-square')
->addClass('phame-blog-list-icon');
$add_new = phutil_tag(
'a',
array(
'href' => '/phame/post/edit/?blog='.$blog->getID(),
'class' => 'phame-blog-list-new-post',
),
$icon);
$list[] = phutil_tag(
'div',
array(
'class' => 'phame-blog-list-item',
),
array(
$image,
$title,
$add_new,
));
}
if (empty($list)) {
$list = phutil_tag(
'a',
array(
'href' => '/phame/blog/edit/',
),
pht('Create a Blog'));
}
$header = phutil_tag(
'h4',
array(
'class' => 'phame-blog-list-header',
),
phutil_tag(
'a',
array(
'href' => '/phame/blog/',
),
pht('Blogs')));
return id(new PHUIBoxView())
->appendChild($header)
->appendChild($list)
->addClass('pl')
->setColor(PHUIBoxView::BLUE);
}
}
diff --git a/src/applications/phame/view/PhameDraftListView.php b/src/applications/phame/view/PhameDraftListView.php
index 87c5a6d7b5..294eeb11bc 100644
--- a/src/applications/phame/view/PhameDraftListView.php
+++ b/src/applications/phame/view/PhameDraftListView.php
@@ -1,102 +1,96 @@
<?php
final class PhameDraftListView extends AphrontTagView {
private $posts;
private $blogs;
- private $viewer;
public function setPosts($posts) {
assert_instances_of($posts, 'PhamePost');
$this->posts = $posts;
return $this;
}
public function setBlogs($blogs) {
assert_instances_of($blogs, 'PhameBlog');
$this->blogs = $blogs;
return $this;
}
- public function setViewer($viewer) {
- $this->viewer = $viewer;
- return $this;
- }
-
protected function getTagAttributes() {
$classes = array();
$classes[] = 'phame-blog-list';
return array('class' => implode(' ', $classes));
}
protected function getTagContent() {
require_celerity_resource('phame-css');
$list = array();
foreach ($this->posts as $post) {
$blog = $post->getBlog();
$image_uri = $blog->getProfileImageURI();
$image = phutil_tag(
'a',
array(
'class' => 'phame-blog-list-image',
'style' => 'background-image: url('.$image_uri.');',
'href' => $blog->getViewURI(),
));
$title = phutil_tag(
'a',
array(
'class' => 'phame-blog-list-title',
'href' => $post->getViewURI(),
),
$post->getTitle());
$icon = id(new PHUIIconView())
->setIcon('fa-pencil-square-o')
->addClass('phame-blog-list-icon');
$edit = phutil_tag(
'a',
array(
'href' => '/phame/post/edit/'.$post->getID().'/',
'class' => 'phame-blog-list-new-post',
),
$icon);
$list[] = phutil_tag(
'div',
array(
'class' => 'phame-blog-list-item',
),
array(
$image,
$title,
$edit,
));
}
if (empty($list)) {
$list = pht('You have no draft posts.');
}
$header = phutil_tag(
'h4',
array(
'class' => 'phame-blog-list-header',
),
phutil_tag(
'a',
array(
'href' => '/phame/post/query/draft/',
),
pht('Drafts')));
return id(new PHUIBoxView())
->appendChild($header)
->appendChild($list)
->addClass('pl')
->setColor(PHUIBoxView::BLUE);
}
}
diff --git a/src/applications/phame/view/PhamePostListView.php b/src/applications/phame/view/PhamePostListView.php
index dbe77d4aa6..fe6da36541 100644
--- a/src/applications/phame/view/PhamePostListView.php
+++ b/src/applications/phame/view/PhamePostListView.php
@@ -1,150 +1,144 @@
<?php
final class PhamePostListView extends AphrontTagView {
private $posts;
private $nodata;
- private $viewer;
private $showBlog = false;
private $isExternal;
private $isLive;
public function setPosts($posts) {
assert_instances_of($posts, 'PhamePost');
$this->posts = $posts;
return $this;
}
public function setNodata($nodata) {
$this->nodata = $nodata;
return $this;
}
public function showBlog($show) {
$this->showBlog = $show;
return $this;
}
- public function setViewer($viewer) {
- $this->viewer = $viewer;
- return $this;
- }
-
public function setIsExternal($is_external) {
$this->isExternal = $is_external;
return $this;
}
public function getIsExternal() {
return $this->isExternal;
}
public function setIsLive($is_live) {
$this->isLive = $is_live;
return $this;
}
public function getIsLive() {
return $this->isLive;
}
protected function getTagAttributes() {
return array();
}
protected function getTagContent() {
- $viewer = $this->viewer;
+ $viewer = $this->getViewer();
$posts = $this->posts;
$nodata = $this->nodata;
$handle_phids = array();
foreach ($posts as $post) {
$handle_phids[] = $post->getBloggerPHID();
if ($post->getBlog()) {
$handle_phids[] = $post->getBlog()->getPHID();
}
}
$handles = $viewer->loadHandles($handle_phids);
$list = array();
foreach ($posts as $post) {
$blogger = $handles[$post->getBloggerPHID()]->renderLink();
$blogger_uri = $handles[$post->getBloggerPHID()]->getURI();
$blogger_image = $handles[$post->getBloggerPHID()]->getImageURI();
$phame_post = null;
if ($post->getBody()) {
$phame_post = PhabricatorMarkupEngine::summarize($post->getBody());
$phame_post = new PHUIRemarkupView($viewer, $phame_post);
} else {
$phame_post = phutil_tag('em', array(), pht('(Empty Post)'));
}
$blogger = phutil_tag('strong', array(), $blogger);
$date = phabricator_datetime($post->getDatePublished(), $viewer);
$blog = $post->getBlog();
if ($this->getIsLive()) {
if ($this->getIsExternal()) {
$blog_uri = $blog->getExternalLiveURI();
$post_uri = $post->getExternalLiveURI();
} else {
$blog_uri = $blog->getInternalLiveURI();
$post_uri = $post->getInternalLiveURI();
}
} else {
$blog_uri = $blog->getViewURI();
$post_uri = $post->getViewURI();
}
$blog_link = phutil_tag(
'a',
array(
'href' => $blog_uri,
),
$blog->getName());
if ($this->showBlog) {
if ($post->isDraft()) {
$subtitle = pht(
'Unpublished draft by %s in %s.',
$blogger,
$blog_link);
} else {
$subtitle = pht(
'Written by %s on %s in %s.',
$blogger,
$date,
$blog_link);
}
} else {
if ($post->isDraft()) {
$subtitle = pht('Unpublished draft by %s.', $blogger);
} else {
$subtitle = pht('Written by %s on %s.', $blogger, $date);
}
}
$item = id(new PHUIDocumentSummaryView())
->setTitle($post->getTitle())
->setHref($post_uri)
->setSubtitle($subtitle)
->setImage($blogger_image)
->setImageHref($blogger_uri)
->setSummary($phame_post)
->setDraft($post->isDraft());
$list[] = $item;
}
if (empty($list)) {
$list = id(new PHUIInfoView())
->setSeverity(PHUIInfoView::SEVERITY_NODATA)
->appendChild($nodata);
}
return $list;
}
}
diff --git a/src/applications/ponder/view/PonderAddAnswerView.php b/src/applications/ponder/view/PonderAddAnswerView.php
index 989837aa94..d958e9843e 100644
--- a/src/applications/ponder/view/PonderAddAnswerView.php
+++ b/src/applications/ponder/view/PonderAddAnswerView.php
@@ -1,90 +1,90 @@
<?php
final class PonderAddAnswerView extends AphrontView {
private $question;
private $actionURI;
private $draft;
public function setQuestion($question) {
$this->question = $question;
return $this;
}
public function setActionURI($uri) {
$this->actionURI = $uri;
return $this;
}
public function render() {
$question = $this->question;
- $viewer = $this->user;
+ $viewer = $this->getViewer();
$authors = mpull($question->getAnswers(), null, 'getAuthorPHID');
if (isset($authors[$viewer->getPHID()])) {
$view = id(new PHUIInfoView())
->setSeverity(PHUIInfoView::SEVERITY_NOTICE)
->setTitle(pht('Already Answered'))
->appendChild(
pht(
'You have already answered this question. You can not answer '.
'twice, but you can edit your existing answer.'));
return phutil_tag_div('ponder-add-answer-view', $view);
}
$info_panel = null;
if ($question->getStatus() != PonderQuestionStatus::STATUS_OPEN) {
$info_panel = id(new PHUIInfoView())
->setSeverity(PHUIInfoView::SEVERITY_NOTICE)
->appendChild(
pht(
'This question has been marked as closed,
but you can still leave a new answer.'));
}
$box_style = null;
$header = id(new PHUIHeaderView())
->setHeader(pht('New Answer'))
->addClass('ponder-add-answer-header');
$form = new AphrontFormView();
$form
- ->setUser($this->user)
+ ->setViewer($viewer)
->setAction($this->actionURI)
->setWorkflow(true)
->addHiddenInput('question_id', $question->getID())
->appendChild(
id(new PhabricatorRemarkupControl())
->setName('answer')
->setLabel(pht('Answer'))
->setError(true)
->setID('answer-content')
- ->setUser($this->user))
+ ->setViewer($viewer))
->appendChild(
id(new AphrontFormSubmitControl())
->setValue(pht('Add Answer')));
if (!$viewer->isLoggedIn()) {
$login_href = id(new PhutilURI('/auth/start/'))
->setQueryParam('next', '/Q'.$question->getID());
$form = id(new PHUIFormLayoutView())
->addClass('login-to-participate')
->appendChild(
id(new PHUIButtonView())
->setTag('a')
->setText(pht('Login to Answer'))
->setHref((string)$login_href));
}
$box = id(new PHUIObjectBoxView())
->appendChild($form)
->setHeaderText('Answer')
->addClass('ponder-add-answer-view');
if ($info_panel) {
$box->setInfoView($info_panel);
}
return array($header, $box);
}
}
diff --git a/src/applications/project/view/PhabricatorProjectUserListView.php b/src/applications/project/view/PhabricatorProjectUserListView.php
index e7f6631bfb..d590cbb559 100644
--- a/src/applications/project/view/PhabricatorProjectUserListView.php
+++ b/src/applications/project/view/PhabricatorProjectUserListView.php
@@ -1,145 +1,145 @@
<?php
abstract class PhabricatorProjectUserListView extends AphrontView {
private $project;
private $userPHIDs;
private $limit;
private $background;
public function setProject(PhabricatorProject $project) {
$this->project = $project;
return $this;
}
public function getProject() {
return $this->project;
}
public function setUserPHIDs(array $user_phids) {
$this->userPHIDs = $user_phids;
return $this;
}
public function getUserPHIDs() {
return $this->userPHIDs;
}
public function setLimit($limit) {
$this->limit = $limit;
return $this;
}
public function getLimit() {
return $this->limit;
}
public function setBackground($color) {
$this->background = $color;
return $this;
}
abstract protected function canEditList();
abstract protected function getNoDataString();
abstract protected function getRemoveURI($phid);
abstract protected function getHeaderText();
public function render() {
- $viewer = $this->getUser();
+ $viewer = $this->getViewer();
$project = $this->getProject();
$user_phids = $this->getUserPHIDs();
$can_edit = $this->canEditList();
$no_data = $this->getNoDataString();
$list = id(new PHUIObjectItemListView())
->setNoDataString($no_data);
$limit = $this->getLimit();
// If we're showing everything, show oldest to newest. If we're showing
// only a slice, show newest to oldest.
if (!$limit) {
$user_phids = array_reverse($user_phids);
}
$handles = $viewer->loadHandles($user_phids);
// Always put the viewer first if they are on the list.
$user_phids = array_fuse($user_phids);
$user_phids =
array_select_keys($user_phids, array($viewer->getPHID())) +
$user_phids;
if ($limit) {
$render_phids = array_slice($user_phids, 0, $limit);
} else {
$render_phids = $user_phids;
}
foreach ($render_phids as $user_phid) {
$handle = $handles[$user_phid];
$item = id(new PHUIObjectItemView())
->setHeader($handle->getFullName())
->setHref($handle->getURI())
->setImageURI($handle->getImageURI());
$icon = id(new PHUIIconView())
->setIcon($handle->getIcon());
$subtitle = $handle->getSubtitle();
$item->addAttribute(array($icon, ' ', $subtitle));
if ($can_edit && !$limit) {
$remove_uri = $this->getRemoveURI($user_phid);
$item->addAction(
id(new PHUIListItemView())
->setIcon('fa-times')
->setName(pht('Remove'))
->setHref($remove_uri)
->setWorkflow(true));
}
$list->addItem($item);
}
if ($user_phids) {
$header_text = pht(
'%s (%s)',
$this->getHeaderText(),
phutil_count($user_phids));
} else {
$header_text = $this->getHeaderText();
}
$id = $project->getID();
$header = id(new PHUIHeaderView())
->setHeader($header_text);
if ($limit) {
$header->addActionLink(
id(new PHUIButtonView())
->setTag('a')
->setIcon(
id(new PHUIIconView())
->setIcon('fa-list-ul'))
->setText(pht('View All'))
->setHref("/project/members/{$id}/"));
}
$box = id(new PHUIObjectBoxView())
->setHeader($header)
->setObjectList($list);
if ($this->background) {
$box->setBackground($this->background);
}
return $box;
}
}
diff --git a/src/infrastructure/diff/view/PHUIDiffInlineCommentEditView.php b/src/infrastructure/diff/view/PHUIDiffInlineCommentEditView.php
index 3a9bc616d9..a7c10b5b48 100644
--- a/src/infrastructure/diff/view/PHUIDiffInlineCommentEditView.php
+++ b/src/infrastructure/diff/view/PHUIDiffInlineCommentEditView.php
@@ -1,178 +1,177 @@
<?php
final class PHUIDiffInlineCommentEditView
extends PHUIDiffInlineCommentView {
private $inputs = array();
private $uri;
private $title;
private $number;
private $length;
private $renderer;
private $isNewFile;
private $replyToCommentPHID;
private $changesetID;
public function setIsNewFile($is_new_file) {
$this->isNewFile = $is_new_file;
return $this;
}
public function getIsNewFile() {
return $this->isNewFile;
}
public function setRenderer($renderer) {
$this->renderer = $renderer;
return $this;
}
public function getRenderer() {
return $this->renderer;
}
public function addHiddenInput($key, $value) {
$this->inputs[] = array($key, $value);
return $this;
}
public function setSubmitURI($uri) {
$this->uri = $uri;
return $this;
}
public function setTitle($title) {
$this->title = $title;
return $this;
}
public function setReplyToCommentPHID($reply_to_phid) {
$this->replyToCommentPHID = $reply_to_phid;
return $this;
}
public function getReplyToCommentPHID() {
return $this->replyToCommentPHID;
}
public function setChangesetID($changeset_id) {
$this->changesetID = $changeset_id;
return $this;
}
public function getChangesetID() {
return $this->changesetID;
}
public function setNumber($number) {
$this->number = $number;
return $this;
}
public function setLength($length) {
$this->length = $length;
return $this;
}
public function render() {
if (!$this->uri) {
throw new PhutilInvalidStateException('setSubmitURI');
}
- if (!$this->user) {
- throw new PhutilInvalidStateException('setUser');
- }
+
+ $viewer = $this->getViewer();
$content = phabricator_form(
- $this->user,
+ $viewer,
array(
'action' => $this->uri,
'method' => 'POST',
'sigil' => 'inline-edit-form',
),
array(
$this->renderInputs(),
$this->renderBody(),
));
return $content;
}
private function renderInputs() {
$inputs = $this->inputs;
$out = array();
$inputs[] = array('on_right', (bool)$this->getIsOnRight());
$inputs[] = array('replyToCommentPHID', $this->getReplyToCommentPHID());
$inputs[] = array('renderer', $this->getRenderer());
$inputs[] = array('changesetID', $this->getChangesetID());
foreach ($inputs as $input) {
list($name, $value) = $input;
$out[] = phutil_tag(
'input',
array(
'type' => 'hidden',
'name' => $name,
'value' => $value,
));
}
return $out;
}
private function renderBody() {
$buttons = array();
$buttons[] = phutil_tag('button', array(), pht('Save Draft'));
$buttons[] = javelin_tag(
'button',
array(
'sigil' => 'inline-edit-cancel',
'class' => 'grey',
),
pht('Cancel'));
$title = phutil_tag(
'div',
array(
'class' => 'differential-inline-comment-edit-title',
),
$this->title);
$body = phutil_tag(
'div',
array(
'class' => 'differential-inline-comment-edit-body',
),
$this->renderChildren());
$edit = phutil_tag(
'div',
array(
'class' => 'differential-inline-comment-edit-buttons grouped',
),
array(
$buttons,
));
return javelin_tag(
'div',
array(
'class' => 'differential-inline-comment-edit',
'sigil' => 'differential-inline-comment',
'meta' => array(
'changesetID' => $this->getChangesetID(),
'on_right' => $this->getIsOnRight(),
'isNewFile' => (bool)$this->getIsNewFile(),
'number' => $this->number,
'length' => $this->length,
'replyToCommentPHID' => $this->getReplyToCommentPHID(),
),
),
array(
$title,
$body,
$edit,
));
}
}
diff --git a/src/view/AphrontDialogView.php b/src/view/AphrontDialogView.php
index f8bc3fa060..26dee0c398 100644
--- a/src/view/AphrontDialogView.php
+++ b/src/view/AphrontDialogView.php
@@ -1,399 +1,399 @@
<?php
final class AphrontDialogView
extends AphrontView
implements AphrontResponseProducerInterface {
private $title;
private $shortTitle;
private $submitButton;
private $cancelURI;
private $cancelText = 'Cancel';
private $submitURI;
private $hidden = array();
private $class;
private $renderAsForm = true;
private $formID;
private $footers = array();
private $isStandalone;
private $method = 'POST';
private $disableWorkflowOnSubmit;
private $disableWorkflowOnCancel;
private $width = 'default';
private $errors = array();
private $flush;
private $validationException;
private $objectList;
const WIDTH_DEFAULT = 'default';
const WIDTH_FORM = 'form';
const WIDTH_FULL = 'full';
public function setMethod($method) {
$this->method = $method;
return $this;
}
public function setIsStandalone($is_standalone) {
$this->isStandalone = $is_standalone;
return $this;
}
public function setErrors(array $errors) {
$this->errors = $errors;
return $this;
}
public function getIsStandalone() {
return $this->isStandalone;
}
public function setSubmitURI($uri) {
$this->submitURI = $uri;
return $this;
}
public function setTitle($title) {
$this->title = $title;
return $this;
}
public function getTitle() {
return $this->title;
}
public function setShortTitle($short_title) {
$this->shortTitle = $short_title;
return $this;
}
public function getShortTitle() {
return $this->shortTitle;
}
public function addSubmitButton($text = null) {
if (!$text) {
$text = pht('Okay');
}
$this->submitButton = $text;
return $this;
}
public function addCancelButton($uri, $text = null) {
if (!$text) {
$text = pht('Cancel');
}
$this->cancelURI = $uri;
$this->cancelText = $text;
return $this;
}
public function addFooter($footer) {
$this->footers[] = $footer;
return $this;
}
public function addHiddenInput($key, $value) {
if (is_array($value)) {
foreach ($value as $hidden_key => $hidden_value) {
$this->hidden[] = array($key.'['.$hidden_key.']', $hidden_value);
}
} else {
$this->hidden[] = array($key, $value);
}
return $this;
}
public function setClass($class) {
$this->class = $class;
return $this;
}
public function setFlush($flush) {
$this->flush = $flush;
return $this;
}
public function setRenderDialogAsDiv() {
// TODO: This API is awkward.
$this->renderAsForm = false;
return $this;
}
public function setFormID($id) {
$this->formID = $id;
return $this;
}
public function setWidth($width) {
$this->width = $width;
return $this;
}
public function setObjectList(PHUIObjectItemListView $list) {
$this->objectList = true;
$box = id(new PHUIObjectBoxView())
->setObjectList($list);
return $this->appendChild($box);
}
public function appendParagraph($paragraph) {
return $this->appendChild(
phutil_tag(
'p',
array(
'class' => 'aphront-dialog-view-paragraph',
),
$paragraph));
}
public function appendList(array $items) {
$listitems = array();
foreach ($items as $item) {
$listitems[] = phutil_tag(
'li',
array(
'class' => 'remarkup-list-item',
),
$item);
}
return $this->appendChild(
phutil_tag(
'ul',
array(
'class' => 'remarkup-list',
),
$listitems));
}
public function appendForm(AphrontFormView $form) {
return $this->appendChild($form->buildLayoutView());
}
public function setDisableWorkflowOnSubmit($disable_workflow_on_submit) {
$this->disableWorkflowOnSubmit = $disable_workflow_on_submit;
return $this;
}
public function getDisableWorkflowOnSubmit() {
return $this->disableWorkflowOnSubmit;
}
public function setDisableWorkflowOnCancel($disable_workflow_on_cancel) {
$this->disableWorkflowOnCancel = $disable_workflow_on_cancel;
return $this;
}
public function getDisableWorkflowOnCancel() {
return $this->disableWorkflowOnCancel;
}
public function setValidationException(
PhabricatorApplicationTransactionValidationException $ex = null) {
$this->validationException = $ex;
return $this;
}
public function render() {
require_celerity_resource('aphront-dialog-view-css');
$buttons = array();
if ($this->submitButton) {
$meta = array();
if ($this->disableWorkflowOnSubmit) {
$meta['disableWorkflow'] = true;
}
$buttons[] = javelin_tag(
'button',
array(
'name' => '__submit__',
'sigil' => '__default__',
'type' => 'submit',
'meta' => $meta,
),
$this->submitButton);
}
if ($this->cancelURI) {
$meta = array();
if ($this->disableWorkflowOnCancel) {
$meta['disableWorkflow'] = true;
}
$buttons[] = javelin_tag(
'a',
array(
'href' => $this->cancelURI,
'class' => 'button grey',
'name' => '__cancel__',
'sigil' => 'jx-workflow-button',
'meta' => $meta,
),
$this->cancelText);
}
- if (!$this->user) {
+ if (!$this->hasViewer()) {
throw new Exception(
pht(
'You must call %s when rendering an %s.',
- 'setUser()',
+ 'setViewer()',
__CLASS__));
}
$classes = array();
$classes[] = 'aphront-dialog-view';
$classes[] = $this->class;
if ($this->flush) {
$classes[] = 'aphront-dialog-flush';
}
switch ($this->width) {
case self::WIDTH_FORM:
case self::WIDTH_FULL:
$classes[] = 'aphront-dialog-view-width-'.$this->width;
break;
case self::WIDTH_DEFAULT:
break;
default:
throw new Exception(
pht(
"Unknown dialog width '%s'!",
$this->width));
}
if ($this->isStandalone) {
$classes[] = 'aphront-dialog-view-standalone';
}
if ($this->objectList) {
$classes[] = 'aphront-dialog-object-list';
}
$attributes = array(
'class' => implode(' ', $classes),
'sigil' => 'jx-dialog',
);
$form_attributes = array(
'action' => $this->submitURI,
'method' => $this->method,
'id' => $this->formID,
);
$hidden_inputs = array();
$hidden_inputs[] = phutil_tag(
'input',
array(
'type' => 'hidden',
'name' => '__dialog__',
'value' => '1',
));
foreach ($this->hidden as $desc) {
list($key, $value) = $desc;
$hidden_inputs[] = javelin_tag(
'input',
array(
'type' => 'hidden',
'name' => $key,
'value' => $value,
'sigil' => 'aphront-dialog-application-input',
));
}
if (!$this->renderAsForm) {
$buttons = array(
phabricator_form(
- $this->user,
+ $this->getViewer(),
$form_attributes,
array_merge($hidden_inputs, $buttons)),
);
}
$children = $this->renderChildren();
$errors = $this->errors;
$ex = $this->validationException;
$exception_errors = null;
if ($ex) {
foreach ($ex->getErrors() as $error) {
$errors[] = $error->getMessage();
}
}
if ($errors) {
$children = array(
id(new PHUIInfoView())->setErrors($errors),
$children,
);
}
$header = new PHUIHeaderView();
$header->setHeader($this->title);
$footer = null;
if ($this->footers) {
$footer = phutil_tag(
'div',
array(
'class' => 'aphront-dialog-foot',
),
$this->footers);
}
$tail = null;
if ($buttons || $footer) {
$tail = phutil_tag(
'div',
array(
'class' => 'aphront-dialog-tail grouped',
),
array(
$buttons,
$footer,
));
}
$content = array(
phutil_tag(
'div',
array(
'class' => 'aphront-dialog-head',
),
$header),
phutil_tag('div',
array(
'class' => 'aphront-dialog-body phabricator-remarkup grouped',
),
$children),
$tail,
);
if ($this->renderAsForm) {
return phabricator_form(
- $this->user,
+ $this->getViewer(),
$form_attributes + $attributes,
array($hidden_inputs, $content));
} else {
return javelin_tag(
'div',
$attributes,
$content);
}
}
/* -( AphrontResponseProducerInterface )----------------------------------- */
public function produceAphrontResponse() {
return id(new AphrontDialogResponse())
->setDialog($this);
}
}
diff --git a/src/view/AphrontView.php b/src/view/AphrontView.php
index 91565ca6bd..c014d7d50c 100644
--- a/src/view/AphrontView.php
+++ b/src/view/AphrontView.php
@@ -1,179 +1,225 @@
<?php
/**
* @task children Managing Children
*/
abstract class AphrontView extends Phobject
implements PhutilSafeHTMLProducerInterface {
- protected $user;
+ private $viewer;
protected $children = array();
/* -( Configuration )------------------------------------------------------ */
/**
+ * Set the user viewing this element.
+ *
+ * @param PhabricatorUser Viewing user.
+ * @return this
+ */
+ public function setViewer(PhabricatorUser $viewer) {
+ $this->viewer = $viewer;
+ return $this;
+ }
+
+
+ /**
+ * Get the user viewing this element.
+ *
+ * Throws an exception if no viewer has been set.
+ *
+ * @return PhabricatorUser Viewing user.
+ */
+ public function getViewer() {
+ if (!$this->viewer) {
+ throw new PhutilInvalidStateException('setViewer');
+ }
+
+ return $this->viewer;
+ }
+
+
+ /**
+ * Test if a viewer has been set on this elmeent.
+ *
+ * @return bool True if a viewer is available.
+ */
+ public function hasViewer() {
+ return (bool)$this->viewer;
+ }
+
+
+ /**
+ * Deprecated, use @{method:setViewer}.
+ *
* @task config
+ * @deprecated
*/
public function setUser(PhabricatorUser $user) {
- $this->user = $user;
- return $this;
+ return $this->setViewer($user);
}
/**
+ * Deprecated, use @{method:getViewer}.
+ *
* @task config
+ * @deprecated
*/
protected function getUser() {
- return $this->user;
+ if (!$this->hasViewer()) {
+ return null;
+ }
+ return $this->getViewer();
}
/* -( Managing Children )-------------------------------------------------- */
/**
* Test if this View accepts children.
*
* By default, views accept children, but subclases may override this method
* to prevent children from being appended. Doing so will cause
* @{method:appendChild} to throw exceptions instead of appending children.
*
* @return bool True if the View should accept children.
* @task children
*/
protected function canAppendChild() {
return true;
}
/**
* Append a child to the list of children.
*
* This method will only work if the view supports children, which is
* determined by @{method:canAppendChild}.
*
* @param wild Something renderable.
* @return this
*/
final public function appendChild($child) {
if (!$this->canAppendChild()) {
$class = get_class($this);
throw new Exception(
pht("View '%s' does not support children.", $class));
}
$this->children[] = $child;
return $this;
}
/**
* Produce children for rendering.
*
* Historically, this method reduced children to a string representation,
* but it no longer does.
*
* @return wild Renderable children.
* @task
*/
final protected function renderChildren() {
return $this->children;
}
/**
* Test if an element has no children.
*
* @return bool True if this element has children.
* @task children
*/
final public function hasChildren() {
if ($this->children) {
$this->children = $this->reduceChildren($this->children);
}
return (bool)$this->children;
}
/**
* Reduce effectively-empty lists of children to be actually empty. This
* recursively removes `null`, `''`, and `array()` from the list of children
* so that @{method:hasChildren} can more effectively align with expectations.
*
* NOTE: Because View children are not rendered, a View which renders down
* to nothing will not be reduced by this method.
*
* @param list<wild> Renderable children.
* @return list<wild> Reduced list of children.
* @task children
*/
private function reduceChildren(array $children) {
foreach ($children as $key => $child) {
if ($child === null) {
unset($children[$key]);
} else if ($child === '') {
unset($children[$key]);
} else if (is_array($child)) {
$child = $this->reduceChildren($child);
if ($child) {
$children[$key] = $child;
} else {
unset($children[$key]);
}
}
}
return $children;
}
public function getDefaultResourceSource() {
return 'phabricator';
}
public function requireResource($symbol) {
$response = CelerityAPI::getStaticResourceResponse();
$response->requireResource($symbol, $this->getDefaultResourceSource());
return $this;
}
public function initBehavior($name, $config = array()) {
Javelin::initBehavior(
$name,
$config,
$this->getDefaultResourceSource());
return $this;
}
/* -( Rendering )---------------------------------------------------------- */
/**
* Inconsistent, unreliable pre-rendering hook.
*
* This hook //may// fire before views render. It is not fired reliably, and
* may fire multiple times.
*
* If it does fire, views might use it to register data for later loads, but
* almost no datasources support this now; this is currently only useful for
* tokenizers. This mechanism might eventually see wider support or might be
* removed.
*/
public function willRender() {
return;
}
abstract public function render();
/* -( PhutilSafeHTMLProducerInterface )------------------------------------ */
public function producePhutilSafeHTML() {
return $this->render();
}
}
diff --git a/src/view/form/AphrontFormView.php b/src/view/form/AphrontFormView.php
index 810208ffae..ecd4c1206e 100644
--- a/src/view/form/AphrontFormView.php
+++ b/src/view/form/AphrontFormView.php
@@ -1,169 +1,169 @@
<?php
final class AphrontFormView extends AphrontView {
private $action;
private $method = 'POST';
private $header;
private $data = array();
private $encType;
private $workflow;
private $id;
private $shaded = false;
private $sigils = array();
private $metadata;
private $controls = array();
private $fullWidth = false;
public function setMetadata($metadata) {
$this->metadata = $metadata;
return $this;
}
public function getMetadata() {
return $this->metadata;
}
public function setID($id) {
$this->id = $id;
return $this;
}
public function setAction($action) {
$this->action = $action;
return $this;
}
public function setMethod($method) {
$this->method = $method;
return $this;
}
public function setEncType($enc_type) {
$this->encType = $enc_type;
return $this;
}
public function setShaded($shaded) {
$this->shaded = $shaded;
return $this;
}
public function addHiddenInput($key, $value) {
$this->data[$key] = $value;
return $this;
}
public function setWorkflow($workflow) {
$this->workflow = $workflow;
return $this;
}
public function addSigil($sigil) {
$this->sigils[] = $sigil;
return $this;
}
public function setFullWidth($full_width) {
$this->fullWidth = $full_width;
return $this;
}
public function getFullWidth() {
return $this->fullWidth;
}
public function appendInstructions($text) {
return $this->appendChild(
phutil_tag(
'div',
array(
'class' => 'aphront-form-instructions',
),
$text));
}
public function appendRemarkupInstructions($remarkup) {
return $this->appendInstructions(
- new PHUIRemarkupView($this->getUser(), $remarkup));
+ new PHUIRemarkupView($this->getViewer(), $remarkup));
}
public function buildLayoutView() {
foreach ($this->controls as $control) {
- $control->setUser($this->getUser());
+ $control->setViewer($this->getViewer());
$control->willRender();
}
return id(new PHUIFormLayoutView())
->setFullWidth($this->getFullWidth())
->appendChild($this->renderDataInputs())
->appendChild($this->renderChildren());
}
/**
* Append a control to the form.
*
* This method behaves like @{method:appendChild}, but it only takes
* controls. It will propagate some information from the form to the
* control to simplify rendering.
*
* @param AphrontFormControl Control to append.
* @return this
*/
public function appendControl(AphrontFormControl $control) {
$this->controls[] = $control;
return $this->appendChild($control);
}
public function render() {
require_celerity_resource('phui-form-view-css');
$layout = $this->buildLayoutView();
- if (!$this->user) {
+ if (!$this->hasViewer()) {
throw new Exception(
pht(
'You must pass the user to %s.',
__CLASS__));
}
$sigils = $this->sigils;
if ($this->workflow) {
$sigils[] = 'workflow';
}
return phabricator_form(
- $this->user,
+ $this->getViewer(),
array(
'class' => $this->shaded ? 'phui-form-shaded' : null,
'action' => $this->action,
'method' => $this->method,
'enctype' => $this->encType,
'sigil' => $sigils ? implode(' ', $sigils) : null,
'meta' => $this->metadata,
'id' => $this->id,
),
$layout->render());
}
private function renderDataInputs() {
$inputs = array();
foreach ($this->data as $key => $value) {
if ($value === null) {
continue;
}
$inputs[] = phutil_tag(
'input',
array(
'type' => 'hidden',
'name' => $key,
'value' => $value,
));
}
return $inputs;
}
}
diff --git a/src/view/form/control/AphrontFormDateControl.php b/src/view/form/control/AphrontFormDateControl.php
index 75398d688a..25dec8eef0 100644
--- a/src/view/form/control/AphrontFormDateControl.php
+++ b/src/view/form/control/AphrontFormDateControl.php
@@ -1,374 +1,371 @@
<?php
final class AphrontFormDateControl extends AphrontFormControl {
private $initialTime;
private $zone;
private $valueDate;
private $valueTime;
private $allowNull;
private $continueOnInvalidDate = false;
private $isTimeDisabled;
private $isDisabled;
private $endDateID;
public function setAllowNull($allow_null) {
$this->allowNull = $allow_null;
return $this;
}
public function setIsTimeDisabled($is_disabled) {
$this->isTimeDisabled = $is_disabled;
return $this;
}
public function setIsDisabled($is_datepicker_disabled) {
$this->isDisabled = $is_datepicker_disabled;
return $this;
}
public function setEndDateID($value) {
$this->endDateID = $value;
return $this;
}
const TIME_START_OF_DAY = 'start-of-day';
const TIME_END_OF_DAY = 'end-of-day';
const TIME_START_OF_BUSINESS = 'start-of-business';
const TIME_END_OF_BUSINESS = 'end-of-business';
public function setInitialTime($time) {
$this->initialTime = $time;
return $this;
}
public function readValueFromRequest(AphrontRequest $request) {
$date = $request->getStr($this->getDateInputName());
$time = $request->getStr($this->getTimeInputName());
$enabled = $request->getBool($this->getCheckboxInputName());
if ($this->allowNull && !$enabled) {
$this->setError(null);
$this->setValue(null);
return;
}
$err = $this->getError();
if ($date || $time) {
$this->valueDate = $date;
$this->valueTime = $time;
// Assume invalid.
$err = pht('Invalid');
$zone = $this->getTimezone();
try {
$datetime = new DateTime("{$date} {$time}", $zone);
$value = $datetime->format('U');
} catch (Exception $ex) {
$value = null;
}
if ($value) {
$this->setValue($value);
$err = null;
} else {
$this->setValue(null);
}
} else {
$value = $this->getInitialValue();
if ($value) {
$this->setValue($value);
} else {
$this->setValue(null);
}
}
$this->setError($err);
return $this->getValue();
}
protected function getCustomControlClass() {
return 'aphront-form-control-date';
}
public function setValue($epoch) {
if ($epoch instanceof AphrontFormDateControlValue) {
$this->continueOnInvalidDate = true;
$this->valueDate = $epoch->getValueDate();
$this->valueTime = $epoch->getValueTime();
$this->allowNull = $epoch->getOptional();
$this->isDisabled = $epoch->isDisabled();
return parent::setValue($epoch->getEpoch());
}
$result = parent::setValue($epoch);
if ($epoch === null) {
return $result;
}
$readable = $this->formatTime($epoch, 'Y!m!d!g:i A');
$readable = explode('!', $readable, 4);
$year = $readable[0];
$month = $readable[1];
$day = $readable[2];
$this->valueDate = $month.'/'.$day.'/'.$year;
$this->valueTime = $readable[3];
return $result;
}
private function getDateInputValue() {
$date_format = $this->getDateFormat();
$timezone = $this->getTimezone();
$datetime = new DateTime($this->valueDate, $timezone);
$date = $datetime->format($date_format);
return $date;
}
private function getTimeFormat() {
- return $this->getUser()
+ return $this->getViewer()
->getPreference(PhabricatorUserPreferences::PREFERENCE_TIME_FORMAT);
}
private function getDateFormat() {
- return $this->getUser()
+ return $this->getViewer()
->getPreference(PhabricatorUserPreferences::PREFERENCE_DATE_FORMAT);
}
private function getTimeInputValue() {
return $this->valueTime;
}
private function formatTime($epoch, $fmt) {
return phabricator_format_local_time(
$epoch,
- $this->user,
+ $this->getViewer(),
$fmt);
}
private function getDateInputName() {
return $this->getName().'_d';
}
private function getTimeInputName() {
return $this->getName().'_t';
}
private function getCheckboxInputName() {
return $this->getName().'_e';
}
protected function renderInput() {
$disabled = null;
if ($this->getValue() === null && !$this->continueOnInvalidDate) {
$this->setValue($this->getInitialValue());
if ($this->allowNull) {
$disabled = 'disabled';
}
}
if ($this->isDisabled) {
$disabled = 'disabled';
}
$checkbox = null;
if ($this->allowNull) {
$checkbox = javelin_tag(
'input',
array(
'type' => 'checkbox',
'name' => $this->getCheckboxInputName(),
'sigil' => 'calendar-enable',
'class' => 'aphront-form-date-enabled-input',
'value' => 1,
'checked' => ($disabled === null ? 'checked' : null),
));
}
$date_sel = javelin_tag(
'input',
array(
'autocomplete' => 'off',
'name' => $this->getDateInputName(),
'sigil' => 'date-input',
'value' => $this->getDateInputValue(),
'type' => 'text',
'class' => 'aphront-form-date-input',
),
'');
$date_div = javelin_tag(
'div',
array(
'class' => 'aphront-form-date-input-container',
),
$date_sel);
$cicon = id(new PHUIIconView())
->setIcon('fa-calendar');
$cal_icon = javelin_tag(
'a',
array(
'href' => '#',
'class' => 'calendar-button',
'sigil' => 'calendar-button',
),
$cicon);
$values = $this->getTimeTypeaheadValues();
$time_id = celerity_generate_unique_node_id();
Javelin::initBehavior('time-typeahead', array(
'startTimeID' => $time_id,
'endTimeID' => $this->endDateID,
'timeValues' => $values,
'format' => $this->getTimeFormat(),
));
$time_sel = javelin_tag(
'input',
array(
'autocomplete' => 'off',
'name' => $this->getTimeInputName(),
'sigil' => 'time-input',
'value' => $this->getTimeInputValue(),
'type' => 'text',
'class' => 'aphront-form-time-input',
),
'');
$time_div = javelin_tag(
'div',
array(
'id' => $time_id,
'class' => 'aphront-form-time-input-container',
),
$time_sel);
- $preferences = $this->user->loadPreferences();
+ $preferences = $this->getViewer()->loadPreferences();
$pref_week_start = PhabricatorUserPreferences::PREFERENCE_WEEK_START_DAY;
$week_start = $preferences->getPreference($pref_week_start, 0);
Javelin::initBehavior('fancy-datepicker', array(
'format' => $this->getDateFormat(),
'weekStart' => $week_start,
));
$classes = array();
$classes[] = 'aphront-form-date-container';
if ($disabled) {
$classes[] = 'datepicker-disabled';
}
if ($this->isTimeDisabled) {
$classes[] = 'no-time';
}
return javelin_tag(
'div',
array(
'class' => implode(' ', $classes),
'sigil' => 'phabricator-date-control',
'meta' => array(
'disabled' => (bool)$disabled,
),
'id' => $this->getID(),
),
array(
$checkbox,
$date_div,
$cal_icon,
$time_div,
));
}
private function getTimezone() {
if ($this->zone) {
return $this->zone;
}
- $user = $this->getUser();
- if (!$this->getUser()) {
- throw new PhutilInvalidStateException('setUser');
- }
+ $viewer = $this->getViewer();
- $user_zone = $user->getTimezoneIdentifier();
+ $user_zone = $viewer->getTimezoneIdentifier();
$this->zone = new DateTimeZone($user_zone);
return $this->zone;
}
private function getInitialValue() {
$zone = $this->getTimezone();
// TODO: We could eventually allow these to be customized per install or
// per user or both, but let's wait and see.
switch ($this->initialTime) {
case self::TIME_START_OF_DAY:
default:
$time = '12:00 AM';
break;
case self::TIME_START_OF_BUSINESS:
$time = '9:00 AM';
break;
case self::TIME_END_OF_BUSINESS:
$time = '5:00 PM';
break;
case self::TIME_END_OF_DAY:
$time = '11:59 PM';
break;
}
$today = $this->formatTime(time(), 'Y-m-d');
try {
$date = new DateTime("{$today} {$time}", $zone);
$value = $date->format('U');
} catch (Exception $ex) {
$value = null;
}
return $value;
}
private function getTimeTypeaheadValues() {
$time_format = $this->getTimeFormat();
$times = array();
if ($time_format == 'g:i A') {
$am_pm_list = array('AM', 'PM');
foreach ($am_pm_list as $am_pm) {
for ($hour = 0; $hour < 12; $hour++) {
$actual_hour = ($hour == 0) ? 12 : $hour;
$times[] = $actual_hour.':00 '.$am_pm;
$times[] = $actual_hour.':30 '.$am_pm;
}
}
} else if ($time_format == 'H:i') {
for ($hour = 0; $hour < 24; $hour++) {
$written_hour = ($hour > 9) ? $hour : '0'.$hour;
$times[] = $written_hour.':00';
$times[] = $written_hour.':30';
}
}
foreach ($times as $key => $time) {
$times[$key] = array($key, $time);
}
return $times;
}
}
diff --git a/src/view/form/control/AphrontFormTokenizerControl.php b/src/view/form/control/AphrontFormTokenizerControl.php
index 3f24dd1348..3d65c4e525 100644
--- a/src/view/form/control/AphrontFormTokenizerControl.php
+++ b/src/view/form/control/AphrontFormTokenizerControl.php
@@ -1,150 +1,150 @@
<?php
final class AphrontFormTokenizerControl extends AphrontFormControl {
private $datasource;
private $disableBehavior;
private $limit;
private $placeholder;
private $handles;
private $initialValue;
public function setDatasource(PhabricatorTypeaheadDatasource $datasource) {
$this->datasource = $datasource;
return $this;
}
public function setDisableBehavior($disable) {
$this->disableBehavior = $disable;
return $this;
}
protected function getCustomControlClass() {
return 'aphront-form-control-tokenizer';
}
public function setLimit($limit) {
$this->limit = $limit;
return $this;
}
public function setPlaceholder($placeholder) {
$this->placeholder = $placeholder;
return $this;
}
public function setInitialValue(array $initial_value) {
$this->initialValue = $initial_value;
return $this;
}
public function getInitialValue() {
return $this->initialValue;
}
public function willRender() {
// Load the handles now so we'll get a bulk load later on when we actually
// render them.
$this->loadHandles();
}
protected function renderInput() {
$name = $this->getName();
$handles = $this->loadHandles();
$handles = iterator_to_array($handles);
if ($this->getID()) {
$id = $this->getID();
} else {
$id = celerity_generate_unique_node_id();
}
$datasource = $this->datasource;
if (!$datasource) {
throw new Exception(
pht('You must set a datasource to use a TokenizerControl.'));
}
$datasource->setViewer($this->getUser());
$placeholder = null;
if (!strlen($this->placeholder)) {
$placeholder = $datasource->getPlaceholderText();
}
$values = nonempty($this->getValue(), array());
$tokens = $datasource->renderTokens($values);
foreach ($tokens as $token) {
$token->setInputName($this->getName());
}
$template = id(new AphrontTokenizerTemplateView())
->setName($name)
->setID($id)
->setValue($tokens);
$initial_value = $this->getInitialValue();
if ($initial_value !== null) {
$template->setInitialValue($initial_value);
}
$username = null;
- if ($this->user) {
- $username = $this->user->getUsername();
+ if ($this->hasViewer()) {
+ $username = $this->getViewer()->getUsername();
}
$datasource_uri = $datasource->getDatasourceURI();
$browse_uri = $datasource->getBrowseURI();
if ($browse_uri) {
$template->setBrowseURI($browse_uri);
}
if (!$this->disableBehavior) {
Javelin::initBehavior('aphront-basic-tokenizer', array(
'id' => $id,
'src' => $datasource_uri,
'value' => mpull($tokens, 'getValue', 'getKey'),
'icons' => mpull($tokens, 'getIcon', 'getKey'),
'types' => mpull($tokens, 'getTokenType', 'getKey'),
'colors' => mpull($tokens, 'getColor', 'getKey'),
'limit' => $this->limit,
'username' => $username,
'placeholder' => $placeholder,
'browseURI' => $browse_uri,
'disabled' => $this->getDisabled(),
));
}
return $template->render();
}
private function loadHandles() {
if ($this->handles === null) {
$viewer = $this->getUser();
if (!$viewer) {
throw new Exception(
pht(
'Call %s before rendering tokenizers. '.
'Use %s on %s to do this easily.',
'setUser()',
'appendControl()',
'AphrontFormView'));
}
$values = nonempty($this->getValue(), array());
$phids = array();
foreach ($values as $value) {
if (!PhabricatorTypeaheadDatasource::isFunctionToken($value)) {
$phids[] = $value;
}
}
$this->handles = $viewer->loadHandles($phids);
}
return $this->handles;
}
}
diff --git a/src/view/layout/AphrontSideNavFilterView.php b/src/view/layout/AphrontSideNavFilterView.php
index 3a267510f0..d59bf5ccac 100644
--- a/src/view/layout/AphrontSideNavFilterView.php
+++ b/src/view/layout/AphrontSideNavFilterView.php
@@ -1,341 +1,338 @@
<?php
/**
* Provides a navigation sidebar. For example:
*
* $nav = new AphrontSideNavFilterView();
* $nav
* ->setBaseURI($some_uri)
* ->addLabel('Cats')
* ->addFilter('meow', 'Meow')
* ->addFilter('purr', 'Purr')
* ->addLabel('Dogs')
* ->addFilter('woof', 'Woof')
* ->addFilter('bark', 'Bark');
* $valid_filter = $nav->selectFilter($user_selection, $default = 'meow');
*
*/
final class AphrontSideNavFilterView extends AphrontView {
private $items = array();
private $baseURI;
private $selectedFilter = false;
private $flexible;
private $collapsed = false;
private $active;
private $menu;
private $crumbs;
private $classes = array();
private $menuID;
private $mainID;
private $isProfileMenu;
private $footer = array();
public function setMenuID($menu_id) {
$this->menuID = $menu_id;
return $this;
}
public function getMenuID() {
return $this->menuID;
}
public function __construct() {
$this->menu = new PHUIListView();
}
public function addClass($class) {
$this->classes[] = $class;
return $this;
}
public function setCrumbs(PHUICrumbsView $crumbs) {
$this->crumbs = $crumbs;
return $this;
}
public function getCrumbs() {
return $this->crumbs;
}
public function setIsProfileMenu($is_profile) {
$this->isProfileMenu = $is_profile;
return $this;
}
public function getIsProfileMenu() {
return $this->isProfileMenu;
}
public function setActive($active) {
$this->active = $active;
return $this;
}
public function setFlexible($flexible) {
$this->flexible = $flexible;
return $this;
}
public function setCollapsed($collapsed) {
$this->collapsed = $collapsed;
return $this;
}
public function getMenuView() {
return $this->menu;
}
public function addMenuItem(PHUIListItemView $item) {
$this->menu->addMenuItem($item);
return $this;
}
public function getMenu() {
return $this->menu;
}
public function addFilter($key, $name, $uri = null) {
return $this->addThing(
$key, $name, $uri, PHUIListItemView::TYPE_LINK);
}
public function addButton($key, $name, $uri = null) {
return $this->addThing(
$key, $name, $uri, PHUIListItemView::TYPE_BUTTON);
}
private function addThing($key, $name, $uri, $type) {
$item = id(new PHUIListItemView())
->setName($name)
->setType($type);
if (strlen($key)) {
$item->setKey($key);
}
if ($uri) {
$item->setHref($uri);
} else {
$href = clone $this->baseURI;
$href->setPath(rtrim($href->getPath().$key, '/').'/');
$href = (string)$href;
$item->setHref($href);
}
return $this->addMenuItem($item);
}
public function addCustomBlock($block) {
$this->menu->addMenuItem(
id(new PHUIListItemView())
->setType(PHUIListItemView::TYPE_CUSTOM)
->appendChild($block));
return $this;
}
public function addLabel($name) {
return $this->addMenuItem(
id(new PHUIListItemView())
->setType(PHUIListItemView::TYPE_LABEL)
->setName($name));
}
public function setBaseURI(PhutilURI $uri) {
$this->baseURI = $uri;
return $this;
}
public function getBaseURI() {
return $this->baseURI;
}
public function selectFilter($key, $default = null) {
$this->selectedFilter = $default;
if ($this->menu->getItem($key) && strlen($key)) {
$this->selectedFilter = $key;
}
return $this->selectedFilter;
}
public function getSelectedFilter() {
return $this->selectedFilter;
}
public function appendFooter($footer) {
$this->footer[] = $footer;
return $this;
}
public function getMainID() {
if (!$this->mainID) {
$this->mainID = celerity_generate_unique_node_id();
}
return $this->mainID;
}
public function render() {
if ($this->menu->getItems()) {
if (!$this->baseURI) {
throw new PhutilInvalidStateException('setBaseURI');
}
if ($this->selectedFilter === false) {
throw new PhutilInvalidStateException('selectFilter');
}
}
if ($this->selectedFilter !== null) {
$selected_item = $this->menu->getItem($this->selectedFilter);
if ($selected_item) {
$selected_item->addClass('phui-list-item-selected');
}
}
require_celerity_resource('phabricator-side-menu-view-css');
return $this->renderFlexNav();
}
private function renderFlexNav() {
-
- $user = $this->user;
-
require_celerity_resource('phabricator-nav-view-css');
$nav_classes = array();
$nav_classes[] = 'phabricator-nav';
if ($this->getIsProfileMenu()) {
require_celerity_resource('phui-profile-menu-css');
// No class, we're going to put it on the shell instead.
} else {
$nav_classes[] = 'phabricator-basic-nav';
}
$nav_id = null;
$drag_id = null;
$content_id = celerity_generate_unique_node_id();
$local_id = null;
$background_id = null;
$local_menu = null;
$main_id = $this->getMainID();
if ($this->flexible) {
$drag_id = celerity_generate_unique_node_id();
$flex_bar = phutil_tag(
'div',
array(
'class' => 'phabricator-nav-drag',
'id' => $drag_id,
),
'');
} else {
$flex_bar = null;
}
$nav_menu = null;
if ($this->menu->getItems()) {
$local_id = celerity_generate_unique_node_id();
$background_id = celerity_generate_unique_node_id();
if (!$this->collapsed) {
$nav_classes[] = 'has-local-nav';
}
$local_menu =
phutil_tag(
'div',
array(
'class' => 'phabricator-nav-local phabricator-side-menu',
'id' => $local_id,
),
$this->menu->setID($this->getMenuID()));
}
$crumbs = null;
if ($this->crumbs) {
$crumbs = $this->crumbs->render();
$nav_classes[] = 'has-crumbs';
}
if ($this->flexible) {
if (!$this->collapsed) {
$nav_classes[] = 'has-drag-nav';
}
Javelin::initBehavior(
'phabricator-nav',
array(
'mainID' => $main_id,
'localID' => $local_id,
'dragID' => $drag_id,
'contentID' => $content_id,
'backgroundID' => $background_id,
'collapsed' => $this->collapsed,
));
if ($this->active) {
Javelin::initBehavior(
'phabricator-active-nav',
array(
'localID' => $local_id,
));
}
}
$nav_classes = array_merge($nav_classes, $this->classes);
$footer = $this->footer;
if ($this->getIsProfileMenu()) {
$internal_footer = $footer;
$external_footer = null;
} else {
$internal_footer = null;
$external_footer = $footer;
}
$menu = phutil_tag(
'div',
array(
'class' => implode(' ', $nav_classes),
'id' => $main_id,
),
array(
$local_menu,
$flex_bar,
phutil_tag(
'div',
array(
'class' => 'phabricator-nav-content plb',
'id' => $content_id,
),
array(
$crumbs,
$this->renderChildren(),
$internal_footer,
)),
));
if ($this->getIsProfileMenu()) {
$shell = phutil_tag(
'div',
array(
'class' => 'phui-navigation-shell phui-profile-menu',
),
array(
$menu,
));
} else {
$shell = array(
$menu,
$external_footer,
);
}
return $shell;
}
}
diff --git a/src/view/layout/PhabricatorActionListView.php b/src/view/layout/PhabricatorActionListView.php
index 6c343af4fe..4965f02793 100644
--- a/src/view/layout/PhabricatorActionListView.php
+++ b/src/view/layout/PhabricatorActionListView.php
@@ -1,59 +1,57 @@
<?php
final class PhabricatorActionListView extends AphrontView {
private $actions = array();
private $object;
private $id = null;
public function setObject(PhabricatorLiskDAO $object) {
$this->object = $object;
return $this;
}
public function addAction(PhabricatorActionView $view) {
$this->actions[] = $view;
return $this;
}
public function setID($id) {
$this->id = $id;
return $this;
}
public function render() {
- if (!$this->user) {
- throw new PhutilInvalidStateException('setUser');
- }
+ $viewer = $this->getViewer();
$event = new PhabricatorEvent(
PhabricatorEventType::TYPE_UI_DIDRENDERACTIONS,
array(
'object' => $this->object,
'actions' => $this->actions,
));
- $event->setUser($this->user);
+ $event->setUser($viewer);
PhutilEventEngine::dispatchEvent($event);
$actions = $event->getValue('actions');
if (!$actions) {
return null;
}
foreach ($actions as $action) {
- $action->setUser($this->user);
+ $action->setViewer($viewer);
}
require_celerity_resource('phabricator-action-list-view-css');
return phutil_tag(
'ul',
array(
'class' => 'phabricator-action-list-view',
'id' => $this->id,
),
$actions);
}
}
diff --git a/src/view/layout/PhabricatorActionView.php b/src/view/layout/PhabricatorActionView.php
index b89c00daf5..3efa32071d 100644
--- a/src/view/layout/PhabricatorActionView.php
+++ b/src/view/layout/PhabricatorActionView.php
@@ -1,201 +1,201 @@
<?php
final class PhabricatorActionView extends AphrontView {
private $name;
private $icon;
private $href;
private $disabled;
private $label;
private $workflow;
private $renderAsForm;
private $download;
private $sigils = array();
private $metadata;
private $selected;
private $openInNewWindow;
public function setSelected($selected) {
$this->selected = $selected;
return $this;
}
public function getSelected() {
return $this->selected;
}
public function setMetadata($metadata) {
$this->metadata = $metadata;
return $this;
}
public function getMetadata() {
return $this->metadata;
}
public function setDownload($download) {
$this->download = $download;
return $this;
}
public function getDownload() {
return $this->download;
}
public function setHref($href) {
$this->href = $href;
return $this;
}
public function addSigil($sigil) {
$this->sigils[] = $sigil;
return $this;
}
public function getHref() {
return $this->href;
}
public function setIcon($icon) {
$this->icon = $icon;
return $this;
}
public function setName($name) {
$this->name = $name;
return $this;
}
public function setLabel($label) {
$this->label = $label;
return $this;
}
public function setDisabled($disabled) {
$this->disabled = $disabled;
return $this;
}
public function setWorkflow($workflow) {
$this->workflow = $workflow;
return $this;
}
public function setRenderAsForm($form) {
$this->renderAsForm = $form;
return $this;
}
public function setOpenInNewWindow($open_in_new_window) {
$this->openInNewWindow = $open_in_new_window;
return $this;
}
public function getOpenInNewWindow() {
return $this->openInNewWindow;
}
public function render() {
$icon = null;
if ($this->icon) {
$color = '';
if ($this->disabled) {
$color = ' grey';
}
$icon = id(new PHUIIconView())
->addClass('phabricator-action-view-icon')
->setIcon($this->icon.$color);
}
if ($this->href) {
$sigils = array();
if ($this->workflow) {
$sigils[] = 'workflow';
}
if ($this->download) {
$sigils[] = 'download';
}
if ($this->sigils) {
$sigils = array_merge($sigils, $this->sigils);
}
$sigils = $sigils ? implode(' ', $sigils) : null;
if ($this->renderAsForm) {
- if (!$this->user) {
+ if (!$this->hasViewer()) {
throw new Exception(
pht(
'Call %s when rendering an action as a form.',
- 'setUser()'));
+ 'setViewer()'));
}
$item = javelin_tag(
'button',
array(
'class' => 'phabricator-action-view-item',
),
array($icon, $this->name));
$item = phabricator_form(
- $this->user,
+ $this->getViewer(),
array(
'action' => $this->getHref(),
'method' => 'POST',
'sigil' => $sigils,
'meta' => $this->metadata,
),
$item);
} else {
if ($this->getOpenInNewWindow()) {
$target = '_blank';
} else {
$target = null;
}
$item = javelin_tag(
'a',
array(
'href' => $this->getHref(),
'class' => 'phabricator-action-view-item',
'target' => $target,
'sigil' => $sigils,
'meta' => $this->metadata,
),
array($icon, $this->name));
}
} else {
$item = phutil_tag(
'span',
array(
'class' => 'phabricator-action-view-item',
),
array($icon, $this->name));
}
$classes = array();
$classes[] = 'phabricator-action-view';
if ($this->disabled) {
$classes[] = 'phabricator-action-view-disabled';
}
if ($this->label) {
$classes[] = 'phabricator-action-view-label';
}
if ($this->selected) {
$classes[] = 'phabricator-action-view-selected';
}
return phutil_tag(
'li',
array(
'class' => implode(' ', $classes),
),
$item);
}
}
diff --git a/src/view/page/menu/PhabricatorMainMenuSearchView.php b/src/view/page/menu/PhabricatorMainMenuSearchView.php
index a5c5653cc3..d3c7319f7d 100644
--- a/src/view/page/menu/PhabricatorMainMenuSearchView.php
+++ b/src/view/page/menu/PhabricatorMainMenuSearchView.php
@@ -1,231 +1,231 @@
<?php
final class PhabricatorMainMenuSearchView extends AphrontView {
const DEFAULT_APPLICATION_ICON = 'fa-dot-circle-o';
private $id;
private $application;
public function setApplication(PhabricatorApplication $application) {
$this->application = $application;
return $this;
}
public function getApplication() {
return $this->application;
}
public function getID() {
if (!$this->id) {
$this->id = celerity_generate_unique_node_id();
}
return $this->id;
}
public function render() {
- $user = $this->user;
+ $viewer = $this->getViewer();
$target_id = celerity_generate_unique_node_id();
$search_id = $this->getID();
$button_id = celerity_generate_unique_node_id();
$selector_id = celerity_generate_unique_node_id();
$application_id = celerity_generate_unique_node_id();
$input = phutil_tag(
'input',
array(
'type' => 'text',
'name' => 'query',
'id' => $search_id,
'autocomplete' => 'off',
));
$target = javelin_tag(
'div',
array(
'id' => $target_id,
'class' => 'phabricator-main-menu-search-target',
),
'');
$search_datasource = new PhabricatorSearchDatasource();
$scope_key = PhabricatorUserPreferences::PREFERENCE_SEARCH_SCOPE;
Javelin::initBehavior(
'phabricator-search-typeahead',
array(
'id' => $target_id,
'input' => $search_id,
'button' => $button_id,
'selectorID' => $selector_id,
'applicationID' => $application_id,
'defaultApplicationIcon' => self::DEFAULT_APPLICATION_ICON,
'appScope' => PhabricatorSearchController::SCOPE_CURRENT_APPLICATION,
'src' => $search_datasource->getDatasourceURI(),
'limit' => 10,
'placeholder' => pht('Search'),
'scopeUpdateURI' => '/settings/adjust/?key='.$scope_key,
));
$primary_input = phutil_tag(
'input',
array(
'type' => 'hidden',
'name' => 'search:primary',
'value' => 'true',
));
$search_text = javelin_tag(
'span',
array(
'aural' => true,
),
pht('Search'));
$selector = $this->buildModeSelector($selector_id, $application_id);
$form = phabricator_form(
- $user,
+ $viewer,
array(
'action' => '/search/',
'method' => 'POST',
),
phutil_tag_div('phabricator-main-menu-search-container', array(
$input,
phutil_tag(
'button',
array(
'id' => $button_id,
'class' => 'phui-icon-view phui-font-fa fa-search',
),
$search_text),
$selector,
$primary_input,
$target,
)));
return $form;
}
private function buildModeSelector($selector_id, $application_id) {
- $viewer = $this->getUser();
+ $viewer = $this->getViewer();
$items = array();
$items[] = array(
'name' => pht('Search'),
);
$items[] = array(
'icon' => 'fa-globe',
'name' => pht('Search All Documents'),
'value' => 'all',
);
$application_value = null;
$application_icon = self::DEFAULT_APPLICATION_ICON;
$application = $this->getApplication();
if ($application) {
$application_value = get_class($application);
if ($application->getApplicationSearchDocumentTypes()) {
$application_icon = $application->getIcon();
}
}
$items[] = array(
'icon' => $application_icon,
'name' => pht('Search Current Application'),
'value' => PhabricatorSearchController::SCOPE_CURRENT_APPLICATION,
);
$items[] = array(
'name' => pht('Saved Queries'),
);
$engine = id(new PhabricatorSearchApplicationSearchEngine())
->setViewer($viewer);
$engine_queries = $engine->loadEnabledNamedQueries();
$query_map = mpull($engine_queries, 'getQueryName', 'getQueryKey');
foreach ($query_map as $query_key => $query_name) {
if ($query_key == 'all') {
// Skip the builtin "All" query since it's redundant with the default
// setting.
continue;
}
$items[] = array(
'icon' => 'fa-certificate',
'name' => $query_name,
'value' => $query_key,
);
}
$items[] = array(
'name' => pht('More Options'),
);
$items[] = array(
'icon' => 'fa-search-plus',
'name' => pht('Advanced Search'),
'href' => '/search/query/advanced/',
);
$items[] = array(
'icon' => 'fa-book',
'name' => pht('User Guide: Search'),
'href' => PhabricatorEnv::getDoclink('Search User Guide'),
);
$scope_key = PhabricatorUserPreferences::PREFERENCE_SEARCH_SCOPE;
$current_value = $viewer->loadPreferences()->getPreference(
$scope_key,
'all');
$current_icon = 'fa-globe';
foreach ($items as $item) {
if (idx($item, 'value') == $current_value) {
$current_icon = $item['icon'];
break;
}
}
$selector = id(new PHUIButtonView())
->setID($selector_id)
->addClass('phabricator-main-menu-search-dropdown')
->addSigil('global-search-dropdown')
->setMetadata(
array(
'items' => $items,
'icon' => $current_icon,
'value' => $current_value,
))
->setIcon(
id(new PHUIIconView())
->addSigil('global-search-dropdown-icon')
->setIcon($current_icon))
->setDropdown(true);
$input = javelin_tag(
'input',
array(
'type' => 'hidden',
'sigil' => 'global-search-dropdown-input',
'name' => 'search:scope',
'value' => $current_value,
));
$application_input = javelin_tag(
'input',
array(
'type' => 'hidden',
'id' => $application_id,
'sigil' => 'global-search-dropdown-app',
'name' => 'search:application',
'value' => $application_value,
));
return array($selector, $input, $application_input);
}
}
diff --git a/src/view/page/menu/PhabricatorMainMenuView.php b/src/view/page/menu/PhabricatorMainMenuView.php
index 5ce25fb3da..e804573ff0 100644
--- a/src/view/page/menu/PhabricatorMainMenuView.php
+++ b/src/view/page/menu/PhabricatorMainMenuView.php
@@ -1,544 +1,544 @@
<?php
final class PhabricatorMainMenuView extends AphrontView {
private $controller;
private $applicationMenu;
public function setApplicationMenu(PHUIListView $application_menu) {
$this->applicationMenu = $application_menu;
return $this;
}
public function getApplicationMenu() {
return $this->applicationMenu;
}
public function setController(PhabricatorController $controller) {
$this->controller = $controller;
return $this;
}
public function getController() {
return $this->controller;
}
public function render() {
- $user = $this->user;
+ $viewer = $this->getViewer();
require_celerity_resource('phabricator-main-menu-view');
$header_id = celerity_generate_unique_node_id();
$menu_bar = array();
$alerts = array();
$search_button = '';
$app_button = '';
$aural = null;
- if ($user->isLoggedIn() && $user->isUserActivated()) {
+ if ($viewer->isLoggedIn() && $viewer->isUserActivated()) {
list($menu, $dropdowns, $aural) = $this->renderNotificationMenu();
if (array_filter($menu)) {
$alerts[] = $menu;
}
$menu_bar = array_merge($menu_bar, $dropdowns);
$app_button = $this->renderApplicationMenuButton($header_id);
$search_button = $this->renderSearchMenuButton($header_id);
} else {
$app_button = $this->renderApplicationMenuButton($header_id);
if (PhabricatorEnv::getEnvConfig('policy.allow-public')) {
$search_button = $this->renderSearchMenuButton($header_id);
}
}
$search_menu = $this->renderPhabricatorSearchMenu();
if ($alerts) {
$alerts = javelin_tag(
'div',
array(
'class' => 'phabricator-main-menu-alerts',
'aural' => false,
),
$alerts);
}
if ($aural) {
$aural = javelin_tag(
'span',
array(
'aural' => true,
),
phutil_implode_html(' ', $aural));
}
$applications = PhabricatorApplication::getAllInstalledApplications();
$menus = array();
$controller = $this->getController();
foreach ($applications as $application) {
$app_actions = $application->buildMainMenuItems(
- $user,
+ $viewer,
$controller);
$app_extra = $application->buildMainMenuExtraNodes(
- $user,
+ $viewer,
$controller);
foreach ($app_actions as $action) {
$menus[] = id(new PHUIMainMenuView())
->setMenuBarItem($action)
->setOrder($action->getOrder());
}
if ($app_extra !== null) {
$menus[] = id(new PHUIMainMenuView())
->appendChild($app_extra);
}
}
$extensions = PhabricatorMainMenuBarExtension::getAllEnabledExtensions();
foreach ($extensions as $extension) {
- $extension->setViewer($user);
+ $extension->setViewer($viewer);
$controller = $this->getController();
if ($controller) {
$extension->setController($controller);
$application = $controller->getCurrentApplication();
if ($application) {
$extension->setApplication($application);
}
}
}
foreach ($extensions as $key => $extension) {
if (!$extension->isExtensionEnabledForViewer($extension->getViewer())) {
unset($extensions[$key]);
}
}
foreach ($extensions as $extension) {
foreach ($extension->buildMainMenus() as $menu) {
$menus[] = $menu;
}
}
$menus = msort($menus, 'getOrder');
$bar_items = array();
foreach ($menus as $menu) {
$menu_bar[] = $menu;
$item = $menu->getMenuBarItem();
if ($item === null) {
continue;
}
$bar_items[] = $item;
}
$application_menu = $this->renderApplicationMenu($bar_items);
$classes = array();
$classes[] = 'phabricator-main-menu';
$classes[] = 'phabricator-main-menu-background';
return phutil_tag(
'div',
array(
'class' => implode(' ', $classes),
'id' => $header_id,
),
array(
$app_button,
$search_button,
$this->renderPhabricatorLogo(),
$alerts,
$aural,
$application_menu,
$search_menu,
$menu_bar,
));
}
private function renderSearch() {
- $user = $this->user;
+ $viewer = $this->getViewer();
$result = null;
$keyboard_config = array(
'helpURI' => '/help/keyboardshortcut/',
);
- if ($user->isLoggedIn()) {
- $show_search = $user->isUserActivated();
+ if ($viewer->isLoggedIn()) {
+ $show_search = $viewer->isUserActivated();
} else {
$show_search = PhabricatorEnv::getEnvConfig('policy.allow-public');
}
if ($show_search) {
$search = new PhabricatorMainMenuSearchView();
- $search->setUser($user);
+ $search->setViewer($viewer);
$application = null;
$controller = $this->getController();
if ($controller) {
$application = $controller->getCurrentApplication();
}
if ($application) {
$search->setApplication($application);
}
$result = $search;
$pref_shortcut = PhabricatorUserPreferences::PREFERENCE_SEARCH_SHORTCUT;
- if ($user->loadPreferences()->getPreference($pref_shortcut, true)) {
+ if ($viewer->loadPreferences()->getPreference($pref_shortcut, true)) {
$keyboard_config['searchID'] = $search->getID();
}
}
Javelin::initBehavior('phabricator-keyboard-shortcuts', $keyboard_config);
if ($result) {
$result = id(new PHUIListItemView())
->addClass('phabricator-main-menu-search')
->appendChild($result);
}
return $result;
}
public function renderApplicationMenuButton($header_id) {
$button_id = celerity_generate_unique_node_id();
return javelin_tag(
'a',
array(
'class' => 'phabricator-main-menu-expand-button '.
'phabricator-expand-search-menu',
'sigil' => 'jx-toggle-class',
'meta' => array(
'map' => array(
$header_id => 'phabricator-application-menu-expanded',
$button_id => 'menu-icon-selected',
),
),
),
phutil_tag(
'span',
array(
'class' => 'phabricator-menu-button-icon phui-icon-view '.
'phui-font-fa fa-bars',
'id' => $button_id,
),
''));
}
private function renderApplicationMenu(array $bar_items) {
- $user = $this->getUser();
+ $viewer = $this->getViewer();
$view = $this->getApplicationMenu();
if (!$view) {
$view = new PHUIListView();
}
$view->addClass('phabricator-dark-menu');
$view->addClass('phabricator-application-menu');
if ($bar_items) {
$view->addMenuItem(
id(new PHUIListItemView())
->setType(PHUIListItemView::TYPE_LABEL)
->setName(pht('Actions')));
foreach ($bar_items as $bar_item) {
$view->addMenuItem($bar_item);
}
}
return $view;
}
public function renderSearchMenuButton($header_id) {
$button_id = celerity_generate_unique_node_id();
return javelin_tag(
'a',
array(
'class' => 'phabricator-main-menu-search-button '.
'phabricator-expand-application-menu',
'sigil' => 'jx-toggle-class',
'meta' => array(
'map' => array(
$header_id => 'phabricator-search-menu-expanded',
$button_id => 'menu-icon-selected',
),
),
),
phutil_tag(
'span',
array(
'class' => 'phabricator-menu-button-icon phui-icon-view '.
'phui-font-fa fa-search',
'id' => $button_id,
),
''));
}
private function renderPhabricatorSearchMenu() {
$view = new PHUIListView();
$view->addClass('phabricator-dark-menu');
$view->addClass('phabricator-search-menu');
$search = $this->renderSearch();
if ($search) {
$view->addMenuItem($search);
}
return $view;
}
private function renderPhabricatorLogo() {
$style_logo = null;
$custom_header = PhabricatorEnv::getEnvConfig('ui.custom-header');
if ($custom_header) {
$cache = PhabricatorCaches::getImmutableCache();
$cache_key_logo = 'ui.custom-header.logo-phid.v1.'.$custom_header;
$logo_uri = $cache->getKey($cache_key_logo);
if (!$logo_uri) {
$file = id(new PhabricatorFileQuery())
- ->setViewer($this->getUser())
+ ->setViewer($this->getViewer())
->withPHIDs(array($custom_header))
->executeOne();
if ($file) {
$logo_uri = $file->getViewURI();
$cache->setKey($cache_key_logo, $logo_uri);
}
}
if ($logo_uri) {
$style_logo =
'background-size: 96px 40px; '.
'background-position: 0px 0px; '.
'background-image: url('.$logo_uri.');';
}
}
$color = PhabricatorEnv::getEnvConfig('ui.header-color');
if ($color == 'light') {
$color = 'dark';
} else {
$color = 'light';
}
return phutil_tag(
'a',
array(
'class' => 'phabricator-main-menu-brand',
'href' => '/',
),
array(
javelin_tag(
'span',
array(
'aural' => true,
),
pht('Home')),
phutil_tag(
'span',
array(
'class' => 'sprite-menu phabricator-main-menu-eye '.$color.'-eye',
),
''),
phutil_tag(
'span',
array(
'class' => 'sprite-menu phabricator-main-menu-logo '.$color.'-logo',
'style' => $style_logo,
),
''),
));
}
private function renderNotificationMenu() {
- $user = $this->user;
+ $viewer = $this->getViewer();
require_celerity_resource('phabricator-notification-css');
require_celerity_resource('phabricator-notification-menu-css');
$container_classes = array('alert-notifications');
$aural = array();
$dropdown_query = id(new AphlictDropdownDataQuery())
- ->setViewer($user);
+ ->setViewer($viewer);
$dropdown_data = $dropdown_query->execute();
$message_tag = '';
$message_notification_dropdown = '';
$conpherence_app = 'PhabricatorConpherenceApplication';
$conpherence_data = $dropdown_data[$conpherence_app];
if ($conpherence_data['isInstalled']) {
$message_id = celerity_generate_unique_node_id();
$message_count_id = celerity_generate_unique_node_id();
$message_dropdown_id = celerity_generate_unique_node_id();
$message_count_number = $conpherence_data['rawCount'];
if ($message_count_number) {
$aural[] = phutil_tag(
'a',
array(
'href' => '/conpherence/',
),
pht(
'%s unread messages.',
new PhutilNumber($message_count_number)));
} else {
$aural[] = pht('No messages.');
}
$message_count_tag = phutil_tag(
'span',
array(
'id' => $message_count_id,
'class' => 'phabricator-main-menu-message-count',
),
$conpherence_data['count']);
$message_icon_tag = javelin_tag(
'span',
array(
'class' => 'phabricator-main-menu-message-icon phui-icon-view '.
'phui-font-fa fa-comments',
'sigil' => 'menu-icon',
),
'');
if ($message_count_number) {
$container_classes[] = 'message-unread';
}
$message_tag = phutil_tag(
'a',
array(
'href' => '/conpherence/',
'class' => implode(' ', $container_classes),
'id' => $message_id,
),
array(
$message_icon_tag,
$message_count_tag,
));
Javelin::initBehavior(
'aphlict-dropdown',
array(
'bubbleID' => $message_id,
'countID' => $message_count_id,
'dropdownID' => $message_dropdown_id,
'loadingText' => pht('Loading...'),
'uri' => '/conpherence/panel/',
'countType' => $conpherence_data['countType'],
'countNumber' => $message_count_number,
'unreadClass' => 'message-unread',
));
$message_notification_dropdown = javelin_tag(
'div',
array(
'id' => $message_dropdown_id,
'class' => 'phabricator-notification-menu',
'sigil' => 'phabricator-notification-menu',
'style' => 'display: none;',
),
'');
}
$bubble_tag = '';
$notification_dropdown = '';
$notification_app = 'PhabricatorNotificationsApplication';
$notification_data = $dropdown_data[$notification_app];
if ($notification_data['isInstalled']) {
$count_id = celerity_generate_unique_node_id();
$dropdown_id = celerity_generate_unique_node_id();
$bubble_id = celerity_generate_unique_node_id();
$count_number = $notification_data['rawCount'];
if ($count_number) {
$aural[] = phutil_tag(
'a',
array(
'href' => '/notification/',
),
pht(
'%s unread notifications.',
new PhutilNumber($count_number)));
} else {
$aural[] = pht('No notifications.');
}
$count_tag = phutil_tag(
'span',
array(
'id' => $count_id,
'class' => 'phabricator-main-menu-alert-count',
),
$notification_data['count']);
$icon_tag = javelin_tag(
'span',
array(
'class' => 'phabricator-main-menu-alert-icon phui-icon-view '.
'phui-font-fa fa-bell',
'sigil' => 'menu-icon',
),
'');
if ($count_number) {
$container_classes[] = 'alert-unread';
}
$bubble_tag = phutil_tag(
'a',
array(
'href' => '/notification/',
'class' => implode(' ', $container_classes),
'id' => $bubble_id,
),
array($icon_tag, $count_tag));
Javelin::initBehavior(
'aphlict-dropdown',
array(
'bubbleID' => $bubble_id,
'countID' => $count_id,
'dropdownID' => $dropdown_id,
'loadingText' => pht('Loading...'),
'uri' => '/notification/panel/',
'countType' => $notification_data['countType'],
'countNumber' => $count_number,
'unreadClass' => 'alert-unread',
));
$notification_dropdown = javelin_tag(
'div',
array(
'id' => $dropdown_id,
'class' => 'phabricator-notification-menu',
'sigil' => 'phabricator-notification-menu',
'style' => 'display: none;',
),
'');
}
$dropdowns = array(
$notification_dropdown,
$message_notification_dropdown,
);
return array(
array(
$bubble_tag,
$message_tag,
),
$dropdowns,
$aural,
);
}
}
diff --git a/src/view/phui/PHUIFeedStoryView.php b/src/view/phui/PHUIFeedStoryView.php
index bacd266089..978e25062f 100644
--- a/src/view/phui/PHUIFeedStoryView.php
+++ b/src/view/phui/PHUIFeedStoryView.php
@@ -1,277 +1,277 @@
<?php
final class PHUIFeedStoryView extends AphrontView {
private $title;
private $image;
private $imageHref;
private $appIcon;
private $phid;
private $epoch;
private $viewed;
private $href;
private $pontification = null;
private $tokenBar = array();
private $projects = array();
private $actions = array();
private $chronologicalKey;
private $tags;
public function setTags($tags) {
$this->tags = $tags;
return $this;
}
public function getTags() {
return $this->tags;
}
public function setChronologicalKey($chronological_key) {
$this->chronologicalKey = $chronological_key;
return $this;
}
public function getChronologicalKey() {
return $this->chronologicalKey;
}
public function setTitle($title) {
$this->title = $title;
return $this;
}
public function getTitle() {
return $this->title;
}
public function setEpoch($epoch) {
$this->epoch = $epoch;
return $this;
}
public function setImage($image) {
$this->image = $image;
return $this;
}
public function getImage() {
return $this->image;
}
public function setImageHref($image_href) {
$this->imageHref = $image_href;
return $this;
}
public function setAppIcon($icon) {
$this->appIcon = $icon;
return $this;
}
public function setViewed($viewed) {
$this->viewed = $viewed;
return $this;
}
public function getViewed() {
return $this->viewed;
}
public function setHref($href) {
$this->href = $href;
return $this;
}
public function setTokenBar(array $tokens) {
$this->tokenBar = $tokens;
return $this;
}
public function addProject($project) {
$this->projects[] = $project;
return $this;
}
public function addAction(PHUIIconView $action) {
$this->actions[] = $action;
return $this;
}
public function setPontification($text, $title = null) {
if ($title) {
$title = phutil_tag('h3', array(), $title);
}
$copy = phutil_tag(
'div',
array(
'class' => 'phui-feed-story-bigtext-post',
),
array(
$title,
$text,
));
$this->appendChild($copy);
return $this;
}
public function getHref() {
return $this->href;
}
public function renderNotification($user) {
$classes = array(
'phabricator-notification',
);
if (!$this->viewed) {
$classes[] = 'phabricator-notification-unread';
}
if ($this->epoch) {
if ($user) {
$foot = phabricator_datetime($this->epoch, $user);
$foot = phutil_tag(
'span',
array(
'class' => 'phabricator-notification-date',
),
$foot);
} else {
$foot = null;
}
} else {
$foot = pht('No time specified.');
}
return javelin_tag(
'div',
array(
'class' => implode(' ', $classes),
'sigil' => 'notification',
'meta' => array(
'href' => $this->getHref(),
),
),
array($this->title, $foot));
}
public function render() {
require_celerity_resource('phui-feed-story-css');
Javelin::initBehavior('phui-hovercards');
$body = null;
$foot = null;
$actor = new PHUIIconView();
$actor->setImage($this->image);
$actor->addClass('phui-feed-story-actor-image');
if ($this->imageHref) {
$actor->setHref($this->imageHref);
}
if ($this->epoch) {
// TODO: This is really bad; when rendering through Conduit and via
// renderText() we don't have a user.
- if ($this->user) {
- $foot = phabricator_datetime($this->epoch, $this->user);
+ if ($this->hasViewer()) {
+ $foot = phabricator_datetime($this->epoch, $this->getViewer());
} else {
$foot = null;
}
} else {
$foot = pht('No time specified.');
}
if ($this->chronologicalKey) {
$foot = phutil_tag(
'a',
array(
'href' => '/feed/'.$this->chronologicalKey.'/',
),
$foot);
}
$icon = null;
if ($this->appIcon) {
$icon = id(new PHUIIconView())
->setIcon($this->appIcon);
}
$action_list = array();
$icons = null;
foreach ($this->actions as $action) {
$action_list[] = phutil_tag(
'li',
array(
'class' => 'phui-feed-story-action-item',
),
$action);
}
if (!empty($action_list)) {
$icons = phutil_tag(
'ul',
array(
'class' => 'phui-feed-story-action-list',
),
$action_list);
}
$head = phutil_tag(
'div',
array(
'class' => 'phui-feed-story-head',
),
array(
$actor,
nonempty($this->title, pht('Untitled Story')),
$icons,
));
if (!empty($this->tokenBar)) {
$tokenview = phutil_tag(
'div',
array(
'class' => 'phui-feed-token-bar',
),
$this->tokenBar);
$this->appendChild($tokenview);
}
$body_content = $this->renderChildren();
if ($body_content) {
$body = phutil_tag(
'div',
array(
'class' => 'phui-feed-story-body phabricator-remarkup',
),
$body_content);
}
$tags = null;
if ($this->tags) {
$tags = array(
" \xC2\xB7 ",
$this->tags,
);
}
$foot = phutil_tag(
'div',
array(
'class' => 'phui-feed-story-foot',
),
array(
$icon,
$foot,
$tags,
));
$classes = array('phui-feed-story');
return id(new PHUIBoxView())
->addClass(implode(' ', $classes))
->setBorder(true)
->addMargin(PHUI::MARGIN_MEDIUM_BOTTOM)
->appendChild(array($head, $body, $foot));
}
}
diff --git a/src/view/phui/calendar/PHUICalendarDayView.php b/src/view/phui/calendar/PHUICalendarDayView.php
index 34299e39c3..d71554abe5 100644
--- a/src/view/phui/calendar/PHUICalendarDayView.php
+++ b/src/view/phui/calendar/PHUICalendarDayView.php
@@ -1,485 +1,485 @@
<?php
final class PHUICalendarDayView extends AphrontView {
private $rangeStart;
private $rangeEnd;
private $day;
private $month;
private $year;
private $browseURI;
private $query;
private $events = array();
private $allDayEvents = array();
public function addEvent(AphrontCalendarEventView $event) {
$this->events[] = $event;
return $this;
}
public function setBrowseURI($browse_uri) {
$this->browseURI = $browse_uri;
return $this;
}
private function getBrowseURI() {
return $this->browseURI;
}
public function setQuery($query) {
$this->query = $query;
return $this;
}
private function getQuery() {
return $this->query;
}
public function __construct(
$range_start,
$range_end,
$year,
$month,
$day = null) {
$this->rangeStart = $range_start;
$this->rangeEnd = $range_end;
$this->day = $day;
$this->month = $month;
$this->year = $year;
}
public function render() {
require_celerity_resource('phui-calendar-day-css');
$viewer = $this->getUser();
$hours = $this->getHoursOfDay();
$js_hours = array();
$js_today_events = array();
foreach ($hours as $hour) {
$js_hours[] = array(
'hour' => $hour->format('G'),
'hour_meridian' => $hour->format('g A'),
);
}
$first_event_hour = null;
$js_today_all_day_events = array();
$all_day_events = $this->getAllDayEvents();
$day_start = $this->getDateTime();
$day_end = id(clone $day_start)->modify('+1 day');
$day_start_epoch = $day_start->format('U');
$day_end_epoch = $day_end->format('U') - 1;
foreach ($all_day_events as $all_day_event) {
$all_day_start = $all_day_event->getEpochStart();
$all_day_end = $all_day_event->getEpochEnd();
if ($all_day_start < $day_end_epoch && $all_day_end > $day_start_epoch) {
$js_today_all_day_events[] = array(
'name' => $all_day_event->getName(),
'id' => $all_day_event->getEventID(),
'viewerIsInvited' => $all_day_event->getViewerIsInvited(),
'uri' => $all_day_event->getURI(),
);
}
}
$this->events = msort($this->events, 'getEpochStart');
$first_event_hour = $this->getDateTime()->setTime(8, 0, 0);
$midnight = $this->getDateTime()->setTime(0, 0, 0);
foreach ($this->events as $event) {
if ($event->getIsAllDay()) {
continue;
}
if ($event->getEpochStart() <= $day_end_epoch &&
$event->getEpochEnd() > $day_start_epoch) {
if ($event->getEpochStart() < $midnight->format('U') &&
$event->getEpochEnd() > $midnight->format('U')) {
$first_event_hour = clone $midnight;
}
if ($event->getEpochStart() < $first_event_hour->format('U') &&
$event->getEpochStart() > $midnight->format('U')) {
$first_event_hour = PhabricatorTime::getDateTimeFromEpoch(
$event->getEpochStart(),
$viewer);
$first_event_hour->setTime($first_event_hour->format('h'), 0, 0);
}
$event_start = max($event->getEpochStart(), $day_start_epoch);
$event_end = min($event->getEpochEnd(), $day_end_epoch);
$day_duration = ($day_end_epoch - $first_event_hour->format('U')) / 60;
$top = (($event_start - $first_event_hour->format('U'))
/ ($day_end_epoch - $first_event_hour->format('U')))
* $day_duration;
$top = max(0, $top);
$height = (($event_end - $event_start)
/ ($day_end_epoch - $first_event_hour->format('U')))
* $day_duration;
$height = min($day_duration, $height);
$js_today_events[] = array(
'eventStartEpoch' => $event->getEpochStart(),
'eventEndEpoch' => $event->getEpochEnd(),
'eventName' => $event->getName(),
'eventID' => $event->getEventID(),
'viewerIsInvited' => $event->getViewerIsInvited(),
'uri' => $event->getURI(),
'offset' => '0',
'width' => '100%',
'top' => $top.'px',
'height' => $height.'px',
'canEdit' => $event->getCanEdit(),
);
}
}
$header = $this->renderDayViewHeader();
$sidebar = $this->renderSidebar();
$warnings = $this->getQueryRangeWarning();
$table_id = celerity_generate_unique_node_id();
$table_wrapper = phutil_tag(
'div',
array(
'id' => $table_id,
),
'');
Javelin::initBehavior(
'day-view',
array(
'year' => $first_event_hour->format('Y'),
'month' => $first_event_hour->format('m'),
'day' => $first_event_hour->format('d'),
'query' => $this->getQuery(),
'allDayEvents' => $js_today_all_day_events,
'todayEvents' => $js_today_events,
'hours' => $js_hours,
'firstEventHour' => $first_event_hour->format('G'),
'firstEventHourEpoch' => $first_event_hour->format('U'),
'tableID' => $table_id,
));
$table_box = id(new PHUIObjectBoxView())
->setHeader($header)
->appendChild($table_wrapper)
->setFormErrors($warnings)
->setFlush(true);
$layout = id(new AphrontMultiColumnView())
->addColumn($sidebar, 'third')
->addColumn($table_box, 'thirds phui-day-view-column')
->setFluidLayout(true)
->setGutter(AphrontMultiColumnView::GUTTER_MEDIUM);
return phutil_tag(
'div',
array(
'class' => 'ml',
),
$layout);
}
private function getAllDayEvents() {
$all_day_events = array();
foreach ($this->events as $event) {
if ($event->getIsAllDay()) {
$all_day_events[] = $event;
}
}
$all_day_events = array_values(msort($all_day_events, 'getEpochStart'));
return $all_day_events;
}
private function getQueryRangeWarning() {
$errors = array();
$range_start_epoch = null;
$range_end_epoch = null;
if ($this->rangeStart) {
$range_start_epoch = $this->rangeStart->getEpoch();
}
if ($this->rangeEnd) {
$range_end_epoch = $this->rangeEnd->getEpoch();
}
$day_start = $this->getDateTime();
$day_end = id(clone $day_start)->modify('+1 day');
$day_start = $day_start->format('U');
$day_end = $day_end->format('U') - 1;
if (($range_start_epoch != null &&
$range_start_epoch < $day_end &&
$range_start_epoch > $day_start) ||
($range_end_epoch != null &&
$range_end_epoch < $day_end &&
$range_end_epoch > $day_start)) {
$errors[] = pht('Part of the day is out of range');
}
if (($range_end_epoch != null &&
$range_end_epoch < $day_start) ||
($range_start_epoch != null &&
$range_start_epoch > $day_end)) {
$errors[] = pht('Day is out of query range');
}
return $errors;
}
private function renderSidebar() {
$this->events = msort($this->events, 'getEpochStart');
$week_of_boxes = $this->getWeekOfBoxes();
$filled_boxes = array();
foreach ($week_of_boxes as $day_box) {
$box_start = $day_box['start'];
$box_end = id(clone $box_start)->modify('+1 day');
$box_start = $box_start->format('U');
$box_end = $box_end->format('U');
$box_events = array();
foreach ($this->events as $event) {
$event_start = $event->getEpochStart();
$event_end = $event->getEpochEnd();
if ($event_start < $box_end && $event_end > $box_start) {
$box_events[] = $event;
}
}
$filled_boxes[] = $this->renderSidebarBox(
$box_events,
$day_box['title']);
}
return $filled_boxes;
}
private function renderSidebarBox($events, $title) {
$widget = id(new PHUICalendarWidgetView())
->addClass('calendar-day-view-sidebar');
$list = id(new PHUICalendarListView())
- ->setUser($this->user)
+ ->setUser($this->getViewer())
->setView('day');
if (count($events) == 0) {
$list->showBlankState(true);
} else {
$sorted_events = msort($events, 'getEpochStart');
foreach ($sorted_events as $event) {
$list->addEvent($event);
}
}
$widget
->setCalendarList($list)
->setHeader($title);
return $widget;
}
private function getWeekOfBoxes() {
$sidebar_day_boxes = array();
$display_start_day = $this->getDateTime();
$display_end_day = id(clone $display_start_day)->modify('+6 day');
$box_start_time = clone $display_start_day;
- $today_time = PhabricatorTime::getTodayMidnightDateTime($this->user);
+ $today_time = PhabricatorTime::getTodayMidnightDateTime($this->getViewer());
$tomorrow_time = clone $today_time;
$tomorrow_time->modify('+1 day');
while ($box_start_time <= $display_end_day) {
if ($box_start_time == $today_time) {
$title = pht('Today');
} else if ($box_start_time == $tomorrow_time) {
$title = pht('Tomorrow');
} else {
$title = $box_start_time->format('l');
}
$sidebar_day_boxes[] = array(
'title' => $title,
'start' => clone $box_start_time,
);
$box_start_time->modify('+1 day');
}
return $sidebar_day_boxes;
}
private function renderDayViewHeader() {
$button_bar = null;
$uri = $this->getBrowseURI();
if ($uri) {
list($prev_year, $prev_month, $prev_day) = $this->getPrevDay();
$prev_uri = $uri.$prev_year.'/'.$prev_month.'/'.$prev_day.'/';
list($next_year, $next_month, $next_day) = $this->getNextDay();
$next_uri = $uri.$next_year.'/'.$next_month.'/'.$next_day.'/';
$button_bar = new PHUIButtonBarView();
$left_icon = id(new PHUIIconView())
->setIcon('fa-chevron-left bluegrey');
$left = id(new PHUIButtonView())
->setTag('a')
->setColor(PHUIButtonView::GREY)
->setHref($prev_uri)
->setTitle(pht('Previous Day'))
->setIcon($left_icon);
$right_icon = id(new PHUIIconView())
->setIcon('fa-chevron-right bluegrey');
$right = id(new PHUIButtonView())
->setTag('a')
->setColor(PHUIButtonView::GREY)
->setHref($next_uri)
->setTitle(pht('Next Day'))
->setIcon($right_icon);
$button_bar->addButton($left);
$button_bar->addButton($right);
}
$display_day = $this->getDateTime();
$header_text = $display_day->format('l, F j, Y');
$header = id(new PHUIHeaderView())
->setHeader($header_text);
if ($button_bar) {
$header->setButtonBar($button_bar);
}
return $header;
}
private function updateEventsFromCluster($cluster, $hourly_events) {
$cluster_size = count($cluster);
$n = 0;
foreach ($cluster as $cluster_member) {
$event_id = $cluster_member->getEventID();
$offset = (($n / $cluster_size) * 100).'%';
$width = ((1 / $cluster_size) * 100).'%';
if (isset($hourly_events[$event_id])) {
$hourly_events[$event_id]['offset'] = $offset;
$hourly_events[$event_id]['width'] = $width;
}
$n++;
}
return $hourly_events;
}
// returns DateTime of each hour in the day
private function getHoursOfDay() {
$included_datetimes = array();
$day_datetime = $this->getDateTime();
$day_epoch = $day_datetime->format('U');
$day_datetime->modify('+1 day');
$next_day_epoch = $day_datetime->format('U');
$included_time = $day_epoch;
$included_datetime = $this->getDateTime();
while ($included_time < $next_day_epoch) {
$included_datetimes[] = clone $included_datetime;
$included_datetime->modify('+1 hour');
$included_time = $included_datetime->format('U');
}
return $included_datetimes;
}
private function getPrevDay() {
$prev = $this->getDateTime();
$prev->modify('-1 day');
return array(
$prev->format('Y'),
$prev->format('m'),
$prev->format('d'),
);
}
private function getNextDay() {
$next = $this->getDateTime();
$next->modify('+1 day');
return array(
$next->format('Y'),
$next->format('m'),
$next->format('d'),
);
}
private function getDateTime() {
- $user = $this->user;
+ $user = $this->getViewer();
$timezone = new DateTimeZone($user->getTimezoneIdentifier());
$day = $this->day;
$month = $this->month;
$year = $this->year;
$date = new DateTime("{$year}-{$month}-{$day} ", $timezone);
return $date;
}
private function findTodayClusters() {
$events = msort($this->todayEvents, 'getEpochStart');
$clusters = array();
foreach ($events as $event) {
$destination_cluster_key = null;
$event_start = $event->getEpochStart() - (30 * 60);
$event_end = $event->getEpochEnd() + (30 * 60);
foreach ($clusters as $key => $cluster) {
foreach ($cluster as $clustered_event) {
$compare_event_start = $clustered_event->getEpochStart();
$compare_event_end = $clustered_event->getEpochEnd();
if ($event_start < $compare_event_end
&& $event_end > $compare_event_start) {
$destination_cluster_key = $key;
break;
}
}
}
if ($destination_cluster_key !== null) {
$clusters[$destination_cluster_key][] = $event;
} else {
$next_cluster = array();
$next_cluster[] = $event;
$clusters[] = $next_cluster;
}
}
return $clusters;
}
}
diff --git a/src/view/phui/calendar/PHUICalendarMonthView.php b/src/view/phui/calendar/PHUICalendarMonthView.php
index 5efa4c1059..d40736494e 100644
--- a/src/view/phui/calendar/PHUICalendarMonthView.php
+++ b/src/view/phui/calendar/PHUICalendarMonthView.php
@@ -1,598 +1,596 @@
<?php
final class PHUICalendarMonthView extends AphrontView {
private $rangeStart;
private $rangeEnd;
private $day;
private $month;
private $year;
private $events = array();
private $browseURI;
private $image;
private $error;
public function setBrowseURI($browse_uri) {
$this->browseURI = $browse_uri;
return $this;
}
private function getBrowseURI() {
return $this->browseURI;
}
public function addEvent(AphrontCalendarEventView $event) {
$this->events[] = $event;
return $this;
}
public function setImage($uri) {
$this->image = $uri;
return $this;
}
public function setInfoView(PHUIInfoView $error) {
$this->error = $error;
return $this;
}
public function __construct(
$range_start,
$range_end,
$month,
$year,
$day = null) {
$this->rangeStart = $range_start;
$this->rangeEnd = $range_end;
$this->day = $day;
$this->month = $month;
$this->year = $year;
}
public function render() {
- if (empty($this->user)) {
- throw new PhutilInvalidStateException('setUser');
- }
+ $viewer = $this->getViewer();
$events = msort($this->events, 'getEpochStart');
$days = $this->getDatesInMonth();
$cell_lists = array();
require_celerity_resource('phui-calendar-month-css');
foreach ($days as $day) {
$day_number = $day->format('j');
$class = 'phui-calendar-month-day';
$weekday = $day->format('w');
$day->setTime(0, 0, 0);
$day_start_epoch = $day->format('U');
$day_end_epoch = id(clone $day)->modify('+1 day')->format('U');
$list_events = array();
$all_day_events = array();
foreach ($events as $event) {
if ($event->getEpochStart() >= $day_end_epoch) {
break;
}
if ($event->getEpochStart() < $day_end_epoch &&
$event->getEpochEnd() > $day_start_epoch) {
if ($event->getIsAllDay()) {
$all_day_events[] = $event;
} else {
$list_events[] = $event;
}
}
}
$max_daily = 15;
$counter = 0;
$list = new PHUICalendarListView();
- $list->setUser($this->user);
+ $list->setViewer($viewer);
foreach ($all_day_events as $item) {
if ($counter <= $max_daily) {
$list->addEvent($item);
}
$counter++;
}
foreach ($list_events as $item) {
if ($counter <= $max_daily) {
$list->addEvent($item);
}
$counter++;
}
$uri = $this->getBrowseURI();
$uri = $uri.$day->format('Y').'/'.
$day->format('m').'/'.
$day->format('d').'/';
$cell_lists[] = array(
'list' => $list,
'date' => $day,
'uri' => $uri,
'count' => count($all_day_events) + count($list_events),
'class' => $class,
);
}
$rows = array();
$cell_lists_by_week = array_chunk($cell_lists, 7);
foreach ($cell_lists_by_week as $week_of_cell_lists) {
$cells = array();
$max_count = $this->getMaxDailyEventsForWeek($week_of_cell_lists);
foreach ($week_of_cell_lists as $cell_list) {
$cells[] = $this->getEventListCell($cell_list, $max_count);
}
$rows[] = phutil_tag('tr', array(), $cells);
$cells = array();
foreach ($week_of_cell_lists as $cell_list) {
$cells[] = $this->getDayNumberCell($cell_list);
}
$rows[] = phutil_tag('tr', array(), $cells);
}
$header = $this->getDayNamesHeader();
$table = phutil_tag(
'table',
array('class' => 'phui-calendar-view'),
array(
$header,
$rows,
));
$warnings = $this->getQueryRangeWarning();
$box = id(new PHUIObjectBoxView())
->setHeader($this->renderCalendarHeader($this->getDateTime()))
->appendChild($table)
->setFormErrors($warnings);
if ($this->error) {
$box->setInfoView($this->error);
}
return $box;
}
private function getMaxDailyEventsForWeek($week_of_cell_lists) {
$max_count = 0;
foreach ($week_of_cell_lists as $cell_list) {
if ($cell_list['count'] > $max_count) {
$max_count = $cell_list['count'];
}
}
return $max_count;
}
private function getEventListCell($event_list, $max_count = 0) {
$list = $event_list['list'];
$class = $event_list['class'];
$uri = $event_list['uri'];
$count = $event_list['count'];
$viewer_is_invited = $list->getIsViewerInvitedOnList();
$event_count_badge = $this->getEventCountBadge($count, $viewer_is_invited);
$cell_day_secret_link = $this->getHiddenDayLink($uri, $max_count, 125);
$cell_data_div = phutil_tag(
'div',
array(
'class' => 'phui-calendar-month-cell-div',
),
array(
$cell_day_secret_link,
$event_count_badge,
$list,
));
return phutil_tag(
'td',
array(
'class' => 'phui-calendar-month-event-list '.$class,
),
$cell_data_div);
}
private function getDayNumberCell($event_list) {
$class = $event_list['class'];
$date = $event_list['date'];
$cell_day_secret_link = null;
$week_number = null;
if ($date) {
$uri = $event_list['uri'];
$cell_day_secret_link = $this->getHiddenDayLink($uri, 0, 25);
$cell_day = phutil_tag(
'a',
array(
'class' => 'phui-calendar-date-number',
'href' => $uri,
),
$date->format('j'));
if ($date->format('w') == 1) {
$week_number = phutil_tag(
'a',
array(
'class' => 'phui-calendar-week-number',
'href' => $uri,
),
$date->format('W'));
}
} else {
$cell_day = null;
}
if ($date && $date->format('j') == $this->day &&
$date->format('m') == $this->month) {
$today_class = 'phui-calendar-today-slot phui-calendar-today';
} else {
$today_class = 'phui-calendar-today-slot';
}
if ($this->isDateInCurrentWeek($date)) {
$today_class .= ' phui-calendar-this-week';
}
$last_week_day = 6;
if ($date->format('w') == $last_week_day) {
$today_class .= ' last-weekday';
}
$today_slot = phutil_tag(
'div',
array(
'class' => $today_class,
),
null);
$cell_div = phutil_tag(
'div',
array(
'class' => 'phui-calendar-month-cell-div',
),
array(
$cell_day_secret_link,
$week_number,
$cell_day,
$today_slot,
));
return phutil_tag(
'td',
array(
'class' => 'phui-calendar-date-number-container '.$class,
),
$cell_div);
}
private function isDateInCurrentWeek($date) {
list($week_start_date, $week_end_date) = $this->getThisWeekRange();
if ($date->format('U') < $week_end_date->format('U') &&
$date->format('U') >= $week_start_date->format('U')) {
return true;
}
return false;
}
private function getEventCountBadge($count, $viewer_is_invited) {
$class = 'phui-calendar-month-count-badge';
if ($viewer_is_invited) {
$class = $class.' viewer-invited-day-badge';
}
$event_count = null;
if ($count > 0) {
$event_count = phutil_tag(
'div',
array(
'class' => $class,
),
$count);
}
return phutil_tag(
'div',
array(
'class' => 'phui-calendar-month-event-count',
),
$event_count);
}
private function getHiddenDayLink($uri, $count, $max_height) {
// approximately the height of the tallest cell
$height = 18 * $count + 5;
$height = ($height > $max_height) ? $height : $max_height;
$height_style = 'height: '.$height.'px';
return phutil_tag(
'a',
array(
'class' => 'phui-calendar-month-secret-link',
'style' => $height_style,
'href' => $uri,
),
null);
}
private function getDayNamesHeader() {
list($week_start, $week_end) = $this->getWeekStartAndEnd();
$weekday_names = array(
$this->getDayHeader(pht('Sun'), pht('Sunday'), true),
$this->getDayHeader(pht('Mon'), pht('Monday')),
$this->getDayHeader(pht('Tue'), pht('Tuesday')),
$this->getDayHeader(pht('Wed'), pht('Wednesday')),
$this->getDayHeader(pht('Thu'), pht('Thursday')),
$this->getDayHeader(pht('Fri'), pht('Friday')),
$this->getDayHeader(pht('Sat'), pht('Saturday'), true),
);
$sorted_weekday_names = array();
for ($i = $week_start; $i < ($week_start + 7); $i++) {
$sorted_weekday_names[] = $weekday_names[$i % 7];
}
return phutil_tag(
'tr',
array('class' => 'phui-calendar-day-of-week-header'),
$sorted_weekday_names);
}
private function getDayHeader($short, $long, $is_weekend = false) {
$class = null;
if ($is_weekend) {
$class = 'weekend-day-header';
}
$day = array();
$day[] = phutil_tag(
'span',
array(
'class' => 'long-weekday-name',
),
$long);
$day[] = phutil_tag(
'span',
array(
'class' => 'short-weekday-name',
),
$short);
return phutil_tag(
'th',
array(
'class' => $class,
),
$day);
}
private function renderCalendarHeader(DateTime $date) {
$button_bar = null;
// check for a browseURI, which means we need "fancy" prev / next UI
$uri = $this->getBrowseURI();
if ($uri) {
list($prev_year, $prev_month) = $this->getPrevYearAndMonth();
$prev_uri = $uri.$prev_year.'/'.$prev_month.'/';
list($next_year, $next_month) = $this->getNextYearAndMonth();
$next_uri = $uri.$next_year.'/'.$next_month.'/';
$button_bar = new PHUIButtonBarView();
$left_icon = id(new PHUIIconView())
->setIcon('fa-chevron-left bluegrey');
$left = id(new PHUIButtonView())
->setTag('a')
->setColor(PHUIButtonView::GREY)
->setHref($prev_uri)
->setTitle(pht('Previous Month'))
->setIcon($left_icon);
$right_icon = id(new PHUIIconView())
->setIcon('fa-chevron-right bluegrey');
$right = id(new PHUIButtonView())
->setTag('a')
->setColor(PHUIButtonView::GREY)
->setHref($next_uri)
->setTitle(pht('Next Month'))
->setIcon($right_icon);
$button_bar->addButton($left);
$button_bar->addButton($right);
}
$header = id(new PHUIHeaderView())
->setHeader($date->format('F Y'));
if ($button_bar) {
$header->setButtonBar($button_bar);
}
if ($this->image) {
$header->setImage($this->image);
}
return $header;
}
private function getQueryRangeWarning() {
$errors = array();
$range_start_epoch = null;
$range_end_epoch = null;
if ($this->rangeStart) {
$range_start_epoch = $this->rangeStart->getEpoch();
}
if ($this->rangeEnd) {
$range_end_epoch = $this->rangeEnd->getEpoch();
}
$month_start = $this->getDateTime();
$month_end = id(clone $month_start)->modify('+1 month');
$month_start = $month_start->format('U');
$month_end = $month_end->format('U') - 1;
if (($range_start_epoch != null &&
$range_start_epoch < $month_end &&
$range_start_epoch > $month_start) ||
($range_end_epoch != null &&
$range_end_epoch < $month_end &&
$range_end_epoch > $month_start)) {
$errors[] = pht('Part of the month is out of range');
}
if (($range_end_epoch != null &&
$range_end_epoch < $month_start) ||
($range_start_epoch != null &&
$range_start_epoch > $month_end)) {
$errors[] = pht('Month is out of query range');
}
return $errors;
}
private function getNextYearAndMonth() {
$next = $this->getDateTime();
$next->modify('+1 month');
return array(
$next->format('Y'),
$next->format('m'),
);
}
private function getPrevYearAndMonth() {
$prev = $this->getDateTime();
$prev->modify('-1 month');
return array(
$prev->format('Y'),
$prev->format('m'),
);
}
/**
* Return a DateTime object representing the first moment in each day in the
* month, according to the user's locale.
*
* @return list List of DateTimes, one for each day.
*/
private function getDatesInMonth() {
- $user = $this->user;
+ $viewer = $this->getViewer();
- $timezone = new DateTimeZone($user->getTimezoneIdentifier());
+ $timezone = new DateTimeZone($viewer->getTimezoneIdentifier());
$month = $this->month;
$year = $this->year;
list($next_year, $next_month) = $this->getNextYearAndMonth();
$end_date = new DateTime("{$next_year}-{$next_month}-01", $timezone);
list($start_of_week, $end_of_week) = $this->getWeekStartAndEnd();
$days_in_month = id(clone $end_date)->modify('-1 day')->format('d');
$first_month_day_date = new DateTime("{$year}-{$month}-01", $timezone);
$last_month_day_date = id(clone $end_date)->modify('-1 day');
$first_weekday_of_month = $first_month_day_date->format('w');
$last_weekday_of_month = $last_month_day_date->format('w');
$day_date = id(clone $first_month_day_date);
$num_days_display = $days_in_month;
if ($start_of_week !== $first_weekday_of_month) {
$interim_start_num = ($first_weekday_of_month + 7 - $start_of_week) % 7;
$num_days_display += $interim_start_num;
$day_date->modify('-'.$interim_start_num.' days');
}
if ($end_of_week !== $last_weekday_of_month) {
$interim_end_day_num = ($end_of_week - $last_weekday_of_month + 7) % 7;
$num_days_display += $interim_end_day_num;
$end_date->modify('+'.$interim_end_day_num.' days');
}
$days = array();
for ($day = 1; $day <= $num_days_display; $day++) {
$day_epoch = $day_date->format('U');
$end_epoch = $end_date->format('U');
if ($day_epoch >= $end_epoch) {
break;
} else {
$days[] = clone $day_date;
}
$day_date->modify('+1 day');
}
return $days;
}
private function getTodayMidnight() {
$viewer = $this->getUser();
$today = new DateTime('@'.time());
$today->setTimeZone($viewer->getTimeZone());
$today->setTime(0, 0, 0);
return $today;
}
private function getThisWeekRange() {
list($week_start, $week_end) = $this->getWeekStartAndEnd();
$today = $this->getTodayMidnight();
$date_weekday = $today->format('w');
$days_from_week_start = ($date_weekday + 7 - $week_start) % 7;
$days_to_week_end = 7 - $days_from_week_start;
$modify = '-'.$days_from_week_start.' days';
$week_start_date = id(clone $today)->modify($modify);
$modify = '+'.$days_to_week_end.' days';
$week_end_date = id(clone $today)->modify($modify);
return array($week_start_date, $week_end_date);
}
private function getWeekStartAndEnd() {
- $preferences = $this->user->loadPreferences();
+ $preferences = $this->getViewer()->loadPreferences();
$pref_week_start = PhabricatorUserPreferences::PREFERENCE_WEEK_START_DAY;
$week_start = $preferences->getPreference($pref_week_start, 0);
$week_end = ($week_start + 6) % 7;
return array($week_start, $week_end);
}
private function getDateTime() {
- $user = $this->user;
+ $user = $this->getViewer();
$timezone = new DateTimeZone($user->getTimezoneIdentifier());
$month = $this->month;
$year = $this->year;
$date = new DateTime("{$year}-{$month}-01 ", $timezone);
return $date;
}
}

File Metadata

Mime Type
text/x-diff
Expires
Mon, Dec 1, 2:59 PM (1 d, 12 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
430638
Default Alt Text
(166 KB)

Event Timeline