]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/deleteuser.php
New domain regexp for WebFinger matching.
[quix0rs-gnu-social.git] / actions / deleteuser.php
1 <?php
2 /**
3  * StatusNet, the distributed open-source microblogging tool
4  *
5  * Action class to delete a user
6  *
7  * PHP version 5
8  *
9  * LICENCE: This program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU Affero General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU Affero General Public License for more details.
18  *
19  * You should have received a copy of the GNU Affero General Public License
20  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21  *
22  * @category  Action
23  * @package   StatusNet
24  * @author    Evan Prodromou <evan@status.net>
25  * @copyright 2009 StatusNet, Inc.
26  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
27  * @link      http://status.net/
28  */
29
30 if (!defined('GNUSOCIAL')) { exit(1); }
31
32 /**
33  * Delete a user
34  *
35  * @category Action
36  * @package  StatusNet
37  * @author   Evan Prodromou <evan@status.net>
38  * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
39  * @link     http://status.net/
40  */
41 class DeleteuserAction extends ProfileFormAction
42 {
43     var $user = null;
44
45     function prepare(array $args=array())
46     {
47         if (!parent::prepare($args)) {
48             return false;
49         }
50
51         assert($this->scoped instanceof Profile);
52
53         if (!$this->scoped->hasRight(Right::DELETEUSER)) {
54             // TRANS: Client error displayed when trying to delete a user without having the right to delete users.
55             throw new AuthorizationException(_('You cannot delete users.'));
56         }
57
58         try {
59             $this->user = $this->profile->getUser();
60         } catch (NoSuchUserException $e) {
61             // TRANS: Client error displayed when trying to delete a non-local user.
62             throw new ClientException(_('You can only delete local users.'));
63         }
64
65         // Only administrators can delete other privileged users (such as others who have the right to silence).
66         if ($this->profile->isPrivileged() && !$this->scoped->hasRole(Profile_role::ADMINISTRATOR)) {
67             // TRANS: Client error displayed when trying to delete a user that has been granted moderation privileges
68             throw new AuthorizationException(_('You cannot delete other privileged users.'));
69         }
70
71         return true;
72     }
73
74     /**
75      * Handle request
76      *
77      * Shows a page with list of favorite notices
78      *
79      * @param array $args $_REQUEST args; handled in prepare()
80      *
81      * @return void
82      */
83     function handle($args)
84     {
85         if ($_SERVER['REQUEST_METHOD'] == 'POST') {
86             if ($this->arg('no')) {
87                 $this->returnToPrevious();
88             } elseif ($this->arg('yes')) {
89                 $this->handlePost();
90                 $this->returnToPrevious();
91             } else {
92                 $this->showPage();
93             }
94         }
95     }
96
97     function showContent() {
98         $this->areYouSureForm();
99         $block = new AccountProfileBlock($this, $this->profile);
100         $block->show();        
101     }
102
103     function title() {
104         // TRANS: Title of delete user page.
105         return _m('TITLE','Delete user');
106     }
107
108     function showNoticeForm() {
109         // nop
110     }
111
112     /**
113      * Confirm with user.
114      *
115      * Shows a confirmation form.
116      *
117      * @return void
118      */
119     function areYouSureForm()
120     {
121         $id = $this->profile->id;
122         $this->elementStart('form', array('id' => 'deleteuser-' . $id,
123                                            'method' => 'post',
124                                            'class' => 'form_settings form_entity_block',
125                                            'action' => common_local_url('deleteuser')));
126         $this->elementStart('fieldset');
127         $this->hidden('token', common_session_token());
128         // TRANS: Fieldset legend on delete user page.
129         $this->element('legend', _('Delete user'));
130         if (Event::handle('StartDeleteUserForm', array($this, $this->user))) {
131             $this->element('p', null,
132                            // TRANS: Information text to request if a user is certain that the described action has to be performed.
133                            _('Are you sure you want to delete this user? '.
134                              'This will clear all data about the user from the '.
135                              'database, without a backup.'));
136             $this->element('input', array('id' => 'deleteuserto-' . $id,
137                                           'name' => 'profileid',
138                                           'type' => 'hidden',
139                                           'value' => $id));
140             foreach ($this->args as $k => $v) {
141                 if (substr($k, 0, 9) == 'returnto-') {
142                     $this->hidden($k, $v);
143                 }
144             }
145             Event::handle('EndDeleteUserForm', array($this, $this->user));
146         }
147         $this->submit('form_action-no',
148                       // TRANS: Button label on the delete user form.
149                       _m('BUTTON','No'),
150                       'submit form_action-primary',
151                       'no',
152                       // TRANS: Submit button title for 'No' when deleting a user.
153                       _('Do not delete this user.'));
154         $this->submit('form_action-yes',
155                       // TRANS: Button label on the delete user form.
156                       _m('BUTTON','Yes'),
157                       'submit form_action-secondary',
158                       'yes',
159                       // TRANS: Submit button title for 'Yes' when deleting a user.
160                       _('Delete this user.'));
161         $this->elementEnd('fieldset');
162         $this->elementEnd('form');
163     }
164
165     /**
166      * Actually delete a user.
167      *
168      * @return void
169      */
170     function handlePost()
171     {
172         if (Event::handle('StartDeleteUser', array($this, $this->user))) {
173             // Mark the account as deleted and shove low-level deletion tasks
174             // to background queues. Removing a lot of posts can take a while...
175             if (!$this->user->hasRole(Profile_role::DELETED)) {
176                 $this->user->grantRole(Profile_role::DELETED);
177             }
178
179             $qm = QueueManager::get();
180             $qm->enqueue($this->user, 'deluser');
181
182             Event::handle('EndDeleteUser', array($this, $this->user));
183         }
184     }
185 }