3 * Show latest and greatest profile flags
9 * @author Evan Prodromou <evan@status.net>
10 * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
11 * @link http://status.net/
13 * StatusNet - the distributed open-source microblogging tool
14 * Copyright (C) 2009, StatusNet, Inc.
16 * This program is free software: you can redistribute it and/or modify
17 * it under the terms of the GNU Affero General Public License as published by
18 * the Free Software Foundation, either version 3 of the License, or
19 * (at your option) any later version.
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU Affero General Public License for more details.
26 * You should have received a copy of the GNU Affero General Public License
27 * along with this program. If not, see <http://www.gnu.org/licenses/>.
30 if (!defined('STATUSNET')) {
35 * Show the latest and greatest profile flags
39 * @author Evan Prodromou <evan@status.net>
40 * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
41 * @link http://status.net/
43 class AdminprofileflagAction extends Action
49 * Take arguments for running
51 * @param array $args $_REQUEST args
53 * @return boolean success flag
55 function prepare($args)
57 parent::prepare($args);
59 $user = common_current_user();
61 // User must be logged in.
63 if (!common_logged_in()) {
64 // TRANS: Error message displayed when trying to perform an action that requires a logged in user.
65 $this->clientError(_m('Not logged in.'));
69 $user = common_current_user();
71 // ...because they're logged in
73 assert(!empty($user));
75 // It must be a "real" login, not saved cookie login
77 if (!common_is_real_login()) {
78 // Cookie theft is too easy; we require automatic
79 // logins to re-authenticate before admining the site
80 common_set_returnto($this->selfUrl());
81 if (Event::handle('RedirectToLogin', array($this, $user))) {
82 common_redirect(common_local_url('login'), 303);
86 // User must have the right to review flags
88 if (!$user->hasRight(UserFlagPlugin::REVIEWFLAGS)) {
89 $this->clientError(_m('You cannot review profile flags.'));
93 $this->page = $this->trimmed('page');
95 if (empty($this->page)) {
99 $this->profiles = $this->getProfiles();
107 * @param array $args $_REQUEST args; handled in prepare()
111 function handle($args)
113 parent::handle($args);
121 * @return string Title of the page
125 // TRANS: Title for page with a list of profiles that were flagged for review.
126 return _m('Flagged profiles');
130 * save the profile flag
134 function showContent()
136 $pl = new FlaggedProfileList($this->profiles, $this);
140 $this->pagination($this->page > 1, $cnt > PROFILES_PER_PAGE,
141 $this->page, 'adminprofileflag');
145 * Retrieve this action's profiles
147 * @return Profile $profile Profile query results
149 function getProfiles()
151 $ufp = new User_flag_profile();
154 $ufp->selectAdd('profile_id');
155 $ufp->selectAdd('count(*) as flag_count');
157 $ufp->whereAdd('cleared is NULL');
159 $ufp->groupBy('profile_id');
160 $ufp->orderBy('flag_count DESC, profile_id DESC');
162 $offset = ($this->page-1) * PROFILES_PER_PAGE;
163 $limit = PROFILES_PER_PAGE + 1;
165 $ufp->limit($offset, $limit);
170 while ($ufp->fetch()) {
171 $profile = Profile::staticGet('id', $ufp->profile_id);
172 if (!empty($profile)) {
173 $profiles[] = $profile;
180 return new ArrayWrapper($profiles);
185 * Specialization of ProfileList to show flagging information
187 * Most of the hard part is done in FlaggedProfileListItem.
191 * @author Evan Prodromou <evan@status.net>
192 * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
193 * @link http://status.net/
195 class FlaggedProfileList extends ProfileList
198 * Factory method for creating new list items
200 * @param Profile $profile Profile to create an item for
202 * @return ProfileListItem newly-created item
204 function newListItem($profile)
206 return new FlaggedProfileListItem($this->profile, $this->action);
211 * Specialization of ProfileListItem to show flagging information
215 * @author Evan Prodromou <evan@status.net>
216 * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
217 * @link http://status.net/
219 class FlaggedProfileListItem extends ProfileListItem
221 const MAX_FLAGGERS = 5;
227 * Overload parent's action list with our own moderation-oriented buttons
231 function showActions()
233 $this->user = common_current_user();
235 list($action, $this->r2args) = $this->out->returnToArgs();
237 $this->r2args['action'] = $action;
239 $this->startActions();
240 if (Event::handle('StartProfileListItemActionElements', array($this))) {
241 $this->out->elementStart('li', 'entity_moderation');
242 // TRANS: Header for moderation menu with action buttons for flagged profiles (like 'sandbox', 'silence', ...).
243 $this->out->element('p', null, _m('Moderate'));
244 $this->out->elementStart('ul');
245 $this->showSandboxButton();
246 $this->showSilenceButton();
247 $this->showDeleteButton();
248 $this->showClearButton();
249 $this->out->elementEnd('ul');
250 $this->out->elementEnd('li');
251 Event::handle('EndProfileListItemActionElements', array($this));
257 * Show a button to sandbox the profile
261 function showSandboxButton()
263 if ($this->user->hasRight(Right::SANDBOXUSER)) {
264 $this->out->elementStart('li', 'entity_sandbox');
265 if ($this->profile->isSandboxed()) {
266 $usf = new UnSandboxForm($this->out, $this->profile, $this->r2args);
269 $sf = new SandboxForm($this->out, $this->profile, $this->r2args);
272 $this->out->elementEnd('li');
277 * Show a button to silence the profile
281 function showSilenceButton()
283 if ($this->user->hasRight(Right::SILENCEUSER)) {
284 $this->out->elementStart('li', 'entity_silence');
285 if ($this->profile->isSilenced()) {
286 $usf = new UnSilenceForm($this->out, $this->profile, $this->r2args);
289 $sf = new SilenceForm($this->out, $this->profile, $this->r2args);
292 $this->out->elementEnd('li');
297 * Show a button to delete user and profile
301 function showDeleteButton()
304 if ($this->user->hasRight(Right::DELETEUSER)) {
305 $this->out->elementStart('li', 'entity_delete');
306 $df = new DeleteUserForm($this->out, $this->profile, $this->r2args);
308 $this->out->elementEnd('li');
313 * Show a button to clear flags
317 function showClearButton()
319 if ($this->user->hasRight(UserFlagPlugin::CLEARFLAGS)) {
320 $this->out->elementStart('li', 'entity_clear');
321 $cf = new ClearFlagForm($this->out, $this->profile, $this->r2args);
323 $this->out->elementEnd('li');
328 * Overload parent function to add flaggers list
332 function endProfile()
334 $this->showFlaggersList();
335 parent::endProfile();
339 * Show a list of people who've flagged this profile
343 function showFlaggersList()
347 $ufp = new User_flag_profile();
350 $ufp->selectAdd('user_id');
351 $ufp->profile_id = $this->profile->id;
352 $ufp->orderBy('created');
354 if ($ufp->find()) { // XXX: this should always happen
355 while ($ufp->fetch()) {
356 $user = User::staticGet('id', $ufp->user_id);
357 if (!empty($user)) { // XXX: this would also be unusual
358 $flaggers[] = clone($user);
363 $cnt = count($flaggers);
366 if ($cnt > self::MAX_FLAGGERS) {
367 $flaggers = array_slice($flaggers, 0, self::MAX_FLAGGERS);
368 $others = $cnt - self::MAX_FLAGGERS;
373 foreach ($flaggers as $flagger) {
375 $url = common_local_url('showstream',
376 array('nickname' => $flagger->nickname));
378 $lnks[] = XMLStringer::estring('a', array('href' => $url,
379 'class' => 'flagger'),
385 $flagging_users = implode(', ', $lnks);
386 // TRANS: Message displayed on a profile if it has been flagged.
387 // TRANS: %1$s is a comma separated list of at most 5 user nicknames that flagged.
388 // TRANS: %2$d is a positive integer of additional flagging users. Also used for the plural.
389 $text .= sprintf(_m('Flagged by %1$s and %2$d other', 'Flagged by %1$s and %2$d others', $others), $flagging_users, $others);
391 // TRANS: Message displayed on a profile if it has been flagged.
392 // TRANS: %s is a comma separated list of at most 5 user nicknames that flagged.
393 $text .= sprintf(_m('Flagged by %s'), $flagging_users);
396 $this->out->elementStart('p', array('class' => 'flaggers'));
397 $this->out->raw($text);
398 $this->out->elementEnd('p');