Merge "docs: Fix typo"
[mediawiki.git] / includes / user / UserIdentityUtils.php
blob3a0d061016d4a5a27344c48aaf51df52ab2ecc15
1 <?php
3 namespace MediaWiki\User;
5 use MediaWiki\User\TempUser\TempUserConfig;
7 /**
8 * Convenience functions for interpreting UserIdentity objects using additional
9 * services or config.
11 * @since 1.41
13 class UserIdentityUtils {
14 private TempUserConfig $tempUserConfig;
16 /**
17 * @internal
19 * @param TempUserConfig $tempUserConfig
21 public function __construct( TempUserConfig $tempUserConfig ) {
22 $this->tempUserConfig = $tempUserConfig;
25 /**
26 * Is the user a temporary user?
28 * @param UserIdentity $user
29 * @return bool
31 public function isTemp( UserIdentity $user ) {
32 return $this->tempUserConfig->isTempName( $user->getName() );
35 /**
36 * Is the user a normal non-temporary registered user?
38 * @param UserIdentity $user
39 * @return bool
41 public function isNamed( UserIdentity $user ) {
42 return $user->isRegistered()
43 && !$this->tempUserConfig->isTempName( $user->getName() );
46 /**
47 * Get user identity type, used for internal logic like tracking statistics per account type.
48 * Only for internal use like tracking statistics and meet DRY
50 * @internal
51 * @param UserIdentity $user
52 * @return string
54 public function getShortUserTypeInternal( UserIdentity $user ): string {
55 if ( !$user->isRegistered() ) {
56 return 'anon';
58 return $this->isTemp( $user ) ? 'temp' : 'named';