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
49 class DeletegroupAction extends RedirectingAction
56 * @fixme merge common setup code with other group actions
57 * @fixme allow group admins to delete their own groups
60 function prepare($args)
62 parent::prepare($args);
64 if (!common_logged_in()) {
65 $this->clientError(_('You must be logged in to delete a group.'));
69 $nickname_arg = $this->trimmed('nickname');
70 $id = intval($this->arg('id'));
72 $this->group = User_group::staticGet('id', $id);
73 } else if ($nickname_arg) {
74 $nickname = common_canonical_nickname($nickname_arg);
76 // Permanent redirect on non-canonical nickname
78 if ($nickname_arg != $nickname) {
79 $args = array('nickname' => $nickname);
80 common_redirect(common_local_url('leavegroup', $args), 301);
84 $local = Local_group::staticGet('nickname', $nickname);
87 $this->clientError(_('No such group.'), 404);
91 $this->group = User_group::staticGet('id', $local->group_id);
93 $this->clientError(_('No nickname or ID.'), 404);
98 $this->clientError(_('No such group.'), 404);
102 $cur = common_current_user();
103 if (!$cur->hasRight(Right::DELETEGROUP)) {
104 $this->clientError(_('You are not allowed to delete this group.'), 403);
114 * On POST, delete the group.
116 * @param array $args unused
121 function handle($args)
123 parent::handle($args);
124 if ($_SERVER['REQUEST_METHOD'] == 'POST') {
125 if ($this->arg('no')) {
126 $this->returnToPrevious();
128 } elseif ($this->arg('yes')) {
136 function handlePost()
138 $cur = common_current_user();
141 if (Event::handle('StartDeleteGroup', array($this->group))) {
142 $this->group->delete();
143 Event::handle('EndDeleteGroup', array($this->group));
145 } catch (Exception $e) {
146 $this->serverError(sprintf(_('Could not delete group %2$s.'),
147 $this->group->nickname));
150 if ($this->boolean('ajax')) {
151 $this->startHTML('text/xml;charset=utf-8');
152 $this->elementStart('head');
153 $this->element('title', null, sprintf(_('Deleted group %2$s'),
154 $this->group->nickname));
155 $this->elementEnd('head');
156 $this->elementStart('body');
157 // @fixme add a sensible AJAX response form!
158 $this->elementEnd('body');
159 $this->elementEnd('html');
161 // @fixme if we could direct to the page on which this group
162 // would have shown... that would be awesome
163 common_redirect(common_local_url('groups'),
169 return _('Delete group');
172 function showContent() {
173 $this->areYouSureForm();
178 * Ripped from DeleteuserAction
180 * Shows a confirmation form.
182 * @fixme refactor common code for things like this
185 function areYouSureForm()
187 $id = $this->group->id;
188 $this->elementStart('form', array('id' => 'deletegroup-' . $id,
190 'class' => 'form_settings form_entity_block',
191 'action' => common_local_url('deletegroup', array('id' => $this->group->id))));
192 $this->elementStart('fieldset');
193 $this->hidden('token', common_session_token());
194 $this->element('legend', _('Delete group'));
195 if (Event::handle('StartDeleteGroupForm', array($this, $this->group))) {
196 $this->element('p', null,
197 _('Are you sure you want to delete this group? '.
198 'This will clear all data about the group from the '.
199 'database, without a backup. ' .
200 'Public posts to this group will still appear in ' .
201 'individual timelines.'));
202 foreach ($this->args as $k => $v) {
203 if (substr($k, 0, 9) == 'returnto-') {
204 $this->hidden($k, $v);
207 Event::handle('EndDeleteGroupForm', array($this, $this->group));
209 $this->submit('form_action-no',
210 // TRANS: Button label on the delete group form.
212 'submit form_action-primary',
214 // TRANS: Submit button title for 'No' when deleting a group.
215 _('Do not delete this group'));
216 $this->submit('form_action-yes',
217 // TRANS: Button label on the delete group form.
219 'submit form_action-secondary',
221 // TRANS: Submit button title for 'Yes' when deleting a group.
222 _('Delete this group'));
223 $this->elementEnd('fieldset');
224 $this->elementEnd('form');