Add a service for convenient interpretation of UserIdentity instances, especially relating to the TempUser migration. Bug: T341976 Change-Id: I94e8620cd3187f41f04cdf24b5b553baadfbc22d
46 lines
946 B
PHP
46 lines
946 B
PHP
<?php
|
|
|
|
namespace MediaWiki\User;
|
|
|
|
use MediaWiki\User\TempUser\TempUserConfig;
|
|
|
|
/**
|
|
* Convenience functions for interpreting UserIdentity objects using additional
|
|
* services or config.
|
|
*
|
|
* @since 1.41
|
|
*/
|
|
class UserIdentityUtils {
|
|
/** @var TempUserConfig */
|
|
private $tempUserConfig;
|
|
|
|
/**
|
|
* @internal
|
|
*
|
|
* @param TempUserConfig $tempUserConfig
|
|
*/
|
|
public function __construct( TempUserConfig $tempUserConfig ) {
|
|
$this->tempUserConfig = $tempUserConfig;
|
|
}
|
|
|
|
/**
|
|
* Is the user a temporary user?
|
|
*
|
|
* @param UserIdentity $user
|
|
* @return bool
|
|
*/
|
|
public function isTemp( UserIdentity $user ) {
|
|
return $this->tempUserConfig->isTempName( $user->getName() );
|
|
}
|
|
|
|
/**
|
|
* Is the user a normal non-temporary registered user?
|
|
*
|
|
* @param UserIdentity $user
|
|
* @return bool
|
|
*/
|
|
public function isNamed( UserIdentity $user ) {
|
|
return $user->isRegistered()
|
|
&& !$this->tempUserConfig->isTempName( $user->getName() );
|
|
}
|
|
}
|