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 // TRANS: Error message displayed when trying to review profile flags while not authorised.
90 $this->clientError(_m('You cannot review profile flags.'));
94 $this->page = $this->trimmed('page');
96 if (empty($this->page)) {
100 $this->profiles = $this->getProfiles();
108 * @param array $args $_REQUEST args; handled in prepare()
112 function handle($args)
114 parent::handle($args);
122 * @return string Title of the page
126 // TRANS: Title for page with a list of profiles that were flagged for review.
127 return _m('Flagged profiles');
131 * save the profile flag
135 function showContent()
137 $pl = new FlaggedProfileList($this->profiles, $this);
141 $this->pagination($this->page > 1, $cnt > PROFILES_PER_PAGE,
142 $this->page, 'adminprofileflag');
146 * Retrieve this action's profiles
148 * @return Profile $profile Profile query results
150 function getProfiles()
152 $ufp = new User_flag_profile();
155 $ufp->selectAdd('profile_id');
156 $ufp->selectAdd('count(*) as flag_count');
158 $ufp->whereAdd('cleared is NULL');
160 $ufp->groupBy('profile_id');
161 $ufp->orderBy('flag_count DESC, profile_id DESC');
163 $offset = ($this->page-1) * PROFILES_PER_PAGE;
164 $limit = PROFILES_PER_PAGE + 1;
166 $ufp->limit($offset, $limit);
171 while ($ufp->fetch()) {
172 $profile = Profile::staticGet('id', $ufp->profile_id);
173 if (!empty($profile)) {
174 $profiles[] = $profile;
181 return new ArrayWrapper($profiles);
186 * Specialization of ProfileList to show flagging information
188 * Most of the hard part is done in FlaggedProfileListItem.
192 * @author Evan Prodromou <evan@status.net>
193 * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
194 * @link http://status.net/
196 class FlaggedProfileList extends ProfileList
199 * Factory method for creating new list items
201 * @param Profile $profile Profile to create an item for
203 * @return ProfileListItem newly-created item
205 function newListItem($profile)
207 return new FlaggedProfileListItem($this->profile, $this->action);
212 * Specialization of ProfileListItem to show flagging information
216 * @author Evan Prodromou <evan@status.net>
217 * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
218 * @link http://status.net/
220 class FlaggedProfileListItem extends ProfileListItem
222 const MAX_FLAGGERS = 5;
228 * Overload parent's action list with our own moderation-oriented buttons
232 function showActions()
234 $this->user = common_current_user();
236 list($action, $this->r2args) = $this->out->returnToArgs();
238 $this->r2args['action'] = $action;
240 $this->startActions();
241 if (Event::handle('StartProfileListItemActionElements', array($this))) {
242 $this->out->elementStart('li', 'entity_moderation');
243 // TRANS: Header for moderation menu with action buttons for flagged profiles (like 'sandbox', 'silence', ...).
244 $this->out->element('p', null, _m('Moderate'));
245 $this->out->elementStart('ul');
246 $this->showSandboxButton();
247 $this->showSilenceButton();
248 $this->showDeleteButton();
249 $this->showClearButton();
250 $this->out->elementEnd('ul');
251 $this->out->elementEnd('li');
252 Event::handle('EndProfileListItemActionElements', array($this));
258 * Show a button to sandbox the profile
262 function showSandboxButton()
264 if ($this->user->hasRight(Right::SANDBOXUSER)) {
265 $this->out->elementStart('li', 'entity_sandbox');
266 if ($this->profile->isSandboxed()) {
267 $usf = new UnSandboxForm($this->out, $this->profile, $this->r2args);
270 $sf = new SandboxForm($this->out, $this->profile, $this->r2args);
273 $this->out->elementEnd('li');
278 * Show a button to silence the profile
282 function showSilenceButton()
284 if ($this->user->hasRight(Right::SILENCEUSER)) {
285 $this->out->elementStart('li', 'entity_silence');
286 if ($this->profile->isSilenced()) {
287 $usf = new UnSilenceForm($this->out, $this->profile, $this->r2args);
290 $sf = new SilenceForm($this->out, $this->profile, $this->r2args);
293 $this->out->elementEnd('li');
298 * Show a button to delete user and profile
302 function showDeleteButton()
305 if ($this->user->hasRight(Right::DELETEUSER)) {
306 $this->out->elementStart('li', 'entity_delete');
307 $df = new DeleteUserForm($this->out, $this->profile, $this->r2args);
309 $this->out->elementEnd('li');
314 * Show a button to clear flags
318 function showClearButton()
320 if ($this->user->hasRight(UserFlagPlugin::CLEARFLAGS)) {
321 $this->out->elementStart('li', 'entity_clear');
322 $cf = new ClearFlagForm($this->out, $this->profile, $this->r2args);
324 $this->out->elementEnd('li');
329 * Overload parent function to add flaggers list
333 function endProfile()
335 $this->showFlaggersList();
336 parent::endProfile();
340 * Show a list of people who've flagged this profile
344 function showFlaggersList()
348 $ufp = new User_flag_profile();
351 $ufp->selectAdd('user_id');
352 $ufp->profile_id = $this->profile->id;
353 $ufp->orderBy('created');
355 if ($ufp->find()) { // XXX: this should always happen
356 while ($ufp->fetch()) {
357 $user = User::staticGet('id', $ufp->user_id);
358 if (!empty($user)) { // XXX: this would also be unusual
359 $flaggers[] = clone($user);
364 $cnt = count($flaggers);
367 if ($cnt > self::MAX_FLAGGERS) {
368 $flaggers = array_slice($flaggers, 0, self::MAX_FLAGGERS);
369 $others = $cnt - self::MAX_FLAGGERS;
374 foreach ($flaggers as $flagger) {
376 $url = common_local_url('showstream',
377 array('nickname' => $flagger->nickname));
379 $lnks[] = XMLStringer::estring('a', array('href' => $url,
380 'class' => 'flagger'),
386 $flagging_users = implode(', ', $lnks);
387 // TRANS: Message displayed on a profile if it has been flagged.
388 // TRANS: %1$s is a comma separated list of at most 5 user nicknames that flagged.
389 // TRANS: %2$d is a positive integer of additional flagging users. Also used for plural.
390 $text .= sprintf(_m('Flagged by %1$s and %2$d other', 'Flagged by %1$s and %2$d others', $others), $flagging_users, $others);
392 // TRANS: Message displayed on a profile if it has been flagged.
393 // TRANS: %s is a comma separated list of at most 5 user nicknames that flagged.
394 $text .= sprintf(_m('Flagged by %s'), $flagging_users);
397 $this->out->elementStart('p', array('class' => 'flaggers'));
398 $this->out->raw($text);
399 $this->out->elementEnd('p');