2009-10-15 09:47:11 +01:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Show latest and greatest profile flags
|
|
|
|
*
|
|
|
|
* PHP version 5
|
|
|
|
*
|
|
|
|
* @category Action
|
|
|
|
* @package StatusNet
|
2020-07-21 12:43:46 +01:00
|
|
|
*
|
2009-10-15 09:47:11 +01:00
|
|
|
* @author Evan Prodromou <evan@status.net>
|
|
|
|
* @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
|
2020-07-21 12:43:46 +01:00
|
|
|
*
|
|
|
|
* @see http://status.net/
|
2009-10-15 09:47:11 +01:00
|
|
|
*
|
|
|
|
* StatusNet - the distributed open-source microblogging tool
|
|
|
|
* Copyright (C) 2009, StatusNet, Inc.
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
if (!defined('STATUSNET')) {
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show the latest and greatest profile flags
|
|
|
|
*
|
|
|
|
* @category Action
|
|
|
|
* @package StatusNet
|
2020-07-21 12:43:46 +01:00
|
|
|
*
|
2009-10-15 09:47:11 +01:00
|
|
|
* @author Evan Prodromou <evan@status.net>
|
|
|
|
* @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
|
2020-07-21 12:43:46 +01:00
|
|
|
*
|
|
|
|
* @see http://status.net/
|
2009-10-15 09:47:11 +01:00
|
|
|
*/
|
|
|
|
class AdminprofileflagAction extends Action
|
|
|
|
{
|
2020-07-21 12:43:46 +01:00
|
|
|
public $page;
|
|
|
|
public $profiles;
|
2009-12-27 19:04:53 +00:00
|
|
|
|
2009-10-15 09:47:11 +01:00
|
|
|
/**
|
|
|
|
* Take arguments for running
|
|
|
|
*
|
|
|
|
* @param array $args $_REQUEST args
|
|
|
|
*
|
2020-07-21 12:43:46 +01:00
|
|
|
* @return bool success flag
|
2009-10-15 09:47:11 +01:00
|
|
|
*/
|
2020-07-21 12:43:46 +01:00
|
|
|
public function prepare(array $args = [])
|
2009-10-15 09:47:11 +01:00
|
|
|
{
|
2009-11-16 16:43:15 +00:00
|
|
|
parent::prepare($args);
|
|
|
|
|
2009-12-27 19:04:53 +00:00
|
|
|
$user = common_current_user();
|
|
|
|
|
|
|
|
// User must be logged in.
|
|
|
|
|
|
|
|
if (!common_logged_in()) {
|
2011-04-03 23:41:21 +01:00
|
|
|
// TRANS: Error message displayed when trying to perform an action that requires a logged in user.
|
2011-03-30 21:30:23 +01:00
|
|
|
$this->clientError(_m('Not logged in.'));
|
2009-12-27 19:04:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$user = common_current_user();
|
|
|
|
|
|
|
|
// ...because they're logged in
|
|
|
|
|
|
|
|
assert(!empty($user));
|
|
|
|
|
|
|
|
// It must be a "real" login, not saved cookie login
|
|
|
|
|
|
|
|
if (!common_is_real_login()) {
|
|
|
|
// Cookie theft is too easy; we require automatic
|
|
|
|
// logins to re-authenticate before admining the site
|
|
|
|
common_set_returnto($this->selfUrl());
|
2020-07-21 12:43:46 +01:00
|
|
|
if (Event::handle('RedirectToLogin', [$this, $user])) {
|
2009-12-27 19:04:53 +00:00
|
|
|
common_redirect(common_local_url('login'), 303);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// User must have the right to review flags
|
|
|
|
|
|
|
|
if (!$user->hasRight(UserFlagPlugin::REVIEWFLAGS)) {
|
2011-06-17 15:19:18 +01:00
|
|
|
// TRANS: Error message displayed when trying to review profile flags while not authorised.
|
2011-03-30 21:30:23 +01:00
|
|
|
$this->clientError(_m('You cannot review profile flags.'));
|
2009-12-27 19:04:53 +00:00
|
|
|
}
|
|
|
|
|
2009-12-27 19:47:54 +00:00
|
|
|
$this->page = $this->trimmed('page');
|
2009-12-27 19:04:53 +00:00
|
|
|
|
2009-12-27 19:47:54 +00:00
|
|
|
if (empty($this->page)) {
|
2009-12-27 19:04:53 +00:00
|
|
|
$this->page = 1;
|
|
|
|
}
|
|
|
|
|
2009-12-27 19:47:54 +00:00
|
|
|
$this->profiles = $this->getProfiles();
|
|
|
|
|
2009-10-15 09:47:11 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle request
|
|
|
|
*
|
|
|
|
* @param array $args $_REQUEST args; handled in prepare()
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2020-07-21 12:43:46 +01:00
|
|
|
public function handle()
|
2009-10-15 09:47:11 +01:00
|
|
|
{
|
2016-06-01 03:05:11 +01:00
|
|
|
parent::handle();
|
2009-10-15 09:47:11 +01:00
|
|
|
|
|
|
|
$this->showPage();
|
|
|
|
}
|
|
|
|
|
2009-12-28 16:45:21 +00:00
|
|
|
/**
|
|
|
|
* Title of this page
|
|
|
|
*
|
|
|
|
* @return string Title of the page
|
|
|
|
*/
|
2020-07-21 12:43:46 +01:00
|
|
|
public function title()
|
2009-12-28 16:45:21 +00:00
|
|
|
{
|
2010-10-02 21:25:32 +01:00
|
|
|
// TRANS: Title for page with a list of profiles that were flagged for review.
|
|
|
|
return _m('Flagged profiles');
|
2009-10-15 09:47:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* save the profile flag
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2020-07-21 12:43:46 +01:00
|
|
|
public function showContent()
|
2009-10-15 09:47:11 +01:00
|
|
|
{
|
2009-12-27 19:47:54 +00:00
|
|
|
$pl = new FlaggedProfileList($this->profiles, $this);
|
2009-11-16 16:43:15 +00:00
|
|
|
|
2009-12-27 19:47:54 +00:00
|
|
|
$cnt = $pl->show();
|
2009-11-16 16:43:15 +00:00
|
|
|
|
2009-12-27 19:47:54 +00:00
|
|
|
$this->pagination($this->page > 1, $cnt > PROFILES_PER_PAGE,
|
|
|
|
$this->page, 'adminprofileflag');
|
2009-11-16 16:43:15 +00:00
|
|
|
}
|
|
|
|
|
2009-12-28 16:45:21 +00:00
|
|
|
/**
|
|
|
|
* Retrieve this action's profiles
|
|
|
|
*
|
|
|
|
* @return Profile $profile Profile query results
|
|
|
|
*/
|
2020-07-21 12:43:46 +01:00
|
|
|
public function getProfiles()
|
2009-11-16 16:43:15 +00:00
|
|
|
{
|
|
|
|
$ufp = new User_flag_profile();
|
|
|
|
|
|
|
|
$ufp->selectAdd();
|
|
|
|
$ufp->selectAdd('profile_id');
|
|
|
|
$ufp->selectAdd('count(*) as flag_count');
|
|
|
|
|
|
|
|
$ufp->whereAdd('cleared is NULL');
|
|
|
|
|
|
|
|
$ufp->groupBy('profile_id');
|
2009-12-27 19:47:54 +00:00
|
|
|
$ufp->orderBy('flag_count DESC, profile_id DESC');
|
|
|
|
|
2020-07-21 12:43:46 +01:00
|
|
|
$offset = ($this->page - 1) * PROFILES_PER_PAGE;
|
2009-12-28 16:45:21 +00:00
|
|
|
$limit = PROFILES_PER_PAGE + 1;
|
2009-12-27 19:47:54 +00:00
|
|
|
|
|
|
|
$ufp->limit($offset, $limit);
|
2009-11-16 16:43:15 +00:00
|
|
|
|
2020-07-21 12:43:46 +01:00
|
|
|
$profiles = [];
|
2009-11-16 16:43:15 +00:00
|
|
|
|
|
|
|
if ($ufp->find()) {
|
|
|
|
while ($ufp->fetch()) {
|
2013-08-18 12:04:58 +01:00
|
|
|
$profile = Profile::getKV('id', $ufp->profile_id);
|
2009-11-16 16:43:15 +00:00
|
|
|
if (!empty($profile)) {
|
|
|
|
$profiles[] = $profile;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$ufp->free();
|
|
|
|
|
|
|
|
return new ArrayWrapper($profiles);
|
2009-10-15 09:47:11 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-12-28 16:45:21 +00:00
|
|
|
/**
|
|
|
|
* Specialization of ProfileList to show flagging information
|
|
|
|
*
|
|
|
|
* Most of the hard part is done in FlaggedProfileListItem.
|
|
|
|
*
|
|
|
|
* @category Widget
|
|
|
|
* @package StatusNet
|
2020-07-21 12:43:46 +01:00
|
|
|
*
|
2009-12-28 16:45:21 +00:00
|
|
|
* @author Evan Prodromou <evan@status.net>
|
|
|
|
* @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
|
2020-07-21 12:43:46 +01:00
|
|
|
*
|
|
|
|
* @see http://status.net/
|
2009-12-28 16:45:21 +00:00
|
|
|
*/
|
|
|
|
class FlaggedProfileList extends ProfileList
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Factory method for creating new list items
|
|
|
|
*
|
|
|
|
* @param Profile $profile Profile to create an item for
|
|
|
|
*
|
|
|
|
* @return ProfileListItem newly-created item
|
|
|
|
*/
|
2020-07-21 12:43:46 +01:00
|
|
|
public function newListItem(Profile $profile)
|
2009-11-16 16:43:15 +00:00
|
|
|
{
|
2018-08-17 00:16:15 +01:00
|
|
|
return new FlaggedProfileListItem($profile, $this->action);
|
2009-11-16 16:43:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-12-28 16:45:21 +00:00
|
|
|
/**
|
|
|
|
* Specialization of ProfileListItem to show flagging information
|
|
|
|
*
|
|
|
|
* @category Widget
|
|
|
|
* @package StatusNet
|
2020-07-21 12:43:46 +01:00
|
|
|
*
|
2009-12-28 16:45:21 +00:00
|
|
|
* @author Evan Prodromou <evan@status.net>
|
|
|
|
* @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
|
2020-07-21 12:43:46 +01:00
|
|
|
*
|
|
|
|
* @see http://status.net/
|
2009-12-28 16:45:21 +00:00
|
|
|
*/
|
2009-11-16 16:43:15 +00:00
|
|
|
class FlaggedProfileListItem extends ProfileListItem
|
|
|
|
{
|
2009-12-28 16:19:56 +00:00
|
|
|
const MAX_FLAGGERS = 5;
|
|
|
|
|
2020-07-21 12:43:46 +01:00
|
|
|
public $user;
|
|
|
|
public $r2args;
|
2009-11-16 16:43:15 +00:00
|
|
|
|
2009-12-28 16:45:21 +00:00
|
|
|
/**
|
|
|
|
* Overload parent's action list with our own moderation-oriented buttons
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2020-07-21 12:43:46 +01:00
|
|
|
public function showActions()
|
2009-11-16 16:43:15 +00:00
|
|
|
{
|
|
|
|
$this->user = common_current_user();
|
|
|
|
|
2009-11-16 16:55:00 +00:00
|
|
|
list($action, $this->r2args) = $this->out->returnToArgs();
|
|
|
|
|
|
|
|
$this->r2args['action'] = $action;
|
|
|
|
|
2009-11-16 16:43:15 +00:00
|
|
|
$this->startActions();
|
2020-07-21 12:43:46 +01:00
|
|
|
if (Event::handle('StartProfileListItemActionElements', [$this])) {
|
2009-11-26 18:46:11 +00:00
|
|
|
$this->out->elementStart('li', 'entity_moderation');
|
2010-10-02 21:25:32 +01:00
|
|
|
// TRANS: Header for moderation menu with action buttons for flagged profiles (like 'sandbox', 'silence', ...).
|
|
|
|
$this->out->element('p', null, _m('Moderate'));
|
2009-11-26 18:46:11 +00:00
|
|
|
$this->out->elementStart('ul');
|
2009-11-16 16:43:15 +00:00
|
|
|
$this->showSandboxButton();
|
|
|
|
$this->showSilenceButton();
|
|
|
|
$this->showDeleteButton();
|
|
|
|
$this->showClearButton();
|
2009-11-26 18:46:11 +00:00
|
|
|
$this->out->elementEnd('ul');
|
|
|
|
$this->out->elementEnd('li');
|
2020-07-21 12:43:46 +01:00
|
|
|
Event::handle('EndProfileListItemActionElements', [$this]);
|
2009-11-16 16:43:15 +00:00
|
|
|
}
|
|
|
|
$this->endActions();
|
|
|
|
}
|
|
|
|
|
2009-12-28 16:45:21 +00:00
|
|
|
/**
|
|
|
|
* Show a button to sandbox the profile
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2020-07-21 12:43:46 +01:00
|
|
|
public function showSandboxButton()
|
2009-11-16 16:43:15 +00:00
|
|
|
{
|
|
|
|
if ($this->user->hasRight(Right::SANDBOXUSER)) {
|
|
|
|
$this->out->elementStart('li', 'entity_sandbox');
|
2009-11-16 16:55:00 +00:00
|
|
|
if ($this->profile->isSandboxed()) {
|
|
|
|
$usf = new UnSandboxForm($this->out, $this->profile, $this->r2args);
|
2009-11-16 16:43:15 +00:00
|
|
|
$usf->show();
|
|
|
|
} else {
|
2009-11-16 16:55:00 +00:00
|
|
|
$sf = new SandboxForm($this->out, $this->profile, $this->r2args);
|
2009-11-16 16:43:15 +00:00
|
|
|
$sf->show();
|
|
|
|
}
|
|
|
|
$this->out->elementEnd('li');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-12-28 16:45:21 +00:00
|
|
|
/**
|
|
|
|
* Show a button to silence the profile
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2020-07-21 12:43:46 +01:00
|
|
|
public function showSilenceButton()
|
2009-11-16 16:43:15 +00:00
|
|
|
{
|
|
|
|
if ($this->user->hasRight(Right::SILENCEUSER)) {
|
|
|
|
$this->out->elementStart('li', 'entity_silence');
|
2009-11-16 16:55:00 +00:00
|
|
|
if ($this->profile->isSilenced()) {
|
|
|
|
$usf = new UnSilenceForm($this->out, $this->profile, $this->r2args);
|
2009-11-16 16:43:15 +00:00
|
|
|
$usf->show();
|
|
|
|
} else {
|
2009-11-16 16:55:00 +00:00
|
|
|
$sf = new SilenceForm($this->out, $this->profile, $this->r2args);
|
2009-11-16 16:43:15 +00:00
|
|
|
$sf->show();
|
|
|
|
}
|
|
|
|
$this->out->elementEnd('li');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-12-28 16:45:21 +00:00
|
|
|
/**
|
|
|
|
* Show a button to delete user and profile
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2020-07-21 12:43:46 +01:00
|
|
|
public function showDeleteButton()
|
2009-11-16 16:43:15 +00:00
|
|
|
{
|
|
|
|
if ($this->user->hasRight(Right::DELETEUSER)) {
|
|
|
|
$this->out->elementStart('li', 'entity_delete');
|
2009-11-16 16:55:00 +00:00
|
|
|
$df = new DeleteUserForm($this->out, $this->profile, $this->r2args);
|
2009-11-16 16:43:15 +00:00
|
|
|
$df->show();
|
|
|
|
$this->out->elementEnd('li');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-12-28 16:45:21 +00:00
|
|
|
/**
|
|
|
|
* Show a button to clear flags
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2020-07-21 12:43:46 +01:00
|
|
|
public function showClearButton()
|
2009-11-16 16:43:15 +00:00
|
|
|
{
|
2009-12-28 16:19:56 +00:00
|
|
|
if ($this->user->hasRight(UserFlagPlugin::CLEARFLAGS)) {
|
|
|
|
$this->out->elementStart('li', 'entity_clear');
|
|
|
|
$cf = new ClearFlagForm($this->out, $this->profile, $this->r2args);
|
|
|
|
$cf->show();
|
|
|
|
$this->out->elementEnd('li');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-12-28 16:45:21 +00:00
|
|
|
/**
|
|
|
|
* Overload parent function to add flaggers list
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2020-07-21 12:43:46 +01:00
|
|
|
public function endProfile()
|
2009-12-28 16:19:56 +00:00
|
|
|
{
|
|
|
|
$this->showFlaggersList();
|
|
|
|
parent::endProfile();
|
|
|
|
}
|
|
|
|
|
2009-12-28 16:45:21 +00:00
|
|
|
/**
|
|
|
|
* Show a list of people who've flagged this profile
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2020-07-21 12:43:46 +01:00
|
|
|
public function showFlaggersList()
|
2009-12-28 16:19:56 +00:00
|
|
|
{
|
2020-07-21 12:43:46 +01:00
|
|
|
$flaggers = [];
|
2009-12-28 16:19:56 +00:00
|
|
|
|
|
|
|
$ufp = new User_flag_profile();
|
|
|
|
|
|
|
|
$ufp->selectAdd();
|
|
|
|
$ufp->selectAdd('user_id');
|
|
|
|
$ufp->profile_id = $this->profile->id;
|
|
|
|
$ufp->orderBy('created');
|
|
|
|
|
|
|
|
if ($ufp->find()) { // XXX: this should always happen
|
|
|
|
while ($ufp->fetch()) {
|
2013-08-18 12:04:58 +01:00
|
|
|
$user = User::getKV('id', $ufp->user_id);
|
2009-12-28 16:19:56 +00:00
|
|
|
if (!empty($user)) { // XXX: this would also be unusual
|
2020-07-21 12:43:46 +01:00
|
|
|
$flaggers[] = clone $user;
|
2009-12-28 16:19:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-12-28 16:45:21 +00:00
|
|
|
$cnt = count($flaggers);
|
2009-12-28 16:19:56 +00:00
|
|
|
$others = 0;
|
|
|
|
|
|
|
|
if ($cnt > self::MAX_FLAGGERS) {
|
|
|
|
$flaggers = array_slice($flaggers, 0, self::MAX_FLAGGERS);
|
2009-12-28 16:45:21 +00:00
|
|
|
$others = $cnt - self::MAX_FLAGGERS;
|
2009-12-28 16:19:56 +00:00
|
|
|
}
|
|
|
|
|
2020-07-21 12:43:46 +01:00
|
|
|
$lnks = [];
|
2009-12-28 16:19:56 +00:00
|
|
|
|
|
|
|
foreach ($flaggers as $flagger) {
|
|
|
|
$url = common_local_url('showstream',
|
2020-07-21 12:43:46 +01:00
|
|
|
['nickname' => $flagger->nickname]);
|
2009-12-28 16:19:56 +00:00
|
|
|
|
2020-07-21 12:43:46 +01:00
|
|
|
$lnks[] = XMLStringer::estring('a', ['href' => $url,
|
|
|
|
'class' => 'flagger', ],
|
2009-12-28 16:19:56 +00:00
|
|
|
$flagger->nickname);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($cnt > 0) {
|
|
|
|
if ($others > 0) {
|
2010-10-02 21:25:32 +01:00
|
|
|
$flagging_users = implode(', ', $lnks);
|
|
|
|
// TRANS: Message displayed on a profile if it has been flagged.
|
|
|
|
// TRANS: %1$s is a comma separated list of at most 5 user nicknames that flagged.
|
2011-06-17 15:19:18 +01:00
|
|
|
// TRANS: %2$d is a positive integer of additional flagging users. Also used for plural.
|
2010-10-02 21:25:32 +01:00
|
|
|
$text .= sprintf(_m('Flagged by %1$s and %2$d other', 'Flagged by %1$s and %2$d others', $others), $flagging_users, $others);
|
|
|
|
} else {
|
|
|
|
// TRANS: Message displayed on a profile if it has been flagged.
|
|
|
|
// TRANS: %s is a comma separated list of at most 5 user nicknames that flagged.
|
|
|
|
$text .= sprintf(_m('Flagged by %s'), $flagging_users);
|
2009-12-28 16:19:56 +00:00
|
|
|
}
|
|
|
|
|
2020-07-21 12:43:46 +01:00
|
|
|
$this->out->elementStart('p', ['class' => 'flaggers']);
|
2009-12-28 16:19:56 +00:00
|
|
|
$this->out->raw($text);
|
|
|
|
$this->out->elementEnd('p');
|
|
|
|
}
|
2009-11-16 16:43:15 +00:00
|
|
|
}
|
|
|
|
}
|