3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
21 namespace MediaWiki\User
;
23 use CannotCreateActorException
;
24 use InvalidArgumentException
;
26 use Wikimedia\Rdbms\IDatabase
;
27 use Wikimedia\Rdbms\IReadableDatabase
;
30 * Service for dealing with the actor table.
33 interface ActorNormalization
{
36 * Instantiate a new UserIdentity object based on a $row from the actor table.
38 * Use this method when an actor row was already fetched from the DB via a join.
39 * This method just constructs a new instance and does not try fetching missing
40 * values from the DB again, use {@link UserIdentityLookup} for that.
42 * @param stdClass $row with the following fields:
45 * - int|null actor_user
46 * @return UserIdentity
47 * @throws InvalidArgumentException
49 public function newActorFromRow( stdClass
$row ): UserIdentity
;
52 * Instantiate a new UserIdentity object based on field values from a DB row.
54 * Until {@link ActorMigration} is completed, the actor table joins alias actor field names
55 * to legacy field names. This method is convenience to construct the UserIdentity based on
56 * legacy field names. It's more relaxed with typing then ::newFromRow to better support legacy
57 * code, so always prefer ::newFromRow in new code. Eventually, once {@link ActorMigration}
58 * is completed and all queries use explicit join with actor table, this method will be
59 * deprecated and removed.
61 * @throws InvalidArgumentException
62 * @param int|null $userId
63 * @param string|null $name
64 * @param int|null $actorId
65 * @return UserIdentity
67 public function newActorFromRowFields( $userId, $name, $actorId ): UserIdentity
;
70 * Find the actor_id for the given name.
73 * @param IReadableDatabase $db The database connection to operate on.
74 * The database must correspond to the wiki this ActorNormalization is bound to.
77 public function findActorIdByName( string $name, IReadableDatabase
$db ): ?
int;
80 * Find the actor_id of the given $user.
82 * @param UserIdentity $user
83 * @param IReadableDatabase $db The database connection to operate on.
84 * The database must correspond to the wiki this ActorNormalization is bound to.
87 public function findActorId( UserIdentity
$user, IReadableDatabase
$db ): ?
int;
90 * Attempt to assign an actor ID to the given $user
91 * If it is already assigned, return the existing ID.
93 * @param UserIdentity $user
94 * @param IDatabase $dbw The database connection to acquire the ID from.
95 * The database must correspond to the wiki this ActorNormalization is bound to.
96 * @return int greater then 0
97 * @throws CannotCreateActorException if no actor ID has been assigned to this $user
99 public function acquireActorId( UserIdentity
$user, IDatabase
$dbw ): int;
102 * Find an actor by $id.
104 * @param int $actorId
105 * @param IReadableDatabase $db The database connection to operate on.
106 * The database must correspond to the wiki this ActorNormalization is bound to.
107 * @return UserIdentity|null Returns null if no actor with this $actorId exists in the database.
109 public function getActorById( int $actorId, IReadableDatabase
$db ): ?UserIdentity
;
112 * In case all reasonable attempts of initializing a proper actor from the
113 * database have failed, entities can be attributed to special 'Unknown user' actor.
115 * @return UserIdentity
117 public function getUnknownActor(): UserIdentity
;