27use InvalidArgumentException;
46 private $loadBalancer;
49 private $userNameUtils;
52 private $lastUserFromIdentity =
null;
62 $this->loadBalancer = $loadBalancer;
63 $this->userNameUtils = $userNameUtils;
86 string $validate = self::RIGOR_VALID
89 $canonicalName = $this->userNameUtils->getCanonical( $name, $validate );
90 if ( $canonicalName ===
false ) {
95 $user->mName = $canonicalName;
96 $user->mFrom =
'name';
97 $user->setItemLoaded(
'name' );
111 if ( !$this->userNameUtils->isIP( $ip ) ) {
112 throw new InvalidArgumentException(
'Invalid IP address' );
115 $user->setName( $ip );
148 $user->mActorId = $actorId;
149 $user->mFrom =
'actor';
163 if ( $userIdentity instanceof
User ) {
164 return $userIdentity;
167 $id = $userIdentity->
getId();
168 $name = $userIdentity->getName();
174 $this->lastUserFromIdentity
175 && $this->lastUserFromIdentity->getId() === $id
176 && $this->lastUserFromIdentity->getName() === $name
178 return $this->lastUserFromIdentity;
181 $this->lastUserFromIdentity = $this->newFromAnyId(
182 $id === 0 ?
null : $id,
183 $name ===
'' ? null : $name,
187 return $this->lastUserFromIdentity;
208 ?
int $actorId =
null,
214 if ( $dbDomain !== false ) {
220 $user->mFrom =
'defaults';
222 if ( $actorId !==
null ) {
223 $user->mActorId = $actorId;
224 if ( $actorId !== 0 ) {
225 $user->mFrom =
'actor';
230 if ( $userName !==
null && $userName !==
'' ) {
231 $user->mName = $userName;
232 $user->mFrom =
'name';
233 $user->setItemLoaded(
'name' );
236 if ( $userId !==
null ) {
237 $user->mId = $userId;
238 if ( $userId !== 0 ) {
241 $user->setItemLoaded(
'id' );
244 if ( $user->mFrom ===
'defaults' ) {
245 throw new InvalidArgumentException(
246 'Cannot create a user with no name, no ID, and no actor ID'
266 string $confirmationCode,
267 int $flags = self::READ_NORMAL
269 list( $index, $options ) = DBAccessObjectUtils::getDBOptions( $flags );
271 $db = $this->loadBalancer->getConnectionRef( $index );
273 $id = $db->selectField(
277 'user_email_token' => md5( $confirmationCode ),
278 'user_email_token_expires > ' . $db->addQuotes( $db->timestamp() ),
288 return $this->newFromId( (
int)$id );
310 if ( $authority instanceof
User ) {
313 return $this->newFromUserIdentity( $authority->getUser() );
326 $user->setName( $this->userNameUtils->getTempPlaceholder() );
339 $user->setName( $name );
if(!defined('MW_SETUP_CALLBACK'))
The persistent session ID (if any) loaded at startup.
Helper class for DAO classes.
static newFromRow( $row, $data=null)
Create a new user object from a user row.
setItemLoaded( $item)
Set that an item has been loaded.
Interface for database access objects.