Follow-up r83909: Use 'parentheses' message for consistency instead of hardcoded []
[lhc/web/wiklou.git] / includes / specials / SpecialDisableAccount.php
1 <?php
2
3 class SpecialDisableAccount extends SpecialPage {
4 function __construct() {
5 parent::__construct( 'DisableAccount', 'disableaccount',
6 true, array( $this, 'show' ) );
7 }
8
9 public function show( $par ) {
10 $formFields = array(
11 'account' => array(
12 'type' => 'text',
13 'validation-callback' => array( __CLASS__, 'validateUser' ),
14 'label-message' => 'disableaccount-user',
15 ),
16 'comment' => array(
17 'type' => 'text',
18 'label-message' => 'disableaccount-reason',
19 ),
20 'confirm' => array(
21 'type' => 'toggle',
22 'validation-callback' => array( __CLASS__, 'checkConfirmation' ),
23 'label-message' => 'disableaccount-confirm',
24 ),
25 );
26
27 $htmlForm = new HTMLForm( $formFields, 'disableaccount' );
28
29 $htmlForm->setSubmitCallback( array( __CLASS__, 'submit' ) );
30 $htmlForm->setTitle( $this->getTitle() );
31
32 $htmlForm->show();
33 }
34
35 static function validateUser( $field, $allFields ) {
36 $u = User::newFromName( $field );
37
38 if ( $u && $u->getID() != 0 ) {
39 return true;
40 } else {
41 return wfMsgExt( 'disableaccount-nosuchuser', 'parseinline', array( $field ) );
42 }
43 }
44
45 static function checkConfirmation( $field, $allFields ) {
46 if ( $field ) {
47 return true;
48 } else {
49 return wfMsgExt( 'disableaccount-mustconfirm', 'parseinline' );
50 }
51 }
52
53 static function submit( $fields ) {
54 $user = User::newFromName( $fields['account'] );
55
56 $user->setPassword( null );
57 $user->setEmail( null );
58 $user->setToken();
59 $user->addGroup( 'inactive' );
60
61 $user->saveSettings();
62 $user->invalidateCache();
63
64 $logPage = new LogPage( 'rights' );
65
66 $logPage->addEntry( 'disable', $user->getUserPage(), $fields['comment'] );
67
68 global $wgOut;
69 $wgOut->addWikiMsg( 'disableaccount-success', $user->getName() );
70
71 return true;
72 }
73 }