userFactory = $userFactory; $this->userNameUtils = $userNameUtils; } public function setContext( IContextSource $context ): self { $this->context = $context; return $this; } public function setTitle( ?Title $title ): self { $this->title = $title; return $this; } /** * Fetch user data and store locally for performance improvement */ private function fetchData(): ?User { if ( !$this->fetchedData ) { if ( $this->title && $this->title->inNamespace( NS_USER ) && !$this->title->isSubpage() ) { $this->pageUser = $this->buildPageUserObject( $this->title ); } $this->fetchedData = true; } return $this->pageUser; } /** * Return new User object based on username or IP address. */ private function buildPageUserObject( Title $title ): ?User { $titleText = $title->getText(); if ( $this->userNameUtils->isIP( $titleText ) ) { return $this->userFactory->newAnonymous( $titleText ); } $user = $this->userFactory->newFromName( $titleText ); if ( $user && $user->isRegistered() ) { return $user; } return null; } public function getPageUser(): ?User { return $this->fetchData(); } public function isUserPage(): bool { return $this->fetchData() !== null; } public function isUserPageAccessibleToCurrentUser(): bool { $pageUser = $this->fetchData(); $isHidden = $pageUser && $pageUser->isHidden(); $canViewHidden = $this->context && $this->context->getAuthority()->isAllowed( 'hideuser' ); return !$isHidden || $canViewHidden; } }