From aaab1011e5a464ea94c182001a7fe867b19bae5a Mon Sep 17 00:00:00 2001 From: epriestley Date: Sun, 6 Mar 2016 06:26:34 -0800 Subject: [PATCH] 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 --- .../PhabricatorBadgesRecipientsListView.php | 3 +- .../view/PhabricatorDaemonLogEventsView.php | 9 +-- .../view/PhabricatorDaemonLogListView.php | 8 +-- .../view/DifferentialAddCommentView.php | 5 +- .../view/DifferentialChangesetListView.php | 14 +++-- .../view/DifferentialLocalCommitsView.php | 7 +-- .../view/DifferentialRevisionListView.php | 11 ++-- .../diffusion/view/DiffusionTagListView.php | 2 +- .../phame/view/PhameBlogListView.php | 6 -- .../phame/view/PhameDraftListView.php | 6 -- .../phame/view/PhamePostListView.php | 8 +-- .../ponder/view/PonderAddAnswerView.php | 6 +- .../view/PhabricatorProjectUserListView.php | 2 +- .../view/PHUIDiffInlineCommentEditView.php | 7 +-- src/view/AphrontDialogView.php | 8 +-- src/view/AphrontView.php | 56 +++++++++++++++++-- src/view/form/AphrontFormView.php | 8 +-- .../form/control/AphrontFormDateControl.php | 15 ++--- .../control/AphrontFormTokenizerControl.php | 4 +- src/view/layout/AphrontSideNavFilterView.php | 3 - src/view/layout/PhabricatorActionListView.php | 8 +-- src/view/layout/PhabricatorActionView.php | 6 +- .../menu/PhabricatorMainMenuSearchView.php | 6 +- .../page/menu/PhabricatorMainMenuView.php | 28 +++++----- src/view/phui/PHUIFeedStoryView.php | 4 +- .../phui/calendar/PHUICalendarDayView.php | 6 +- .../phui/calendar/PHUICalendarMonthView.php | 14 ++--- 27 files changed, 134 insertions(+), 126 deletions(-) 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 @@ -16,8 +16,7 @@ final class PhabricatorBadgesRecipientsListView extends AphrontView { } public function render() { - - $viewer = $this->user; + $viewer = $this->getViewer(); $badge = $this->badge; $handles = $this->handles; 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 @@ -24,12 +24,9 @@ final class PhabricatorDaemonLogEventsView extends AphrontView { } 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 @@ -83,8 +80,8 @@ final class PhabricatorDaemonLogEventsView extends AphrontView { $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, 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 @@ -11,11 +11,9 @@ final class PhabricatorDaemonLogListView extends AphrontView { } public function render() { - $rows = array(); + $viewer = $this->getViewer(); - if (!$this->user) { - throw new PhutilInvalidStateException('setUser'); - } + $rows = array(); $list = new PHUIObjectItemListView(); $list->setFlush(true); @@ -27,7 +25,7 @@ final class PhabricatorDaemonLogListView extends AphrontView { ->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) { 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 @@ -50,6 +50,7 @@ final class DifferentialAddCommentView extends AphrontView { } public function render() { + $viewer = $this->getViewer(); $this->requireResource('differential-revision-add-comment-css'); $revision = $this->revision; @@ -73,7 +74,7 @@ final class DifferentialAddCommentView extends AphrontView { $form = new AphrontFormView(); $form ->setWorkflow(true) - ->setUser($this->user) + ->setViewer($viewer) ->setAction($this->actionURI) ->addHiddenInput('revision_id', $revision->getID()) ->appendChild( @@ -108,7 +109,7 @@ final class DifferentialAddCommentView extends AphrontView { ->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'))); 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 @@ -113,6 +113,8 @@ final class DifferentialChangesetListView extends AphrontView { } public function render() { + $viewer = $this->getViewer(); + $this->requireResource('differential-changeset-view-css'); $changesets = $this->changesets; @@ -148,7 +150,7 @@ final class DifferentialChangesetListView extends AphrontView { )); $renderer = DifferentialChangesetParser::getDefaultRendererForViewer( - $this->getUser()); + $viewer); $output = array(); $ids = array(); @@ -163,7 +165,7 @@ final class DifferentialChangesetListView extends AphrontView { $ref = $this->references[$key]; $detail = id(new DifferentialChangesetDetailView()) - ->setUser($this->getUser()); + ->setUser($viewer); $uniq_id = 'diff-'.$changeset->getAnchorName(); $detail->setID($uniq_id); @@ -261,6 +263,7 @@ final class DifferentialChangesetListView extends AphrontView { DifferentialChangesetDetailView $detail, $ref, DifferentialChangeset $changeset) { + $viewer = $this->getViewer(); $meta = array(); @@ -280,7 +283,7 @@ final class DifferentialChangesetListView extends AphrontView { try { $meta['diffusionURI'] = (string)$repository->getDiffusionBrowseURIForPath( - $this->user, + $viewer, $changeset->getAbsoluteRepositoryPath($repository, $this->diff), idx($changeset->getMetadata(), 'line:first'), $this->getBranch()); @@ -308,13 +311,12 @@ final class DifferentialChangesetListView extends AphrontView { } } - $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 { 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 @@ -17,10 +17,7 @@ final class DifferentialLocalCommitsView extends AphrontView { } public function render() { - $user = $this->user; - if (!$user) { - throw new PhutilInvalidStateException('setUser'); - } + $viewer = $this->getViewer(); $local = $this->localCommits; if (!$local) { @@ -94,7 +91,7 @@ final class DifferentialLocalCommitsView extends AphrontView { idx($commit, 'date'), idx($commit, 'time')); if ($date) { - $date = phabricator_datetime($date, $user); + $date = phabricator_datetime($date, $viewer); } $row[] = $date; 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 @@ -57,10 +57,7 @@ final class DifferentialRevisionListView extends AphrontView { } public function render() { - $user = $this->user; - if (!$user) { - throw new PhutilInvalidStateException('setUser'); - } + $viewer = $this->getViewer(); $fresh = PhabricatorEnv::getEnvConfig('differential.days-fresh'); if ($fresh) { @@ -83,12 +80,12 @@ final class DifferentialRevisionListView extends AphrontView { 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( @@ -99,7 +96,7 @@ final class DifferentialRevisionListView extends AphrontView { ''); } - if ($revision->getDrafts($user)) { + if ($revision->getDrafts($viewer)) { $icons['draft'] = true; } 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 @@ -100,7 +100,7 @@ final class DiffusionTagListView extends DiffusionView { $build, $author, $description, - phabricator_datetime($tag->getEpoch(), $this->user), + phabricator_datetime($tag->getEpoch(), $this->getViewer()), ); } 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 @@ -3,7 +3,6 @@ final class PhameBlogListView extends AphrontTagView { private $blogs; - private $viewer; public function setBlogs($blogs) { assert_instances_of($blogs, 'PhameBlog'); @@ -11,11 +10,6 @@ final class PhameBlogListView extends AphrontTagView { return $this; } - public function setViewer($viewer) { - $this->viewer = $viewer; - return $this; - } - protected function getTagAttributes() { $classes = array(); $classes[] = 'phame-blog-list'; 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 @@ -4,7 +4,6 @@ final class PhameDraftListView extends AphrontTagView { private $posts; private $blogs; - private $viewer; public function setPosts($posts) { assert_instances_of($posts, 'PhamePost'); @@ -18,11 +17,6 @@ final class PhameDraftListView extends AphrontTagView { return $this; } - public function setViewer($viewer) { - $this->viewer = $viewer; - return $this; - } - protected function getTagAttributes() { $classes = array(); $classes[] = 'phame-blog-list'; 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 @@ -4,7 +4,6 @@ final class PhamePostListView extends AphrontTagView { private $posts; private $nodata; - private $viewer; private $showBlog = false; private $isExternal; private $isLive; @@ -25,11 +24,6 @@ final class PhamePostListView extends AphrontTagView { return $this; } - public function setViewer($viewer) { - $this->viewer = $viewer; - return $this; - } - public function setIsExternal($is_external) { $this->isExternal = $is_external; return $this; @@ -53,7 +47,7 @@ final class PhamePostListView extends AphrontTagView { } protected function getTagContent() { - $viewer = $this->viewer; + $viewer = $this->getViewer(); $posts = $this->posts; $nodata = $this->nodata; 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 @@ -18,7 +18,7 @@ final class PonderAddAnswerView extends AphrontView { public function render() { $question = $this->question; - $viewer = $this->user; + $viewer = $this->getViewer(); $authors = mpull($question->getAnswers(), null, 'getAuthorPHID'); if (isset($authors[$viewer->getPHID()])) { @@ -49,7 +49,7 @@ final class PonderAddAnswerView extends AphrontView { $form = new AphrontFormView(); $form - ->setUser($this->user) + ->setViewer($viewer) ->setAction($this->actionURI) ->setWorkflow(true) ->addHiddenInput('question_id', $question->getID()) @@ -59,7 +59,7 @@ final class PonderAddAnswerView extends AphrontView { ->setLabel(pht('Answer')) ->setError(true) ->setID('answer-content') - ->setUser($this->user)) + ->setViewer($viewer)) ->appendChild( id(new AphrontFormSubmitControl()) ->setValue(pht('Add Answer'))); 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 @@ -45,7 +45,7 @@ abstract class PhabricatorProjectUserListView extends AphrontView { abstract protected function getHeaderText(); public function render() { - $viewer = $this->getUser(); + $viewer = $this->getViewer(); $project = $this->getProject(); $user_phids = $this->getUserPHIDs(); 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 @@ -78,12 +78,11 @@ final class PHUIDiffInlineCommentEditView 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', 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 @@ -236,11 +236,11 @@ final class AphrontDialogView $this->cancelText); } - if (!$this->user) { + if (!$this->hasViewer()) { throw new Exception( pht( 'You must call %s when rendering an %s.', - 'setUser()', + 'setViewer()', __CLASS__)); } @@ -308,7 +308,7 @@ final class AphrontDialogView if (!$this->renderAsForm) { $buttons = array( phabricator_form( - $this->user, + $this->getViewer(), $form_attributes, array_merge($hidden_inputs, $buttons)), ); @@ -376,7 +376,7 @@ final class AphrontDialogView if ($this->renderAsForm) { return phabricator_form( - $this->user, + $this->getViewer(), $form_attributes + $attributes, array($hidden_inputs, $content)); } else { 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 @@ -6,7 +6,7 @@ abstract class AphrontView extends Phobject implements PhutilSafeHTMLProducerInterface { - protected $user; + private $viewer; 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) { - $this->user = $user; + 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) { + 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(); } 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 @@ -85,13 +85,13 @@ final class AphrontFormView extends AphrontView { 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(); } @@ -123,7 +123,7 @@ final class AphrontFormView extends AphrontView { $layout = $this->buildLayoutView(); - if (!$this->user) { + if (!$this->hasViewer()) { throw new Exception( pht( 'You must pass the user to %s.', @@ -136,7 +136,7 @@ final class AphrontFormView extends AphrontView { } return phabricator_form( - $this->user, + $this->getViewer(), array( 'class' => $this->shaded ? 'phui-form-shaded' : null, 'action' => $this->action, 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 @@ -137,12 +137,12 @@ final class AphrontFormDateControl extends AphrontFormControl { } 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); } @@ -153,7 +153,7 @@ final class AphrontFormDateControl extends AphrontFormControl { private function formatTime($epoch, $fmt) { return phabricator_format_local_time( $epoch, - $this->user, + $this->getViewer(), $fmt); } @@ -259,7 +259,7 @@ final class AphrontFormDateControl extends AphrontFormControl { ), $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); @@ -300,12 +300,9 @@ final class AphrontFormDateControl extends AphrontFormControl { 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; } 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 @@ -90,8 +90,8 @@ final class AphrontFormTokenizerControl extends AphrontFormControl { } $username = null; - if ($this->user) { - $username = $this->user->getUsername(); + if ($this->hasViewer()) { + $username = $this->getViewer()->getUsername(); } $datasource_uri = $datasource->getDatasourceURI(); 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 @@ -199,9 +199,6 @@ final class AphrontSideNavFilterView extends AphrontView { } private function renderFlexNav() { - - $user = $this->user; - require_celerity_resource('phabricator-nav-view-css'); $nav_classes = array(); 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 @@ -22,9 +22,7 @@ final class PhabricatorActionListView extends AphrontView { } public function render() { - if (!$this->user) { - throw new PhutilInvalidStateException('setUser'); - } + $viewer = $this->getViewer(); $event = new PhabricatorEvent( PhabricatorEventType::TYPE_UI_DIDRENDERACTIONS, @@ -32,7 +30,7 @@ final class PhabricatorActionListView extends AphrontView { 'object' => $this->object, 'actions' => $this->actions, )); - $event->setUser($this->user); + $event->setUser($viewer); PhutilEventEngine::dispatchEvent($event); $actions = $event->getValue('actions'); @@ -41,7 +39,7 @@ final class PhabricatorActionListView extends AphrontView { } foreach ($actions as $action) { - $action->setUser($this->user); + $action->setViewer($viewer); } require_celerity_resource('phabricator-action-list-view-css'); 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 @@ -125,11 +125,11 @@ final class PhabricatorActionView extends AphrontView { $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( @@ -140,7 +140,7 @@ final class PhabricatorActionView extends AphrontView { array($icon, $this->name)); $item = phabricator_form( - $this->user, + $this->getViewer(), array( 'action' => $this->getHref(), 'method' => 'POST', 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 @@ -24,7 +24,7 @@ final class PhabricatorMainMenuSearchView extends AphrontView { } public function render() { - $user = $this->user; + $viewer = $this->getViewer(); $target_id = celerity_generate_unique_node_id(); $search_id = $this->getID(); @@ -86,7 +86,7 @@ final class PhabricatorMainMenuSearchView extends AphrontView { $selector = $this->buildModeSelector($selector_id, $application_id); $form = phabricator_form( - $user, + $viewer, array( 'action' => '/search/', 'method' => 'POST', @@ -109,7 +109,7 @@ final class PhabricatorMainMenuSearchView extends AphrontView { } private function buildModeSelector($selector_id, $application_id) { - $viewer = $this->getUser(); + $viewer = $this->getViewer(); $items = array(); $items[] = array( 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 @@ -24,7 +24,7 @@ final class PhabricatorMainMenuView extends AphrontView { } public function render() { - $user = $this->user; + $viewer = $this->getViewer(); require_celerity_resource('phabricator-main-menu-view'); @@ -35,7 +35,7 @@ final class PhabricatorMainMenuView extends AphrontView { $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; @@ -77,10 +77,10 @@ final class PhabricatorMainMenuView extends AphrontView { $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) { @@ -97,7 +97,7 @@ final class PhabricatorMainMenuView extends AphrontView { $extensions = PhabricatorMainMenuBarExtension::getAllEnabledExtensions(); foreach ($extensions as $extension) { - $extension->setViewer($user); + $extension->setViewer($viewer); $controller = $this->getController(); if ($controller) { @@ -158,7 +158,7 @@ final class PhabricatorMainMenuView extends AphrontView { } private function renderSearch() { - $user = $this->user; + $viewer = $this->getViewer(); $result = null; @@ -166,15 +166,15 @@ final class PhabricatorMainMenuView extends AphrontView { '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(); @@ -188,7 +188,7 @@ final class PhabricatorMainMenuView extends AphrontView { $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(); } } @@ -230,7 +230,7 @@ final class PhabricatorMainMenuView extends AphrontView { } private function renderApplicationMenu(array $bar_items) { - $user = $this->getUser(); + $viewer = $this->getViewer(); $view = $this->getApplicationMenu(); @@ -302,7 +302,7 @@ final class PhabricatorMainMenuView extends AphrontView { $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) { @@ -355,7 +355,7 @@ final class PhabricatorMainMenuView extends AphrontView { } private function renderNotificationMenu() { - $user = $this->user; + $viewer = $this->getViewer(); require_celerity_resource('phabricator-notification-css'); require_celerity_resource('phabricator-notification-menu-css'); @@ -364,7 +364,7 @@ final class PhabricatorMainMenuView extends AphrontView { $aural = array(); $dropdown_query = id(new AphlictDropdownDataQuery()) - ->setViewer($user); + ->setViewer($viewer); $dropdown_data = $dropdown_query->execute(); $message_tag = ''; 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 @@ -172,8 +172,8 @@ final class PHUIFeedStoryView extends AphrontView { 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; } 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 @@ -278,7 +278,7 @@ final class PHUICalendarDayView extends AphrontView { ->addClass('calendar-day-view-sidebar'); $list = id(new PHUICalendarListView()) - ->setUser($this->user) + ->setUser($this->getViewer()) ->setView('day'); if (count($events) == 0) { @@ -304,7 +304,7 @@ final class PHUICalendarDayView extends AphrontView { $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'); @@ -437,7 +437,7 @@ final class PHUICalendarDayView extends AphrontView { } private function getDateTime() { - $user = $this->user; + $user = $this->getViewer(); $timezone = new DateTimeZone($user->getTimezoneIdentifier()); $day = $this->day; 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 @@ -51,9 +51,7 @@ final class PHUICalendarMonthView extends AphrontView { } public function render() { - if (empty($this->user)) { - throw new PhutilInvalidStateException('setUser'); - } + $viewer = $this->getViewer(); $events = msort($this->events, 'getEpochStart'); $days = $this->getDatesInMonth(); @@ -93,7 +91,7 @@ final class PHUICalendarMonthView extends AphrontView { $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); @@ -495,9 +493,9 @@ final class PHUICalendarMonthView extends AphrontView { * @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; @@ -575,7 +573,7 @@ final class PHUICalendarMonthView extends AphrontView { } 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); @@ -585,7 +583,7 @@ final class PHUICalendarMonthView extends AphrontView { } private function getDateTime() { - $user = $this->user; + $user = $this->getViewer(); $timezone = new DateTimeZone($user->getTimezoneIdentifier()); $month = $this->month;