3 * StatusNet, the distributed open-source microblogging tool
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.
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.
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/>.
24 * @author Evan Prodromou <evan@status.net>
25 * @author Brion Vibber <brion@status.net>
26 * @copyright 2008-2010 StatusNet, Inc.
27 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
28 * @link http://status.net/
31 if (!defined('STATUSNET') && !defined('LACONICA')) {
38 * This is the action for deleting a group.
42 * @author Evan Prodromou <evan@status.net>
43 * @author Brion Vibber <brion@status.net>
44 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
45 * @link http://status.net/
46 * @fixme merge more of this code with related variants
48 class DeletegroupAction extends RedirectingAction
55 * @fixme merge common setup code with other group actions
56 * @fixme allow group admins to delete their own groups
58 function prepare($args)
60 parent::prepare($args);
62 if (!common_logged_in()) {
63 // TRANS: Client error when trying to delete group while not logged in.
64 $this->clientError(_('You must be logged in to delete a group.'));
68 $nickname_arg = $this->trimmed('nickname');
69 $id = intval($this->arg('id'));
71 $this->group = User_group::staticGet('id', $id);
72 } else if ($nickname_arg) {
73 $nickname = common_canonical_nickname($nickname_arg);
75 // Permanent redirect on non-canonical nickname
77 if ($nickname_arg != $nickname) {
78 $args = array('nickname' => $nickname);
79 common_redirect(common_local_url('leavegroup', $args), 301);
83 $local = Local_group::staticGet('nickname', $nickname);
86 // TRANS: Client error when trying to delete a non-local group.
87 $this->clientError(_('No such group.'), 404);
91 $this->group = User_group::staticGet('id', $local->group_id);
93 // TRANS: Client error when trying to delete a group without providing a nickname or ID for the group.
94 $this->clientError(_('No nickname or ID.'), 404);
99 // TRANS: Client error when trying to delete a non-existing group.
100 $this->clientError(_('No such group.'), 404);
104 $cur = common_current_user();
105 if (!$cur->hasRight(Right::DELETEGROUP)) {
106 // TRANS: Client error when trying to delete a group without having the rights to delete it.
107 $this->clientError(_('You are not allowed to delete this group.'), 403);
117 * On POST, delete the group.
119 * @param array $args unused
123 function handle($args)
125 parent::handle($args);
126 if ($_SERVER['REQUEST_METHOD'] == 'POST') {
127 if ($this->arg('no')) {
128 $this->returnToPrevious();
130 } elseif ($this->arg('yes')) {
138 function handlePost()
140 $cur = common_current_user();
143 if (Event::handle('StartDeleteGroup', array($this->group))) {
144 $this->group->delete();
145 Event::handle('EndDeleteGroup', array($this->group));
147 } catch (Exception $e) {
148 // TRANS: Server error displayed if a group could not be deleted.
149 // TRANS: %s is the name of the group that could not be deleted.
150 $this->serverError(sprintf(_('Could not delete group %s.'),
151 $this->group->nickname));
154 if ($this->boolean('ajax')) {
155 $this->startHTML('text/xml;charset=utf-8');
156 $this->elementStart('head');
157 // TRANS: Message given after deleting a group.
158 // TRANS: %s is the deleted group's name.
159 $this->element('title', null, sprintf(_('Deleted group %s'),
160 $this->group->nickname));
161 $this->elementEnd('head');
162 $this->elementStart('body');
163 // @fixme add a sensible AJAX response form!
164 $this->elementEnd('body');
165 $this->elementEnd('html');
167 // @fixme if we could direct to the page on which this group
168 // would have shown... that would be awesome
169 common_redirect(common_local_url('groups'),
176 return _('Delete group');
179 function showContent() {
180 $this->areYouSureForm();
185 * Ripped from DeleteuserAction
187 * Shows a confirmation form.
189 * @fixme refactor common code for things like this
192 function areYouSureForm()
194 $id = $this->group->id;
195 $this->elementStart('form', array('id' => 'deletegroup-' . $id,
197 'class' => 'form_settings form_entity_block',
198 'action' => common_local_url('deletegroup', array('id' => $this->group->id))));
199 $this->elementStart('fieldset');
200 $this->hidden('token', common_session_token());
201 // TRANS: Form legend for deleting a group.
202 $this->element('legend', _('Delete group'));
203 if (Event::handle('StartDeleteGroupForm', array($this, $this->group))) {
204 // TRANS: Warning in form for deleleting a group.
205 $this->element('p', null,
206 _('Are you sure you want to delete this group? '.
207 'This will clear all data about the group from the '.
208 'database, without a backup. ' .
209 'Public posts to this group will still appear in ' .
210 'individual timelines.'));
211 foreach ($this->args as $k => $v) {
212 if (substr($k, 0, 9) == 'returnto-') {
213 $this->hidden($k, $v);
216 Event::handle('EndDeleteGroupForm', array($this, $this->group));
218 $this->submit('form_action-no',
219 // TRANS: Button label on the delete group form.
221 'submit form_action-primary',
223 // TRANS: Submit button title for 'No' when deleting a group.
224 _('Do not delete this group'));
225 $this->submit('form_action-yes',
226 // TRANS: Button label on the delete group form.
228 'submit form_action-secondary',
230 // TRANS: Submit button title for 'Yes' when deleting a group.
231 _('Delete this group'));
232 $this->elementEnd('fieldset');
233 $this->elementEnd('form');