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.'));
67 $nickname_arg = $this->trimmed('nickname');
68 $id = intval($this->arg('id'));
70 $this->group = User_group::getKV('id', $id);
71 } else if ($nickname_arg) {
72 $nickname = common_canonical_nickname($nickname_arg);
74 // Permanent redirect on non-canonical nickname
76 if ($nickname_arg != $nickname) {
77 $args = array('nickname' => $nickname);
78 common_redirect(common_local_url('leavegroup', $args), 301);
81 $local = Local_group::getKV('nickname', $nickname);
84 // TRANS: Client error when trying to delete a non-local group.
85 $this->clientError(_('No such group.'), 404);
88 $this->group = User_group::getKV('id', $local->group_id);
90 // TRANS: Client error when trying to delete a group without providing a nickname or ID for the group.
91 $this->clientError(_('No nickname or ID.'), 404);
95 // TRANS: Client error when trying to delete a non-existing group.
96 $this->clientError(_('No such group.'), 404);
99 $cur = common_current_user();
100 if (!$cur->hasRight(Right::DELETEGROUP)) {
101 // TRANS: Client error when trying to delete a group without having the rights to delete it.
102 $this->clientError(_('You are not allowed to delete this group.'), 403);
111 * On POST, delete the group.
113 * @param array $args unused
117 function handle($args)
119 parent::handle($args);
120 if ($_SERVER['REQUEST_METHOD'] == 'POST') {
121 if ($this->arg('no')) {
122 $this->returnToPrevious();
124 } elseif ($this->arg('yes')) {
132 function handlePost()
134 $cur = common_current_user();
137 if (Event::handle('StartDeleteGroup', array($this->group))) {
138 $this->group->delete();
139 Event::handle('EndDeleteGroup', array($this->group));
141 } catch (Exception $e) {
142 // TRANS: Server error displayed if a group could not be deleted.
143 // TRANS: %s is the name of the group that could not be deleted.
144 $this->serverError(sprintf(_('Could not delete group %s.'),
145 $this->group->nickname));
148 if ($this->boolean('ajax')) {
149 $this->startHTML('text/xml;charset=utf-8');
150 $this->elementStart('head');
151 // TRANS: Message given after deleting a group.
152 // TRANS: %s is the deleted group's name.
153 $this->element('title', null, sprintf(_('Deleted group %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');
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'), 303);
168 // TRANS: Title of delete group page.
169 return _('Delete group');
172 function showContent() {
173 $this->areYouSureForm();
174 $block = new GroupProfileBlock($this, $this->group);
180 * Ripped from DeleteuserAction
182 * Shows a confirmation form.
184 * @fixme refactor common code for things like this
187 function areYouSureForm()
189 $id = $this->group->id;
190 $this->elementStart('form', array('id' => 'deletegroup-' . $id,
192 'class' => 'form_settings form_entity_block',
193 'action' => common_local_url('deletegroup', array('id' => $this->group->id))));
194 $this->elementStart('fieldset');
195 $this->hidden('token', common_session_token());
196 // TRANS: Form legend for deleting a group.
197 $this->element('legend', _('Delete group'));
198 if (Event::handle('StartDeleteGroupForm', array($this, $this->group))) {
199 $this->element('p', null,
200 // TRANS: Warning in form for deleleting a group.
201 _('Are you sure you want to delete this group? '.
202 'This will clear all data about the group from the '.
203 'database, without a backup. ' .
204 'Public posts to this group will still appear in ' .
205 'individual timelines.'));
206 foreach ($this->args as $k => $v) {
207 if (substr($k, 0, 9) == 'returnto-') {
208 $this->hidden($k, $v);
211 Event::handle('EndDeleteGroupForm', array($this, $this->group));
213 $this->submit('form_action-no',
214 // TRANS: Button label on the delete group form.
216 'submit form_action-primary',
218 // TRANS: Submit button title for 'No' when deleting a group.
219 _('Do not delete this group.'));
220 $this->submit('form_action-yes',
221 // TRANS: Button label on the delete group form.
223 'submit form_action-secondary',
225 // TRANS: Submit button title for 'Yes' when deleting a group.
226 _('Delete this group.'));
227 $this->elementEnd('fieldset');
228 $this->elementEnd('form');