deleteuser.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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. if (!defined('STATUSNET') && !defined('LACONICA')) {
  30. 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. * Take arguments for running
  46. *
  47. * @param array $args $_REQUEST args
  48. *
  49. * @return boolean success flag
  50. */
  51. function prepare($args)
  52. {
  53. if (!parent::prepare($args)) {
  54. return false;
  55. }
  56. $cur = common_current_user();
  57. assert(!empty($cur)); // checked by parent
  58. if (!$cur->hasRight(Right::DELETEUSER)) {
  59. // TRANS: Client error displayed when trying to delete a user without having the right to delete users.
  60. $this->clientError(_('You cannot delete users.'));
  61. }
  62. $this->user = User::getKV('id', $this->profile->id);
  63. if (empty($this->user)) {
  64. // TRANS: Client error displayed when trying to delete a non-local user.
  65. $this->clientError(_('You can only delete local users.'));
  66. }
  67. return true;
  68. }
  69. /**
  70. * Handle request
  71. *
  72. * Shows a page with list of favorite notices
  73. *
  74. * @param array $args $_REQUEST args; handled in prepare()
  75. *
  76. * @return void
  77. */
  78. function handle($args)
  79. {
  80. if ($_SERVER['REQUEST_METHOD'] == 'POST') {
  81. if ($this->arg('no')) {
  82. $this->returnToPrevious();
  83. } elseif ($this->arg('yes')) {
  84. $this->handlePost();
  85. $this->returnToPrevious();
  86. } else {
  87. $this->showPage();
  88. }
  89. }
  90. }
  91. function showContent() {
  92. $this->areYouSureForm();
  93. $block = new AccountProfileBlock($this, $this->profile);
  94. $block->show();
  95. }
  96. function title() {
  97. // TRANS: Title of delete user page.
  98. return _m('TITLE','Delete user');
  99. }
  100. function showNoticeForm() {
  101. // nop
  102. }
  103. /**
  104. * Confirm with user.
  105. *
  106. * Shows a confirmation form.
  107. *
  108. * @return void
  109. */
  110. function areYouSureForm()
  111. {
  112. $id = $this->profile->id;
  113. $this->elementStart('form', array('id' => 'deleteuser-' . $id,
  114. 'method' => 'post',
  115. 'class' => 'form_settings form_entity_block',
  116. 'action' => common_local_url('deleteuser')));
  117. $this->elementStart('fieldset');
  118. $this->hidden('token', common_session_token());
  119. // TRANS: Fieldset legend on delete user page.
  120. $this->element('legend', _('Delete user'));
  121. if (Event::handle('StartDeleteUserForm', array($this, $this->user))) {
  122. $this->element('p', null,
  123. // TRANS: Information text to request if a user is certain that the described action has to be performed.
  124. _('Are you sure you want to delete this user? '.
  125. 'This will clear all data about the user from the '.
  126. 'database, without a backup.'));
  127. $this->element('input', array('id' => 'deleteuserto-' . $id,
  128. 'name' => 'profileid',
  129. 'type' => 'hidden',
  130. 'value' => $id));
  131. foreach ($this->args as $k => $v) {
  132. if (substr($k, 0, 9) == 'returnto-') {
  133. $this->hidden($k, $v);
  134. }
  135. }
  136. Event::handle('EndDeleteUserForm', array($this, $this->user));
  137. }
  138. $this->submit('form_action-no',
  139. // TRANS: Button label on the delete user form.
  140. _m('BUTTON','No'),
  141. 'submit form_action-primary',
  142. 'no',
  143. // TRANS: Submit button title for 'No' when deleting a user.
  144. _('Do not delete this user.'));
  145. $this->submit('form_action-yes',
  146. // TRANS: Button label on the delete user form.
  147. _m('BUTTON','Yes'),
  148. 'submit form_action-secondary',
  149. 'yes',
  150. // TRANS: Submit button title for 'Yes' when deleting a user.
  151. _('Delete this user.'));
  152. $this->elementEnd('fieldset');
  153. $this->elementEnd('form');
  154. }
  155. /**
  156. * Actually delete a user.
  157. *
  158. * @return void
  159. */
  160. function handlePost()
  161. {
  162. if (Event::handle('StartDeleteUser', array($this, $this->user))) {
  163. // Mark the account as deleted and shove low-level deletion tasks
  164. // to background queues. Removing a lot of posts can take a while...
  165. if (!$this->user->hasRole(Profile_role::DELETED)) {
  166. $this->user->grantRole(Profile_role::DELETED);
  167. }
  168. $qm = QueueManager::get();
  169. $qm->enqueue($this->user, 'deluser');
  170. Event::handle('EndDeleteUser', array($this, $this->user));
  171. }
  172. }
  173. }