1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of Peachy MediaWiki Bot API |
5
|
|
|
* |
6
|
|
|
* Peachy is free software: you can redistribute it and/or modify |
7
|
|
|
* it under the terms of the GNU General Public License as published by |
8
|
|
|
* the Free Software Foundation, either version 3 of the License, or |
9
|
|
|
* (at your option) any later version. |
10
|
|
|
* |
11
|
|
|
* This program is distributed in the hope that it will be useful, |
12
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14
|
|
|
* GNU General Public License for more details. |
15
|
|
|
* |
16
|
|
|
* You should have received a copy of the GNU General Public License |
17
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
18
|
|
|
*/ |
19
|
|
|
|
20
|
|
|
class GlobalUserInfo { |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Wiki class |
24
|
|
|
* |
25
|
|
|
* @var Wiki |
26
|
|
|
* @access private |
27
|
|
|
*/ |
28
|
|
|
private $wiki; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Username |
32
|
|
|
* |
33
|
|
|
* @var string |
34
|
|
|
* @access private |
35
|
|
|
*/ |
36
|
|
|
private $pgUsername; |
|
|
|
|
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Global groups member is a part of |
40
|
|
|
* |
41
|
|
|
* @var array |
42
|
|
|
* @access private |
43
|
|
|
*/ |
44
|
|
|
private $groups = array(); |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Accounts that user has merged on other wikis |
48
|
|
|
* |
49
|
|
|
* @var array |
50
|
|
|
* @access private |
51
|
|
|
*/ |
52
|
|
|
private $merged = array(); |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Accounts that are not attached to the global account |
56
|
|
|
* |
57
|
|
|
* @var array |
58
|
|
|
* @access private |
59
|
|
|
*/ |
60
|
|
|
private $unattached = array(); |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Whether or not global account exists |
64
|
|
|
* |
65
|
|
|
* @var bool |
66
|
|
|
* @access private |
67
|
|
|
*/ |
68
|
|
|
private $exists = true; |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Date that global account was created |
72
|
|
|
* |
73
|
|
|
* @var string |
74
|
|
|
* @access private |
75
|
|
|
*/ |
76
|
|
|
private $registration; |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* Global account ID |
80
|
|
|
* |
81
|
|
|
* @var int |
82
|
|
|
* @access private |
83
|
|
|
*/ |
84
|
|
|
private $id; |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* Construction method for the GlobalUserInfo class |
88
|
|
|
* |
89
|
|
|
* @access public |
90
|
|
|
* @param Wiki &$wikiClass The Wiki class object |
91
|
|
|
* @param mixed $pgUsername Username |
92
|
|
|
* @throws APIError |
93
|
|
|
* @throws AssertFailure |
94
|
|
|
* @throws DependencyError |
95
|
|
|
* @throws LoggedOut |
96
|
|
|
* @throws MWAPIError |
97
|
|
|
*/ |
98
|
|
|
function __construct( Wiki &$wikiClass, $pgUsername ) { |
|
|
|
|
99
|
|
|
|
100
|
|
|
if( !array_key_exists( 'Central Auth', $wikiClass->get_extensions() ) ) { |
101
|
|
|
throw new DependencyError( "CentralAuth", "http://www.mediawiki.org/wiki/Extension:CentralAuth" ); |
|
|
|
|
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
$this->username = ucfirst( $pgUsername ); |
|
|
|
|
105
|
|
|
$this->wiki = $wikiClass; |
106
|
|
|
|
107
|
|
|
$guiRes = $this->wiki->apiQuery( |
108
|
|
|
array( |
109
|
|
|
'action' => 'query', |
110
|
|
|
'meta' => 'globaluserinfo', |
111
|
|
|
'guiuser' => ucfirst( $pgUsername ), |
112
|
|
|
'guiprop' => 'groups|merged|unattached', |
113
|
|
|
), false, false |
114
|
|
|
); |
115
|
|
|
|
116
|
|
|
if( !isset( $guiRes['query']['globaluserinfo'] ) ) { |
117
|
|
|
$this->exists = false; |
118
|
|
|
if( isset( $guiRes['error'] ) && $guiRes['error']['code'] != 'guinosuchuser' ) { |
119
|
|
|
throw new MWAPIError($guiRes['error']); |
120
|
|
|
} elseif( @$guiRes['error']['code'] != 'guinosuchuser' ) { |
121
|
|
|
throw new MWAPIError(array('code' => 'UnknownError', 'info' => 'Unknown API Error')); |
122
|
|
|
} |
123
|
|
|
} else { |
124
|
|
|
$this->groups = $guiRes['query']['globaluserinfo']['groups']; |
125
|
|
|
$this->merged = $guiRes['query']['globaluserinfo']['merged']; |
126
|
|
|
$this->merged = $guiRes['query']['globaluserinfo']['unattached']; |
127
|
|
|
$this->id = $guiRes['query']['globaluserinfo']['id']; |
128
|
|
|
$this->registration = $guiRes['query']['globaluserinfo']['registration']; |
129
|
|
|
} |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* Returns the global account ID |
134
|
|
|
* |
135
|
|
|
* @return int |
136
|
|
|
* @access public |
137
|
|
|
*/ |
138
|
|
|
public function get_id() { |
139
|
|
|
return $this->id; |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* Returns the date that global account was created |
144
|
|
|
* |
145
|
|
|
* @return string |
146
|
|
|
* @access public |
147
|
|
|
*/ |
148
|
|
|
public function get_registration() { |
149
|
|
|
return $this->registration; |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
/** |
153
|
|
|
* Returns the global groups member is a part of |
154
|
|
|
* |
155
|
|
|
* @return array |
156
|
|
|
* @access public |
157
|
|
|
*/ |
158
|
|
|
public function get_groups() { |
159
|
|
|
return $this->groups; |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
/** |
163
|
|
|
* Returns the accounts that user has merged on other wikis |
164
|
|
|
* |
165
|
|
|
* @return array |
166
|
|
|
* @access public |
167
|
|
|
*/ |
168
|
|
|
public function get_merged() { |
169
|
|
|
return $this->merged; |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
/** |
173
|
|
|
* Returns the accounts that are not attached to the global account |
174
|
|
|
* |
175
|
|
|
* @return array |
176
|
|
|
* @access public |
177
|
|
|
*/ |
178
|
|
|
public function get_unattached() { |
179
|
|
|
return $this->unattached; |
180
|
|
|
} |
181
|
|
|
|
182
|
|
|
/** |
183
|
|
|
* Returns whether or not global account exists |
184
|
|
|
* |
185
|
|
|
* @return bool |
186
|
|
|
* @access public |
187
|
|
|
*/ |
188
|
|
|
public function get_exists() { |
189
|
|
|
return $this->unattached; |
190
|
|
|
} |
191
|
|
|
|
192
|
|
|
} |
This check marks private properties in classes that are never used. Those properties can be removed.