title = $title; } /** * Fetch user data and store locally for performance improvement * @return User|null */ private function fetchData() { if ( $this->fetchedData === false ) { 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. * @param Title $title * @return User|null */ private function buildPageUserObject( Title $title ) { $titleText = $title->getText(); if ( User::isIP( $titleText ) ) { return User::newFromAnyId( null, $titleText, null ); } $pageUserId = User::idFromName( $titleText ); if ( $pageUserId ) { return User::newFromId( $pageUserId ); } return null; } /** * @return User|null */ public function getPageUser() { return $this->fetchData(); } /** * @return bool */ public function isUserPage() { return $this->fetchData() !== null; } }