Merge "HTML escape parameter 'text' of hook 'SkinEditSectionLinks'"
[lhc/web/wiklou.git] / includes / user / UserIdentityValue.php
1 <?php
2 /**
3 * Value object representing a user's identity.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
19 *
20 * @file
21 */
22
23 namespace MediaWiki\User;
24
25 use Wikimedia\Assert\Assert;
26
27 /**
28 * Value object representing a user's identity.
29 *
30 * @since 1.31
31 */
32 class UserIdentityValue implements UserIdentity {
33
34 /**
35 * @var int
36 */
37 private $id;
38
39 /**
40 * @var string
41 */
42 private $name;
43
44 /**
45 * @var int
46 */
47 private $actor;
48
49 /**
50 * @param int $id
51 * @param string $name
52 * @param int $actor
53 */
54 public function __construct( $id, $name, $actor ) {
55 Assert::parameterType( 'integer', $id, '$id' );
56 Assert::parameterType( 'string', $name, '$name' );
57 Assert::parameterType( 'integer', $actor, '$actor' );
58
59 $this->id = $id;
60 $this->name = $name;
61 $this->actor = $actor;
62 }
63
64 /**
65 * @return int The user ID. May be 0 for anonymous users or for users with no local account.
66 */
67 public function getId() {
68 return $this->id;
69 }
70
71 /**
72 * @return string The user's logical name. May be an IPv4 or IPv6 address for anonymous users.
73 */
74 public function getName() {
75 return $this->name;
76 }
77
78 /**
79 * @return int The user's actor ID. May be 0 if no actor ID has been assigned.
80 */
81 public function getActorId() {
82 return $this->actor;
83 }
84
85 /**
86 * @since 1.32
87 *
88 * @param UserIdentity $user
89 * @return bool
90 */
91 public function equals( UserIdentity $user ) {
92 // XXX it's not clear whether central ID providers are supposed to obey this
93 return $this->getName() === $user->getName();
94 }
95
96 /**
97 * @since 1.34
98 *
99 * @return bool True if user is registered on this wiki, i.e., has a user ID. False if user is
100 * anonymous or has no local account (which can happen when importing). This is equivalent to
101 * getId() != 0 and is provided for code readability.
102 */
103 public function isRegistered() {
104 return $this->getId() != 0;
105 }
106 }