mirror of
https://we.phorge.it/source/phorge.git
synced 2025-01-18 02:31:10 +01:00
Give AphrontTagView a getViewer()
, deprecate getUser()
Summary: Two minor changes here: - Replace `get/setUser()` with `get/setViewer()` for consistency with everything else. - `getViewer()` now throws if no viewer is set. We had a lot of code that either "should" check this but didn't, or did check it in an identical way, duplicating work. In contrast, very little code checks for a viewer but works if one is not present. Test Plan: - Grepped for `->user`. - Attempted to fix all callsites inside `*View` classes. - Browsed around a bunch of applications, particularly Calendar, Differential and Diffusion, which seemed most heavily affected. Reviewers: chad Reviewed By: chad Differential Revision: https://secure.phabricator.com/D15412
This commit is contained in:
parent
abb4c03b47
commit
aaab1011e5
27 changed files with 134 additions and 126 deletions
|
@ -16,8 +16,7 @@ final class PhabricatorBadgesRecipientsListView extends AphrontView {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function render() {
|
public function render() {
|
||||||
|
$viewer = $this->getViewer();
|
||||||
$viewer = $this->user;
|
|
||||||
|
|
||||||
$badge = $this->badge;
|
$badge = $this->badge;
|
||||||
$handles = $this->handles;
|
$handles = $this->handles;
|
||||||
|
|
|
@ -24,12 +24,9 @@ final class PhabricatorDaemonLogEventsView extends AphrontView {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function render() {
|
public function render() {
|
||||||
|
$viewer = $this->getViewer();
|
||||||
$rows = array();
|
$rows = array();
|
||||||
|
|
||||||
if (!$this->user) {
|
|
||||||
throw new PhutilInvalidStateException('setUser');
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach ($this->events as $event) {
|
foreach ($this->events as $event) {
|
||||||
|
|
||||||
// Limit display log size. If a daemon gets stuck in an output loop this
|
// Limit display log size. If a daemon gets stuck in an output loop this
|
||||||
|
@ -83,8 +80,8 @@ final class PhabricatorDaemonLogEventsView extends AphrontView {
|
||||||
|
|
||||||
$row = array(
|
$row = array(
|
||||||
$event->getLogType(),
|
$event->getLogType(),
|
||||||
phabricator_date($event->getEpoch(), $this->user),
|
phabricator_date($event->getEpoch(), $viewer),
|
||||||
phabricator_time($event->getEpoch(), $this->user),
|
phabricator_time($event->getEpoch(), $viewer),
|
||||||
array(
|
array(
|
||||||
$message,
|
$message,
|
||||||
$more,
|
$more,
|
||||||
|
|
|
@ -11,11 +11,9 @@ final class PhabricatorDaemonLogListView extends AphrontView {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function render() {
|
public function render() {
|
||||||
$rows = array();
|
$viewer = $this->getViewer();
|
||||||
|
|
||||||
if (!$this->user) {
|
$rows = array();
|
||||||
throw new PhutilInvalidStateException('setUser');
|
|
||||||
}
|
|
||||||
|
|
||||||
$list = new PHUIObjectItemListView();
|
$list = new PHUIObjectItemListView();
|
||||||
$list->setFlush(true);
|
$list->setFlush(true);
|
||||||
|
@ -27,7 +25,7 @@ final class PhabricatorDaemonLogListView extends AphrontView {
|
||||||
->setObjectName(pht('Daemon %s', $id))
|
->setObjectName(pht('Daemon %s', $id))
|
||||||
->setHeader($log->getDaemon())
|
->setHeader($log->getDaemon())
|
||||||
->setHref("/daemon/log/{$id}/")
|
->setHref("/daemon/log/{$id}/")
|
||||||
->addIcon('none', phabricator_datetime($epoch, $this->user));
|
->addIcon('none', phabricator_datetime($epoch, $viewer));
|
||||||
|
|
||||||
$status = $log->getStatus();
|
$status = $log->getStatus();
|
||||||
switch ($status) {
|
switch ($status) {
|
||||||
|
|
|
@ -50,6 +50,7 @@ final class DifferentialAddCommentView extends AphrontView {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function render() {
|
public function render() {
|
||||||
|
$viewer = $this->getViewer();
|
||||||
|
|
||||||
$this->requireResource('differential-revision-add-comment-css');
|
$this->requireResource('differential-revision-add-comment-css');
|
||||||
$revision = $this->revision;
|
$revision = $this->revision;
|
||||||
|
@ -73,7 +74,7 @@ final class DifferentialAddCommentView extends AphrontView {
|
||||||
$form = new AphrontFormView();
|
$form = new AphrontFormView();
|
||||||
$form
|
$form
|
||||||
->setWorkflow(true)
|
->setWorkflow(true)
|
||||||
->setUser($this->user)
|
->setViewer($viewer)
|
||||||
->setAction($this->actionURI)
|
->setAction($this->actionURI)
|
||||||
->addHiddenInput('revision_id', $revision->getID())
|
->addHiddenInput('revision_id', $revision->getID())
|
||||||
->appendChild(
|
->appendChild(
|
||||||
|
@ -108,7 +109,7 @@ final class DifferentialAddCommentView extends AphrontView {
|
||||||
->setID('comment-content')
|
->setID('comment-content')
|
||||||
->setLabel(pht('Comment'))
|
->setLabel(pht('Comment'))
|
||||||
->setValue($this->draft ? $this->draft->getDraft() : null)
|
->setValue($this->draft ? $this->draft->getDraft() : null)
|
||||||
->setUser($this->user))
|
->setViewer($viewer))
|
||||||
->appendChild(
|
->appendChild(
|
||||||
id(new AphrontFormSubmitControl())
|
id(new AphrontFormSubmitControl())
|
||||||
->setValue(pht('Submit')));
|
->setValue(pht('Submit')));
|
||||||
|
|
|
@ -113,6 +113,8 @@ final class DifferentialChangesetListView extends AphrontView {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function render() {
|
public function render() {
|
||||||
|
$viewer = $this->getViewer();
|
||||||
|
|
||||||
$this->requireResource('differential-changeset-view-css');
|
$this->requireResource('differential-changeset-view-css');
|
||||||
|
|
||||||
$changesets = $this->changesets;
|
$changesets = $this->changesets;
|
||||||
|
@ -148,7 +150,7 @@ final class DifferentialChangesetListView extends AphrontView {
|
||||||
));
|
));
|
||||||
|
|
||||||
$renderer = DifferentialChangesetParser::getDefaultRendererForViewer(
|
$renderer = DifferentialChangesetParser::getDefaultRendererForViewer(
|
||||||
$this->getUser());
|
$viewer);
|
||||||
|
|
||||||
$output = array();
|
$output = array();
|
||||||
$ids = array();
|
$ids = array();
|
||||||
|
@ -163,7 +165,7 @@ final class DifferentialChangesetListView extends AphrontView {
|
||||||
$ref = $this->references[$key];
|
$ref = $this->references[$key];
|
||||||
|
|
||||||
$detail = id(new DifferentialChangesetDetailView())
|
$detail = id(new DifferentialChangesetDetailView())
|
||||||
->setUser($this->getUser());
|
->setUser($viewer);
|
||||||
|
|
||||||
$uniq_id = 'diff-'.$changeset->getAnchorName();
|
$uniq_id = 'diff-'.$changeset->getAnchorName();
|
||||||
$detail->setID($uniq_id);
|
$detail->setID($uniq_id);
|
||||||
|
@ -261,6 +263,7 @@ final class DifferentialChangesetListView extends AphrontView {
|
||||||
DifferentialChangesetDetailView $detail,
|
DifferentialChangesetDetailView $detail,
|
||||||
$ref,
|
$ref,
|
||||||
DifferentialChangeset $changeset) {
|
DifferentialChangeset $changeset) {
|
||||||
|
$viewer = $this->getViewer();
|
||||||
|
|
||||||
$meta = array();
|
$meta = array();
|
||||||
|
|
||||||
|
@ -280,7 +283,7 @@ final class DifferentialChangesetListView extends AphrontView {
|
||||||
try {
|
try {
|
||||||
$meta['diffusionURI'] =
|
$meta['diffusionURI'] =
|
||||||
(string)$repository->getDiffusionBrowseURIForPath(
|
(string)$repository->getDiffusionBrowseURIForPath(
|
||||||
$this->user,
|
$viewer,
|
||||||
$changeset->getAbsoluteRepositoryPath($repository, $this->diff),
|
$changeset->getAbsoluteRepositoryPath($repository, $this->diff),
|
||||||
idx($changeset->getMetadata(), 'line:first'),
|
idx($changeset->getMetadata(), 'line:first'),
|
||||||
$this->getBranch());
|
$this->getBranch());
|
||||||
|
@ -308,13 +311,12 @@ final class DifferentialChangesetListView extends AphrontView {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$user = $this->user;
|
if ($viewer && $repository) {
|
||||||
if ($user && $repository) {
|
|
||||||
$path = ltrim(
|
$path = ltrim(
|
||||||
$changeset->getAbsoluteRepositoryPath($repository, $this->diff),
|
$changeset->getAbsoluteRepositoryPath($repository, $this->diff),
|
||||||
'/');
|
'/');
|
||||||
$line = idx($changeset->getMetadata(), 'line:first', 1);
|
$line = idx($changeset->getMetadata(), 'line:first', 1);
|
||||||
$editor_link = $user->loadEditorLink($path, $line, $repository);
|
$editor_link = $viewer->loadEditorLink($path, $line, $repository);
|
||||||
if ($editor_link) {
|
if ($editor_link) {
|
||||||
$meta['editor'] = $editor_link;
|
$meta['editor'] = $editor_link;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -17,10 +17,7 @@ final class DifferentialLocalCommitsView extends AphrontView {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function render() {
|
public function render() {
|
||||||
$user = $this->user;
|
$viewer = $this->getViewer();
|
||||||
if (!$user) {
|
|
||||||
throw new PhutilInvalidStateException('setUser');
|
|
||||||
}
|
|
||||||
|
|
||||||
$local = $this->localCommits;
|
$local = $this->localCommits;
|
||||||
if (!$local) {
|
if (!$local) {
|
||||||
|
@ -94,7 +91,7 @@ final class DifferentialLocalCommitsView extends AphrontView {
|
||||||
idx($commit, 'date'),
|
idx($commit, 'date'),
|
||||||
idx($commit, 'time'));
|
idx($commit, 'time'));
|
||||||
if ($date) {
|
if ($date) {
|
||||||
$date = phabricator_datetime($date, $user);
|
$date = phabricator_datetime($date, $viewer);
|
||||||
}
|
}
|
||||||
$row[] = $date;
|
$row[] = $date;
|
||||||
|
|
||||||
|
|
|
@ -57,10 +57,7 @@ final class DifferentialRevisionListView extends AphrontView {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function render() {
|
public function render() {
|
||||||
$user = $this->user;
|
$viewer = $this->getViewer();
|
||||||
if (!$user) {
|
|
||||||
throw new PhutilInvalidStateException('setUser');
|
|
||||||
}
|
|
||||||
|
|
||||||
$fresh = PhabricatorEnv::getEnvConfig('differential.days-fresh');
|
$fresh = PhabricatorEnv::getEnvConfig('differential.days-fresh');
|
||||||
if ($fresh) {
|
if ($fresh) {
|
||||||
|
@ -83,12 +80,12 @@ final class DifferentialRevisionListView extends AphrontView {
|
||||||
|
|
||||||
foreach ($this->revisions as $revision) {
|
foreach ($this->revisions as $revision) {
|
||||||
$item = id(new PHUIObjectItemView())
|
$item = id(new PHUIObjectItemView())
|
||||||
->setUser($user);
|
->setUser($viewer);
|
||||||
|
|
||||||
$icons = array();
|
$icons = array();
|
||||||
|
|
||||||
$phid = $revision->getPHID();
|
$phid = $revision->getPHID();
|
||||||
$flag = $revision->getFlag($user);
|
$flag = $revision->getFlag($viewer);
|
||||||
if ($flag) {
|
if ($flag) {
|
||||||
$flag_class = PhabricatorFlagColor::getCSSClass($flag->getColor());
|
$flag_class = PhabricatorFlagColor::getCSSClass($flag->getColor());
|
||||||
$icons['flag'] = phutil_tag(
|
$icons['flag'] = phutil_tag(
|
||||||
|
@ -99,7 +96,7 @@ final class DifferentialRevisionListView extends AphrontView {
|
||||||
'');
|
'');
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($revision->getDrafts($user)) {
|
if ($revision->getDrafts($viewer)) {
|
||||||
$icons['draft'] = true;
|
$icons['draft'] = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -100,7 +100,7 @@ final class DiffusionTagListView extends DiffusionView {
|
||||||
$build,
|
$build,
|
||||||
$author,
|
$author,
|
||||||
$description,
|
$description,
|
||||||
phabricator_datetime($tag->getEpoch(), $this->user),
|
phabricator_datetime($tag->getEpoch(), $this->getViewer()),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
final class PhameBlogListView extends AphrontTagView {
|
final class PhameBlogListView extends AphrontTagView {
|
||||||
|
|
||||||
private $blogs;
|
private $blogs;
|
||||||
private $viewer;
|
|
||||||
|
|
||||||
public function setBlogs($blogs) {
|
public function setBlogs($blogs) {
|
||||||
assert_instances_of($blogs, 'PhameBlog');
|
assert_instances_of($blogs, 'PhameBlog');
|
||||||
|
@ -11,11 +10,6 @@ final class PhameBlogListView extends AphrontTagView {
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setViewer($viewer) {
|
|
||||||
$this->viewer = $viewer;
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function getTagAttributes() {
|
protected function getTagAttributes() {
|
||||||
$classes = array();
|
$classes = array();
|
||||||
$classes[] = 'phame-blog-list';
|
$classes[] = 'phame-blog-list';
|
||||||
|
|
|
@ -4,7 +4,6 @@ final class PhameDraftListView extends AphrontTagView {
|
||||||
|
|
||||||
private $posts;
|
private $posts;
|
||||||
private $blogs;
|
private $blogs;
|
||||||
private $viewer;
|
|
||||||
|
|
||||||
public function setPosts($posts) {
|
public function setPosts($posts) {
|
||||||
assert_instances_of($posts, 'PhamePost');
|
assert_instances_of($posts, 'PhamePost');
|
||||||
|
@ -18,11 +17,6 @@ final class PhameDraftListView extends AphrontTagView {
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setViewer($viewer) {
|
|
||||||
$this->viewer = $viewer;
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function getTagAttributes() {
|
protected function getTagAttributes() {
|
||||||
$classes = array();
|
$classes = array();
|
||||||
$classes[] = 'phame-blog-list';
|
$classes[] = 'phame-blog-list';
|
||||||
|
|
|
@ -4,7 +4,6 @@ final class PhamePostListView extends AphrontTagView {
|
||||||
|
|
||||||
private $posts;
|
private $posts;
|
||||||
private $nodata;
|
private $nodata;
|
||||||
private $viewer;
|
|
||||||
private $showBlog = false;
|
private $showBlog = false;
|
||||||
private $isExternal;
|
private $isExternal;
|
||||||
private $isLive;
|
private $isLive;
|
||||||
|
@ -25,11 +24,6 @@ final class PhamePostListView extends AphrontTagView {
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setViewer($viewer) {
|
|
||||||
$this->viewer = $viewer;
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setIsExternal($is_external) {
|
public function setIsExternal($is_external) {
|
||||||
$this->isExternal = $is_external;
|
$this->isExternal = $is_external;
|
||||||
return $this;
|
return $this;
|
||||||
|
@ -53,7 +47,7 @@ final class PhamePostListView extends AphrontTagView {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getTagContent() {
|
protected function getTagContent() {
|
||||||
$viewer = $this->viewer;
|
$viewer = $this->getViewer();
|
||||||
$posts = $this->posts;
|
$posts = $this->posts;
|
||||||
$nodata = $this->nodata;
|
$nodata = $this->nodata;
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,7 @@ final class PonderAddAnswerView extends AphrontView {
|
||||||
|
|
||||||
public function render() {
|
public function render() {
|
||||||
$question = $this->question;
|
$question = $this->question;
|
||||||
$viewer = $this->user;
|
$viewer = $this->getViewer();
|
||||||
|
|
||||||
$authors = mpull($question->getAnswers(), null, 'getAuthorPHID');
|
$authors = mpull($question->getAnswers(), null, 'getAuthorPHID');
|
||||||
if (isset($authors[$viewer->getPHID()])) {
|
if (isset($authors[$viewer->getPHID()])) {
|
||||||
|
@ -49,7 +49,7 @@ final class PonderAddAnswerView extends AphrontView {
|
||||||
|
|
||||||
$form = new AphrontFormView();
|
$form = new AphrontFormView();
|
||||||
$form
|
$form
|
||||||
->setUser($this->user)
|
->setViewer($viewer)
|
||||||
->setAction($this->actionURI)
|
->setAction($this->actionURI)
|
||||||
->setWorkflow(true)
|
->setWorkflow(true)
|
||||||
->addHiddenInput('question_id', $question->getID())
|
->addHiddenInput('question_id', $question->getID())
|
||||||
|
@ -59,7 +59,7 @@ final class PonderAddAnswerView extends AphrontView {
|
||||||
->setLabel(pht('Answer'))
|
->setLabel(pht('Answer'))
|
||||||
->setError(true)
|
->setError(true)
|
||||||
->setID('answer-content')
|
->setID('answer-content')
|
||||||
->setUser($this->user))
|
->setViewer($viewer))
|
||||||
->appendChild(
|
->appendChild(
|
||||||
id(new AphrontFormSubmitControl())
|
id(new AphrontFormSubmitControl())
|
||||||
->setValue(pht('Add Answer')));
|
->setValue(pht('Add Answer')));
|
||||||
|
|
|
@ -45,7 +45,7 @@ abstract class PhabricatorProjectUserListView extends AphrontView {
|
||||||
abstract protected function getHeaderText();
|
abstract protected function getHeaderText();
|
||||||
|
|
||||||
public function render() {
|
public function render() {
|
||||||
$viewer = $this->getUser();
|
$viewer = $this->getViewer();
|
||||||
$project = $this->getProject();
|
$project = $this->getProject();
|
||||||
$user_phids = $this->getUserPHIDs();
|
$user_phids = $this->getUserPHIDs();
|
||||||
|
|
||||||
|
|
|
@ -78,12 +78,11 @@ final class PHUIDiffInlineCommentEditView
|
||||||
if (!$this->uri) {
|
if (!$this->uri) {
|
||||||
throw new PhutilInvalidStateException('setSubmitURI');
|
throw new PhutilInvalidStateException('setSubmitURI');
|
||||||
}
|
}
|
||||||
if (!$this->user) {
|
|
||||||
throw new PhutilInvalidStateException('setUser');
|
$viewer = $this->getViewer();
|
||||||
}
|
|
||||||
|
|
||||||
$content = phabricator_form(
|
$content = phabricator_form(
|
||||||
$this->user,
|
$viewer,
|
||||||
array(
|
array(
|
||||||
'action' => $this->uri,
|
'action' => $this->uri,
|
||||||
'method' => 'POST',
|
'method' => 'POST',
|
||||||
|
|
|
@ -236,11 +236,11 @@ final class AphrontDialogView
|
||||||
$this->cancelText);
|
$this->cancelText);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$this->user) {
|
if (!$this->hasViewer()) {
|
||||||
throw new Exception(
|
throw new Exception(
|
||||||
pht(
|
pht(
|
||||||
'You must call %s when rendering an %s.',
|
'You must call %s when rendering an %s.',
|
||||||
'setUser()',
|
'setViewer()',
|
||||||
__CLASS__));
|
__CLASS__));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -308,7 +308,7 @@ final class AphrontDialogView
|
||||||
if (!$this->renderAsForm) {
|
if (!$this->renderAsForm) {
|
||||||
$buttons = array(
|
$buttons = array(
|
||||||
phabricator_form(
|
phabricator_form(
|
||||||
$this->user,
|
$this->getViewer(),
|
||||||
$form_attributes,
|
$form_attributes,
|
||||||
array_merge($hidden_inputs, $buttons)),
|
array_merge($hidden_inputs, $buttons)),
|
||||||
);
|
);
|
||||||
|
@ -376,7 +376,7 @@ final class AphrontDialogView
|
||||||
|
|
||||||
if ($this->renderAsForm) {
|
if ($this->renderAsForm) {
|
||||||
return phabricator_form(
|
return phabricator_form(
|
||||||
$this->user,
|
$this->getViewer(),
|
||||||
$form_attributes + $attributes,
|
$form_attributes + $attributes,
|
||||||
array($hidden_inputs, $content));
|
array($hidden_inputs, $content));
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
abstract class AphrontView extends Phobject
|
abstract class AphrontView extends Phobject
|
||||||
implements PhutilSafeHTMLProducerInterface {
|
implements PhutilSafeHTMLProducerInterface {
|
||||||
|
|
||||||
protected $user;
|
private $viewer;
|
||||||
protected $children = array();
|
protected $children = array();
|
||||||
|
|
||||||
|
|
||||||
|
@ -14,19 +14,65 @@ abstract class AphrontView extends Phobject
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @task config
|
* Set the user viewing this element.
|
||||||
|
*
|
||||||
|
* @param PhabricatorUser Viewing user.
|
||||||
|
* @return this
|
||||||
*/
|
*/
|
||||||
public function setUser(PhabricatorUser $user) {
|
public function setViewer(PhabricatorUser $viewer) {
|
||||||
$this->user = $user;
|
$this->viewer = $viewer;
|
||||||
return $this;
|
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
|
* @task config
|
||||||
|
* @deprecated
|
||||||
|
*/
|
||||||
|
public function setUser(PhabricatorUser $user) {
|
||||||
|
return $this->setViewer($user);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deprecated, use @{method:getViewer}.
|
||||||
|
*
|
||||||
|
* @task config
|
||||||
|
* @deprecated
|
||||||
*/
|
*/
|
||||||
protected function getUser() {
|
protected function getUser() {
|
||||||
return $this->user;
|
if (!$this->hasViewer()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return $this->getViewer();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -85,13 +85,13 @@ final class AphrontFormView extends AphrontView {
|
||||||
|
|
||||||
public function appendRemarkupInstructions($remarkup) {
|
public function appendRemarkupInstructions($remarkup) {
|
||||||
return $this->appendInstructions(
|
return $this->appendInstructions(
|
||||||
new PHUIRemarkupView($this->getUser(), $remarkup));
|
new PHUIRemarkupView($this->getViewer(), $remarkup));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function buildLayoutView() {
|
public function buildLayoutView() {
|
||||||
foreach ($this->controls as $control) {
|
foreach ($this->controls as $control) {
|
||||||
$control->setUser($this->getUser());
|
$control->setViewer($this->getViewer());
|
||||||
$control->willRender();
|
$control->willRender();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -123,7 +123,7 @@ final class AphrontFormView extends AphrontView {
|
||||||
|
|
||||||
$layout = $this->buildLayoutView();
|
$layout = $this->buildLayoutView();
|
||||||
|
|
||||||
if (!$this->user) {
|
if (!$this->hasViewer()) {
|
||||||
throw new Exception(
|
throw new Exception(
|
||||||
pht(
|
pht(
|
||||||
'You must pass the user to %s.',
|
'You must pass the user to %s.',
|
||||||
|
@ -136,7 +136,7 @@ final class AphrontFormView extends AphrontView {
|
||||||
}
|
}
|
||||||
|
|
||||||
return phabricator_form(
|
return phabricator_form(
|
||||||
$this->user,
|
$this->getViewer(),
|
||||||
array(
|
array(
|
||||||
'class' => $this->shaded ? 'phui-form-shaded' : null,
|
'class' => $this->shaded ? 'phui-form-shaded' : null,
|
||||||
'action' => $this->action,
|
'action' => $this->action,
|
||||||
|
|
|
@ -137,12 +137,12 @@ final class AphrontFormDateControl extends AphrontFormControl {
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getTimeFormat() {
|
private function getTimeFormat() {
|
||||||
return $this->getUser()
|
return $this->getViewer()
|
||||||
->getPreference(PhabricatorUserPreferences::PREFERENCE_TIME_FORMAT);
|
->getPreference(PhabricatorUserPreferences::PREFERENCE_TIME_FORMAT);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getDateFormat() {
|
private function getDateFormat() {
|
||||||
return $this->getUser()
|
return $this->getViewer()
|
||||||
->getPreference(PhabricatorUserPreferences::PREFERENCE_DATE_FORMAT);
|
->getPreference(PhabricatorUserPreferences::PREFERENCE_DATE_FORMAT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -153,7 +153,7 @@ final class AphrontFormDateControl extends AphrontFormControl {
|
||||||
private function formatTime($epoch, $fmt) {
|
private function formatTime($epoch, $fmt) {
|
||||||
return phabricator_format_local_time(
|
return phabricator_format_local_time(
|
||||||
$epoch,
|
$epoch,
|
||||||
$this->user,
|
$this->getViewer(),
|
||||||
$fmt);
|
$fmt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -259,7 +259,7 @@ final class AphrontFormDateControl extends AphrontFormControl {
|
||||||
),
|
),
|
||||||
$time_sel);
|
$time_sel);
|
||||||
|
|
||||||
$preferences = $this->user->loadPreferences();
|
$preferences = $this->getViewer()->loadPreferences();
|
||||||
$pref_week_start = PhabricatorUserPreferences::PREFERENCE_WEEK_START_DAY;
|
$pref_week_start = PhabricatorUserPreferences::PREFERENCE_WEEK_START_DAY;
|
||||||
$week_start = $preferences->getPreference($pref_week_start, 0);
|
$week_start = $preferences->getPreference($pref_week_start, 0);
|
||||||
|
|
||||||
|
@ -300,12 +300,9 @@ final class AphrontFormDateControl extends AphrontFormControl {
|
||||||
return $this->zone;
|
return $this->zone;
|
||||||
}
|
}
|
||||||
|
|
||||||
$user = $this->getUser();
|
$viewer = $this->getViewer();
|
||||||
if (!$this->getUser()) {
|
|
||||||
throw new PhutilInvalidStateException('setUser');
|
|
||||||
}
|
|
||||||
|
|
||||||
$user_zone = $user->getTimezoneIdentifier();
|
$user_zone = $viewer->getTimezoneIdentifier();
|
||||||
$this->zone = new DateTimeZone($user_zone);
|
$this->zone = new DateTimeZone($user_zone);
|
||||||
return $this->zone;
|
return $this->zone;
|
||||||
}
|
}
|
||||||
|
|
|
@ -90,8 +90,8 @@ final class AphrontFormTokenizerControl extends AphrontFormControl {
|
||||||
}
|
}
|
||||||
|
|
||||||
$username = null;
|
$username = null;
|
||||||
if ($this->user) {
|
if ($this->hasViewer()) {
|
||||||
$username = $this->user->getUsername();
|
$username = $this->getViewer()->getUsername();
|
||||||
}
|
}
|
||||||
|
|
||||||
$datasource_uri = $datasource->getDatasourceURI();
|
$datasource_uri = $datasource->getDatasourceURI();
|
||||||
|
|
|
@ -199,9 +199,6 @@ final class AphrontSideNavFilterView extends AphrontView {
|
||||||
}
|
}
|
||||||
|
|
||||||
private function renderFlexNav() {
|
private function renderFlexNav() {
|
||||||
|
|
||||||
$user = $this->user;
|
|
||||||
|
|
||||||
require_celerity_resource('phabricator-nav-view-css');
|
require_celerity_resource('phabricator-nav-view-css');
|
||||||
|
|
||||||
$nav_classes = array();
|
$nav_classes = array();
|
||||||
|
|
|
@ -22,9 +22,7 @@ final class PhabricatorActionListView extends AphrontView {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function render() {
|
public function render() {
|
||||||
if (!$this->user) {
|
$viewer = $this->getViewer();
|
||||||
throw new PhutilInvalidStateException('setUser');
|
|
||||||
}
|
|
||||||
|
|
||||||
$event = new PhabricatorEvent(
|
$event = new PhabricatorEvent(
|
||||||
PhabricatorEventType::TYPE_UI_DIDRENDERACTIONS,
|
PhabricatorEventType::TYPE_UI_DIDRENDERACTIONS,
|
||||||
|
@ -32,7 +30,7 @@ final class PhabricatorActionListView extends AphrontView {
|
||||||
'object' => $this->object,
|
'object' => $this->object,
|
||||||
'actions' => $this->actions,
|
'actions' => $this->actions,
|
||||||
));
|
));
|
||||||
$event->setUser($this->user);
|
$event->setUser($viewer);
|
||||||
PhutilEventEngine::dispatchEvent($event);
|
PhutilEventEngine::dispatchEvent($event);
|
||||||
|
|
||||||
$actions = $event->getValue('actions');
|
$actions = $event->getValue('actions');
|
||||||
|
@ -41,7 +39,7 @@ final class PhabricatorActionListView extends AphrontView {
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($actions as $action) {
|
foreach ($actions as $action) {
|
||||||
$action->setUser($this->user);
|
$action->setViewer($viewer);
|
||||||
}
|
}
|
||||||
|
|
||||||
require_celerity_resource('phabricator-action-list-view-css');
|
require_celerity_resource('phabricator-action-list-view-css');
|
||||||
|
|
|
@ -125,11 +125,11 @@ final class PhabricatorActionView extends AphrontView {
|
||||||
$sigils = $sigils ? implode(' ', $sigils) : null;
|
$sigils = $sigils ? implode(' ', $sigils) : null;
|
||||||
|
|
||||||
if ($this->renderAsForm) {
|
if ($this->renderAsForm) {
|
||||||
if (!$this->user) {
|
if (!$this->hasViewer()) {
|
||||||
throw new Exception(
|
throw new Exception(
|
||||||
pht(
|
pht(
|
||||||
'Call %s when rendering an action as a form.',
|
'Call %s when rendering an action as a form.',
|
||||||
'setUser()'));
|
'setViewer()'));
|
||||||
}
|
}
|
||||||
|
|
||||||
$item = javelin_tag(
|
$item = javelin_tag(
|
||||||
|
@ -140,7 +140,7 @@ final class PhabricatorActionView extends AphrontView {
|
||||||
array($icon, $this->name));
|
array($icon, $this->name));
|
||||||
|
|
||||||
$item = phabricator_form(
|
$item = phabricator_form(
|
||||||
$this->user,
|
$this->getViewer(),
|
||||||
array(
|
array(
|
||||||
'action' => $this->getHref(),
|
'action' => $this->getHref(),
|
||||||
'method' => 'POST',
|
'method' => 'POST',
|
||||||
|
|
|
@ -24,7 +24,7 @@ final class PhabricatorMainMenuSearchView extends AphrontView {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function render() {
|
public function render() {
|
||||||
$user = $this->user;
|
$viewer = $this->getViewer();
|
||||||
|
|
||||||
$target_id = celerity_generate_unique_node_id();
|
$target_id = celerity_generate_unique_node_id();
|
||||||
$search_id = $this->getID();
|
$search_id = $this->getID();
|
||||||
|
@ -86,7 +86,7 @@ final class PhabricatorMainMenuSearchView extends AphrontView {
|
||||||
$selector = $this->buildModeSelector($selector_id, $application_id);
|
$selector = $this->buildModeSelector($selector_id, $application_id);
|
||||||
|
|
||||||
$form = phabricator_form(
|
$form = phabricator_form(
|
||||||
$user,
|
$viewer,
|
||||||
array(
|
array(
|
||||||
'action' => '/search/',
|
'action' => '/search/',
|
||||||
'method' => 'POST',
|
'method' => 'POST',
|
||||||
|
@ -109,7 +109,7 @@ final class PhabricatorMainMenuSearchView extends AphrontView {
|
||||||
}
|
}
|
||||||
|
|
||||||
private function buildModeSelector($selector_id, $application_id) {
|
private function buildModeSelector($selector_id, $application_id) {
|
||||||
$viewer = $this->getUser();
|
$viewer = $this->getViewer();
|
||||||
|
|
||||||
$items = array();
|
$items = array();
|
||||||
$items[] = array(
|
$items[] = array(
|
||||||
|
|
|
@ -24,7 +24,7 @@ final class PhabricatorMainMenuView extends AphrontView {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function render() {
|
public function render() {
|
||||||
$user = $this->user;
|
$viewer = $this->getViewer();
|
||||||
|
|
||||||
require_celerity_resource('phabricator-main-menu-view');
|
require_celerity_resource('phabricator-main-menu-view');
|
||||||
|
|
||||||
|
@ -35,7 +35,7 @@ final class PhabricatorMainMenuView extends AphrontView {
|
||||||
$app_button = '';
|
$app_button = '';
|
||||||
$aural = null;
|
$aural = null;
|
||||||
|
|
||||||
if ($user->isLoggedIn() && $user->isUserActivated()) {
|
if ($viewer->isLoggedIn() && $viewer->isUserActivated()) {
|
||||||
list($menu, $dropdowns, $aural) = $this->renderNotificationMenu();
|
list($menu, $dropdowns, $aural) = $this->renderNotificationMenu();
|
||||||
if (array_filter($menu)) {
|
if (array_filter($menu)) {
|
||||||
$alerts[] = $menu;
|
$alerts[] = $menu;
|
||||||
|
@ -77,10 +77,10 @@ final class PhabricatorMainMenuView extends AphrontView {
|
||||||
$controller = $this->getController();
|
$controller = $this->getController();
|
||||||
foreach ($applications as $application) {
|
foreach ($applications as $application) {
|
||||||
$app_actions = $application->buildMainMenuItems(
|
$app_actions = $application->buildMainMenuItems(
|
||||||
$user,
|
$viewer,
|
||||||
$controller);
|
$controller);
|
||||||
$app_extra = $application->buildMainMenuExtraNodes(
|
$app_extra = $application->buildMainMenuExtraNodes(
|
||||||
$user,
|
$viewer,
|
||||||
$controller);
|
$controller);
|
||||||
|
|
||||||
foreach ($app_actions as $action) {
|
foreach ($app_actions as $action) {
|
||||||
|
@ -97,7 +97,7 @@ final class PhabricatorMainMenuView extends AphrontView {
|
||||||
|
|
||||||
$extensions = PhabricatorMainMenuBarExtension::getAllEnabledExtensions();
|
$extensions = PhabricatorMainMenuBarExtension::getAllEnabledExtensions();
|
||||||
foreach ($extensions as $extension) {
|
foreach ($extensions as $extension) {
|
||||||
$extension->setViewer($user);
|
$extension->setViewer($viewer);
|
||||||
|
|
||||||
$controller = $this->getController();
|
$controller = $this->getController();
|
||||||
if ($controller) {
|
if ($controller) {
|
||||||
|
@ -158,7 +158,7 @@ final class PhabricatorMainMenuView extends AphrontView {
|
||||||
}
|
}
|
||||||
|
|
||||||
private function renderSearch() {
|
private function renderSearch() {
|
||||||
$user = $this->user;
|
$viewer = $this->getViewer();
|
||||||
|
|
||||||
$result = null;
|
$result = null;
|
||||||
|
|
||||||
|
@ -166,15 +166,15 @@ final class PhabricatorMainMenuView extends AphrontView {
|
||||||
'helpURI' => '/help/keyboardshortcut/',
|
'helpURI' => '/help/keyboardshortcut/',
|
||||||
);
|
);
|
||||||
|
|
||||||
if ($user->isLoggedIn()) {
|
if ($viewer->isLoggedIn()) {
|
||||||
$show_search = $user->isUserActivated();
|
$show_search = $viewer->isUserActivated();
|
||||||
} else {
|
} else {
|
||||||
$show_search = PhabricatorEnv::getEnvConfig('policy.allow-public');
|
$show_search = PhabricatorEnv::getEnvConfig('policy.allow-public');
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($show_search) {
|
if ($show_search) {
|
||||||
$search = new PhabricatorMainMenuSearchView();
|
$search = new PhabricatorMainMenuSearchView();
|
||||||
$search->setUser($user);
|
$search->setViewer($viewer);
|
||||||
|
|
||||||
$application = null;
|
$application = null;
|
||||||
$controller = $this->getController();
|
$controller = $this->getController();
|
||||||
|
@ -188,7 +188,7 @@ final class PhabricatorMainMenuView extends AphrontView {
|
||||||
$result = $search;
|
$result = $search;
|
||||||
|
|
||||||
$pref_shortcut = PhabricatorUserPreferences::PREFERENCE_SEARCH_SHORTCUT;
|
$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();
|
$keyboard_config['searchID'] = $search->getID();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -230,7 +230,7 @@ final class PhabricatorMainMenuView extends AphrontView {
|
||||||
}
|
}
|
||||||
|
|
||||||
private function renderApplicationMenu(array $bar_items) {
|
private function renderApplicationMenu(array $bar_items) {
|
||||||
$user = $this->getUser();
|
$viewer = $this->getViewer();
|
||||||
|
|
||||||
$view = $this->getApplicationMenu();
|
$view = $this->getApplicationMenu();
|
||||||
|
|
||||||
|
@ -302,7 +302,7 @@ final class PhabricatorMainMenuView extends AphrontView {
|
||||||
$logo_uri = $cache->getKey($cache_key_logo);
|
$logo_uri = $cache->getKey($cache_key_logo);
|
||||||
if (!$logo_uri) {
|
if (!$logo_uri) {
|
||||||
$file = id(new PhabricatorFileQuery())
|
$file = id(new PhabricatorFileQuery())
|
||||||
->setViewer($this->getUser())
|
->setViewer($this->getViewer())
|
||||||
->withPHIDs(array($custom_header))
|
->withPHIDs(array($custom_header))
|
||||||
->executeOne();
|
->executeOne();
|
||||||
if ($file) {
|
if ($file) {
|
||||||
|
@ -355,7 +355,7 @@ final class PhabricatorMainMenuView extends AphrontView {
|
||||||
}
|
}
|
||||||
|
|
||||||
private function renderNotificationMenu() {
|
private function renderNotificationMenu() {
|
||||||
$user = $this->user;
|
$viewer = $this->getViewer();
|
||||||
|
|
||||||
require_celerity_resource('phabricator-notification-css');
|
require_celerity_resource('phabricator-notification-css');
|
||||||
require_celerity_resource('phabricator-notification-menu-css');
|
require_celerity_resource('phabricator-notification-menu-css');
|
||||||
|
@ -364,7 +364,7 @@ final class PhabricatorMainMenuView extends AphrontView {
|
||||||
$aural = array();
|
$aural = array();
|
||||||
|
|
||||||
$dropdown_query = id(new AphlictDropdownDataQuery())
|
$dropdown_query = id(new AphlictDropdownDataQuery())
|
||||||
->setViewer($user);
|
->setViewer($viewer);
|
||||||
$dropdown_data = $dropdown_query->execute();
|
$dropdown_data = $dropdown_query->execute();
|
||||||
|
|
||||||
$message_tag = '';
|
$message_tag = '';
|
||||||
|
|
|
@ -172,8 +172,8 @@ final class PHUIFeedStoryView extends AphrontView {
|
||||||
if ($this->epoch) {
|
if ($this->epoch) {
|
||||||
// TODO: This is really bad; when rendering through Conduit and via
|
// TODO: This is really bad; when rendering through Conduit and via
|
||||||
// renderText() we don't have a user.
|
// renderText() we don't have a user.
|
||||||
if ($this->user) {
|
if ($this->hasViewer()) {
|
||||||
$foot = phabricator_datetime($this->epoch, $this->user);
|
$foot = phabricator_datetime($this->epoch, $this->getViewer());
|
||||||
} else {
|
} else {
|
||||||
$foot = null;
|
$foot = null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -278,7 +278,7 @@ final class PHUICalendarDayView extends AphrontView {
|
||||||
->addClass('calendar-day-view-sidebar');
|
->addClass('calendar-day-view-sidebar');
|
||||||
|
|
||||||
$list = id(new PHUICalendarListView())
|
$list = id(new PHUICalendarListView())
|
||||||
->setUser($this->user)
|
->setUser($this->getViewer())
|
||||||
->setView('day');
|
->setView('day');
|
||||||
|
|
||||||
if (count($events) == 0) {
|
if (count($events) == 0) {
|
||||||
|
@ -304,7 +304,7 @@ final class PHUICalendarDayView extends AphrontView {
|
||||||
|
|
||||||
$box_start_time = clone $display_start_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 = clone $today_time;
|
||||||
$tomorrow_time->modify('+1 day');
|
$tomorrow_time->modify('+1 day');
|
||||||
|
|
||||||
|
@ -437,7 +437,7 @@ final class PHUICalendarDayView extends AphrontView {
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getDateTime() {
|
private function getDateTime() {
|
||||||
$user = $this->user;
|
$user = $this->getViewer();
|
||||||
$timezone = new DateTimeZone($user->getTimezoneIdentifier());
|
$timezone = new DateTimeZone($user->getTimezoneIdentifier());
|
||||||
|
|
||||||
$day = $this->day;
|
$day = $this->day;
|
||||||
|
|
|
@ -51,9 +51,7 @@ final class PHUICalendarMonthView extends AphrontView {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function render() {
|
public function render() {
|
||||||
if (empty($this->user)) {
|
$viewer = $this->getViewer();
|
||||||
throw new PhutilInvalidStateException('setUser');
|
|
||||||
}
|
|
||||||
|
|
||||||
$events = msort($this->events, 'getEpochStart');
|
$events = msort($this->events, 'getEpochStart');
|
||||||
$days = $this->getDatesInMonth();
|
$days = $this->getDatesInMonth();
|
||||||
|
@ -93,7 +91,7 @@ final class PHUICalendarMonthView extends AphrontView {
|
||||||
$counter = 0;
|
$counter = 0;
|
||||||
|
|
||||||
$list = new PHUICalendarListView();
|
$list = new PHUICalendarListView();
|
||||||
$list->setUser($this->user);
|
$list->setViewer($viewer);
|
||||||
foreach ($all_day_events as $item) {
|
foreach ($all_day_events as $item) {
|
||||||
if ($counter <= $max_daily) {
|
if ($counter <= $max_daily) {
|
||||||
$list->addEvent($item);
|
$list->addEvent($item);
|
||||||
|
@ -495,9 +493,9 @@ final class PHUICalendarMonthView extends AphrontView {
|
||||||
* @return list List of DateTimes, one for each day.
|
* @return list List of DateTimes, one for each day.
|
||||||
*/
|
*/
|
||||||
private function getDatesInMonth() {
|
private function getDatesInMonth() {
|
||||||
$user = $this->user;
|
$viewer = $this->getViewer();
|
||||||
|
|
||||||
$timezone = new DateTimeZone($user->getTimezoneIdentifier());
|
$timezone = new DateTimeZone($viewer->getTimezoneIdentifier());
|
||||||
|
|
||||||
$month = $this->month;
|
$month = $this->month;
|
||||||
$year = $this->year;
|
$year = $this->year;
|
||||||
|
@ -575,7 +573,7 @@ final class PHUICalendarMonthView extends AphrontView {
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getWeekStartAndEnd() {
|
private function getWeekStartAndEnd() {
|
||||||
$preferences = $this->user->loadPreferences();
|
$preferences = $this->getViewer()->loadPreferences();
|
||||||
$pref_week_start = PhabricatorUserPreferences::PREFERENCE_WEEK_START_DAY;
|
$pref_week_start = PhabricatorUserPreferences::PREFERENCE_WEEK_START_DAY;
|
||||||
|
|
||||||
$week_start = $preferences->getPreference($pref_week_start, 0);
|
$week_start = $preferences->getPreference($pref_week_start, 0);
|
||||||
|
@ -585,7 +583,7 @@ final class PHUICalendarMonthView extends AphrontView {
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getDateTime() {
|
private function getDateTime() {
|
||||||
$user = $this->user;
|
$user = $this->getViewer();
|
||||||
$timezone = new DateTimeZone($user->getTimezoneIdentifier());
|
$timezone = new DateTimeZone($user->getTimezoneIdentifier());
|
||||||
|
|
||||||
$month = $this->month;
|
$month = $this->month;
|
||||||
|
|
Loading…
Reference in a new issue