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 $this->clientError(_('Not logged in.'));
68 $user = common_current_user();
70 // ...because they're logged in
72 assert(!empty($user));
74 // It must be a "real" login, not saved cookie login
76 if (!common_is_real_login()) {
77 // Cookie theft is too easy; we require automatic
78 // logins to re-authenticate before admining the site
79 common_set_returnto($this->selfUrl());
80 if (Event::handle('RedirectToLogin', array($this, $user))) {
81 common_redirect(common_local_url('login'), 303);
85 // User must have the right to review flags
87 if (!$user->hasRight(UserFlagPlugin::REVIEWFLAGS)) {
88 $this->clientError(_('You cannot review profile flags.'));
92 $this->page = $this->trimmed('page');
94 if (empty($this->page)) {
98 $this->profiles = $this->getProfiles();
106 * @param array $args $_REQUEST args; handled in prepare()
110 function handle($args)
112 parent::handle($args);
120 * @return string Title of the page
124 // TRANS: Title for page with a list of profiles that were flagged for review.
125 return _m('Flagged profiles');
129 * save the profile flag
133 function showContent()
135 $pl = new FlaggedProfileList($this->profiles, $this);
139 $this->pagination($this->page > 1, $cnt > PROFILES_PER_PAGE,
140 $this->page, 'adminprofileflag');
144 * Retrieve this action's profiles
146 * @return Profile $profile Profile query results
148 function getProfiles()
150 $ufp = new User_flag_profile();
153 $ufp->selectAdd('profile_id');
154 $ufp->selectAdd('count(*) as flag_count');
156 $ufp->whereAdd('cleared is NULL');
158 $ufp->groupBy('profile_id');
159 $ufp->orderBy('flag_count DESC, profile_id DESC');
161 $offset = ($this->page-1) * PROFILES_PER_PAGE;
162 $limit = PROFILES_PER_PAGE + 1;
164 $ufp->limit($offset, $limit);
169 while ($ufp->fetch()) {
170 $profile = Profile::staticGet('id', $ufp->profile_id);
171 if (!empty($profile)) {
172 $profiles[] = $profile;
179 return new ArrayWrapper($profiles);
184 * Specialization of ProfileList to show flagging information
186 * Most of the hard part is done in FlaggedProfileListItem.
190 * @author Evan Prodromou <evan@status.net>
191 * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
192 * @link http://status.net/
194 class FlaggedProfileList extends ProfileList
197 * Factory method for creating new list items
199 * @param Profile $profile Profile to create an item for
201 * @return ProfileListItem newly-created item
203 function newListItem($profile)
205 return new FlaggedProfileListItem($this->profile, $this->action);
210 * Specialization of ProfileListItem to show flagging information
214 * @author Evan Prodromou <evan@status.net>
215 * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
216 * @link http://status.net/
218 class FlaggedProfileListItem extends ProfileListItem
220 const MAX_FLAGGERS = 5;
226 * Overload parent's action list with our own moderation-oriented buttons
230 function showActions()
232 $this->user = common_current_user();
234 list($action, $this->r2args) = $this->out->returnToArgs();
236 $this->r2args['action'] = $action;
238 $this->startActions();
239 if (Event::handle('StartProfileListItemActionElements', array($this))) {
240 $this->out->elementStart('li', 'entity_moderation');
241 // TRANS: Header for moderation menu with action buttons for flagged profiles (like 'sandbox', 'silence', ...).
242 $this->out->element('p', null, _m('Moderate'));
243 $this->out->elementStart('ul');
244 $this->showSandboxButton();
245 $this->showSilenceButton();
246 $this->showDeleteButton();
247 $this->showClearButton();
248 $this->out->elementEnd('ul');
249 $this->out->elementEnd('li');
250 Event::handle('EndProfileListItemActionElements', array($this));
256 * Show a button to sandbox the profile
260 function showSandboxButton()
262 if ($this->user->hasRight(Right::SANDBOXUSER)) {
263 $this->out->elementStart('li', 'entity_sandbox');
264 if ($this->profile->isSandboxed()) {
265 $usf = new UnSandboxForm($this->out, $this->profile, $this->r2args);
268 $sf = new SandboxForm($this->out, $this->profile, $this->r2args);
271 $this->out->elementEnd('li');
276 * Show a button to silence the profile
280 function showSilenceButton()
282 if ($this->user->hasRight(Right::SILENCEUSER)) {
283 $this->out->elementStart('li', 'entity_silence');
284 if ($this->profile->isSilenced()) {
285 $usf = new UnSilenceForm($this->out, $this->profile, $this->r2args);
288 $sf = new SilenceForm($this->out, $this->profile, $this->r2args);
291 $this->out->elementEnd('li');
296 * Show a button to delete user and profile
300 function showDeleteButton()
303 if ($this->user->hasRight(Right::DELETEUSER)) {
304 $this->out->elementStart('li', 'entity_delete');
305 $df = new DeleteUserForm($this->out, $this->profile, $this->r2args);
307 $this->out->elementEnd('li');
312 * Show a button to clear flags
316 function showClearButton()
318 if ($this->user->hasRight(UserFlagPlugin::CLEARFLAGS)) {
319 $this->out->elementStart('li', 'entity_clear');
320 $cf = new ClearFlagForm($this->out, $this->profile, $this->r2args);
322 $this->out->elementEnd('li');
327 * Overload parent function to add flaggers list
331 function endProfile()
333 $this->showFlaggersList();
334 parent::endProfile();
338 * Show a list of people who've flagged this profile
342 function showFlaggersList()
346 $ufp = new User_flag_profile();
349 $ufp->selectAdd('user_id');
350 $ufp->profile_id = $this->profile->id;
351 $ufp->orderBy('created');
353 if ($ufp->find()) { // XXX: this should always happen
354 while ($ufp->fetch()) {
355 $user = User::staticGet('id', $ufp->user_id);
356 if (!empty($user)) { // XXX: this would also be unusual
357 $flaggers[] = clone($user);
362 $cnt = count($flaggers);
365 if ($cnt > self::MAX_FLAGGERS) {
366 $flaggers = array_slice($flaggers, 0, self::MAX_FLAGGERS);
367 $others = $cnt - self::MAX_FLAGGERS;
372 foreach ($flaggers as $flagger) {
374 $url = common_local_url('showstream',
375 array('nickname' => $flagger->nickname));
377 $lnks[] = XMLStringer::estring('a', array('href' => $url,
378 'class' => 'flagger'),
384 $flagging_users = implode(', ', $lnks);
385 // TRANS: Message displayed on a profile if it has been flagged.
386 // TRANS: %1$s is a comma separated list of at most 5 user nicknames that flagged.
387 // TRANS: %2$d is a positive integer of additional flagging users. Also used for the plural.
388 $text .= sprintf(_m('Flagged by %1$s and %2$d other', 'Flagged by %1$s and %2$d others', $others), $flagging_users, $others);
390 // TRANS: Message displayed on a profile if it has been flagged.
391 // TRANS: %s is a comma separated list of at most 5 user nicknames that flagged.
392 $text .= sprintf(_m('Flagged by %s'), $flagging_users);
395 $this->out->elementStart('p', array('class' => 'flaggers'));
396 $this->out->raw($text);
397 $this->out->elementEnd('p');