-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSpecialEditAccount_body.php
727 lines (653 loc) · 22.7 KB
/
SpecialEditAccount_body.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
<?php
/**
* Main logic of the EditAccount extension
*
* @file
* @ingroup Extensions
* @author Łukasz Garczewski (TOR) <tor@wikia-inc.com>
* @date 2008-09-17
* @copyright Copyright © 2008 Łukasz Garczewski, Wikia Inc.
* @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
*/
class EditAccount extends SpecialPage {
public $mUser = null;
public $mStatus = null;
public $mStatusMsg;
public $mStatusMsg2 = null;
public $mTempUser = null;
/**
* Constructor -- set up the new special page
*/
public function __construct() {
parent::__construct( 'EditAccount' ); // restriction intentionally removed
// Show this special page on Special:SpecialPages only for registered
// users
$this->setListed( $this->getUser()->isLoggedIn() );
}
/**
* Group this special page under the correct header in Special:SpecialPages.
*
* @return string
*/
function getGroupName() {
return 'users';
}
/**
* Special page description shown on Special:SpecialPages -- different for
* privileged users and mortals
*
* @return string Special page description
*/
function getDescription() {
if ( $this->getUser()->isAllowed( 'editaccount' ) ) {
return $this->msg( 'editaccount' )->plain();
} else {
return $this->msg( 'editaccount-general-description' )->plain();
}
}
/**
* Show the special page
*
* @param string|null $par Parameter (user name) passed to the page or null
*/
public function execute( $par ) {
$out = $this->getOutput();
$request = $this->getRequest();
$user = $this->getUser();
// Anons should not be allowed to access this special page
if ( !$user->isLoggedIn() ) {
throw new PermissionsError( 'editaccount' );
}
// Show a message if the database is in read-only mode
if ( wfReadOnly() ) {
$out->readOnlyPage();
return;
}
// If user is blocked, s/he doesn't need to access this page
if ( $user->isBlocked() ) {
throw new UserBlockedError( $user->mBlock );
}
// Set page title and other stuff
$this->setHeaders();
// Special:EditAccount is a fairly stupid page title
$out->setPageTitle( $this->getDescription() );
// If the user isn't permitted to access this special page, display an error
if ( $user->isAllowed( 'editaccount' ) ) {
// Get name to work on. Subpage is supported, but form submit name trumps
$userName = $request->getVal( 'wpUserName', $par );
$action = $request->getVal( 'wpAction' );
} else {
// Mortals can only close their own account
$userName = $user->getName();
$action = 'closeaccount';
}
if( $userName !== null ) {
// Got a name, clean it up
$userName = str_replace( '_', ' ', trim( $userName ) );
// User names begin with a capital letter
$userName = $this->getLanguage()->ucfirst( $userName );
// Check if user name is an existing user
if ( User::isValidUserName( $userName ) ) {
$this->mUser = User::newFromName( $userName );
$id = $this->mUser->idFromName( $userName );
if( empty( $action ) ) {
$action = 'displayuser';
}
if ( empty( $id ) ) {
// Wikia stuff...
if ( class_exists( 'TempUser' ) ) {
$this->mTempUser = TempUser::getTempUserFromName( $userName );
}
if ( $this->mTempUser ) {
$id = $this->mTempUser->getId();
$this->mUser = User::newFromId( $id );
} else {
$this->mStatus = false;
$this->mStatusMsg = $this->msg( 'editaccount-nouser', $userName )->text();
$action = '';
}
}
}
}
// FB:23860
if ( !( $this->mUser instanceof User ) ) {
$action = '';
}
$changeReason = $request->getVal( 'wpReason' );
// What to do, what to show? Hmm...
switch( $action ) {
case 'setemail':
$newEmail = $request->getVal( 'wpNewEmail' );
$this->mStatus = $this->setEmail( $newEmail, $changeReason );
$template = 'DisplayUser';
break;
case 'setpass':
$newPass = $request->getVal( 'wpNewPass' );
$this->mStatus = $this->setPassword( $newPass, $changeReason );
$template = 'DisplayUser';
break;
case 'setrealname':
$newRealName = $request->getVal( 'wpNewRealName' );
$this->mStatus = $this->setRealName( $newRealName, $changeReason );
$template = 'DisplayUser';
break;
case 'closeaccount':
$template = 'CloseAccount';
$this->mStatus = (bool) $this->mUser->getOption( 'requested-closure', 0 );
if ( $this->mStatus ) {
$this->mStatusMsg = $this->msg( 'editaccount-requested' )->text();
} else {
$this->mStatusMsg = $this->msg( 'editaccount-not-requested' )->text();
}
break;
case 'closeaccountconfirm':
$this->mStatus = $this->closeAccount( $changeReason );
$template = $this->mStatus ? 'SelectUser' : 'DisplayUser';
break;
case 'clearunsub':
$this->mStatus = $this->clearUnsubscribe();
$template = 'DisplayUser';
break;
case 'cleardisable':
$this->mStatus = $this->clearDisable();
$template = 'DisplayUser';
break;
case 'toggleadopter':
$this->mStatus = $this->toggleAdopterStatus();
$template = 'DisplayUser';
break;
case 'displayuser':
$template = 'DisplayUser';
break;
default:
$template = 'SelectUser';
}
// Load the correct template file, build the class name and initiate a
// new template object (so that we can set variables later on)
include( 'templates/' . strtolower( $template ) . '.tmpl.php' );
$templateClassName = 'EditAccount' . $template . 'Template';
$tmpl = new $templateClassName;
$templateVariables = array(
'status' => $this->mStatus,
'statusMsg' => $this->mStatusMsg,
'statusMsg2' => $this->mStatusMsg2,
'user' => $userName,
'userEmail' => null,
'userRealName' => null,
'userEncoded' => urlencode( $userName ),
'user_hsc' => htmlspecialchars( $userName ),
'userId' => null,
'userReg' => null,
'isUnsub' => null,
'isDisabled' => null,
'isAdopter' => null,
'returnURL' => $this->getTitle()->getFullURL(),
'logLink' => Linker::linkKnown(
SpecialPage::getTitleFor( 'Log', 'editaccnt' ),
$this->msg( 'log-name-editaccnt' )->escaped()
),
'userStatus' => null,
'emailStatus' => null,
'disabled' => null,
'changeEmailRequested' => null,
);
foreach ( $templateVariables as $templateVariable => $variableValue ) {
$tmpl->set( $templateVariable, $variableValue );
}
if ( is_object( $this->mUser ) ) {
if ( $this->mTempUser ) {
$this->mUser = $this->mTempUser->mapTempUserToUser( false );
$userStatus = $this->msg( 'editaccount-status-tempuser' )->plain();
$tmpl->set( 'disabled', 'disabled="disabled"' );
} else {
$userStatus = $this->msg( 'editaccount-status-realuser' )->plain();
}
$this->mUser->load();
// get new e-mail (unconfirmed)
$optionNewEmail = $this->mUser->getOption( 'new_email' );
if ( empty( $optionNewEmail ) ) {
$changeEmailRequested = '';
} else {
$changeEmailRequested = $this->msg( 'editaccount-email-change-requested', $optionNewEmail )->parse();
}
// emailStatus is the status of the e-mail in the "Set new email address" field
if ( $this->mUser->isEmailConfirmed() ) {
$emailStatus = $this->msg( 'editaccount-status-confirmed' )->plain();
} else {
$emailStatus = $this->msg( 'editaccount-status-unconfirmed' )->plain();
}
$templateVariables2 = array(
'userEmail' => $this->mUser->getEmail(),
'userRealName' => $this->mUser->getRealName(),
'userId' => $this->mUser->getId(),
'userReg' => date( 'r', strtotime( $this->mUser->getRegistration() ) ),
'isUnsub' => $this->mUser->getOption( 'unsubscribed' ),
'isDisabled' => $this->mUser->getOption( 'disabled' ),
'isAdopter' => $this->mUser->getOption( 'AllowAdoption', 1 ),
'userStatus' => $userStatus,
'emailStatus' => $emailStatus,
'changeEmailRequested' => $changeEmailRequested,
);
// This will overwrite the previous variables which are null
foreach ( $templateVariables2 as $templateVariable2 => $variableValue2 ) {
$tmpl->set( $templateVariable2, $variableValue2 );
}
}
// HTML output
$out->addTemplate( $tmpl );
}
/**
* Set a user's e-mail
*
* @param string $email E-mail address to set to the user
* @param string $changeReason Reason for change
* @return bool True on success, false on failure (i.e. if we were given an invalid email address)
*/
function setEmail( $email, $changeReason = '' ) {
$oldEmail = $this->mUser->getEmail();
if ( Sanitizer::validateEmail( $email ) || $email == '' ) {
if ( $this->mTempUser ) {
if ( $email == '' ) {
$this->mStatusMsg = $this->msg( 'editaccount-error-tempuser-email' )->text();
return false;
} else {
$this->mTempUser->setEmail( $email );
$this->mUser = $this->mTempUser->activateUser( $this->mUser );
// reset temp user after activating the user
$this->mTempUser = null;
}
} else {
$this->mUser->setEmail( $email );
if ( $email != '' ) {
$this->mUser->confirmEmail();
$this->mUser->setOption( 'new_email', null );
} else {
$this->mUser->invalidateEmail();
}
$this->mUser->saveSettings();
}
// Check if everything went through OK, just in case
if ( $this->mUser->getEmail() == $email ) {
// Log the change
$logEntry = new ManualLogEntry( 'editaccnt', 'mailchange' );
$logEntry->setPerformer( $this->getUser() );
$logEntry->setTarget( $this->mUser->getUserPage() );
$logEntry->setComment( $changeReason ); // JP 13 April 2013: not sure if this is the correct one, CHECKME
$logId = $logEntry->insert();
if ( $email == '' ) {
$this->mStatusMsg = $this->msg( 'editaccount-success-email-blank', $this->mUser->mName )->text();
} else {
$this->mStatusMsg = $this->msg( 'editaccount-success-email', $this->mUser->mName, $email )->text();
}
return true;
} else {
$this->mStatusMsg = $this->msg( 'editaccount-error-email', $this->mUser->mName )->text();
return false;
}
} else {
$this->mStatusMsg = $this->msg( 'editaccount-invalid-email', $email )->text();
return false;
}
}
/**
* Set a user's password.
*
* @param mixed $pass Password to set to the user
* @param string $changeReason Reason for change
* @return bool True on success, false on failure
*/
function setPassword( $pass, $changeReason = '' ) {
if ( $this->mUser->setPassword( $pass ) ) {
// Save the new settings
if ( $this->mTempUser ) {
$this->mTempUser->setPassword( $this->mUser->mPassword );
$this->mTempUser->updateData();
$this->mTempUser->saveSettingsTempUserToUser( $this->mUser );
$this->mUser->mName = $this->mTempUser->getName();
} else {
$this->mUser->saveSettings();
}
// Log what was done
$logEntry = new ManualLogEntry( 'editaccnt', 'passchange' );
$logEntry->setPerformer( $this->getUser() );
$logEntry->setTarget( $this->mUser->getUserPage() );
$logEntry->setComment( $changeReason ); // JP 13 April 2013: not sure if this is the correct one, CHECKME
$logId = $logEntry->insert();
// And finally, inform the user that everything went as planned
$this->mStatusMsg = $this->msg( 'editaccount-success-pass', $this->mUser->mName )->text();
return true;
} else {
// We have errors, let's inform the user about those
$this->mStatusMsg = $this->msg( 'editaccount-error-pass', $this->mUser->mName )->text();
return false;
}
}
/**
* Set a user's real name.
*
* @param mixed $pass Real name to set to the user
* @param string $changeReason Reason for change
* @return bool True on success, false on failure
*/
function setRealName( $realName, $changeReason = '' ) {
$this->mUser->setRealName( $realName );
$this->mUser->saveSettings();
// Was the change saved successfully? The setRealName function doesn't
// return a boolean value...
if ( $this->mUser->getRealName() == $realName ) {
// Log what was done
$logEntry = new ManualLogEntry( 'editaccnt', 'realnamechange' );
$logEntry->setPerformer( $this->getUser() );
$logEntry->setTarget( $this->mUser->getUserPage() );
$logEntry->setComment( $changeReason ); // JP 13 April 2013: not sure if this is the correct one, CHECKME
$logId = $logEntry->insert();
// And finally, inform the user that everything went as planned
$this->mStatusMsg = $this->msg( 'editaccount-success-realname', $this->mUser->mName )->text();
return true;
} else {
// We have errors, let's inform the user about those
$this->mStatusMsg = $this->msg( 'editaccount-error-realname', $this->mUser->mName )->text();
return false;
}
}
/**
* Scrambles the user's password, sets an empty e-mail and marks the
* account as disabled
*
* @param string $changeReason Reason for change
* @return bool True on success, false on failure
*/
function closeAccount( $changeReason = '' ) {
// Set flag for Special:Contributions
// NOTE: requires FlagClosedAccounts.php to be included separately
if ( defined( 'CLOSED_ACCOUNT_FLAG' ) ) {
$this->mUser->setRealName( CLOSED_ACCOUNT_FLAG );
} else {
// magic value not found, so let's at least blank it
$this->mUser->setRealName( '' );
}
// remove user's avatar
if ( class_exists( 'wAvatar' ) ) { // SocialProfile
// Commented out because as of 17 June 2013, ShoutWiki has only 8
// wikis with SocialProfile enabled and this method is probably
// *very* expensive since it does operations for everything in the
// images directory...
//$this->removeSocialProfileAvatars();
} elseif ( class_exists( 'Masthead' ) ) { // Wikia's avatar extension
$avatar = Masthead::newFromUser( $this->mUser );
if ( !$avatar->isDefault() ) {
if( !$avatar->removeFile( false ) ) {
// don't quit here, since the avatar is a non-critical part
// of closing, but flag for later
$this->mStatusMsg2 = $this->msg( 'editaccount-remove-avatar-fail' )->plain();
}
}
}
// Remove e-mail address and password
$this->mUser->setEmail( '' );
$newPass = $this->generateRandomScrambledPassword();
$this->mUser->setPassword( $newPass );
// Save the new settings
$this->mUser->saveSettings();
$id = $this->mUser->getId();
// Reload user
$this->mUser = User::newFromId( $id );
if ( $this->mUser->getEmail() == '' ) {
// ShoutWiki patch begin
$this->setDisabled();
// ShoutWiki patch end
// Mark as disabled in a more real way, that doesn't depend on the real_name text
$this->mUser->setOption( 'disabled', 1 );
$this->mUser->setOption( 'disabled_date', wfTimestamp( TS_DB ) );
// BugId:18085 - setting a new token causes the user to be logged out.
$this->mUser->setToken( md5( microtime() . mt_rand( 0, 0x7fffffff ) ) );
// BugID:95369 This forces saveSettings() to commit the transaction
// FIXME: this is a total hack, we should add a commit=true flag to saveSettings
$this->getRequest()->setVal( 'action', 'ajax' );
// Need to save these additional changes
$this->mUser->saveSettings();
// Log what was done
$logEntry = new ManualLogEntry( 'editaccnt', 'closeaccnt' );
$logEntry->setPerformer( $this->getUser() );
$logEntry->setTarget( $this->mUser->getUserPage() );
$logEntry->setComment( $changeReason ); // JP 13 April 2013: not sure if this is the correct one, CHECKME
$logId = $logEntry->insert();
// All clear!
$this->mStatusMsg = $this->msg( 'editaccount-success-close', $this->mUser->mName )->text();
return true;
} else {
// There were errors...inform the user about those
$this->mStatusMsg = $this->msg( 'editaccount-error-close', $this->mUser->mName )->text();
return false;
}
}
/**
* Clears the magic unsub bit
*
* @return bool Always true
*/
function clearUnsubscribe() {
$this->mUser->setOption( 'unsubscribed', null );
$this->mUser->saveSettings();
$this->mStatusMsg = $this->msg( 'editaccount-success-unsub', $this->mUser->mName )->text();
return true;
}
/**
* Clears the magic disabled bit
*
* @return bool Always true
*/
function clearDisable() {
$this->mUser->setOption( 'disabled', null );
$this->mUser->setOption( 'disabled_date', null );
$this->mUser->saveSettings();
$this->mStatusMsg = $this->msg( 'editaccount-success-disable', $this->mUser->mName )->text();
return true;
}
/**
* Set the adoption status (i.e. is the user who is being edited allowed to
* automatically adopt wikis or not).
*
* @return bool Always true
*/
function toggleAdopterStatus() {
$this->mUser->setOption( 'AllowAdoption', (int) !$this->mUser->getOption( 'AllowAdoption', 1 ) );
$this->mUser->saveSettings();
$this->mStatusMsg = $this->msg( 'editaccount-success-toggleadopt', $this->mUser->mName )->text();
return true;
}
/**
* Returns a random password which conforms to our password requirements
* and is not easily guessable.
*
* @return string
*/
function generateRandomScrambledPassword() {
// Password requirements need a capital letter, a digit, and a lowercase letter.
// wfGenerateToken() returns a 32 char hex string, which will almost
// always satisfy the digit/letter but not always.
// This suffix shouldn't reduce the entropy of the intentionally
// scrambled password.
$REQUIRED_CHARS = 'A1a';
return ( self::generateToken() . $REQUIRED_CHARS );
}
/**
* Remove SocialProfile avatars from all wikis.
*
* @note The foreach loop is almost a verbatim copy-paste of the private method
* RemoveAvatar::deleteImage() from extensions/SocialProfile/UserProfile/SpecialRemoveAvatar.php
* That method should be made public and this should then be rewritten
* accordingly.
*
* @return bool Always true
*/
function removeSocialProfileAvatars() {
global $IP, $wgUploadDirectory, $wgDBname, $wgMemc, $wgUploadAvatarInRecentChanges;
// @see http://www.developerfusion.com/code/2058/determine-execution-time-in-php/
$mtime = microtime();
$mtime = explode( ' ', $mtime );
$mtime = $mtime[1] + $mtime[0];
$startTime = $mtime;
// @todo FIXME: horribly ShoutWiki-specific
$path = $IP . '/images/';
$handle = opendir( $path );
if ( $handle ) {
$file = readdir( $handle );
while ( $file !== false ) {
// do something with the file
// note that '.' and '..' is returned even
if ( $file != '.' && $file != '..' ) {
$fullpath = $path . $file;
// If this is a directory...
if ( is_dir( $fullpath ) ) {
// change our current working directory to it, then!
chdir( $fullpath );
// Look for the avatars directory
if ( is_dir( getcwd() . '/avatars' ) ) {
// Split the current directory name from right to left
// @see http://stackoverflow.com/questions/717328/how-to-explode-string-right-to-left
$result = array_map( 'strrev', explode( '/', strrev( getcwd() ) ) );
// $result[0] should now hold the image directory
// name, from which we can construct the DB name
// easily
if ( isset( $result[0] ) && $result[0] ) {
// Oh fuck, the directory name contains a
// period (i.e. "fi.starwars")
if ( strpos( $result[0], '.' ) !== false ) {
$splitDirName = explode( '.', $result[0] );
// for fi.starwars, this would look like "starwars_fiwiki"
// which is the expected result.
// Phew, finally!
$dbName = $splitDirName[1] . '_' . $splitDirName[0] . '_wiki';
} else {
// Just append "_wiki" to the image dir
// name to get the DB name.
$dbName = $result[0] . '_wiki';
}
// Normalization...
$dbName = str_replace( '-', '_', $dbName );
// ACTUALLY REMOVE THE DAMN THINGS!
foreach ( array( 's', 'm', 'ml', 'l' ) as $size ) {
$avatar = new wAvatar( $this->mUser->getId(), $size );
$files = glob(
getcwd() . '/avatars/' . $dbName . '_' .
$this->mUser->getId() . '_' . $size . '*'
);
wfSuppressWarnings();
$img = basename( $files[0] );
wfRestoreWarnings();
if ( $img && $img[0] ) {
unlink( getcwd() . '/avatars/' . $img );
}
// clear cache
$key = wfMemcKey( 'user', 'profile', 'avatar', $this->mUser->getId(), $size );
$wgMemc->delete( $key );
}
// Ensure that the logs are placed into the correct DB
$dbw = wfGetDB( DB_MASTER, array(), $dbName );
// Log it!
// Note: old-school logging style is
// intentionally used here because it's what
// SocialProfile uses, too.
$log = new LogPage( 'avatar' );
if ( !$wgUploadAvatarInRecentChanges ) {
$log->updateRecentChanges = false;
}
$logMsg = $this->msg(
'user-profile-picture-log-delete-entry',
$this->mUser->getName()
);
// It should never be empty or disabled, but...
if ( !$logMsg->isEmpty() || !$logMsg->isDisabled() ) {
$log->addEntry(
'avatar',
$this->getUser()->getUserPage(),
$logMsg->text()
);
}
// For good measure, yo.
$dbw->commit();
}
} else {
//error_log( getcwd() . '/avatars/ does not exist, skipping.' );
}
}
}
}
closedir( $handle );
}
$mtime = microtime();
$mtime = explode( ' ', $mtime );
$mtime = $mtime[1] + $mtime[0];
$endTime = $mtime;
$totalTime = ( $endTime - $startTime );
error_log(
__METHOD__ . ': checking for (and possibly deleting) avatars took ' .
$totalTime
);
return true;
}
/**
* Marks the account as disabled, the ShoutWiki way.
*/
function setDisabled() {
if ( !class_exists( 'GlobalPreferences' ) ) {
error_log( 'Cannot use the GlobalPreferences class in ' . __METHOD__ );
return;
}
$dbw = GlobalPreferences::getPrefsDB( DB_MASTER );
$dbw->begin();
$dbw->insert(
'global_preferences',
array(
'gp_property' => 'disabled',
'gp_value' => 1,
'gp_user' => $this->mUser->getId()
),
__METHOD__
);
$dbw->commit();
$dbw->begin();
$dbw->insert(
'global_preferences',
array(
'gp_property' => 'disabled_date',
'gp_value' => wfTimestamp( TS_DB ),
'gp_user' => $this->mUser->getId()
),
__METHOD__
);
$dbw->commit();
}
/**
* Is the given user account disabled?
*
* @param $user User
* @return bool True if it is disabled, otherwise false
*/
public static function isAccountDisabled( $user ) {
if ( !class_exists( 'GlobalPreferences' ) ) {
error_log( 'Cannot use the GlobalPreferences class in ' . __METHOD__ );
return;
}
$dbr = GlobalPreferences::getPrefsDB();
$retVal = $dbr->selectField(
'global_preferences',
'gp_value',
array(
'gp_property' => 'disabled',
'gp_user' => $user->getId()
),
__METHOD__
);
return (bool) $retVal;
}
/**
* Copypasta from pre-1.23 /includes/GlobalFunctions.php
* @see https://git.wikimedia.org/commitdiff/mediawiki%2Fcore/118567a4ba0ded669f43a58713733cab915afe39
*/
public static function generateToken( $salt = '' ) {
$salt = serialize( $salt );
return md5( mt_rand( 0, 0x7fffffff ) . $salt );
}
}