1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Mediawiki\DataModel; |
4
|
|
|
|
5
|
|
|
use InvalidArgumentException; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Represents a mediawiki user |
9
|
|
|
* |
10
|
|
|
* @author Addshore |
11
|
|
|
*/ |
12
|
|
|
class User { |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* @var string |
16
|
|
|
*/ |
17
|
|
|
private $name; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @var int |
21
|
|
|
*/ |
22
|
|
|
private $id; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @var int |
26
|
|
|
*/ |
27
|
|
|
private $editcount; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var string |
31
|
|
|
*/ |
32
|
|
|
private $registration; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var array |
36
|
|
|
*/ |
37
|
|
|
private $groups; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @var array |
41
|
|
|
*/ |
42
|
|
|
private $rights; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @var string |
46
|
|
|
*/ |
47
|
|
|
private $gender; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @param string $name |
51
|
|
|
* @param int $id |
52
|
|
|
* @param int $editcount |
53
|
|
|
* @param string $registration |
54
|
|
|
* @param array[] $groups groups grouped by type. |
55
|
|
|
* Keys to use are |
56
|
|
|
* 'groups' and |
57
|
|
|
* 'implicitgroups' as |
58
|
|
|
* returned by the api. |
59
|
|
|
* @param array $rights |
60
|
13 |
|
* @param string $gender |
61
|
13 |
|
* |
62
|
1 |
|
* @throws InvalidArgumentException |
63
|
|
|
*/ |
64
|
12 |
|
public function __construct( $name, $id, $editcount, $registration, $groups, $rights, $gender ) { |
65
|
1 |
|
if ( !is_string( $name ) || empty( $name ) ) { |
66
|
|
|
throw new InvalidArgumentException( '$name must be a string and can not be empty' ); |
67
|
11 |
|
} |
68
|
1 |
|
if ( !is_int( $id ) ) { |
69
|
|
|
throw new InvalidArgumentException( '$id must be an int' ); |
70
|
10 |
|
} |
71
|
4 |
|
if ( !is_int( $editcount ) ) { |
72
|
|
|
throw new InvalidArgumentException( '$editcount must be an int' ); |
73
|
6 |
|
} |
74
|
1 |
|
if ( !is_array( $groups ) || !array_key_exists( 'groups', $groups ) || !array_key_exists( 'implicitgroups', $groups ) ) { |
75
|
|
|
throw new InvalidArgumentException( '$groups must be an array or arrays with keys "groups" and "implicitgroups"' ); |
76
|
5 |
|
} |
77
|
1 |
|
if ( !is_array( $rights ) ) { |
78
|
|
|
throw new InvalidArgumentException( '$rights must be an array' ); |
79
|
|
|
} |
80
|
4 |
|
if ( !is_string( $gender ) ) { |
81
|
4 |
|
throw new InvalidArgumentException( '$gender must be a string' ); |
82
|
4 |
|
} |
83
|
4 |
|
|
84
|
4 |
|
$this->editcount = $editcount; |
85
|
4 |
|
$this->gender = $gender; |
86
|
4 |
|
$this->groups = $groups; |
87
|
4 |
|
$this->id = $id; |
88
|
|
|
$this->name = $name; |
89
|
|
|
$this->registration = $registration; |
90
|
|
|
$this->rights = $rights; |
91
|
|
|
} |
92
|
4 |
|
|
93
|
4 |
|
/** |
94
|
|
|
* @return int |
95
|
|
|
*/ |
96
|
|
|
public function getEditcount() { |
97
|
|
|
return $this->editcount; |
98
|
|
|
} |
99
|
4 |
|
|
100
|
4 |
|
/** |
101
|
|
|
* @return string |
102
|
|
|
*/ |
103
|
|
|
public function getGender() { |
104
|
|
|
return $this->gender; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
4 |
|
* @param string $type 'groups' or 'implicitgroups' |
109
|
4 |
|
* |
110
|
|
|
* @return array |
111
|
|
|
*/ |
112
|
|
|
public function getGroups( $type = 'groups' ) { |
113
|
|
|
return $this->groups[$type]; |
114
|
|
|
} |
115
|
4 |
|
|
116
|
4 |
|
/** |
117
|
|
|
* @return int |
118
|
|
|
*/ |
119
|
|
|
public function getId() { |
120
|
|
|
return $this->id; |
121
|
|
|
} |
122
|
4 |
|
|
123
|
4 |
|
/** |
124
|
|
|
* @return string |
125
|
|
|
*/ |
126
|
|
|
public function getName() { |
127
|
|
|
return $this->name; |
128
|
|
|
} |
129
|
4 |
|
|
130
|
4 |
|
/** |
131
|
|
|
* @return string |
132
|
|
|
*/ |
133
|
|
|
public function getRegistration() { |
134
|
|
|
return $this->registration; |
135
|
|
|
} |
136
|
4 |
|
|
137
|
4 |
|
/** |
138
|
|
|
* @return array |
139
|
|
|
*/ |
140
|
|
|
public function getRights() { |
141
|
|
|
return $this->rights; |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
} |
145
|
|
|
|