|
1
|
|
|
<?php |
|
2
|
|
|
/****************************************************************************** |
|
3
|
|
|
* Wikipedia Account Creation Assistance tool * |
|
4
|
|
|
* * |
|
5
|
|
|
* All code in this file is released into the public domain by the ACC * |
|
6
|
|
|
* Development Team. Please see team.json for a list of contributors. * |
|
7
|
|
|
******************************************************************************/ |
|
8
|
|
|
|
|
9
|
|
|
namespace Waca\Helpers; |
|
10
|
|
|
|
|
11
|
|
|
use Exception; |
|
12
|
|
|
use Waca\DataObject; |
|
13
|
|
|
use Waca\DataObjects\Ban; |
|
14
|
|
|
use Waca\DataObjects\Comment; |
|
15
|
|
|
use Waca\DataObjects\EmailTemplate; |
|
16
|
|
|
use Waca\DataObjects\Log; |
|
17
|
|
|
use Waca\DataObjects\Request; |
|
18
|
|
|
use Waca\DataObjects\SiteNotice; |
|
19
|
|
|
use Waca\DataObjects\User; |
|
20
|
|
|
use Waca\DataObjects\WelcomeTemplate; |
|
21
|
|
|
use Waca\PdoDatabase; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* Helper class for creating log entries |
|
25
|
|
|
* |
|
26
|
|
|
* Logger description. |
|
27
|
|
|
* |
|
28
|
|
|
* @version 1.0 |
|
29
|
|
|
* @author stwalkerster |
|
30
|
|
|
*/ |
|
31
|
|
|
class Logger |
|
32
|
|
|
{ |
|
33
|
|
|
/** |
|
34
|
|
|
* @param PdoDatabase $database |
|
35
|
|
|
* @param Request $object |
|
36
|
|
|
*/ |
|
37
|
|
|
public static function emailConfirmed(PdoDatabase $database, Request $object) |
|
38
|
|
|
{ |
|
39
|
|
|
self::createLogEntry($database, $object, "Email Confirmed", null, User::getCommunity()); |
|
|
|
|
|
|
40
|
|
|
} |
|
|
|
|
|
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* @param PdoDatabase $database |
|
44
|
|
|
* @param DataObject $object |
|
45
|
|
|
* @param string $logAction |
|
46
|
|
|
* @param null|string $comment |
|
47
|
|
|
* @param User $user |
|
48
|
|
|
* |
|
49
|
|
|
* @throws Exception |
|
50
|
|
|
*/ |
|
51
|
|
|
private static function createLogEntry( |
|
52
|
|
|
PdoDatabase $database, |
|
53
|
|
|
DataObject $object, |
|
54
|
|
|
$logAction, |
|
55
|
|
|
$comment = null, |
|
|
|
|
|
|
56
|
|
|
$user = null |
|
|
|
|
|
|
57
|
|
|
) { |
|
58
|
|
|
if ($user == null) { |
|
59
|
|
|
$user = User::getCurrent($database); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
$objectType = get_class($object); |
|
63
|
|
|
if (strpos($objectType, 'Waca\\DataObjects\\') !== false) { |
|
64
|
|
|
$objectType = str_replace('Waca\\DataObjects\\', '', $objectType); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
$log = new Log(); |
|
68
|
|
|
$log->setDatabase($database); |
|
69
|
|
|
$log->setAction($logAction); |
|
70
|
|
|
$log->setObjectId($object->getId()); |
|
71
|
|
|
$log->setObjectType($objectType); |
|
72
|
|
|
$log->setUser($user); |
|
73
|
|
|
$log->setComment($comment); |
|
74
|
|
|
$log->save(); |
|
75
|
|
|
} |
|
|
|
|
|
|
76
|
|
|
|
|
77
|
|
|
#region Users |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* @param PdoDatabase $database |
|
81
|
|
|
* @param User $user |
|
82
|
|
|
*/ |
|
83
|
|
|
public static function newUser(PdoDatabase $database, User $user) |
|
84
|
|
|
{ |
|
85
|
|
|
self::createLogEntry($database, $user, 'Registered', null, User::getCommunity()); |
|
86
|
|
|
} |
|
|
|
|
|
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* @param PdoDatabase $database |
|
90
|
|
|
* @param User $object |
|
91
|
|
|
*/ |
|
92
|
|
|
public static function approvedUser(PdoDatabase $database, User $object) |
|
93
|
|
|
{ |
|
94
|
|
|
self::createLogEntry($database, $object, "Approved"); |
|
|
|
|
|
|
95
|
|
|
} |
|
|
|
|
|
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* @param PdoDatabase $database |
|
99
|
|
|
* @param User $object |
|
100
|
|
|
* @param string $comment |
|
101
|
|
|
*/ |
|
102
|
|
|
public static function declinedUser(PdoDatabase $database, User $object, $comment) |
|
103
|
|
|
{ |
|
104
|
|
|
self::createLogEntry($database, $object, "Declined", $comment); |
|
|
|
|
|
|
105
|
|
|
} |
|
|
|
|
|
|
106
|
|
|
|
|
107
|
|
|
/** |
|
108
|
|
|
* @param PdoDatabase $database |
|
109
|
|
|
* @param User $object |
|
110
|
|
|
* @param string $comment |
|
111
|
|
|
*/ |
|
112
|
|
|
public static function suspendedUser(PdoDatabase $database, User $object, $comment) |
|
113
|
|
|
{ |
|
114
|
|
|
self::createLogEntry($database, $object, "Suspended", $comment); |
|
|
|
|
|
|
115
|
|
|
} |
|
|
|
|
|
|
116
|
|
|
|
|
117
|
|
|
/** |
|
118
|
|
|
* @param PdoDatabase $database |
|
119
|
|
|
* @param User $object |
|
120
|
|
|
* @param string $comment |
|
121
|
|
|
*/ |
|
122
|
|
|
public static function demotedUser(PdoDatabase $database, User $object, $comment) |
|
123
|
|
|
{ |
|
124
|
|
|
self::createLogEntry($database, $object, "Demoted", $comment); |
|
|
|
|
|
|
125
|
|
|
} |
|
|
|
|
|
|
126
|
|
|
|
|
127
|
|
|
/** |
|
128
|
|
|
* @param PdoDatabase $database |
|
129
|
|
|
* @param User $object |
|
130
|
|
|
*/ |
|
131
|
|
|
public static function promotedUser(PdoDatabase $database, User $object) |
|
132
|
|
|
{ |
|
133
|
|
|
self::createLogEntry($database, $object, "Promoted"); |
|
|
|
|
|
|
134
|
|
|
} |
|
|
|
|
|
|
135
|
|
|
|
|
136
|
|
|
/** |
|
137
|
|
|
* @param PdoDatabase $database |
|
138
|
|
|
* @param User $object |
|
139
|
|
|
* @param string $comment |
|
140
|
|
|
*/ |
|
141
|
|
|
public static function renamedUser(PdoDatabase $database, User $object, $comment) |
|
142
|
|
|
{ |
|
143
|
|
|
self::createLogEntry($database, $object, "Renamed", $comment); |
|
|
|
|
|
|
144
|
|
|
} |
|
|
|
|
|
|
145
|
|
|
|
|
146
|
|
|
/** |
|
147
|
|
|
* @param PdoDatabase $database |
|
148
|
|
|
* @param User $object |
|
149
|
|
|
*/ |
|
150
|
|
|
public static function userPreferencesChange(PdoDatabase $database, User $object) |
|
151
|
|
|
{ |
|
152
|
|
|
self::createLogEntry($database, $object, "Prefchange"); |
|
|
|
|
|
|
153
|
|
|
} |
|
|
|
|
|
|
154
|
|
|
|
|
155
|
|
|
/** |
|
156
|
|
|
* @param PdoDatabase $database |
|
157
|
|
|
* @param User $object |
|
158
|
|
|
* @param string $reason |
|
159
|
|
|
* @param array $added |
|
160
|
|
|
* @param array $removed |
|
161
|
|
|
*/ |
|
162
|
|
|
public static function userRolesEdited(PdoDatabase $database, User $object, $reason, $added, $removed) |
|
163
|
|
|
{ |
|
164
|
|
|
$logData = serialize(array( |
|
165
|
|
|
'added' => $added, |
|
166
|
|
|
'removed' => $removed, |
|
167
|
|
|
'reason' => $reason, |
|
168
|
|
|
)); |
|
169
|
|
|
|
|
170
|
|
|
self::createLogEntry($database, $object, "RoleChange", $logData); |
|
|
|
|
|
|
171
|
|
|
} |
|
|
|
|
|
|
172
|
|
|
|
|
173
|
|
|
#endregion |
|
174
|
|
|
|
|
175
|
|
|
/** |
|
176
|
|
|
* @param PdoDatabase $database |
|
177
|
|
|
* @param SiteNotice $object |
|
178
|
|
|
*/ |
|
179
|
|
|
public static function siteNoticeEdited(PdoDatabase $database, SiteNotice $object) |
|
180
|
|
|
{ |
|
181
|
|
|
self::createLogEntry($database, $object, "Edited"); |
|
|
|
|
|
|
182
|
|
|
} |
|
|
|
|
|
|
183
|
|
|
|
|
184
|
|
|
#region Welcome Templates |
|
185
|
|
|
|
|
186
|
|
|
/** |
|
187
|
|
|
* @param PdoDatabase $database |
|
188
|
|
|
* @param WelcomeTemplate $object |
|
189
|
|
|
*/ |
|
190
|
|
|
public static function welcomeTemplateCreated(PdoDatabase $database, WelcomeTemplate $object) |
|
191
|
|
|
{ |
|
192
|
|
|
self::createLogEntry($database, $object, "CreatedTemplate"); |
|
|
|
|
|
|
193
|
|
|
} |
|
|
|
|
|
|
194
|
|
|
|
|
195
|
|
|
/** |
|
196
|
|
|
* @param PdoDatabase $database |
|
197
|
|
|
* @param WelcomeTemplate $object |
|
198
|
|
|
*/ |
|
199
|
|
|
public static function welcomeTemplateEdited(PdoDatabase $database, WelcomeTemplate $object) |
|
200
|
|
|
{ |
|
201
|
|
|
self::createLogEntry($database, $object, "EditedTemplate"); |
|
|
|
|
|
|
202
|
|
|
} |
|
|
|
|
|
|
203
|
|
|
|
|
204
|
|
|
/** |
|
205
|
|
|
* @param PdoDatabase $database |
|
206
|
|
|
* @param WelcomeTemplate $object |
|
207
|
|
|
*/ |
|
208
|
|
|
public static function welcomeTemplateDeleted(PdoDatabase $database, WelcomeTemplate $object) |
|
209
|
|
|
{ |
|
210
|
|
|
self::createLogEntry($database, $object, "DeletedTemplate"); |
|
|
|
|
|
|
211
|
|
|
} |
|
|
|
|
|
|
212
|
|
|
|
|
213
|
|
|
#endregion |
|
214
|
|
|
|
|
215
|
|
|
#region Bans |
|
216
|
|
|
|
|
217
|
|
|
/** |
|
218
|
|
|
* @param PdoDatabase $database |
|
219
|
|
|
* @param Ban $object |
|
220
|
|
|
* @param string $reason |
|
221
|
|
|
*/ |
|
222
|
|
|
public static function banned(PdoDatabase $database, Ban $object, $reason) |
|
223
|
|
|
{ |
|
224
|
|
|
self::createLogEntry($database, $object, "Banned", $reason); |
|
|
|
|
|
|
225
|
|
|
} |
|
|
|
|
|
|
226
|
|
|
|
|
227
|
|
|
/** |
|
228
|
|
|
* @param PdoDatabase $database |
|
229
|
|
|
* @param Ban $object |
|
230
|
|
|
* @param string $reason |
|
231
|
|
|
*/ |
|
232
|
|
|
public static function unbanned(PdoDatabase $database, Ban $object, $reason) |
|
233
|
|
|
{ |
|
234
|
|
|
self::createLogEntry($database, $object, "Unbanned", $reason); |
|
|
|
|
|
|
235
|
|
|
} |
|
|
|
|
|
|
236
|
|
|
|
|
237
|
|
|
#endregion |
|
238
|
|
|
|
|
239
|
|
|
#region Requests |
|
240
|
|
|
|
|
241
|
|
|
/** |
|
242
|
|
|
* @param PdoDatabase $database |
|
243
|
|
|
* @param Request $object |
|
244
|
|
|
* @param string $target |
|
245
|
|
|
*/ |
|
246
|
|
|
public static function deferRequest(PdoDatabase $database, Request $object, $target) |
|
247
|
|
|
{ |
|
248
|
|
|
self::createLogEntry($database, $object, "Deferred to $target"); |
|
|
|
|
|
|
249
|
|
|
} |
|
|
|
|
|
|
250
|
|
|
|
|
251
|
|
|
/** |
|
252
|
|
|
* @param PdoDatabase $database |
|
253
|
|
|
* @param Request $object |
|
254
|
|
|
* @param integer $target |
|
255
|
|
|
* @param string $comment |
|
256
|
|
|
*/ |
|
257
|
|
|
public static function closeRequest(PdoDatabase $database, Request $object, $target, $comment) |
|
258
|
|
|
{ |
|
259
|
|
|
self::createLogEntry($database, $object, "Closed $target", $comment); |
|
|
|
|
|
|
260
|
|
|
} |
|
|
|
|
|
|
261
|
|
|
|
|
262
|
|
|
/** |
|
263
|
|
|
* @param PdoDatabase $database |
|
264
|
|
|
* @param Request $object |
|
265
|
|
|
*/ |
|
266
|
|
|
public static function reserve(PdoDatabase $database, Request $object) |
|
267
|
|
|
{ |
|
268
|
|
|
self::createLogEntry($database, $object, "Reserved"); |
|
|
|
|
|
|
269
|
|
|
} |
|
|
|
|
|
|
270
|
|
|
|
|
271
|
|
|
/** |
|
272
|
|
|
* @param PdoDatabase $database |
|
273
|
|
|
* @param Request $object |
|
274
|
|
|
*/ |
|
275
|
|
|
public static function breakReserve(PdoDatabase $database, Request $object) |
|
276
|
|
|
{ |
|
277
|
|
|
self::createLogEntry($database, $object, "BreakReserve"); |
|
|
|
|
|
|
278
|
|
|
} |
|
|
|
|
|
|
279
|
|
|
|
|
280
|
|
|
/** |
|
281
|
|
|
* @param PdoDatabase $database |
|
282
|
|
|
* @param Request $object |
|
283
|
|
|
*/ |
|
284
|
|
|
public static function unreserve(PdoDatabase $database, Request $object) |
|
285
|
|
|
{ |
|
286
|
|
|
self::createLogEntry($database, $object, "Unreserved"); |
|
|
|
|
|
|
287
|
|
|
} |
|
|
|
|
|
|
288
|
|
|
|
|
289
|
|
|
/** |
|
290
|
|
|
* @param PdoDatabase $database |
|
291
|
|
|
* @param Comment $object |
|
292
|
|
|
* @param Request $request |
|
293
|
|
|
*/ |
|
294
|
|
|
public static function editComment(PdoDatabase $database, Comment $object, Request $request) |
|
295
|
|
|
{ |
|
296
|
|
|
self::createLogEntry($database, $request, "EditComment-r"); |
|
|
|
|
|
|
297
|
|
|
self::createLogEntry($database, $object, "EditComment-c"); |
|
|
|
|
|
|
298
|
|
|
} |
|
|
|
|
|
|
299
|
|
|
|
|
300
|
|
|
/** |
|
301
|
|
|
* @param PdoDatabase $database |
|
302
|
|
|
* @param Request $object |
|
303
|
|
|
* @param User $target |
|
304
|
|
|
*/ |
|
305
|
|
|
public static function sendReservation(PdoDatabase $database, Request $object, User $target) |
|
306
|
|
|
{ |
|
307
|
|
|
self::createLogEntry($database, $object, "SendReserved"); |
|
|
|
|
|
|
308
|
|
|
self::createLogEntry($database, $object, "ReceiveReserved", null, $target); |
|
|
|
|
|
|
309
|
|
|
} |
|
|
|
|
|
|
310
|
|
|
|
|
311
|
|
|
/** |
|
312
|
|
|
* @param PdoDatabase $database |
|
313
|
|
|
* @param Request $object |
|
314
|
|
|
* @param string $comment |
|
315
|
|
|
*/ |
|
316
|
|
|
public static function sentMail(PdoDatabase $database, Request $object, $comment) |
|
317
|
|
|
{ |
|
318
|
|
|
self::createLogEntry($database, $object, "SentMail", $comment); |
|
|
|
|
|
|
319
|
|
|
} |
|
|
|
|
|
|
320
|
|
|
#endregion |
|
321
|
|
|
|
|
322
|
|
|
#region Email templates |
|
323
|
|
|
|
|
324
|
|
|
/** |
|
325
|
|
|
* @param PdoDatabase $database |
|
326
|
|
|
* @param EmailTemplate $object |
|
327
|
|
|
*/ |
|
328
|
|
|
public static function createEmail(PdoDatabase $database, EmailTemplate $object) |
|
329
|
|
|
{ |
|
330
|
|
|
self::createLogEntry($database, $object, "CreatedEmail"); |
|
|
|
|
|
|
331
|
|
|
} |
|
|
|
|
|
|
332
|
|
|
|
|
333
|
|
|
/** |
|
334
|
|
|
* @param PdoDatabase $database |
|
335
|
|
|
* @param EmailTemplate $object |
|
336
|
|
|
*/ |
|
337
|
|
|
public static function editedEmail(PdoDatabase $database, EmailTemplate $object) |
|
338
|
|
|
{ |
|
339
|
|
|
self::createLogEntry($database, $object, "EditedEmail"); |
|
|
|
|
|
|
340
|
|
|
} |
|
|
|
|
|
|
341
|
|
|
|
|
342
|
|
|
#endregion |
|
343
|
|
|
|
|
344
|
|
|
#region Display |
|
345
|
|
|
|
|
346
|
|
|
#endregion |
|
347
|
|
|
} |
|
|
|
|
|
|
348
|
|
|
|
PHP provides two ways to mark string literals. Either with single quotes
'literal'or with double quotes"literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (
\') and the backslash (\\). Every other character is displayed as is.Double quoted string literals may contain other variables or more complex escape sequences.
will print an indented:
Single is ValueIf your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.
For more information on PHP string literals and available escape sequences see the PHP core documentation.